双人互动白板会话功能
通过阅读本章节,您将快速了解双人互动白板的相关功能,并且能通过本章节中介绍的流程和接口快速搭建一个双人互动白板会话。双人互动白板也称点对点互动白板,参与互动白板的共有两方,按照发起会话与接收会话区分为主叫与被叫角色。SDK提供点对点互动白板从发起会话、建立会话、会话互动到解散会话整个过程的能力,包括呼叫/接收、发送白板数据、结束白板等基础能力接口与异常流程控制与回调。 考虑到白板使用场景与音频使用场景强关联,双人互动白板中包含语音通道(可选)更方便快捷满足简单白板的场景,需要注意的是语音通道全局只能有一个,并且与音视频通话和互动直播功能互斥。
流程中涉及到的API介绍如下:
主叫发起实时会话请求
API介绍
创建rts会话,允许用户发起多个会话,并可以指定是否带有音频通道。音频通道的会话必须初始化音视频能力,并只允许存在一个。在需要音频通话时,需要打开麦克风和播放器。
API原型
C++
static void StartChannel(int channel_type, const std::string& uid, RtsStartInfo info, const StartChannelCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
static void Start(NIMRtsChannelType channelType, string uid, RtsStartInfo info, StartResHandler startResHandler)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_start(int channel_type, const char *uid, const char *json_extension, nim_rts_start_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
channel_type | int | 会话类型,见NIMRtsChannelType,其中如果是单纯的tcp通道填1,如果需要附加音频能力,填5(kNIMRtsChannelTypeTcp+kNIMRtsChannelTypeVchat) |
uid | string | 被邀请者的id |
info | struct | 点对点白板扩展参数 |
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
channelType | int | 会话类型,见NIMRtsChannelType,其中如果是单纯的tcp通道填1,如果需要附加音频能力,填5(kNIMRtsChannelTypeTcp+kNIMRtsChannelTypeVchat) |
uid | string | 被邀请者的id |
info | object | 点对点白板扩展参数 |
startResHandler | function | 回调函数 |
- C
参数 | 类型 | 说明 |
---|---|---|
channel_type | int | 会话类型,见NIMRtsChannelType,其中如果是单纯的tcp通道填1,如果需要附加音频能力,填5(kNIMRtsChannelTypeTcp+kNIMRtsChannelTypeVchat) |
uid | string | 被邀请者的id |
json_extension | string | 点对点白板扩展参数 |
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
- NIMRtsChannelType
枚举定义 | 值 | 说明 |
---|---|---|
kNIMRtsChannelTypeNone | 0 | 无通道 |
kNIMRtsChannelTypeTcp | 1 | tcp通道 |
kNIMRtsChannelTypeUdp | 2 | udp通道 暂不支持 |
kNIMRtsChannelTypeVchat | 4 | 音视频通道 |
- 会话扩展参数(C)
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsSessionId | session_id | string | 发起会话的标识id,用于在关闭时做对应标识。Ack有效 |
kNIMRtsVChatCustomAudio | custom_audio | int | 是否用自主的音频数据 >0表示是 Ack有效 |
kNIMRtsDataRecord | data_record | int | 是否需要服务器录制白板数据 >0表示是 Ack有效 |
kNIMRtsAudioRecord | audio_record | int | 是否需要服务器录制音频数据 >0表示是 Ack有效 |
kNIMRtsApnsText | apns | string | 推送用的文本 |
kNIMRtsCreateCustomInfo | custom_info | string | 自定义数据,透传给被邀请方 |
kNIMRtsPushEnable | push_enable | int | 是否需要推送 >0表示是 默认是 |
kNIMRtsNeedBadge | need_badge | int | 是否需要角标计数 >0表示是 默认是 |
kNIMRtsNeedFromNick | need_nick | int | 是否需要推送昵称 >0表示是 默认是 |
kNIMRtsApnsPayload | payload | string | JSON格式,推送payload |
kNIMRtsSound | sound | string | 推送声音 |
kNIMRtsKeepCalling | keepcalling | int | 是否强制持续呼叫(对方离线也会呼叫),1表示是,0表示否。默认是 |
返回值说明
无返回值。
- 回调扩展(C)
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsChannelId | channel_id | int64 | 通话的通道id |
示例
C++
static void OnStartCb(nim::NIMResCode res_code, const std::string& session_id, int channel_type, const std::string& uid) { if (res_code == nim::kNIMResSuccess) { //发起成功 } } void foo() { int type = 1;//如果需要带音频,填5 nim::RtsStartInfo info; info.apns_ = ""; info.custom_info_ = "rts custom info"; info.data_record_ = data_record; info.audio_record_ = audio_record; info.webrtc_ = webrtc; info.session_id_ = session_id_; nim::Rts::StartChannel(type, uid, info, &OnStartCb); }
C#
public void RtsTest()
{
NIM.NIMRts.RtsStartInfo info = new NIM.NIMRts.RtsStartInfo();
info.ApnsText = "123";
info.CustomInfo = "456";
RtsAPI.Start((NIM.NIMRts.NIMRtsChannelType.kNIMRtsChannelTypeTcp | NIM.NIMRts.NIMRtsChannelType.kNIMRtsChannelTypeVchat), _peerId, info,
(code, sessionId, channelType, uid) =>
{
this.InvokeOnMainThread(() =>
{
if (code == 200)
{
MessageBox.Show("邀请已发送,等待对方加入");
}
else
{
MessageBox.Show("邀请失败:" + ((NIM.ResponseCode)code).ToString());
}
});
});
}
C
static void StartChannelCallback(int code, const char *session_id, int channel_type, const char* uid, const char *json_extension, const void *user_data) { if (res_code == nim::kNIMResSuccess) { //发起成功 } } typedef bool(*nim_rts_start)(int channel_type, const char *uid, const char *json_extension, nim_rts_start_cb_func cb, const void *user_data); void foo() { Json::FastWriter fs; Json::Value value; value[nim::kNIMVChatSessionId] = "session_id"; value[nim::kNIMRtsDataRecord] = 1; std::string json_value = fs.write(value); nim_rts_start func = (nim_rts_start) GetProcAddress(hInst, "nim_rts_start"); func(1, "uid", json_value.c_str(), &StartChannelCallback, NULL); }
被叫收到实时会话请求回调
API介绍
注册全局的收到实时白板通话请求回调,建议在sdk初始化完成后注册。
API原型
C++
static void SetStartNotifyCb(const StartNotifyCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void SetStartNotifyCallback(OnStartNotify cb)
public delegate void OnStartNotify(string sessionId, int channelType, string uid, string customInfo)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_set_start_notify_cb_func(nim_rts_start_notify_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
sessionId | string | 本地的一个通话标记,用于之后操作对应 |
channelType | int | 会话类型,见NIMRtsChannelType,其中如果是单纯的tcp通道填1,如果需要附加音频能力,填5(kNIMRtsChannelTypeTcp+kNIMRtsChannelTypeVchat) |
uid | string | 被邀请者的id |
customInfo | string | 扩展信息 |
- C
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
示例
C++
static void OnStartRtsNotify(const std::string& session_id, int channel_type, const std::string& uid, const std::string& custom_info) { if (!StartRtsForm(channel_type, uid, session_id)) { nim::Rts::Ack(session_id, channel_type, false, true, true, nim::Rts::AckCallback()); } } void foo() { nim::Rts::SetStartNotifyCb(&StartNotifyCb); }
C#
void OnReceiveSessionRequest(string sessionId, int channelType, string uid, string custom) { InvokeOnForm(() => { var msg = string.Format("收到来自{0}的白板演示请求", uid); var ret = MessageBox.Show(msg, "白板演示", MessageBoxButtons.OKCancel); NIM.RtsAPI.Ack(sessionId, (NIM.NIMRts.NIMRtsChannelType) channelType, ret == DialogResult.OK, null, Response); }); } void RegisterRtsCallback() { NIM.RtsAPI.SetStartNotifyCallback(OnReceiveSessionRequest); }
C
static void StartNotifyCallback(const char *session_id, int channel_type, const char* uid, const char *json_extension, const void *user_data) { std::string custom_info;//发起者填写的自定义数据 std::string json(json_extension); Json::Value valus; Json::Reader reader; if (reader.parse(json, valus) && valus.isObject()) { custom_info = valus[nim::kNIMRtsCreateCustomInfo].asString(); } //uid邀请我进行会话 } typedef void(*nim_rts_set_start_notify_cb_func)(nim_rts_start_notify_cb_func cb, const void *user_data); void foo() { nim_rts_set_start_notify_cb_func func = (nim_rts_set_start_notify_cb_func) GetProcAddress(hInst, "nim_rts_set_start_notify_cb_func"); func(&StartNotifyCallback, NULL); }
被叫响应实时会话请求
API介绍
被邀请者回复邀请接口。如果是音频通道的会话必须初始化音视频能力,并只允许存在一个。在需要音频通话时,需要打开麦克风和播放器。
API原型
C++
static void Ack(const std::string& session_id, int channel_type, bool accept, bool data_record, bool audio_record, const AckCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
static void static void Ack(string sessionId, NIMRtsChannelType channelType, bool accept, RtsStartInfo info, AckResHandler ackResHandler)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_ack(const char *session_id, int channel_type, bool accept, const char *json_extension, nim_rts_ack_res_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
channel_type | int | 会话类型 |
accept | bool | 是否接起 |
data_record | bool | 服务器白板数据录制参数 |
audio_record | bool | 服务器音频数据录制参数 |
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
sessionId | string | 本地的一个通话标记 |
channelType | int | 会话类型 |
accept | bool | 是否接起 |
info | object | 点对点白板扩展参数 |
ackResHandler | function | 回调函数 |
- C
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
channel_type | int | 会话类型 |
accept | bool | 是否接起 |
json_extension | string | 点对点白板扩展参数 |
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
示例
C++
static void OnAckCallback(nim::NIMResCode res_code, const std::string& session_id, int channel_type, bool accept) { if (res_code == nim::kNIMResSuccess) { //接起,等待接通 } else { //接起失败,结束。 } } void foo() { bool accept = true;//是否接起 bool data_record = true;//服务器白板数据录制 bool audio_record = true;//服务器音频数据录制 nim::Rts::Ack(session_id, 1, accept, data_record, audio_record, &OnAckCallback); }
C#
//收到一个邀请 void OnReceiveSessionRequest(string sessionId, int channelType, string uid, string custom) { InvokeOnForm(() => { var msg = string.Format("收到来自{0}的白板演示请求", uid); var ret = MessageBox.Show(msg, "白板演示", MessageBoxButtons.OKCancel); NIM.NIMRts.RtsStartInfo info = new NIM.NIMRts.RtsStartInfo(); info.DataRecord = 1; info.AudioRecord = 1; NIM.RtsAPI.Ack(sessionId, (NIM.NIMRts.NIMRtsChannelType) channelType, ret == DialogResult.OK, info, Response); }); } //ack结果 void Response(int code, string sessionId, int channelType, bool accept) { if (accept && code == (int)NIM.ResponseCode.kNIMResSuccess) { InvokeOnForm(() => { var form = new RtsForm(sessionId); form.Show(); }); } else if(code != (int)NIM.ResponseCode.kNIMResSuccess) { MessageBox.Show("建立白板会话失败:" + code.ToString()); } }
C
static void AckCallback(int code, const char *session_id, int channel_type, bool accept, const char *json_extension, const void *user_data) { if (code == nim::kNIMResSuccess) { //接听成功 } } typedef void(*nim_rts_ack)(const char *session_id, int channel_type, bool accept, const char *json_extension, nim_rts_ack_res_cb_func cb, const void *user_data) void foo() { std::string json; Json::Value values_temp; values_temp[nim::kNIMRtsDataRecord] = data_record ? 1 : 0; values_temp[nim::kNIMRtsAudioRecord] = audio_record ? 1 : 0; Json::FastWriter fs; json = fs.write(values_temp); nim_rts_ack func = (nim_rts_ack) GetProcAddress(hInst, "nim_rts_ack"); func(session_id, 1, true, json.c_str(), &AckCallback, NULL); }
主叫收到被叫实时会话响应回调
API介绍
注册全局收到被邀请者的回复结果接口。
API原型
C++
static void SetAckNotifyCb(const AckNotifyCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void SetAckNotifyCallback(OnAckNotify cb)
public delegate void OnAckNotify(string sessionId, int channelType, bool accept, string uid)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_set_ack_notify_cb_func(nim_rts_ack_notify_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
sessionId | string | 本地的一个通话标记 |
channelType | int | 会话类型 |
accept | bool | 对方是否接起 |
uid | string | 对方id |
- C
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
示例
C++
static void OnAckRtsNotify(const std::string& session_id, int channel_type, bool accept, const std::string& uid) { if (accept) { //uid接起会话 } else { //uid拒绝会话 } } void foo() { nim::Rts::SetAckNotifyCb(&OnAckRtsNotify); }
C#
void OnAckNotify(string sessionId, int channelType, bool accept, string uid) { this.InvokeOnMainThread(() => { if (!c) MessageBox.Show("对方拒绝"); else { RtsForm f = new RtsForm(a); f.Show(); } }); } void RegisterRtsCallback() { RtsAPI.SetAckNotifyCallback(OnAckNotify); }
C
static void AckNotifyCallback(const char *session_id, int channel_type, bool accept, const char* uid, const char *json_extension, const void *user_data) { if (accept) { //uid接起会话 } else { //uid拒绝会话 } } typedef void(*nim_rts_set_ack_notify_cb_func)(nim_rts_ack_notify_cb_func cb, const void *user_data) void foo() { nim_rts_set_ack_notify_cb_func func = (nim_rts_set_ack_notify_cb_func) GetProcAddress(hInst, "nim_rts_set_ack_notify_cb_func"); func(&AckNotifyCallback, NULL); }
实时会话状态反馈回调
API介绍
在会话邀请接起后,双方通过连接状态和成员变化接口得知会话状态。
API原型
C++
注册连接状态接口
static void SetConnectNotifyCb(const ConnectNotifyCallback& cb)
注册成员状态接口
static void SetMemberChangeCb(const MemberNotifyCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
注册连接状态接口
public static void SetConnectionNotifyCallback(OnConnectNotify cb)
public delegate void OnConnectNotify(string sessionId, int channelType, int code)
注册成员状态接口
public static void SetMemberChangedNotifyCallback(OnMemberNotify cb)
public delegate void OnMemberNotify(string sessionId, int channelType, int type, string uid)
Namespace:NIM
Class:RtsAPI
C
注册连接状态接口
void nim_rts_set_connect_notify_cb_func(nim_rts_connect_notify_cb_func cb, const void *user_data)
注册成员状态接口
void nim_rts_set_member_change_cb_func(nim_rts_member_change_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
sessionId | string | 本地的一个通话标记 |
channelType | int | 会话类型 |
type | int | 成员进出状态 |
uid | string | 对方id |
- C
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
- NIMRtsMemberStatus成员变化类型
枚举定义 | 值 | 说明 |
---|---|---|
kNIMRtsMemberStatusJoined | 0 | 成员进入 |
kNIMRtsMemberStatusLeaved | 1 | 成员退出 |
返回值说明
无返回值。
- 回调扩展(C)
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsRecordFile | record_file | string | 录制的文件名(服务器开启录制时有效,音视频类型时为音频文件名) |
kNIMRtsVideoRecordFile | video_record_file | string | 录制的视频文件名(服务器开启录制时有效) |
kNIMRtsLeaveType | leave_type | int | 客户端类型NIMRtsMemberLeftType |
- NIMRtsMemberLeftType成员退出类型
枚举定义 | 值 | 说明 |
---|---|---|
kNIMRtsMemberLeftTimeout | -1 | 成员超时掉线 |
kNIMRtsMemberLeftNormal | 0 | 成员离开 |
示例
C++
static void ConnectNotifyCallback(const std::string& session_id, int channel_type, int code, const std::string& json) { if (channel_type == nim::kNIMRtsChannelTypeTcp) { if (code == nim::kNIMRtsConnectStatusSuccess) { //白板连接成功 } else { //白板连接失败 } } else if (channel_type == nim::kNIMRtsChannelTypeVchat) { if (code == nim::kNIMRtsConnectStatusSuccess) { //语音连接成功 } else { //语音连接失败 } } } static void MemberNotifyCallback(const std::string& session_id, int channel_type, const std::string& uid, int code, int leave_type) { switch (channel_type) { case nim::kNIMRtsChannelTypeTcp: if (code == nim::kNIMRtsMemberStatusJoined) { //uid加入白板 } else { //uid离开白板 } break; case nim::kNIMRtsChannelTypeVchat: if (code == nim::kNIMRtsMemberStatusJoined) { //uid连接音频 } break; default: break; } } void foo() { nim::Rts::SetConnectNotifyCb(&ConnectNotifyCallback); nim::Rts::SetMemberChangeCb(&MemberNotifyCallback); }
C#
void OnConnectNotify(string sessionId, int channelType, int code) { if (channel_type == NIM.NIMRts.NIMRtsChannelType.kNIMRtsChannelTypeTcp) { if (code == 200) { //白板连接成功 } else { //白板连接失败 } } else if (channel_type == NIM.NIMRts.NIMRtsChannelType.kNIMRtsChannelTypeVchat) { if (code == 200) { //语音连接成功 } else { //语音连接失败 } } } void OnMemberNotifyCb(string sessionId, int channelType, int type, string uid) { switch (channelType) { case NIM.NIMRts.NIMRtsChannelType.kNIMRtsChannelTypeTcp: if (code == NIM.NIMRts.NIMRtsMemberStatus.kNIMRtsMemberStatusJoined) { //uid加入白板 } else { //uid离开白板 } break; case NIM.NIMRts.NIMRtsChannelType.kNIMRtsChannelTypeVchat: if (code == NIM.NIMRts.NIMRtsMemberStatus.kNIMRtsMemberStatusJoined) { //uid连接音频 } break; default: break; } } void RegisterRtsCallback() { RtsAPI.SetConnectionNotifyCallback(OnConnectNotifyCb); RtsAPI.SetMemberChangedNotifyCallback(OnMemberNotifyCb); }
C
void ConnectNotifyCallback(const char *session_id, int channel_type, int code, const char *json_extension, const void *user_data) { if (channel_type == nim::kNIMRtsChannelTypeTcp) { if (code == nim::kNIMRtsConnectStatusSuccess) { //白板连接成功 } else { //白板连接失败 } } else if (channel_type == nim::kNIMRtsChannelTypeVchat) { if (code == nim::kNIMRtsConnectStatusSuccess) { //语音连接成功 } else { //语音连接失败 } } } void MemberNotifyCallback(const char *session_id, int channel_type, int type, const char* uid, const char *json_extension, const void *user_data) { int32_t leave_type = kNIMRtsMemberLeftNormal; Json::Value values; Json::Reader reader; std::string json = PCharToString(json_extension); if (reader.parse(json, values) && values.isObject()) { leave_type = values[kNIMRtsLeaveType].asInt(); } switch (channel_type) { case nim::kNIMRtsChannelTypeTcp: if (code == nim::kNIMRtsMemberStatusJoined) { //uid加入白板 } else { if (leave_type == kNIMRtsMemberLeftNormal) { //uid离开白板 } else { //与uid断开 } } break; case nim::kNIMRtsChannelTypeVchat: if (code == nim::kNIMRtsMemberStatusJoined) { //uid连接音频 } else { if (leave_type == kNIMRtsMemberLeftNormal) { //uid离开音频 } else { //与uid断开 } } break; default: break; } } typedef void (*nim_rts_set_connect_notify_cb_func)(nim_rts_connect_notify_cb_func cb, const void *user_data); typedef void (*nim_rts_set_member_change_cb_func)(nim_rts_member_change_cb_func cb, const void *user_data); void foo() { nim_rts_set_connect_notify_cb_func func1 = (nim_rts_set_connect_notify_cb_func) GetProcAddress(hInst, "nim_rts_set_connect_notify_cb_func"); nim_rts_set_member_change_cb_func func2 = (nim_rts_set_member_change_cb_func) GetProcAddress(hInst, "nim_rts_set_member_change_cb_func"); func1(&ConnectNotifyCallback, NULL); func2(&MemberNotifyCallback, NULL); }
发送实时会话数据
发送数据,暂时支持tcp通道,建议发送频率在20Hz以下,现在只支持50k的长度。
API原型
C++
static void SendData(const std::string& session_id, int channel_type, const std::string& data, const std::string& uid="")
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void SendData(string sessionId, NIMRtsChannelType channelType, IntPtr data, int size)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_send_data(const char *session_id, int channel_type, const char *data, unsigned int size, const char *json_extension)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
channel_type | int | 会话类型,暂时只支持kNIMRtsChannelTypeTcp |
data | string | tcp数据流 |
uid | string | 指定发送某人,不填则群发 |
- C#
参数 | 类型 | 说明 |
---|---|---|
sessionId | string | 本地的一个通话标记 |
channelType | int | 会话类型 |
data | IntPtr | 数据指针 |
size | int | 数据长度 |
- C
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
channel_type | int | 会话类型 |
accept | bool | 是否接起 |
data | char* | 数据指针 |
size | int | 数据长度 |
json_extension | string | 扩展参数kNIMRtsUid |
- 扩展参数
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsUid | uid | string | 用户账号uid |
返回值说明
无返回值。
示例
C++
void foo() { nim::Rts::SendData(session_id_, nim::kNIMRtsChannelTypeTcp, cur_buffer_); }
C#
private void sendDataBtn_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(sessionIdTxt.Text)) { var content = contentTxt.Text; var bytes = System.Text.Encoding.Default.GetBytes(content); var len = System.Text.Encoding.Default.GetByteCount(content); var ptr = Marshal.AllocCoTaskMem(len); int i = 0; while (i < len) { Marshal.WriteByte(ptr, i, bytes[i]); i++; } NIM.RtsAPI.SendData(sessionIdTxt.Text, NIM.NIMRts.NIMRtsChannelType.kNIMRtsChannelTypeTcp, ptr, len); } }
C
typedef void (*nim_rts_send_data)(const char *session_id, int channel_type, const char* data, unsigned int size, const char *json_extension); void foo() { std::string json; if (!uid.empty()) { Json::Value values_temp; values_temp[nim::kNIMRtsUid] = uid; Json::FastWriter fs; json = fs.write(values_temp); } nim_rts_send_data func = (nim_rts_send_data) GetProcAddress(hInst, "nim_rts_send_data"); func(session_id, 1, data.c_str(), data.size(), json.c_str()); }
特殊说明
白板数据当遇到网络异常时不能保证对方肯定收到,对需要高保障的数据,建议用户自己用数据流做回执保证。
收到实时会话数据回调
API介绍
收到其他人发给我的白板数据。
API原型
C++
static void SetRecDataCb(const RecDataCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void SetReceiveDataCallback(OnRecData callback)
public delegate void OnRecData(string sessionId, int channelType, string uid, IntPtr data, int size)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_set_rec_data_cb_func(nim_rts_rec_data_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
callback | function | 回调函数 |
sessionId | string | 本地的一个通话标记 |
channelType | int | 会话类型 |
uid | string | 对方id |
data | IntPtr | 数据指针 |
size | int | 数据长度 |
- C
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
示例
C++
static void RecDataCallback(const std::string& session_id, int channel_type, const std::string& uid, const std::string& data) { if (channel_type == nim::kNIMRtsChannelTypeTcp) { //OnParseTcpData(data); } } void foo() { nim::Rts::SetRecDataCb(RecDataCallback); }
C#
void OnReceiveRtsData(string sessionId, int channelType, string uid, IntPtr data, int size)
{
var content = Marshal.PtrToStringAnsi(data, size);
//解析content,处理逻辑
}
void RegisterRtsCallback()
{
NIM.RtsAPI.SetReceiveDataCallback(OnReceiveRtsData);
}
C
static void RecDataCallback(const char *session_id, int channel_type, const char* uid, const char* data, unsigned int size, const char *json_extension, const void *user_data) { //解析data,处理逻辑 } typedef void (*nim_rts_set_rec_data_cb_func)(nim_rts_rec_data_cb_func cb, const void *user_data); void foo() { nim_rts_set_rec_data_cb_func func = (nim_rts_set_rec_data_cb_func) GetProcAddress(hInst, "nim_rts_set_rec_data_cb_func"); func(&RecDataCallback, NULL); }
发送实时会话控制指令
API介绍
发送用户控制指令,允许在通话发起后发送一些自定义的通知。
API原型
C++
static void Control(const std::string& session_id, const std::string& info, const ControlCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void Control(string sessionId, string info, ControlResHandler controlResHandler)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_control(const char *session_id, const char *info, const char *json_extension, nim_rts_control_res_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
info | string | 自定义数据 |
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
sessionId | string | 本地的一个通话标记 |
info | string | 自定义数据 |
controlResHandler | function | 回调函数 |
- C
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
info | char* | 自定义字符串数据 |
json_extension | string | 扩展参数kNIMRtsUid |
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
- 扩展参数
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsUid | uid | string | 用户账号uid |
返回值说明
无返回值。
示例
C++
void foo() { nim::Rts::Control(session_id_, nbase::UTF16ToUTF8(L"开启音频"), nim::Rts::ControlCallback()); }
C#
private void AudioCtrlBtn_Click(object sender, EventArgs e) { var tag = audioCtrlBtn.Tag.ToString(); string open = "开启音频"; string close = "关闭音频"; var i = tag == "0" ? open : close; NIM.RtsAPI.Control(_sessionId, i, (int code, string sessionId, string info) => { if (code == 200) { Func<string, int> func = (ret) => { if (info == open) { audioCtrlBtn.Text = "关闭麦克风"; audioCtrlBtn.Tag = 1; } if (info == close) { audioCtrlBtn.Text = "开启麦克风"; audioCtrlBtn.Tag = 0; } return 0; }; this.audioCtrlBtn.BeginInvoke(func, info); } }); }
C
void ControlCallback(int code, const char *session_id, const char *info, const char *json_extension, const void *user_data) { if (code == 200) { //发送成功 } } typedef void (*nim_rts_control)(const char *session_id, const char* info, const char* json_extension, nim_rts_control_res_cb_func cb, const void *user_data); void foo() { nim_rts_control func = (nim_rts_control) GetProcAddress(hInst, "nim_rts_control"); func(session_id.c_str(), info.c_str(), "", &ControlCallback, cb_pointer); }
收到实时会话控制指令
API介绍
注册接收白板的控制指令的回调函数。
API原型
C++
static void SetControlNotifyCb(const ControlNotifyCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void SetControlNotifyCallback(OnControlNotify cb)
public delegate void OnControlNotify(string sessionId, string info, string uid)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_set_control_notify_cb_func(nim_rts_control_notify_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
sessionId | string | 本地的一个通话标记 |
info | string | 自定义的控制 |
uid | string | 对方id |
- C
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
示例
C++
static void ControlNotifyCallback(const std::string& session_id, const std::string& info, const std::string& uid) { //uid,通知info } void foo() { nim::Rts::SetControlNotifyCb(ControlNotifyCallback); }
C#
void OnControlNotify(string sessionId, string info, string uid) { if (sessionId != _sessionId) return; SetPromptTip(uid + " " + info); } void RegisterRtsCallback() { NIM.RtsAPI.SetControlNotifyCallback(OnControlNotify); }
C
static void ControlNotifyCallback(const char *session_id, const char *info, const char* uid, const char *json_extension, const void *user_data) { //uid,通知info } typedef void (*nim_rts_set_control_notify_cb_func)(nim_rts_control_notify_cb_func cb, const void *user_data); void foo() { nim_rts_set_control_notify_cb_func func = (nim_rts_set_control_notify_cb_func) GetProcAddress(hInst, "nim_rts_set_control_notify_cb_func"); func(&ControlNotifyCallback, NULL); }
结束实时会话
API介绍
结束会话,清理会话。如果是主动结束,会通知对方。
API原型
C++
static void Hangup(const std::string& session_id, const HangupCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void Hangup(string sessionId, HangupResHandler hangupResHandler)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_hangup(const char *session_id, const char *json_extension, nim_rts_hangup_res_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
hangupResHandler | function | 回调函数 |
- C
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 本地的一个通话标记 |
json_extension | string | 无效扩展 |
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
示例
C++
void foo() { nim::Rts::Hangup(session_id, nim::Rts::HangupCallback()); }
C#
private void RtsForm_FormClosed(object sender, EventArgs e) { NIM.RtsAPI.Hangup(_sessionId, (a, b) => { }); }
C
void HangupCallback(int code, const char *session_id, const char *json_extension, const void *user_data) { if (code == 200) { } } typedef void (*nim_rts_hangup)(const char *session_id, const char *json_extension, nim_rts_hangup_res_cb_func cb, const void *user_data); void foo() { nim_rts_hangup func = (nim_rts_hangup) GetProcAddress(hInst, "nim_rts_hangup"); func(session_id.c_str(), "", &HangupCallback, NULL); }
对方结束实时会话回调
API介绍
注册收到对方结束会话的通知回调接口。
API原型
C++
static void SetHangupNotifyCb(const HangupNotifyCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void SetHungupNotify(OnHangupNotify cb)
public delegate void OnHangupNotify(string sessionId, string uid)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_set_hangup_notify_cb_func(nim_rts_hangup_notify_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
sessionId | string | 本地的一个通话标记 |
uid | string | 对方id |
- C
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
示例
C++
static void HungupNotifyCallback(const std::string& session_id, const std::string& uid) { //uid,结束了通话 } void foo() { nim::Rts::SetHangupNotifyCb(&HungupNotifyCallback); }
C#
void OnControlNotify(string sessionId, string uid) { //uid,结束了通话 } void RegisterRtsCallback() { NIM.RtsAPI.SetHungupNotify(OnHangupNotify); }
C
static void HangupNotifyCallback(const char *session_id, const char* uid, const char *json_extension, const void *user_data) { //uid,结束了通话 } typedef void (*nim_rts_set_hangup_notify_cb_func)(nim_rts_hangup_notify_cb_func cb, const void *user_data); void foo() { nim_rts_set_hangup_notify_cb_func func = (nim_rts_set_hangup_notify_cb_func) GetProcAddress(hInst, "nim_rts_set_hangup_notify_cb_func"); func(&HangupNotifyCallback, NULL); }
呼入的实时会话请求已经被该帐号其他端处理回调
API介绍
多端同步接口,注册该账号在其他端处理了的回调通知接口。
API原型
C++
static void SetSyncAckNotifyCb(const SyncAckNotifyCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
public static void SetSyncAckNotifyCallback(OnSyncAckNotify cb)
public delegate void OnSyncAckNotify(string sessionId, int channelType, bool accept, int client)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_set_sync_ack_notify_cb_func(nim_rts_sync_ack_notify_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
sessionId | string | 本地的一个通话标记 |
channelType | int | 会话类型 |
accept | bool | 是否接起 |
client | int | 客户端类型,见NIMClientType |
- C
参数 | 类型 | 说明 |
---|---|---|
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
- NIMClientType客户端类型
枚举定义 | 值 | 说明 |
---|---|---|
kNIMClientTypeDefault | 0 | Default, unset |
kNIMClientTypeAndroid | 1 | Android |
kNIMClientTypeiOS | 2 | iOS |
kNIMClientTypePCWindows | 4 | PC Windows |
kNIMClientTypeWeb | 16 | Web |
kNIMClientTypeRestAPI | 32 | RestAPI |
kNIMClientTypeMacOS | 64 | Mac |
返回值说明
无返回值。
- 回调扩展(C)
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsClientType | client_type | int | 客户端类型NIMClientType |
示例
C++
static void SyncAckNotifyCallback(const std::string& session_id, int channel_type, bool accept) { if (accept) { //在其他端接起会话 } else { //在其他端拒绝会话 } } void foo() { nim::Rts::SetSyncAckNotifyCb(&SyncAckNotifyCallback); }
C#
void OnSyncAckNotify(string sessionId, int channelType, bool accept, int client) { if (accept) { //在其他端接起会话 } else { //在其他端拒绝会话 } } void RegisterRtsCallback() { NIM.RtsAPI.SetSyncAckNotifyCallback(OnSyncAckNotify); }
C
static void SyncAckNotifyCallback(const char *session_id, int channel_type, bool accept, const char *json_extension, const void *user_data) { if (accept) { //在其他端接起会话 } else { //在其他端拒绝会话 } } typedef void (*nim_rts_set_sync_ack_notify_cb_func)(nim_rts_sync_ack_notify_cb_func cb, const void *user_data); void foo() { nim_rts_set_sync_ack_notify_cb_func func = (nim_rts_set_sync_ack_notify_cb_func) GetProcAddress(hInst, "nim_rts_set_sync_ack_notify_cb_func"); func(&SyncAckNotifyCallback, NULL); }
设置静音
API介绍
设置自己的音频静音,全局有效,重新发起会话时也生效。此开关打开音频只发静音包。
获取音频静音状态。
API原型
C++
static void SetAudioMuted(bool muted)
static bool GetAudioMuteEnabled()
File: nim_cpp_vchat.h
Namespace: nim
Class: VChat
C#
static void SetAudioMute(bool muted)
static bool GetAudioMuteEnabled()
Namespace: NIM
Class: VChatAPI
C
NIM_SDK_DLL_API void nim_vchat_set_audio_mute(bool muted)
NIM_SDK_DLL_API bool nim_vchat_audio_mute_enabled()
File: nim_vchat.h
参数说明
参数 | 类型 | 所在函数 | 说明 |
---|---|---|---|
muted | bool | SetAudioMuted(C/C#) nim_vchat_set_audio_mute(C) |
true静音,false不静音。 |
返回值说明
设置静音接口无返回值。
获取静音状态接口返回静音状态。
示例
C++
void foo() { nim::VChat::SetAudioMuted(true); bool mute = nim::VChat::GetAudioMuteEnabled(); }
C#
void foo() { NIM.VChatAPI.SetAudioMute(true); bool mute = NIM.VChatAPI.GetAudioMuteEnabled(); }
C
typedef void(*nim_vchat_set_audio_mute)(bool muted); typedef bool(*nim_vchat_audio_mute_enabled)(); void foo() { nim_vchat_set_audio_mute func1 = (nim_vchat_set_audio_mute) GetProcAddress(hInst, "nim_vchat_set_audio_mute"); nim_vchat_audio_mute_enabled func2 = (nim_vchat_audio_mute_enabled) GetProcAddress(hInst, "nim_vchat_audio_mute_enabled"); func1(true); bool mute = func2(); }
开启音频设备
API介绍
启动设备。同一NIMDeviceType下设备将不重复启动,不同的设备会先关闭前一个设备开启新设备。如果需要打开非默认设备,则需要遍历设备,选择需要的设备path。
API原型
C++
static void StartDevice(nim::NIMDeviceType type, const std::string& device_path, unsigned fps, int width, int height, nim_vchat_start_device_cb_func cb)
File: nim_cpp_vchat.h
Namespace: nim
Class: VChat
C#
static void StartDevice(NIMDeviceType type, string devicePath, uint fps, NIMStartDeviceJsonEX StartDeviceInfo,StartDeviceResultHandler handler)
Namespace: NIM
Class: DeviceAPI
C
NIM_SDK_DLL_API void nim_vchat_start_device(enum NIMDeviceType type, const char *device_path, unsigned fps, const char *json_extension, nim_vchat_start_device_cb_func cb, const void *user_data)
File: nim_device.h
参数说明
参数 | 类型 | 说明 |
---|---|---|
type | enum | 设备类型,见NIMDeviceType |
device_path | string | 设备路径对应kNIMDevicePath,如果是kNIMDeviceTypeAudioHook,对应播放器本地全路径。 |
fps | unsigned int | 摄像头的采样频率,非摄像头类型设备无效(麦克风采样频率由底层控制,播放器采样频率也由底层控制)。 |
width(C++) | int | 摄像头采集宽度期望值,取0则底层选默认值,非摄像头类型设备无效。 |
height(C++) | int | 摄像头采集高度期望值,取0则底层选默认值,非摄像头类型设备无效。 |
StartDeviceInfo(C#) | object | 启动设备json封装类。 |
cb(C/C++)/handler(C#) | function | 结果回调 |
user_data(C) | void* | APP的自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理! |
- NIMDeviceType
枚举定义 | 值 | 说明 |
---|---|---|
kNIMDeviceTypeAudioIn | 0 | 麦克风设备 |
kNIMDeviceTypeAudioOut | 1 | 听筒设备用于播放本地采集音频数据,麦克风试音 |
kNIMDeviceTypeAudioOutChat | 2 | 听筒设备用于通话音频数据,由kNIMDeviceTypeAudioOut遍历得到设备 |
kNIMDeviceTypeVideo | 3 | 摄像头 |
kNIMDeviceTypeSoundcardCapturer | 4 | 声卡声音采集,由kNIMDeviceTypeAudioOut遍历得到设备,得到的数据混音到发送的通话声音中(此模式使用条件苛刻不建议使用) |
kNIMDeviceTypeAudioHook | 5 | 伴音,使用本地播放器的启动路径(exe启动文件的全路径),启动第三方播放器并获取音频数据(只允许存在一个进程钩子),只混音到发送的通话声音中 |
返回值说明
无返回值。
示例
C++
void StartDeviceCb(nim::NIMDeviceType type, bool ret, const char *json, const void*) { } void foo() { nim::VChat::StartDevice(nim::kNIMDeviceTypeAudioIn, "", 0, 0, 0, &StartDeviceCb); nim::VChat::StartDevice(nim::kNIMDeviceTypeAudioOutChat, "", 0, 0, 0, &StartDeviceCb); }
C#
void foo() { NIM.DeviceAPI.StartDeviceResultHandler handle = (type, ret) => { Action action = () => { if(ret) { } else { MessageBox.Show("启动设备失败"); } }; this.Invoke(action); }; NIM.DeviceAPI.StartDevice(NIM.NIMDeviceType.kNIMDeviceTypeAudioIn, "", 0, handle); NIM.DeviceAPI.StartDevice(NIM.NIMDeviceType.kNIMDeviceTypeAudioOutChat, "", 0, handle); }
C
void StartDeviceCb(nim::NIMDeviceType type, bool ret, const char *json, const void*) { } typedef void(*nim_vchat_start_device)(nim::NIMDeviceType type, const char* device_path, unsigned fps, const char* json_extension, nim_vchat_start_device_cb_func cb, const void *user_data); void foo() { nim_vchat_start_device func = (nim_vchat_start_device) GetProcAddress(hInst, "nim_vchat_start_device"); fun(nim::kNIMDeviceTypeAudioIn, "", 0, "", &StartDeviceCb, nullptr); fun(nim::kNIMDeviceTypeAudioOutChat, "", 0, "", &StartDeviceCb, nullptr); }
结束音频设备
API介绍
结束设备
API原型
C++
static void EndDevice(nim::NIMDeviceType type)
File: nim_cpp_vchat.h
Namespace: nim
Class: VChat
C#
static void EndDevice(NIMDeviceType type)
Namespace: NIM
Class: DeviceAPI
C
NIM_SDK_DLL_API void nim_vchat_end_device(enum NIMDeviceType type, const char *json_extension)
File: nim_device.h
参数说明
参数 | 类型 | 说明 |
---|---|---|
type | enum | 设备类型NIMDeviceType |
json_extension(C) | string | 无效的扩展字段。 |
返回值说明
无返回值。
示例
C++
void foo() { nim::VChat::EndDevice(nim::kNIMDeviceTypeAudioIn); nim::VChat::EndDevice(nim::kNIMDeviceTypeAudioOutChat); }
C#
void foo() { NIM.DeviceAPI.EndDevice(NIM.NIMDeviceType.kNIMDeviceTypeAudioIn); NIM.DeviceAPI.EndDevice(NIM.NIMDeviceType.kNIMDeviceTypeAudioOutChat); }
C
typedef void(*nim_vchat_end_device)(nim::NIMDeviceType type, const char *json_extension); void foo() { nim_vchat_end_device func = (nim_vchat_end_device) GetProcAddress(hInst, "nim_vchat_end_device"); fun(nim::kNIMDeviceTypeAudioIn, ""); fun(nim::kNIMDeviceTypeAudioOutChat, ""); }