yodaRT.activity. Activity

The Activity is the APIs for apps developer.

module.exports = activity => {
  activity.on('create', () => {
    console.log('app is created')
  })
  activity.on('destroy', () => {
    console.log('app is destroyed')
  })
  activity.on('request', nlp => {
    // handle nlp
  })
}

Extends

Classes

ActivityTestClient
HttpgwClient
KeyboardClient
LightClient
MediaClient
TtsClient
TurenClient
WormholeClient

Members

light :yodaRT.activity.Activity.LightClient

The LightClient is used to control LED APIs.

media :yodaRT.activity.Activity.MediaClient

The MediaClient is used to control multimedia APIs.

tts :yodaRT.activity.Activity.TtsClient

The TtsClient is used to control TextToSpeech APIs.

keyboard :yodaRT.activity.Activity.KeyboardClient

The KeyboardClient is used to control behaviors of key code events.

wormhole :yodaRT.activity.Activity.WormholeClient

The WormholeClient is used to send or receive mqtt message to/from Rokid.

turen :yodaRT.activity.Activity.TurenClient

The TurenClient is used to communication with turen

httpgw :yodaRT.activity.Activity.HttpgwClient

The HttpgwClient is used to work with Rokid HTTPGW service.

appId :string

Get current appId.

appHome :string

Get home directory of current app.

Methods

get() → {Promise.<object>}

Get all properties, it contains the following fields:

  • deviceId the device id.
  • deviceTypeId the device type id.
  • key the cloud key.
  • secret the cloud secret.
  • masterId the userId or masterId.
Returns:
Type:
Promise<object>
Example
module.exports = function (activity) {
  activity.on('ready', () => {
    activity.get().then((props) => console.log(props))
  })
}

exit(optionsopt) → {Promise.<void>}

Exits the current application.

Parameters:
Name Type Attributes Description
options object <optional>
Name Type Attributes Description
clearContext boolean <optional>

also clears contexts

Returns:
Type:
Promise<void>

idle() → {Promise.<void>}

Put device into idle state. Terminates apps in stack (i.e. apps in active and paused).

Also clears apps' contexts.

Returns:
Type:
Promise<void>

login(optionsopt) → {Promise.<void>}

Starts the login flow.

Parameters:
Name Type Attributes Description
options object <optional>

the options to login

Name Type Attributes Description
masterId string <optional>

the masterId to bind.

Returns:
Type:
Promise<void>

setPickup(pickup, durationopt) → {Promise.<void>}

Open the mics for continuely listenning for your users without activation.

Parameters:
Name Type Attributes Default Description
pickup boolean
duration number <optional>
6000
Returns:
Type:
Promise<void>

setConfirm(intent, slot, optionsopt, attrsopt) → {Promise.<void>}

Set the app is confirmed.

Parameters:
Name Type Attributes Description
intent string
slot string
options object <optional>
attrs object <optional>
Returns:
Type:
Promise<void>

setBackground() → {Promise.<void>}

Set your application in background mode, in this mode, the application still could keep alive, and listen other events, but no ablitity to control TTS, light and multimedia.

To use this API, you must specify the permission INTERRUPT in your application manifest.

Returns:
Type:
Promise<void>

setForeground(optionsopt) → {Promise.<void>}

Push the app in foreground, the reverse slide to setBackground(), it requires the INTERRUPT permission, either.

Parameters:
Name Type Attributes Description
options 'cut' | 'scene' | object <optional>
Name Type Attributes Description
form 'cut' | 'scene' <optional>

the running form of the activity, available value are: cut or scene.

skillId string <optional>

update cloud skill stack if specified.

Returns:
Type:
Promise<void>

setContextOptions(options) → {Promise.<object>}

Set context options to current context.

Options would be merged to current options so that it's not required to provide a full set of options each time.

Parameters:
Name Type Description
options object

context options to be set.

Name Type Attributes Description
keepAlive boolean <optional>

