CloudHub Docs
Download Documents

RTC


CloudHub JSSDK

Client Event document

What it does: This callback notifies the App that a chat message has been received.

Base

app-exception

What it does: This callback notifies the App program of an exception.

Callback parameter evt structure:

{
    errorinfo:"error info"
}

// Example:
client.on("app-exception", function (evt) {
    console.error("app-exception", evt.errorinfo);
})

signal-connect-fail

What it does: This callback notification failed to establish a connection with the server.

Callback parameter evt structure:

{
    errflag:"INVALID_ARG"
    message:"channel or tokenOrKey is invalid param",
    retryConnect: false
}

Note: The possible values ​​for Errflag are as follows:

// Example:
client.on("signal-connect-fail", function(evt) {
    console.log("signal-connect-fail", evt);
});

need-reload-page

What it does: The callback notification interface needs to be reloaded (ie: interface refresh).

Note: After testing, it was found that some machines on Win8.1 failed to open the camera after the request of the video device failed. The SDK will remember this device state, but the interface needs to be reloaded (ie: interface refresh) to restore the use of the camera.

// Example:
client.on("need-reload-page", function(evt) {
    console.log("need-reload-page", evt);
    window.location.reload();
});

client-role-changed

What it does: This callback notifies the role of the local user changes.

Live scenes, this callback is triggered when the user role switch is switched, that is, the anchor is switched to the audience, or the audience switches to an anchor.

Callback parameter evt structure:

// Example:
client.on("client-role-changed", function(evt) {
    console.log("client-role-changed", evt);
});

request-token

What it does: This callback notifies the App that a new Token needs to be generated, and then calls join Channel to rejoin the channel with the new Token.

Callback parameter evt structure:

{
    token:"token encrypted string"
}

Note:

  1. When receiving this callback, the SDK has automatically left the channel.
  2. Token is generated by a combination of authkey, secretkey, channel, userid, and expiretime, so please ensure that the authkey, secretkey, channel, and userid used by the newly generated token remain unchanged.
// Example:

client.on("request-token", function(evt) {
    console.log("request-token", evt);
});

token-privilege-will-expire

What it does: This callback informs the App Token service that the callback is about to expire.

Callback parameter evt structure:

{
    token:"token encrypted string"
}

Note:

// Example:

client.on("token-privilege-will-expire", function(evt) {
    console.log("token-privilege-will-expire", evt);
});

server-record-state-change

What it does: This callback notifies the App server that the recording status has changed.

Callback parameter evt structure:

{
    isRecording:true,
    isPause:false,
    recordState:1,
    startTs:1600152559163,
    pauseDuration:2798,
    recordDuration:9081,
    currTs:1600152962101
}

Note:

// Example:

client.on("server-record-state-change", function(evt) {
    console.log("server-record-state-change", evt);
});

stream-publish-failure

What it does: This callback notifies the App stream that the publishing failed. After this event is triggered, the stream will not be republished.

Callback parameter evt structure:

{
reason:"PUBLISH_STREAM_LIMIT",
stream:Stream
}

Note: Note:reason The following values are available

// Example:
client.on("stream-publish-failure",function(evt){
    var stream = evt.stream;
    console.log("stream-publish-failure",stream.getId());
})

stream-subscribe-failure

What it does: This callback notifies the App stream subscription failure. After this event is triggered, the stream will not be re-subscribed.

Callback parameter evt structure:

{
reason:"SUBSCRIBE_NOT_PERMISSION",
stream:Stream
}

Note: Note:Reason has the following values

// Example:

client.on("stream-subscribe-failure",function(evt){
    var stream = evt.stream;
    console.log("stream-subscribe-failure",stream.getId());
})

publish-permission

What it does: This callback informs whether the App has publishing permission.

Callback parameter evt structure:

{
    hasPermission: true
}

Note:

// Example:

client.on("publish-permission", function(evt) {
    console.log("publish-permission", evt);
})

