EventEmitter
Kind: global class
Extends: EventEmitter
EventEmitter
Promise.<Object>
Promise.<void>
Promise.<MediaConnection>
Client class of SkyWay IoT Room Utility
Param | Type | Description |
---|---|---|
roomName | string |
The name of the room. |
options | Object |
option argument of skyway constructor. For more detail, please check https://webrtc.ecl.ntt.com/en/js-reference/Peer.html. |
options.key | string |
SkyWay API key. This is only one mandatory parameter in options. |
Example
const client = new SiRuClient( 'testroom', { key: 'YOUR_API_KEY' } );
client.on('connect', () => { ... });
publish message to all connecting peer. when subscribing by myself, fire ‘message’ event internally as well.
Kind: instance method of SiRuClient
Param | Type |
---|---|
topic | string |
data | string | object |
Example
client.publish('testtopic/message', {payload: 'hello'});
subscribe to topic
Kind: instance method of SiRuClient
Param | Type |
---|---|
topic | string |
Example
client.subscribe('testtopic/+');
client.on('message', ( topic, name ) => {
console.log(topic, name); // #=> 'testtopic/message hello'
});
unsubscribe topic
Kind: instance method of SiRuClient
Param | Type |
---|---|
topic | string |
Example
client.unsubscribe('testtopic/+');
Promise.<Object>
request streaming to SSG
Kind: instance method of SiRuClient
Returns: Promise.<Object>
- returns stream object
Param | Type |
---|---|
uuid | string |
Example
client.requestStreaming(uuid)
.then( stream => { ... } )
Promise.<void>
request stop streaming to SSG
Kind: instance method of SiRuClient
Param | Type |
---|---|
uuid | string |
Example
client.stopStreaming(uuid)
.then( () => { ... } )
Promise.<MediaConnection>
This method will send mediaStream to device. This method is useful for playing voice at remote speaker, recording audio and remote audio recognition etc. About options, see more detail at https://webrtc.ecl.ntt.com/skyway-js-sdk-doc/en/peer/#call-options-object
Kind: instance method of SiRuClient
Returns: Promise.<MediaConnection>
- - see https://webrtc.ecl.ntt.com/skyway-js-sdk-doc/en/mediaconnection/
Param | Type | Default | Description |
---|---|---|---|
uuid | string |
uuid of target device | |
stream | Object |
media stream object | |
[options] | Object |
||
[options.audioCodec] | string |
"'opus'" |
audio codec |
[options.videoCodec] | string |
"'H264'" |
video codec |
Example
const client = new SiRuClient( 'testroom', { key: 'YOUR_API_KEY' } );
client.on('meta', profile => {
navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then( stream =>
client.sendStream( profile.uuid, stream )
)
.then( call => console.log('start sending local stream') )
.catch( err => console.warn(err) );
});
When connect to room completed, it will fire
Kind: event emitted by SiRuClient
When other device connected
Kind: event emitted by SiRuClient
Properties
Name | Type | Description |
---|---|---|
uuid | string |
uuid of the device |
profile | object |
profile object of the device |
Example
client.on('device:connected', (uuid, profile) => {
console.log(uuid)
// #=> 'sample-uuid'
console.log(profile)
// #=> { description: "...",
// handle_id: "...",
// name: "some device",
// ssg_peerid: "SSG_id",
// streaming: true,
// topics: [ ... ],
// uuid: 'sample-uuid'
// }
})
When other device connected, it will fire ‘meta’ event as well.
Kind: event emitted by SiRuClient
Properties
Name | Type |
---|---|
profile | object |
When connection closed to other device, it will fire
Kind: event emitted by SiRuClient
When publish message received, this event will be fired.
Kind: event emitted by SiRuClient
Properties
Name | Type |
---|---|
topic | string |
data | data |
Example
client.on('message', (topic, data) => {
console.log(topic, data)
// #=> "metric/cpu 42.2"
})
When media stream received from peer
Kind: event emitted by SiRuClient
Properties
Name | Type | Description |
---|---|---|
stream | object |
stream object |
uuid | string |
uuid of peer |
Example
client.on('stream', stream => {
video.srcObject = stream
})
When error happens while requesting media stream
Kind: event emitted by SiRuClient
Properties
Name | Type | Description |
---|---|---|
error | object |
Error object |
uuid | string |
uuid of peer |
When media stream closed
Kind: event emitted by SiRuClient
When state changed until connecting room completed, it will fire
Kind: event emitted by SiRuClient
Properties
Name | Type | Description |
---|---|---|
state | string |
state |