多人互动白板会话功能
通过阅读本章节,您将快速了解多人互动白板的相关功能,并且能通过本章节中介绍的流程和接口快速搭建多人互动白板会话。多人互动白板,顾名思义,参与互动白板的有多方,SDK提供多人互动白板从创建白板会话、加入会话、会话互动到解散会话整个过程的能力,包括创建多人白板会话、发送白板数据、结束白板等基础能力接口与异常流程控制与回调。 多人互动白板不配套提供语音通道,如果需要,可以与多人音视频通话功能结合使用,方便灵活满足各类音视频与白板相结合的多人场景。
预订多人实时会话
API介绍
在多人会话前需要通过此接口创建多人房间,之后以第一个加入的成员开始计算房间时间,直到最后一人退出。多人只有tcp模式。
API原型
C++
static void CreateConf(const std::string& name, const std::string& custom_info, const CreateConfCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
static void CreateConference(string name, string custom_info, NimRtsCreateCbFunc cb)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_create_conf(const char *name, const char *custom_info, const char *json_extension, nim_rts_create_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
name | string | 多人房间名 |
custom_info | string | 自定义数据,所有加入房间时会从回调中得到此字段 |
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
name | string | 多人房间名 |
custom_info | string | 自定义数据,所有加入房间时会从回调中得到此字段 |
cb | function | 回调函数 |
- C
参数 | 类型 | 说明 |
---|---|---|
name | string | 多人房间名 |
custom_info | string | 自定义数据,所有加入房间时会从回调中得到此字段 |
json_extension | string | 无效扩展字段 |
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
返回值说明
无返回值。
回调返回中417代表房间已经存在。其他非200是房间生成错误。
示例
C++
static void OnCreateConfCb(nim::NIMResCode res_code) { if (res_code == nim::kNIMResSuccess) { //创建成功 } else if (res_code == nim::kNIMResExist) { //已存在 } } void foo() { nim::Rts::CreateConf("room name", "custom info", &OnCreateConfCb); }
C#
private void createConfBtn_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textBox1.Text)) NIM.RtsAPI.CreateConference(textBox1.Text, textBox2.Text, OnConfCreated); } private void OnConfCreated(int code, string json_extension, IntPtr user_data) { string info = string.Format("创建多人白板:\r\nres:{0}", code); _outputTools.ShowInfo(info); }
C
static void OnCreateConfCb(int code, const char *json_extension, const void *user_data) { if (res_code == nim::kNIMResSuccess) { //创建成功 } else if (res_code == nim::kNIMResExist) { //已存在 } } typedef bool(*nim_rts_create_conf)(int channel_type, const char *uid, const char *json_extension, nim_rts_start_cb_func cb, const void *user_data); void foo() { nim_rts_create_conf func = (nim_rts_create_conf) GetProcAddress(hInst, "nim_rts_create_conf"); func("room name", "custom info", "", &OnCreateConfCb, NULL); }
加入多人会话
API介绍
加入多人会话。允许加入多个会话,但如果同一个房间名重复加入(session_id不同)则会导致
API原型
C++
static void JoinConf(const std::string& name, const std::string& session_id, bool record, const JoinConfCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
static void JoinConference(string name, string json_extension, NimRtsJoinCbFunc cb)
Namespace:NIM
Class:RtsAPI
C
void nim_rts_join_conf(const char *name, const char *json_extension, nim_rts_join_cb_func cb, const void *user_data)
File:nim_rts.h
参数说明
- C++
参数 | 类型 | 说明 |
---|---|---|
name | string | 多人房间名 |
session_id | string | 本地的一个通话标记 |
record | bool | 是否服务器录制 |
cb | function | 回调函数 |
- C#
参数 | 类型 | 说明 |
---|---|---|
name | string | 多人房间名 |
json_extension | string | Json 扩展参数kNIMRtsDataRecord,kNIMRtsSessionId |
cb | function | 回调函数 |
- C
参数 | 类型 | 说明 |
---|---|---|
name | string | 多人房间名 |
json_extension | string | Json 扩展参数kNIMRtsDataRecord,kNIMRtsSessionId |
cb | function | 回调函数 |
user_data | void* | 注册回调时的APP自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理 |
- 会话扩展参数
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsSessionId | session_id | string | 发起会话的标识id,用于在关闭时做对应标识。 |
kNIMRtsDataRecord | data_record | int | 是否需要服务器录制白板数据 >0表示是 |
返回值说明
无返回值。
示例
C++
static void OnJoinConfCb(nim::NIMResCode res_code, const std::string& session_id, int64_t channel_id, const std::string& custom_info) { if (res_code == nim::kNIMResSuccess) { //加入成功 } } void foo() { nim::Rts::JoinConf("room name", session_id.c_str(), true, &OnJoinConfCb); }
C#
private void joinConfBtn_Click(object sender, EventArgs e) { NIM.RtsAPI.JoinConference(textBox1.Text, null, OnJoinConf); } private void OnJoinConf(int code, string session_id, string json_extension, IntPtr user_data) { string info; if (code == 200) { info = string.Format("加入成功:\r\nsession id:{0}\r\ncustom info:{1}", session_id, json_extension); Action action = () => { sessionIdTxt.Text = session_id; }; _actionWrapper.InvokeAction(action); } else { info = string.Format("加入失败:{0} \r\n{1}", code, json_extension); } _outputTools.ShowInfo(info); }
C
static void OnJoinConfCb(int code, const char *session_id, const char *json_extension, const void *user_data) { int64_t channel_id = 0; std::string custom_info; Json::Value values; Json::Reader reader; std::string json(json_extension); if (reader.parse(json, values) && values.isObject()) { channel_id = values[kNIMRtsChannelId].asInt64(); custom_info = values[kNIMRtsCustomInfo].asString(); } } typedef bool(*nim_rts_join_conf)(int channel_type, const char *uid, const char *json_extension, nim_rts_start_cb_func cb, const void *user_data); void foo() { nim_rts_join_conf func = (nim_rts_join_conf) GetProcAddress(hInst, "nim_rts_join_conf");
std::string json;
Json::Value values_temp;
values_temp[nim::kNIMRtsDataRecord] = record ? 1 : 0;
values_temp[nim::kNIMRtsSessionId] = session_id;
Json::FastWriter fs;
json = fs.write(values_temp);
func("room name", json.c_str(), &OnJoinConfCb, NULL);
}
发送多人会话数据
API介绍
发送数据,暂时支持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() { //带uid是指定发送,不带是群发 nim::Rts::SendData(session_id_, nim::kNIMRtsChannelTypeTcp, cur_buffer_, uid); }
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; //带uid是指定发送,不带是群发 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) { //收到uid的数据 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)
{
//收到uid的数据
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) { //收到uid的数据 //解析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介绍
有成员进出时会通知上层,多人模式下只有tcp类型。
API原型
C++
static void SetMemberChangeCb(const MemberNotifyCallback& cb)
File:nim_cpp_rts.h
Namespace:NIM
Class:Rts
C#
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_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)
键常量名 | 键常量值 | 值类型 | 说明 |
---|---|---|---|
kNIMRtsLeaveType | leave_type | int | 客户端类型NIMRtsMemberLeftType |
- NIMRtsMemberLeftType成员退出类型
枚举定义 | 值 | 说明 |
---|---|---|
kNIMRtsMemberLeftTimeout | -1 | 成员超时掉线 |
kNIMRtsMemberLeftNormal | 0 | 成员离开 |
示例
C++
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; default: break; } } void foo() { nim::Rts::SetMemberChangeCb(&MemberNotifyCallback); }
C#
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; default: break; } } void RegisterRtsCallback() { RtsAPI.SetMemberChangedNotifyCallback(OnMemberNotifyCb); }
C
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; default: break; } } 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_member_change_cb_func func = (nim_rts_set_member_change_cb_func) GetProcAddress(hInst, "nim_rts_set_member_change_cb_func"); func(&MemberNotifyCallback, 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 Relogin(const std::string& session_id, int channel_type, OptCallback cb)
File: nim_cpp_rts.h
Namespace: nim
Class: Rts
C#
static void ReLogin(string session_id, int channel_type, string json_extension, NimRtsOptCbFunc cb)
Namespace: NIM
Class: RtsAPI
C
NIM_SDK_DLL_API void nim_rts_relogin(const char *session_id, int channel_type, const char *json_extension, nim_vchat_opt_cb_func cb, const void *user_data)
File: nim_rts.h
参数说明
参数 | 类型 | 说明 |
---|---|---|
session_id | string | 会话id |
channel_type | int | 通道类型,暂时只支持白板类型 |
json_extension | string | 无效扩展 |
cb | function | 回调函数 |
user_data(C) | void* | APP的自定义用户数据,SDK只负责传回给回调函数cb,不做任何处理! |
返回值说明
调用结果返回见回调函数,连接结果监听connect回调
示例
C++
void OnOptCallback(nim::NIMResCode res_code, const std::string& session_id, int channel_type, const std::string& json) { ... } void foo(const std::string& session_id) { nim::Rts::Relogin(session_id, kNIMRtsChannelTypeTcp, &OnOptCallback); }
C#
NimRtsOptCbFunc _relogin_cb = null; _relogin_cb = new NimRtsOptCbFunc((ret, code, json_extension,user_data) => { if (ret) { ... } }); RtsAPI.Relogin(session_id,kNIMRtsChannelTypeTcp,"",_relogin_cb);
C
void OnOptCallback(int code, const char *session_id, int channel_type, const char *json_extension, const void *user_data) { if (user_data) { ... } } typedef void(*nim_rts_relogin)(const char *session_id, int channel_type, const char *json_extension, nim_rts_opt_cb_func cb, const void *user_data); void foo(const char *session_id) { nim_rts_relogin func = (nim_rts_relogin) GetProcAddress(hInst, "nim_rts_relogin"); func(session_id, kNIMRtsChannelTypeTcp, "", &OnOptCallback, nullptr); }