iOS

# 消息通道

透明通道消息主要为通话内消息,具体使用要求和场景举例参考下表:

通话内消息
一对一发送 支持
群发消息 支持
是否支持异步发送结果上报 不支持
是否需要登录
是否需要建立通话
使用场景举例 1、实现通话中的一些自定义信令、通知等;2、实现通话中单聊和群聊;
消息内容支持 只支持文本消息
消息内容大小最大支持(bit) 4K

# 1. 通话内消息

img

调用 JRTCGuest (opens new window) 下的 sendMessage (opens new window) 方法

/**
 * 发送消息,消息内容不能大于4K
 *
 * 指定成员会收到 {@link JRTCGuestCallback.onMessageReceived} 回调
 * @param contentType 消息内容类型
 * @param content 消息内容
 * @param toUserId 指定成员的用户ID,传 null 给通话中全部成员发送消息
 * @returns 接口调用结果
 * - true: 接口调用成功
 * - false: 接口调用异常
 */
public sendMessage(contentType: string, content: string, toUserId: string):boolean/**
 * 发送消息,消息内容不能大于4K
 *
 * 指定成员会收到 {@link JRTCGuestCallback.onMessageReceived} 回调
 * @param contentType 消息内容类型
 * @param content 消息内容
 * @param toUserId 指定成员的用户ID,传 null 给通话中全部成员发送消息
 * @returns 接口调用结果
 * - true: 接口调用成功
 * - false: 接口调用异常
 */
public sendMessage(contentType: string, content: string, toUserId: string):boolean

接收消息通过实现 JRTCGuestCallback (opens new window) 中的 onMessageReceived (opens new window) 接口上报。

/**
 * 收到消息回调
 *
 * 通话中的访客和座席可分别调用 {@link JRTCGuest.sendMessage} 接口给通话中的指定成员或全体成员发送文本消息,接收消息的成员会收到此回调,由此获取消息具体信息。
 * @param content 消息内容
 * @param contentType 消息内容类型
 * @param messageType 消息归属类型
 * - {@link MessageType#TYPE_1TO1} : 一对一消息
 * - {@link MessageType#TYPE_GROUP} : 群发消息(发送给通话中所有成员)
 * @param fromUserId 发送方的用户ID
 */
onMessageReceived(content: string, contentType: string, messageType: MessageType, fromUserId: string): void;/**
 * 收到消息回调
 *
 * 通话中的访客和座席可分别调用 {@link JRTCGuest.sendMessage} 接口给通话中的指定成员或全体成员发送文本消息,接收消息的成员会收到此回调,由此获取消息具体信息。
 * @param content 消息内容
 * @param contentType 消息内容类型
 * @param messageType 消息归属类型
 * - {@link MessageType#TYPE_1TO1} : 一对一消息
 * - {@link MessageType#TYPE_GROUP} : 群发消息(发送给通话中所有成员)
 * @param fromUserId 发送方的用户ID
 */
onMessageReceived(content: string, contentType: string, messageType: MessageType, fromUserId: string): void;

示例代码:

// 给成员 agent1 发送消息
guest.sendMessage("messageType", "content", "agent1");
// 给通话中所有成员发送消息
guest.sendMessage("messageType", "content", null);
// 收到消息
onMessageReceived(content, contentType, messageType, fromUserId) {
    // 收到消息,消息内容为 content,消息来自 fromUserId  
}// 给成员 agent1 发送消息
guest.sendMessage("messageType", "content", "agent1");
// 给通话中所有成员发送消息
guest.sendMessage("messageType", "content", null);
// 收到消息
onMessageReceived(content, contentType, messageType, fromUserId) {
    // 收到消息,消息内容为 content,消息来自 fromUserId  
}

# 2. 在线消息

img

只要登录到 Juphoon RTC 平台就可以通过 JRTCClient (opens new window)sendOnlineMessage (opens new window) 实现在线消息的收发,消息内容不能大于4K。

/**
 * 发送在线消息
 * 
 * @note 消息大小不超过4k
 * @param message 消息内容
 * @param userId 对端的用户名
 * @returns 接口调用结果
 * - 操作id: 接口调用成功,对应 {@link JRTCClientCallback.onOnlineMessageSendResult} 回调的 operatorId 参数
 * - -1: 接口调用异常,不会收到回调
 */
 public sendOnlineMessage(message: string, userId: string): number/**
 * 发送在线消息
 * 
 * @note 消息大小不超过4k
 * @param message 消息内容
 * @param userId 对端的用户名
 * @returns 接口调用结果
 * - 操作id: 接口调用成功,对应 {@link JRTCClientCallback.onOnlineMessageSendResult} 回调的 operatorId 参数
 * - -1: 接口调用异常,不会收到回调
 */
 public sendOnlineMessage(message: string, userId: string): number

在线消息发送结果通过 onOnlineMessageSendResult (opens new window) 回调通知。

/**
 * 在线消息发送结果回调
 *
 * @param result     发送结果是否成功
 *                   - true:发送成功
 *                   - false:发送失败
 * @param operatorId 操作id,对应 {@link JRTCClient.sendOnlineMessage} 的返回值
 */
 onOnlineMessageSendResult(result: boolean, operatorId: number): void;
/**
 * 在线消息发送结果回调
 *
 * @param result     发送结果是否成功
 *                   - true:发送成功
 *                   - false:发送失败
 * @param operatorId 操作id,对应 {@link JRTCClient.sendOnlineMessage} 的返回值
 */
 onOnlineMessageSendResult(result: boolean, operatorId: number): void;

在线消息接收者会收到 onOnlineMessageReceived (opens new window) 回调通知。

/**
 * 收到在线消息回调
 *
 * @param message 消息内容
 * @param userId  对方用户ID
 */
 onOnlineMessageReceived(message: string, userId: string): void;/**
 * 收到在线消息回调
 *
 * @param message 消息内容
 * @param userId  对方用户ID
 */
 onOnlineMessageReceived(message: string, userId: string): void;

示例代码:

// 给成员 agent1 发送在线消息
client.sendOnlineMessage("content", "agent1");
// 在线消息发送结果回调
onOnlineMessageSendResult(result,operatorId) {}
// 收到消息
onMessageReceived(content, fromUserId) {
// 收到消息,消息内容为 content,消息来自 fromUserId  
}// 给成员 agent1 发送在线消息
client.sendOnlineMessage("content", "agent1");
// 在线消息发送结果回调
onOnlineMessageSendResult(result,operatorId) {}
// 收到消息
onMessageReceived(content, fromUserId) {
// 收到消息,消息内容为 content,消息来自 fromUserId  
}