if app is preferring entering background instead of being destroyed on preemption

Returns:
Type:
Promise<object>

getContextOptions() → {Promise.<object>}

Get current context options previously set.

Returns:
Type:
Promise<object>

setContextSkillId(skillId, formopt) → {Promise.<object>}

Set skill id of current context.

Parameters:
Name Type Attributes Description
skillId string
form 'cut' | 'scene' <optional>

derive from current app if not specified.

Returns:
Type:
Promise<object>

getContextSkillId(formopt) → {Promise.<(string|undefined)>}

Get skill id of current context.

Parameters:
Name Type Attributes Description
form 'cut' | 'scene' <optional>

derive from current app if not specified.

Returns:
Type:
Promise<(string|undefined)>

playSound(uri) → {Promise.<void>}

Play the sound effect, support the following schemas: system:// and self://.

Parameters:
Name Type Description
uri string

the sound resource uri.

Returns:
Type:
Promise<void>

voiceCommand(text) → {Promise.<void>}

Send a voice command to the main process. It requires the permission ACCESS_VOICE_COMMAND.

Parameters:
Name Type Description
text string

voice asr/text command to be parsed and executed.

Returns:
Type:
Promise<void>

startMonologue(optionsopt) → {Promise.<void>}

Start a session of monologue. In session of monologue, no other apps could preempt top of stack.

It requires the permission ACCESS_MONOPOLIZATION.

Parameters:
Name Type Attributes Description
options object <optional>
Name Type Attributes Default Description
allowCut boolean <optional>
true

allows the cut skill.

Returns:
Type:
Promise<void>

stopMonologue() → {Promise.<void>}

Stop a session of monologue started previously.

It requires the permission ACCESS_MONOPOLIZATION.

Returns:
Type:
Promise<void>

openUrl(url, optionsopt) → {Promise.<boolean>}

Use this method to open the specified resource. If the specified URL could be handled by another app, YodaOS launches that app and passes the URL to it. (Launching the app brings the other app to the foreground.) If no app is capable of handling the specified scheme, the returning promise is resolved with false.

Parameters:
Name Type Attributes Description
url string
options 'cut' | 'scene' | object <optional>
Name Type Attributes Default Description
preemptive boolean <optional>
true
Returns:
Type:
Promise<boolean>

setMicMute(muteopt) → {Promise.<boolean>}

Mute microphone if mute is true, or unmute microphone if mute is false. Switch microphone mute state if mute is not set.

Parameters:
Name Type Attributes Description
mute boolean <optional>

set mic to mute, switch mute if not given.

Returns:
Type:
Promise<boolean>

Promise of mic muted

getMicMute() → {Promise.<boolean>}

Get microphone is muted.

Returns:
Type:
Promise<boolean>

Promise of mic muted

Events

active

When the app is active.

ready

When the Activity API is ready.

create

When an activity is created.

pause

When an activity is about been paused.

resume

When an activity is resumed.

destroy

When an activity is about been destroyed.

background

When an activity is put into background.

request

Fires on nlp requests.

Parameters:
Name Type Description
data object
Name Type Description
intent string

your nlp intent.

slots object

your nlp slots.

asr string

the asr text.

action object

the cloud post-processed data.

url

Fires on url requests.

URL offer a potential attack vector into your app, so make sure to validate all URL parameters and discard any malformed URLs. In addition, limit the available actions to those that do not risk the user’s data. For example, do not allow other apps to directly delete content or access sensitive information about the user. When testing your URL-handling code, make sure your test cases include improperly formatted URLs.

Parameters:
Name Type Description
url module:url~UrlWithParsedQuery

oppressing

Fires on oppressing of other apps in monologue mode.

Only fires to apps in monologue mode.

Parameters:
Name Type Description
event 'request' | 'url'

the event of oppressed app which would had activated the app if not in monologue mode.

notification

Fires on notification requests.

Parameters:
Name Type Description
channel string