The room status change diagram is as follows.
Among them, the room status is described as follows.
Room name | Description |
---|---|
Connecting | Connecting room |
Connected | The connection is successful. Only then can real-time interaction work normally |
Disconnecting | Leaving the room |
Reconnecting | Reconnecting room |
Disconnected | Leaving the room |
Among them, the event that changes the state of the room is described as follows.
Event name | Description |
---|---|
join room | Join a room, triggered by the user's initiative call |
fail | Failed to connect to the room, the specific reason needs to be determined according to the description of the error thrown |
success | Successfully joined the room |
leave room | Leaving the room, triggered by the user's initiative call |
disconnect | The connection is disconnected due to network reasons, which will trigger the disconnection reconnection process |
connected | Successfully reconnected after disconnection, re-enter the room |
catch error | There is an error in the real-time room, this error cannot be ignored and handled, you must leave the room |
On the front end/client side, the current room status can be obtained at any time through the following code.
var phase = room.phase;
You can also add a monitor when you join the room to monitor the room status changes.
import {RoomPhase} from "white-web-sdk";
var joinRoomParams = {
uuid: uuid,
roomToken: roomToken,
};
whiteWebSdk.joinRoom(joinRoomParams, {
onPhaseChanged: function(phase) {
// Get the room status and execute the business code according to the room status
switch (phase) {
case RoomPhase.Connecting: {
break;
}
case RoomPhase.Connected: {
break;
}
case RoomPhase.Reconnecting: {
break;
}
case RoomPhase.Disconnecting: {
break;
}
case RoomPhase.Disconnected: {
break;
}
}
},
});
Except for the Connected state, all other states are not writable. These states mean that the room is neither ready to receive signaling from other people in the room, nor is it ready to send signaling. At this time, equipment operation will be automatically prohibited. Any operation to modify the room status will report an error.
Therefore, these operations are prohibited in the unwritable state.
The real-time room may have to interrupt service due to various abnormal conditions. In order to ensure the stability of your application, at the beginning of designing business logic, you should take the exception process into consideration.
You can handle the abnormal flow by adding a listener when you join the room.
var joinRoomParams = {
uuid: roomUUID,
roomToken: roomToken,
};
whiteWebSdk.joinRoom(joinRoomParams, {
onDisconnectWithError: function(err) {
// The room was disconnected from the server due to an error
},
onKickedWithReason: function(err) {
// User is kicked out of the room
},
});
If you no longer use the whiteboard, you should leave the room. Netless interactive whiteboard will not leave the room automatically. For the following reasons, we should not miss the "leave room" operation.
room.disconnect().then(function() {
// successfully left the room
}).catch(function(err) {
// Failed to leave the room, get an error err
});
For the front end, if the user directly closes the browser or closes the current web page Tab, the room will be automatically released, so there is no need to worry.