subscribe-permission

What it does: This callback informs whether the App has subscription permission.

Callback parameter evt structure:

{
    hasPermission: true,
}

Note:

// Example:
client.on("subscribe-permission", function(evt) {
    console.log("subscribe-permission", evt);
})

channel-media-relay-state

What it does: This callback notifies the app of the status of cross-room streaming.

Callback parameter evt structure:

{
    destChannelName: 'dest01',
    connState: 'connecting',
    stateDesc: 'connecting to dest channel'
}

There are several situations in connState:

Note:

// Example:
client.on("channel-media-relay-state", function(evt) {
    console.log("channel-media-relay-state", evt);
})

channel-force-closed

What it does: This callback informs that the App channel has been forcibly closed.

Callback parameter evt structure:

{
    reasoncode: 1,
}

sound and video

stream-volume-indicator

What it does: This callback periodically returns the volume reminder of the published/subscribed stream.

Disabled by default. It can be turned on through the enableAudioVolumeIndicator (interval?:number) method; when turned on, the volume prompt will be returned every interval millisecond, regardless of whether someone is speaking in the channel.

The volume range is an integer between 0 and 100.

Only return volume prompts with video type (that is, stream.getType() = “video”)

Callback parameter evt structure:

[{
    stream:Stream
    volume:10,
}]

// Example:
client.on("stream-volume-indicator", function(evt){
    var volsobj = {};
    evt.forEach(function(item){
        volsobj[item.stream.getId()] = item.volume;
    });
    console.log("recv client event, stream-volume-indicator", volsobj);
});

stream-published

What it does: This callback notifies the App that the local audio and video stream has been released.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("stream-published", function(evt) {
    console.log("stream-published", evt.stream.getId());
})

stream-unpublished

What it does: This callback notification application The local audio and video stream has been released.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("stream-unpublished", function(evt) {
    console.log("stream-unpublished", evt.stream.getId());
})

first-audio-frame-decode

What it does: The remote audio first frame decoding callback has been completed.

The callback is triggered when the local subscription remote stream is successful and the first frame of audio decoding is completed.

Callback parameter evt structure:

{
    stream:Stream
}

Note: Edge browser does not support

// Example:
client.on('first-audio-frame-decode', function (evt) {
    console.log('first-audio-frame-decode');
    console.log(evt.stream.getId());
});

first-video-frame-decode

What it does: The callback for decoding the first frame of the remote video has been completed.

This callback is triggered when the remote stream is successful and the first frame of video decoding is completed.

Callback parameter evt structure:

{
    stream:Stream
}

Note: Edge browser does not support

// Example:
client.on('first-video-frame-decode', function (evt) {
    console.log('first-video-frame-decode');
    console.log(evt.stream.getId());
})

stream-added

What it does: This callback notifies App that the remote audio and video stream has been added.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("stream-added", function(evt) {
    var stream = evt.stream;
    console.log("new stream added", stream.getId());
})

stream-removed

What it does: This callback informs App that the remote audio and video stream has been deleted.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("stream-removed", function(evt) {
    var stream = evt.stream;
    console.log("remote stream was removed", stream.getId());

});

stream-reconnect-start

What it does: This callback informs SDK to start trying to republish / subscribe to the audio / video stream.

Callback parameter evt structure:

{
    reason:"PUB_FAILED",
    stream:Stream
}

Note: Reason has the following values

// Example:
client.on("stream-reconnect-start", function(evt) {
    console.log(evt.stream.getId(), evt.reason);
})

stream-reconnect-end

What it does: This callback notifies the end of republishing/subscribing audio and video streams.

Callback parameters evt structure

{
    reason:"",
    success:true,
    stream:Stream
}
// Example:
client.on('stream-reconnect-end', function(evt) {
    console.log(evt.stream.getId(), evt.success, evt.reason);
})

stream-subscribed

