You need to enable JavaScript to run this app.
导航
客户端与客户端通信
最近更新时间:2024.11.27 10:25:29首次发布时间:2022.09.16 15:44:38

通过集成 RTC SDK 或 RTS SDK,你可以在客户端发送、接收文本信息或二进制消息。可用于用户之间的文本通信,例如私信、群聊等场景。

前提条件

  1. 已开通实时音视频服务
  2. 已集成 RTC SDKRTS SDK

    注意

    建议不要混用 RTC SDK 和 RTS SDK。

  3. 已通过 login 接口成功登录 RTS 服务。

参考 跑通 RTS 快速开始 Demo 实现前置步骤。

发送和接收点对点消息

已登录或已进房的用户可以给指定用户发送文本或二进制消息。可用于用户私信等场景。

RTC SDK 收发房间内点对点消息

已进房的 RTC 用户可以通过以下接口发送和接收点对点消息。

功能简述AndroidiOSmacOSWindowsLinuxWeb
加入房间joinRoomjoinRoom:userInfo:roomConfig:joinRoom:userInfo:roomConfig:joinRoomjoinRoomjoinRoom
加入房间结果回调onRoomStateChangedrtcRoom:onRoomStateChanged:withUid:state:extraInfo:rtcRoom:onRoomStateChanged:withUid:state:extraInfo:onRoomStateChangedonRoomStateChanged
给房间内指定的用户发送文本消息sendUserMessagesendUserMessage:message:config:sendUserMessage:message:config:sendUserMessagesendUserMessagesendUserMessage
接收到消息所属用户发送的文本消息内容onUserMessageReceivedrtcRoom:onUserMessageReceived:message:rtcRoom:onUserMessageReceived:message:onUserMessageReceivedonUserMessageReceivedonUserMessageReceived
给房间内指定的用户发送二进制消息sendUserBinaryMessagesendUserBinaryMessage:message:config:sendUserBinaryMessage:message:config:sendUserBinaryMessagesendUserBinaryMessagesendUserBinaryMessage
接收到消息所属用户发送的二进制消息内容onUserBinaryMessageReceivedrtcRoom:onUserBinaryMessageReceived:message:rtcRoom:onUserBinaryMessageReceived:message:onUserBinaryMessageReceivedonUserBinaryMessageReceivedonUserBinaryMessageReceived
查看发送消息结果onUserMessageSendResultrtcRoom:onUserMessageSendResult:error:rtcRoom:onUserMessageSendResult:error:onUserMessageSendResultonUserMessageSendResult

RTC SDK 收发房间外点对点消息

已登录的 RTC 用户可以收发房间外的点对点消息。

功能简述AndroidiOSmacOSWindowsLinuxWeb
登录loginlogin:uid:login:uid:loginloginlogin
收到登录结果onLoginResultrtcEngine:onLoginResult:errorCode:elapsed:rtcEngine:onLoginResult:errorCode:elapsed:onLoginResultonLoginResult
更新用于登录的 Token(可选)updateLoginTokenupdateLoginToken:updateLoginToken:updateLoginTokenupdateLoginTokenupdateLoginToken
查询对端或本端用户在线状态(可选)getPeerOnlineStatusgetPeerOnlineStatus:getPeerOnlineStatus:getPeerOnlineStatusgetPeerOnlineStatusgetPeerOnlineStatus
获取用户在线状态查询结果(可选)onGetPeerOnlineStatusrtcEngine:onGetPeerOnlineStatus:status:rtcEngine:onGetPeerOnlineStatus:status:onGetPeerOnlineStatusonGetPeerOnlineStatus
向房间外用户发送文本消息sendUserMessageOutsideRoomsendUserMessageOutsideRoom:message:config:sendUserMessageOutsideRoom:message:config:sendUserMessageOutsideRoomsendUserMessageOutsideRoomsendUserMessageOutsideRoom
收到房间外用户发送的文本消息onUserMessageReceivedOutsideRoomrtcEngine:onUserMessageReceivedOutsideRoom:message:rtcEngine:onUserMessageReceivedOutsideRoom:message:onUserMessageReceivedOutsideRoomonUserMessageReceivedOutsideRoomonUserMessageReceivedOutsideRoom
向房间外用户发送二进制消息sendUserBinaryMessageOutsideRoomsendUserBinaryMessageOutsideRoom:message:config:sendUserBinaryMessageOutsideRoom:message:config:sendUserBinaryMessageOutsideRoomsendUserBinaryMessageOutsideRoomsendUserBinaryMessageOutsideRoom
收到房间外用户发送的二进制消息onUserBinaryMessageReceivedOutsideRoomrtcEngine:onUserBinaryMessageReceivedOutsideRoom:message:rtcEngine:onUserBinaryMessageReceivedOutsideRoom:message:onUserBinaryMessageReceivedOutsideRoomonUserBinaryMessageReceivedOutsideRoomonUserBinaryMessageReceivedOutsideRoom
获得消息发送结果onUserMessageSendResultOutsideRoomrtcEngine:onUserMessageSendResultOutsideRoom:error:rtcEngine:onUserMessageSendResultOutsideRoom:error:onUserMessageSendResultOutsideRoomonUserMessageSendResultOutsideRoom
登出logoutlogoutlogoutlogoutlogoutlogout
收到登出结果onlogoutrtcEngine:onLogout:rtcEngine:onLogout:onLogoutonLogout

