You need to enable JavaScript to run this app.
导航
客户端与业务服务器通信
最近更新时间:2024.09.10 11:10:50首次发布时间:2022.09.16 15:44:38

客户端向业务服务器发送消息

RTC 客户端可以向业务服务器发送文本或二进制消息。可用于客户端向业务服务器同步状态、上报数据等场景。

客户端接口AndroidiOSmacOSWindowsLinuxWebElectronFlutter
设置业务服务器参数setServerParamssetServerParams:url:setServerParams:url:setServerParamssetServerParams:url:setServerParamssetServerParamssetServerParams
客户端给业务服务器发送文本消息(P2Server)sendServerMessagesendServerMessage:sendServerMessage:sendServerMessagesendServerMessagesendServerMessagesendServerMessagesendServerMessage
客户端给业务服务器发送二进制消息(P2Server)sendServerBinaryMessagesendServerBinaryMessage:sendServerBinaryMessage:sendServerBinaryMessagesendServerBinaryMessagesendServerBinaryMessagesendServerBinaryMessagesendServerBinaryMessage

客户端通过上述接口成功发送消息后,业务服务器将通过来自 RTC 服务器的 HTTP/HTTPS POST 请求收到消息,示例如下:

{"message":"xxxx","binary":false,"signature":"00160af4c8dcb758d00ce35adb3EQD24BQDeruMYfoMjmEDAGh5ZiAARgps6T5ZgcTz9bw5DewuRkzxBmTgnGEk+ZBv3mW5n58="}

以上示例所含字段解释如下:

字段名含义类型合法性
message消息内容string/
binary是否二进制bool非空
signature签名包含消息发送用户用于发送实时信令的 用户 IDAppID 信息,用于鉴权string非空

业务服务器向客户端发送消息

业务服务器可以向已登录或已进房的用户发送消息。可用于业务服务器向客户端同步状态、广播公告等场景。

服务端发送房间内点对点消息

业务服务器可以通过 SendRoomUnicastBatchSendRoomUnicast 接口向房间内指定用户发送文本或二进制消息,已进房用户可以通过以下回调接收消息。

客户端回调AndroidiOSmacOSWindowsLinuxWebElectronFlutterUnity
接收到业务服务器发送的房间内点对点文本消息内容onUserMessageReceivedrtcRoom:onUserMessageReceived:message:rtcRoom:onUserMessageReceived:message:onUserMessageReceivedonUserMessageReceivedonUserMessageReceivedonUserMessageReceivedonUserMessageReceivedOnUserMessageReceivedEventHandler
接收到业务服务器发送的房间内点对点二进制消息内容onUserBinaryMessageReceivedrtcRoom:onUserBinaryMessageReceived:message:rtcRoom:onUserBinaryMessageReceived:message:onUserBinaryMessageReceivedonUserBinaryMessageReceivedonUserBinaryMessageReceivedonUserBinaryMessageReceivedonUserBinaryMessageReceived

服务端发送房间内广播消息

业务服务器可以通过 SendBroadcast 接口向客户端发送房间内文本或二进制广播消息,已进房用户可以通过以下回调接收消息。

客户端回调AndroidiOSmacOSWindowsLinuxWebElectronFlutterUnity
接收到业务服务器发送的房间内文本广播消息内容onRoomMessageReceivedrtcRoom:onRoomMessageReceived:message:rtcRoom:onRoomMessageReceived:message:onRoomMessageReceivedonRoomMessageReceivedonRoomMessageReceivedonRoomMessageReceivedonRoomMessageReceivedOnRoomMessageReceivedEventHandler
接收到业务服务器发送的房间内二进制广播消息内容onRoomBinaryMessageReceivedrtcRoom:onRoomBinaryMessageReceived:message:rtcRoom:onRoomBinaryMessageReceived:message:onRoomBinaryMessageReceivedonRoomBinaryMessageReceivedonRoomBinaryMessageReceivedonRoomBinaryMessageReceivedonRoomBinaryMessageReceived

服务端发送房间外点对点消息

业务服务器可以通过 SendUnicast 接口向房间外指定用户发送文本或二进制消息,已登录用户可以通过以下回调接收消息。

客户端回调AndroidiOSmacOSWindowsLinuxWebElectronFlutter
接收到业务服务器发送的房间内点对点文本消息内容onUserMessageReceivedOutsideRoomrtcEngine:onUserMessageReceivedOutsideRoom:message:rtcEngine:onUserMessageReceivedOutsideRoom:message:onUserMessageReceivedOutsideRoomonUserMessageReceivedOutsideRoomonUserMessageReceivedOutsideRoomonUserMessageReceivedOutsideRoomonUserMessageReceivedOutsideRoom
接收到业务服务器发送的房间内点对点二进制消息内容onUserBinaryMessageReceivedOutsideRoomrtcEngine:onUserBinaryMessageReceivedOutsideRoom:message:rtcEngine:onUserBinaryMessageReceivedOutsideRoom:message:onUserBinaryMessageReceivedOutsideRoomonUserBinaryMessageReceivedOutsideRoomonUserBinaryMessageReceivedOutsideRoomonUserBinaryMessageReceivedOutsideRoomonUserBinaryMessageReceivedOutsideRoom