What it does: This callback notifies the app that the remote audio and video stream has been subscribed.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("stream-subscribed", function(evt) {
    var stream = evt.stream;
    console.log("stream-subscribed", stream.getId());
})

stream-unsubscribed

What it does: This callback notifies the app that the remote audio and video stream has been unsubscribed.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("stream-unsubscribed", function(evt) {
    var stream = evt.stream;
    console.log("stream-unsubscribed", stream.getId());
})

stream-network-quality

What it does: This callback reports the network quality of the stream.

This callback is triggered every 2 seconds and reports the current uplink and downlink network quality of the local user to the App.

Callback parameter evt structure:

[{
    stream:Stream   //stream:Stream  Stream Object
    quality:NetworkQualityStats   //quality:object  NetworkQualityStats See CloudHubRTC Data object document
}]

Note: Edge browser does not support

// Example:
client.on("stream-network-quality", function (evt) {
    var netobjs = {};
    evt.forEach(function(item){
        netobjs[item.stream.getId()] = item.quality;
    });
    console.log("recv client event, stream-network-quality", netobjs);
})

mute-audio

What it does: This callback notifies the other user of the App to turn off their voice.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("mute-audio", function(evt) {
    console.log("mute audio:" + evt.stream.getId());
});

unmute-audio

What it does: This callback notifies the other user of the App to turn on their voice.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("unmute-audio", function (evt) {
    console.log("unmute audio:" + evt.stream.getId());
});

mute-video

What it does: This callback notifies the other user of the App to turn off their video.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("mute-video", function (evt) {
    console.log("mute video" + evt.stream.getId());
})

unmute-video

What it does: This callback notifies the other user of the App to turn on their video.

Callback parameter evt structure:

{
    stream:Stream
}
// Example:
client.on("unmute-video", function (evt) {
    console.log("unmute video:" + evt.stream.getId());
})

Signaling

recv-pub-msg

What it does: This callback notifies the App that the “send signaling message” has been received.

Callback parameter evt structure:

{
    isNowMsg :true,
    fromID: "7f890bd6-d79d-9b99-3861-5dc08377ab6a",
    data: {info: "pubMsg"},
    id: "TestPubmsgId",
    name: 'TestPubmsg',
    seq: 1,
    toID: "__all",
    ts: 1587974788
}

Note: isNowMsg If it is true, it means that the signaling message is sent after the user himself joins the channel. If it is false, it means that the signaling message was sent before the user himself joined the channel.

// Example:
client.on("recv-pub-msg", function(evt){
    console.log(evt);
});

recv-del-msg

What it does: This callback notifies the App that the “delete signaling message” has been received.

Callback parameter evt structure:

{
    fromID: "7f890bd6-d79d-9b99-3861-5dc08377ab6a",
    id: "TestPubmsgId",
    name: "TestPubmsg",
    seq: 1,
    toID: "__all",
    ts: 1587974788
}
// Example:
client.on("recv-del-msg", function(evt){
    console.log(evt);
});

signal-connected

What it does: The callback notifies that a connection has been successfully established with the server.

Callback parameter evt structure:

{
    currServerTs: 1587974203,
}
// Example:
client.on("signal-connected", function(evt) {
    console.log("signal-connected", evt);
});

signal-reconnect

What it does: The callback notification is reconnecting to the server.

Note: When you receive this event, you need to clear the cached data in the UI layer, such as flow lists, user lists, UI interfaces, and so on.

// Example:
client.on("signal-reconnect", function() {
    console.log("signal-reconnect");
})

signal-connection-state-change

What it does: This callback notifies App SDK that the state of the connection to the server has changed.

There are three connection states between SDK and the server:

Callback parameter evt structure:

{
    curState:"CONNECTING",
    prevState:"CONNECTED"
}

Note:

// Example:
client.on("signal-connection-state-change", function(evt) {
    console.log(evt.prevState, evt.curState);
})

Chat

recv-chat-msg

What it does: The callback informs App that a chat message was received.

Callback parameter evt structure:

{
    fromID: "7f890bd6-d79d-9b99-3861-5dc08377ab6a",
    message:"abcd",
    extraData: {
        nickname: "Superman",
        role: 2,
        sendTs: 1587974207200,
        key1: 'value1',
        key2: 'value2',
        ...sendExtraData
    }
}
// Example:
client.on("recv-chat-msg", function(evt){
    console.log(evt);
});

User

peer-join

What it does: This callback reminds that a remote user/host has joined the channel.

In the communication scenario, the callback prompts that a remote user has joined the channel, and returns the ID and custom user attributes of the new user; if there are other users in the channel before joining, the new user will also receive these Callback for an existing user to join the channel.

In the live broadcast scenario, the callback prompts that an anchor has joined the channel, and returns the anchor’s ID and custom user attributes. If there is an anchor in the channel before joining, the new user will also receive a callback for the existing anchor to join the channel.

The callback will be triggered under the following circumstances:

Callback parameter evt structure:

{
    isNowUser:true,
    id: 'uid',
    properties: {}
}

Note: isNowUser If it is true, it means that the user joined the channel after the user joined the channel. If it is false, it means that the user joined the channel before the user joined the channel.

// Example:
client.on("peer-join", function(evt) {
    console.log("peer-join", evt);
});

peer-leave

What it does: The callback notifies the application that a remote user is offline.

This callback will be triggered in the following cases:

Callback parameter evt structure:

{
    id: 'uid', //id:string User id
    reason: 'Quit', //reason: string Reasons for users to leave 
    reasoncode: 1, //reasoncode:number Leave reason code 
}

Reasons for users going offline.

Note: In live broadcast scenarios, only characters are an anchor user triggering the callback.

// Example:
client.on("peer-leave", function(evt) {
    console.log("peer-leave", evt);
});

user-properties-update

What it does: This callback notifies the App user of the update of the custom properties.

Callback parameter evt structure:

{
    fromID: "fb4be6d4-4cfa-9d54-94b6-f58433baf88d",
    id: "fb4be6d4-4cfa-9d54-94b6-f58433baf88d",
    properties: {
        publishstate: 0
    }
    toID: "__all",
    ts: 1589875212
}

Note:

// Example:
client.on("user-properties-update", function(evt) {
    console.log("user-properties-update", evt);
});

peer-evicted

What it does: This callback notifies the App user that he has been kicked out of the channel.

Callback parameter evt structure:

{
    fromID: 'uid',
    reason: 'reason'
}

Note:

// Example:
client.on("peer-evicted", function(evt) {
    console.log("peer-evicted", evt);
});

Equipment

camera-device-changed

What it does: This callback notifies the App that a camera has been added or removed.

Callback parameter evt structure:

{
    state: 'add',
    devices:[{
        kind: 'videoinput',
        label: 'label',
        deviceId: 'deviceid'
    }]
}

// Example:
client.on("camera-device-changed", function(evt) {
    console.log("camera-device-changed", evt.state, evt.devices);
});

microphone-device-changed

What it does: This callback notifies the App that a microphone has been added or removed.

Callback parameter evt structure:

{
    state: 'add',
    devices: [{kind:"audioinput",label:"label",deviceId:"deviceid"}]
}
// Example:
client.on("microphone-device-changed", function(evt) {
    console.log("microphone-device-changed", evt.state, evt.devices);
});

speaker-device-changed

What it does: This callback notifies the App that a speaker has been added or removed.

Callback parameter evt structure:

{
    state: 'add',
    devices: [{
        kind:'audiooutput',
        label:'label',
        deviceId:'deviceid'
    }]
}
// Example:
client.on("speaker-device-changed", function(evt) {
    console.log("speaker-device-changed", evt.state, evt.devices);
});