RTS SDK 收发点对点消息

已登录的 RTS 用户可以收发点对点消息。

我们不推荐混用 RTC SDK 和 RTS SDK。如果你的业务场景必须混用 RTC SDK 和 RTS SDK,请避免调用 login 时传入相同的 userId,这将导致登录失败。

功能简述AndroidiOSWeb
登录loginlogin:uid:login
收到登录结果onLoginResultrtsEngine:onLoginResult:errorCode:elapsed:
更新用于登录的 Token(可选)updateLoginTokenupdateLoginToken:updateLoginToken
查询对端或本端用户在线状态(可选)getPeerOnlineStatusgetPeerOnlineStatus:getPeerOnlineStatus
获取用户在线状态查询结果(可选)onGetPeerOnlineStatusrtsEngine:onGetPeerOnlineStatus:status:
向房间外用户发送文本消息sendMessagesendMessage:message:config:sendMessage
收到房间外用户发送的文本消息onMessageReceivedrtsEngine:onMessageReceived:message:onMessageReceived
向房间外用户发送二进制消息sendUserBinaryMessageOutsideRoomsendBinaryMessage:message:config:sendBinaryMessage
收到房间外用户发送的二进制消息onBinaryMessageReceivedrtsEngine:onBinaryMessageReceived:message:onBinaryMessageReceived
获得消息发送结果onMessageSendResultrtsEngine:onMessageSendResult:error:
登出logoutlogoutlogout
收到登出结果onLogoutrtsEngineOnLogout:

发送和接收广播消息

已进房的用户可以在房间内广播文本或二进制消息。可用于发送群聊公告、广播消息等场景。

RTC SDK 收发广播消息

功能简述AndroidiOSmacOSWindowsLinuxWeb
加入房间joinRoomjoinRoom:userInfo:roomConfig:joinRoom:userInfo:roomConfig:joinRoomjoinRoomjoinRoom
加入房间结果回调onRoomStateChangedrtcRoom:onRoomStateChanged:withUid:state:extraInfo:rtcRoom:onRoomStateChanged:withUid:state:extraInfo:onRoomStateChangedonRoomStateChanged
给房间内所有用户发送文本消息sendRoomMessagesendRoomMessage:sendRoomMessage:sendRoomMessagesendRoomMessagesendRoomMessage
接收到房间内文本广播消息onRoomMessageReceivedrtcRoom:onRoomMessageReceived:message:rtcRoom:onRoomMessageReceived:message:onRoomMessageReceivedonRoomMessageReceivedonRoomMessageReceived
给房间内所有用户发送二进制消息sendRoomBinaryMessagesendRoomBinaryMessage:sendRoomBinaryMessage:SendRoomBinaryMessageSendRoomBinaryMessageSendRoomBinaryMessage
接收到房间内二进制广播消息onRoomBinaryMessageReceivedrtcRoom:onRoomBinaryMessageReceived:message:rtcRoom:onRoomBinaryMessageReceived:message:onRoomBinaryMessageReceivedonRoomBinaryMessageReceivedonRoomBinaryMessageReceived
查看发送广播消息结果onRoomMessageSendResultrtcRoom:onRoomMessageSendResult:error:rtcRoom:onRoomMessageSendResult:error:onRoomMessageSendResultonRoomMessageSendResult

RTS SDK 收发广播消息

进房前,RTS 用户调用 login 登录。

我们不推荐混用 RTC SDK 和 RTS SDK。如果你的业务场景必须混用 RTC SDK 和 RTS SDK,请避免调用 RTC SDK joinRoom 和 RTS SDK 的 login 时传入相同的 userId,这将导致进房失败。

功能简述AndroidiOSWeb
加入房间joinRoomjoinRoomjoinRoom
加入房间结果回调onRoomStateChangedrtsRoom:onRoomStateChanged:withUid:state:extraInfo:
给房间内所有用户发送文本消息sendRoomMessagesendRoomMessage:sendRoomMessage
接收到房间内文本广播消息onRoomMessageReceivedrtsRoom:onRoomMessageReceived:message:onMessageReceived
给房间内指定的用户发送二进制消息sendRoomBinaryMessagesendRoomBinaryMessage:sendRoomBinaryMessage
接收到房间内二进制广播消息onRoomBinaryMessageReceivedrtsRoom:onRoomBinaryMessageReceived:message:onBinaryMessageReceived
查看发送广播消息结果onRoomMessageSendResultrtsRoom:onRoomMessageSendResult:error: