Skip to content

Latest commit

 

History

History
281 lines (218 loc) · 7.88 KB

SiRuClient.md

File metadata and controls

281 lines (218 loc) · 7.88 KB

SiRuClient ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

new SiRuClient(roomName, options)

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', () => { ... });

siRuClient.publish(topic, data)

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'});

siRuClient.subscribe(topic)

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'
});

siRuClient.unsubscribe(topic)

unsubscribe topic

Kind: instance method of SiRuClient

Param Type
topic string

Example

client.unsubscribe('testtopic/+');

siRuClient.requestStreaming(uuid) ⇒ 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 => { ... } )

siRuClient.stopStreaming(uuid) ⇒ Promise.<void>

request stop streaming to SSG

Kind: instance method of SiRuClient

Param Type
uuid string

Example

client.stopStreaming(uuid)
  .then( () => { ... } )

siRuClient.sendStream(uuid, stream, [options]) ⇒ 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) );
});

"connect"

When connect to room completed, it will fire

Kind: event emitted by SiRuClient

"device:connected"

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'
  //     }
})

"meta"

When other device connected, it will fire 'meta' event as well.

Kind: event emitted by SiRuClient
Properties

Name Type
profile object

"device:closed"

When connection closed to other device, it will fire

Kind: event emitted by SiRuClient

"message"

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"
})

"stream"

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
})

"stream:error"

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

"stream:closed"

When media stream closed

Kind: event emitted by SiRuClient

"state:change"

When state changed until connecting room completed, it will fire

Kind: event emitted by SiRuClient
Properties

Name Type Description
state string state