+
80
-

ScaleDrone是什么?为什么webrtc要用

ScaleDrone是什么?为什么webrtc要用

网友回复

+
0
-

webrtc两个客户通讯首先需要信令服务,scaledrone提供一个信令服务,可以登录官网注册获取一个通道id

要将Scaledrone客户端库包含在您的网站中,请将Scaledrone JavaScript库脚本标记添加到<head>HTML文件的部分。 <script src='https://cdn.scaledrone.com/scaledrone.min.js' type='text/javascript'></script> 要连接到频道,您需要首先在Scaledrone网站的管理面板中创建它。Scaledrone的一个实例建立了一个连接。 const drone = new Scaledrone('CHANNEL_ID_FROM_DASHBOARD'); open 事件

连接已打开。该error参数指示连接有问题。 drone.on('open', error => { // Connection has been opened if no error });

error 事件 连接发生错误。 drone.on('error', error => { // An error has occurred with the connection });

close 事件 与Scaledrone的连接已关闭。在此事件之后,Scaledrone将不会尝试自动重新连接。 drone.on('close', event => { // Connection has been closed });

disconnect 事件 用户已断开连接,并且Scaledrone尝试重新连接。 drone.on('disconnect', () => { // User has disconnected, Scaledrone will try to reconnect soon });

reconnect 事件 断开连接后,用户已成功重新连接。 drone.on('reconnect', () => { // User has been reconnected });

听消息 所有消息在房间内移动。要收听消息,您需要预订特定的房间。 用户可以连接到多个房间(这不会创建额外的连接)。 // Subscribe after the 'open' or 'authenticate' event from the Scaledrone instance const room = drone.subscribe('room_name'); room.on('open', error => { if (error) { return console.error(error); } // Connected to room }); room.on('message', message => { // Received message from room });

message 事件 收到发送到会议室的消息。message消息可以是以下类型

传送讯息

订阅会议室的所有用户都将收到该消息(如果已订阅,则还会是发布用户)。发布房间时,您不必订阅房间。 消息可以是可以字符串化为JSON然后进行解析的任何内容(例如,数字,字符串或对象)。 drone.publish({ room: 'room_name', message: {hello: 'world'} });

断开连接 关闭与Scaledrone的连接。 drone.close();

取消订阅房间 停止收听会议室中的消息。 room.unsubscribe();

我知道答案,我要回答