private void CreateMultiVChatRoomCallback(int code, long channel_id, string json_extension) { if (code == 200) { NIM.NIMJoinRoomJsonEx joinRoomJsonEx = new NIMJoinRoomJsonEx(); CustomLayout layout_json = new CustomLayout(); layout_json.Hostarea = new HostArea(); layout_json.Background = new BackGround(); joinRoomJsonEx.Layout = layout_json.Serialize(); //创建房间成功,将内容抛至UI线程 Action action = () => { if (VChatAPI.JoinRoom(NIMVideoChatMode.kNIMVideoChatModeVideo, room_name, joinRoomJsonEx, _joinroomcb)) { //调用成功 } else { string info = String.Format("加入房间-{0}-失败", room_name); MessageBox.Show(info); } }; this.Invoke(action); } else { Action action = () => { MessageBox.Show("创建房间失败-错误码:" + code.ToString()); }; this.BeginInvoke(action); } }
private void CallFriend(string peerId) { NIMVChatInfo info = new NIMVChatInfo(); info.Uids = new System.Collections.Generic.List <string>(); info.Uids.Add(peerId); VChatAPI.Start(NIMVideoChatMode.kNIMVideoChatModeVideo, "C# demo呼叫", info);//邀请test_id进行语音通话 }
public void VideoTest() { NIMVChatInfo info = new NIMVChatInfo(); info.Uids = new System.Collections.Generic.List <string>(); info.Uids.Add(_peerId); VChatAPI.Start(NIMVideoChatMode.kNIMVideoChatModeVideo, "C# demo呼叫", info);//邀请test_id进行语音通话 }
/// <summary> /// 邀请会话 /// </summary> /// <param name="targetId">目标accid</param> /// <param name="mode"></param> public static void Start(string targetId, NIMVideoChatMode mode) { var info = new NIMVChatInfo { Uids = new List <string> { targetId } }; VChatAPI.Start(mode, info); }
private void btn_createmultiroom_Click(object sender, EventArgs e) { string custom_info = "你们好"; //string json_extension = ""; room_name = Guid.NewGuid().ToString("N"); // VChatAPI.CreateRoom(room_name, custom_info, null, _createroomcb); }
private void btn_createmultiroom_Click(object sender, EventArgs e) { NIMDemo.Helper.VChatHelper.CurrentVChatType = NIMDemo.Helper.VChatType.kMulti; string custom_info = "custom_info"; //string json_extension = ""; room_name = Guid.NewGuid().ToString("N"); // VChatAPI.CreateRoom(room_name, custom_info, null, _createroomcb); }
/// <summary> /// 设置通话回调函数 /// </summary> public static void InitVChatInfo() { _vchatHandlers.onSessionStartRes = OnSessionStartRes; _vchatHandlers.onSessionInviteNotify = OnSessionInviteNotify; _vchatHandlers.onSessionCalleeAckRes = OnSessionCalleeAckRes; _vchatHandlers.onSessionCalleeAckNotify = OnSessionCalleeAckNotify; _vchatHandlers.onSessionControlRes = OnSessionControlRes; _vchatHandlers.onSessionControlNotify = OnSessionControlNotify; _vchatHandlers.onSessionConnectNotify = OnSessionConnectNotify; _vchatHandlers.onSessionPeopleStatus = OnSessionPeopleStatus; _vchatHandlers.onSessionNetStatus = OnSessionNetStatus; _vchatHandlers.onSessionHangupRes = OnSessionHangupRes; _vchatHandlers.onSessionHangupNotify = OnSessionHangupNotify; //本人其他端响应通知 _vchatHandlers.onSessionSyncAckNotify = (channel_id, code, uid, mode, accept, time, client) => { Application.Current.Dispatcher.BeginInvoke((Action)(() => { if (string.IsNullOrEmpty(uid)) { uid = targetUid; } MainWindowVm.HandlerSessionSyncAckNotify(channel_id, code, uid, mode, accept, time, client); })); }; //注册音视频会话交互回调 VChatAPI.SetSessionStatusCb(_vchatHandlers); //注册音频接收数据回调 DeviceAPI.SetAudioReceiveDataCb(AudioDataRecHandler, null); //注册视频接收数据回调 //DeviceAPI.SetVideoReceiveDataCb(VideoDataRecHandler, null); //注册视频采集数据回调 //DeviceAPI.SetVideoCaptureDataCb(VideoDataCaptureHandler, null); //DeviceAPI.AddDeviceStatusCb(NIM.NIMDeviceType.kNIMDeviceTypeVideo, DeviceStatusHandler); SetAudioCaptureVolumn(255); SetAudioPlayVolumn(120); }
/// <summary> /// 退出程序清理 /// </summary> public static void ExitClearApi() { //退出前需要结束音视频设备,防止错误的数据上报\ if (_devicesIsStart) { EndDevices(); } if (!IsInit) { return; } System.Threading.Thread.Sleep(500); //在释放前需要按步骤清理音视频模块和nim client模块 VChatAPI.Cleanup(); System.Threading.Semaphore s = new System.Threading.Semaphore(0, 1); Logout(NIMLogoutType.kNIMLogoutAppExit, (r) => { s.Release(); }); //需要logout执行完才能退出程序 s.WaitOne(TimeSpan.FromSeconds(10)); ClientAPI.Cleanup(); }
private void JoinMultiVChatRoomCallback(int code, Int64 channel_id, string json_extension) { if (code == 200) { //进入房间成功 Action action = () => { MultiVChatForm vchat = new MultiVChatForm(_room_name); vchat.Show(); this.Close(); }; this.BeginInvoke(action); } else { Action action = () => { MessageBox.Show("加入房间失败-错误码:" + code.ToString()); VChatAPI.End(); }; this.BeginInvoke(action); } }
private void button1_Click(object sender, EventArgs e) { // string json_extension = "{\"session_id\":\"\"}"; _room_name = tb_roomid.Text; NIM.NIMJoinRoomJsonEx joinRoomJsonEx = new NIMJoinRoomJsonEx(); CustomLayout layout = new CustomLayout(); layout.Hostarea = new HostArea(); layout.Background = new BackGround(); joinRoomJsonEx.Layout = layout.Serialize(); if (VChatAPI.JoinRoom(NIMVideoChatMode.kNIMVideoChatModeVideo, _room_name, joinRoomJsonEx, _joinroomcb)) { //调用成功 } else { Action action = () => { MessageBox.Show("JoinRoom 调用失败:"); }; this.BeginInvoke(action); } }
/// <summary> /// 挂断 /// </summary> public static void End() { VChatAPI.End(); }
private void lv_members_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (lv_members.SelectedItems.Count > 0) { select_id_ = lv_members.SelectedItems[0].Text; if (select_id_.Equals(NIMDemo.Helper.UserHelper.SelfId)) { return; } bool isBlacklist = _audioblacklist.Contains(select_id_); if (cm_item1 == null) { cm_item1 = new MenuItem(); cm.MenuItems.Add(cm_item1); _audiosetblacklistop = new NIMVChatOptHandler( (ret, code, json_extension) => { if (ret) { bool blackmember = _audioblacklist.Contains(select_id_); if (!blackmember) { Action action = () => { rtb_multichat_info.Text += select_id_ + "加入音频黑名单成功\n"; _audioblacklist.Add(select_id_); }; this.BeginInvoke(action); } else { Action action = () => { rtb_multichat_info.Text += select_id_ + "取消音频黑名单成功\n"; _audioblacklist.Remove(select_id_); }; this.BeginInvoke(action); } } else { } } ); cm_item1.Click += (o, ex) => { isBlacklist = _audioblacklist.Contains(select_id_); VChatAPI.SetMemberInBlackList(select_id_, !isBlacklist, true, "", _audiosetblacklistop); }; } cm_item1.Text = isBlacklist ? "取消音频黑名单" : "加入音频黑名单"; bool muted = _vedioblacklist.Contains(select_id_); if (cm_item2 == null) { cm_item2 = new MenuItem(); cm.MenuItems.Add(cm_item2); _vediosetblacklistop = new NIMVChatOptHandler( (ret, code, json_extension) => { if (ret) { bool blackmember = _vedioblacklist.Contains(select_id_); if (!blackmember) { Action action = () => { rtb_multichat_info.Text += select_id_ + "加入视频黑名单成功\n"; _vedioblacklist.Add(select_id_); }; this.BeginInvoke(action); } else { Action action = () => { rtb_multichat_info.Text += select_id_ + "取消视频黑名单成功\n"; _vedioblacklist.Remove(select_id_); }; this.BeginInvoke(action); } } else { Action action = () => { MessageBox.Show("操作失败"); //_vedioblacklist.Remove(id); }; this.BeginInvoke(action); } } ); cm_item2.Click += (o, ex) => { muted = _vedioblacklist.Contains(select_id_); VChatAPI.SetMemberInBlackList(select_id_, !muted, false, "", _vediosetblacklistop); }; } cm_item2.Text = muted ? "取消视频黑名单" : "加入视频黑名单"; cm.Show(lv_members, e.Location); } } }