private void MembersListview_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (membersListview.SelectedItems.Count > 0) { ContextMenu menu = new ContextMenu(); MenuItem item1 = new MenuItem("临时禁言", (o, args) => { var accid = membersListview.SelectedItems[0].Name; ChatRoomApi.TempMuteMember((long)membersListview.Tag, accid, 120, (a, b, c) => { DemoTrace.WriteLine(new { Op = "临时禁言", RoomId = a, Result = b, Member = c }.Dump()); }, true, accid + " 被禁言120s"); }); MenuItem item2 = new MenuItem("解除临时禁言", (o, args) => { var accid = membersListview.SelectedItems[0].Name; ChatRoomApi.TempMuteMember((long)membersListview.Tag, accid, 0, (a, b, c) => { DemoTrace.WriteLine(new { Op = "解除临时禁言", RoomId = a, Result = b, Member = c }.Dump()); }, true, accid + " 被解除临时禁言"); }); menu.MenuItems.Add(item1); menu.MenuItems.Add(item2); menu.Show(membersListview, e.Location); } } }
private void _targetListView_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { var selectedItems = _targetListView.SelectedItems; if (selectedItems.Count == 0) { ContextMenu contextMenu = new ContextMenu(); MenuItem item1 = new MenuItem("清空未读数", (s, arg) => { NIM.Session.SessionAPI.ResetAllUnreadCount((int rescode, SessionInfo result, int totalUnreadCounts) => { DemoTrace.WriteLine(string.Format("清空会话未读数:{0}", rescode)); }); }); contextMenu.MenuItems.Add(item1); contextMenu.Show(_targetListView, e.Location); return; } var msg = selectedItems[0].Tag as NIM.NIMIMMessage; if (selectedItems.Count > 0) { ShowContextMenu(e.Location, selectedItems[0]); } } }
/// <summary> /// 执行登录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnLoginButtonClicked(object sender, EventArgs e) { //必须保证 NIM.ClientAPI.Init 调用成功 if (!InitSdk()) { return; } DemoTrace.WriteLine("sdk version:" + NIM.ClientAPI.GetVersion()); var ps = ProxySettingForm.GetProxySetting(); if (ps != null && ps.IsValid) { NIM.GlobalAPI.SetProxy(ps.Type, ps.Host, ps.Port, ps.UserName, ps.Password); } _userName = UserNameComboBox.Text; _password = textBox2.Text; //使用明文密码或者其他加密方式请修改此处代码 var password = NIM.ToolsAPI.GetMd5(_password); if (!string.IsNullOrEmpty(_userName) && !string.IsNullOrEmpty(password)) { toolStripProgressBar1.Value = 0; label3.Text = ""; if (string.IsNullOrEmpty(_appKey)) { MessageBox.Show("请设置app key"); return; } NIM.ClientAPI.Login(_appKey, _userName, password, HandleLoginResult); } }
private void viewAttachmentBtn_Click(object sender, EventArgs e) { if (_message.MessageType != NIM.NIMMessageType.kNIMMessageTypeAudio) { OpenFileDialog dialog = new OpenFileDialog(); var path = _message.LocalFilePath; dialog.InitialDirectory = System.IO.Path.GetDirectoryName(path); dialog.FileName = path; dialog.ShowDialog(); } else { var x = NIM.ToolsAPI.GetUserAppDataDir(MainForm.SelfId); if (!NIMAudio.AudioAPI.InitModule("")) { return; } NIMAudio.AudioAPI.RegStartPlayCb((m, n, s, d) => { DemoTrace.WriteLine("开始播放:", m, n, s, d); }); NIMAudio.AudioAPI.RegStopPlayCb((z, xx, c, v) => { DemoTrace.WriteLine("结束播放:", z, xx, c, v); }); var audioMsg = _message as NIM.NIMAudioMessage; var ret = NIMAudio.AudioAPI.PlayAudio(_message.LocalFilePath, "", "", NIMAudio.NIMAudioType.kNIMAudioAAC); } }
//好友列表右键菜单 private void listView1_MouseUp(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right) { return; } ContextMenu cm = new ContextMenu(); if (listView1.SelectedItems.Count > 0) { var id = listView1.SelectedItems[0].Tag.ToString(); cm.MenuItems.Add("查看详情", (s, args) => { new FriendProfileForm(id).Show(); }); cm.MenuItems.Add("删除", (s, args) => { NIM.Friend.FriendAPI.DeleteFriend(id, (a, b, c) => { if (a != 200) { MessageBox.Show("删除失败"); } }); }); bool isBlacklist = _blacklistSet.Contains(id); string m3 = isBlacklist ? "取消黑名单" : "设置黑名单"; cm.MenuItems.Add(m3, (o, ex) => { NIM.User.UserAPI.SetBlacklist(id, !isBlacklist, (a, b, c, d, e1) => { }); }); bool muted = _mutedlistSet.Contains(id); string m4 = muted ? "取消静音" : "静音"; cm.MenuItems.Add(m4, (o, ex) => { NIM.User.UserAPI.SetUserMuted(id, !muted, (a, b, c, d, e1) => { }); }); cm.MenuItems.Add("是否好友", (o, ex) => { var ret = NIM.Friend.FriendAPI.IsActiveFriend(id); DemoTrace.WriteLine("{0} is friend:{1}", id, ret); }); } else { var item = CreateAddFriendMenuItem(); cm.MenuItems.Add(item); } cm.Show(listView1, e.Location); }
private static void OnSessionConnectNotify(long channel_id, int code, string record_file, string video_record_file, long chat_time, ulong chat_rx, ulong chat_tx) { DemoTrace.WriteLine("Session Connect channel_id:" + channel_id.ToString() + " code:" + code.ToString() + " record_file:" + record_file + " video_record_file" + video_record_file + "chat_time:" + chat_time.ToString() + "chat_rx:" + chat_rx.ToString() + "chat_tx" + chat_tx.ToString()); if (code == 200) { Action a = () => { GetInstance().channel_id = channel_id; VideoChatForm vform = VideoChatForm.GetInstance(); VideoChatInfo vchatInfo = vform.VchatInfo; if (vchatInfo.state != VChatState.kVChatUnknow && vchatInfo.state != VChatState.VChatEnd && vchatInfo.state != VChatState.kVChatInviteRefuse) { vchatInfo.state = VChatState.kVChating; vform.VchatInfo = vchatInfo; } }; _ownerMainForm.BeginInvoke(a); StartDevices(); } else { NIM.VChatAPI.End(); GetInstance().channel_id = 0; } }
private void RegisterClientCallback() { NIM.ClientAPI.RegDisconnectedCb(() => { if (_notifyNetworkDisconnect) { MessageBox.Show("网络连接断开,网络恢复后后会自动重连"); } }); NIM.ClientAPI.RegKickoutCb((r) => { _beKicked = true; DemoTrace.WriteLine(r.Dump()); MessageBox.Show(r.Dump(), "被踢下线,请注意账号安全"); Action action = () => { LogoutBtn_Click(null, null); }; _actionWrapper.InvokeAction(action); }); NIM.ClientAPI.RegAutoReloginCb((r) => { if (r.Code == ResponseCode.kNIMResSuccess && r.LoginStep == NIMLoginStep.kNIMLoginStepLogin) { MessageBox.Show("重连成功"); } }); ClientCallbacks.Register(); }
/// <summary> /// 登录结果处理 /// </summary> /// <param name="result"></param> private void HandleLoginResult(NIM.NIMLoginResult result) { DemoTrace.WriteLine(result.LoginStep.ToString()); Action action = () => { toolStripProgressBar1.PerformStep(); this.label3.Text = string.Format("{0} {1}", result.LoginStep, result.Code); if (result.LoginStep == NIM.NIMLoginStep.kNIMLoginStepLogin) { toolStripProgressBar1.Value = 100; if (result.Code == NIM.ResponseCode.kNIMResSuccess) { this.Hide(); new FriendsListForm(_userName).Show(); toolStripProgressBar1.Value = 0; this.label3.Text = ""; System.Threading.ThreadPool.QueueUserWorkItem((s) => { SaveLoginAccount(); }); //PublishLoginEvent(); } else { NIM.ClientAPI.Logout(NIM.NIMLogoutType.kNIMLogoutChangeAccout, HandleLogoutResult); } } }; this.Invoke(action); }
void MultiVChatForm_Load(object sender, EventArgs e) { _multiVChatFormGraphics_pb01 = pb_multivchat_01.CreateGraphics(); _multiVChatFormGraphics_pb02 = pb_multivchat_02.CreateGraphics(); _multiVChatFormGraphics_pb03 = pb_multivchat_03.CreateGraphics(); _multiVChatFormGraphics_pb04 = pb_multivchat_04.CreateGraphics(); _vchatHandlers.onSessionConnectNotify = (channel_id, code, record_addr, record_file, chat_time, chat_rx, chat_tx) => { DemoTrace.WriteLine("Session Connect channel_id:" + channel_id.ToString() + " code:" + code.ToString() + " record_file:" + record_addr + " video_record_file" + record_file + "chat_time:" + chat_time.ToString() + "chat_rx:" + chat_rx.ToString() + "chat_tx" + chat_tx.ToString()); if (code == 200) { StartDevices(); } else { NIM.VChatAPI.End(); } }; SetVChatCallback(); }
void ShowSessionItemMenu(SessionInfo info, Point location) { ContextMenu menu = new ContextMenu(); MenuItem item1 = new MenuItem("删除", (s, e) => { NIM.Session.SessionAPI.DeleteRecentSession(info.SessionType, info.Id, (a, b, c) => { DeleteSession(info); }); }); MenuItem item2 = new MenuItem("标记为已读", (s, e) => { NIM.Session.SessionAPI.SetUnreadCountZero(info.SessionType, info.Id, (a, b, c) => { NIM.Session.SessionAPI.SetUnreadCountZero(info.SessionType, info.Id, null); Update(info, b); }); }); MenuItem item3 = new MenuItem("查看", (s, e) => { NIM.Messagelog.MessagelogAPI.QuerylogById(info.MsgId, (a, b, c) => { if (a != NIM.ResponseCode.kNIMResSuccess || c == null) { return; } Action action = () => { MsgInfoForm form = new MsgInfoForm(c); form.Show(); }; _sessionListBox.Invoke(action); }); }); string itemText = info.IsPinnedOnTop ? "取消置顶" : "置顶"; MenuItem item4 = new MenuItem(itemText, (s, e) => { NIM.Session.SessionAPI.PinSessionOnTop(info.SessionType, info.Id, !info.IsPinnedOnTop, (a, b, c) => { DemoTrace.WriteLine("会话置顶:", a, b.Id, b.IsPinnedOnTop); if (a == 200) { Update(info, b); } }); }); menu.MenuItems.Add(item1); if (info.Status == NIM.Messagelog.NIMMsgLogStatus.kNIMMsgLogStatusUnread) { menu.MenuItems.Add(item2); } menu.MenuItems.Add(item3); menu.MenuItems.Add(item4); menu.Show(_sessionListBox, location); }
private void OnUserNameCardChanged(object sender, UserNameCardChangedArgs e) { if (e != null && e.UserNameCardList != null) { DemoTrace.WriteLine("用户名片变更:" + e.UserNameCardList.Dump()); var card = e.UserNameCardList.Find(c => c.AccountId == SelfId); DisplayMyProfile(card); } }
private static void OnSessionControlNotify(long channel_id, string uid, int type) { DemoTrace.WriteLine("OnSessionControlNotify channel_id:" + channel_id.ToString() + " status:" + type.ToString() + " uid:" + uid); if (Enum.IsDefined(typeof(NIM.NIMVChatControlType), type)) { NIM.NIMVChatControlType control_type = (NIM.NIMVChatControlType)type; switch (control_type) { case NIMVChatControlType.kNIMTagControlOpenAudio: break; case NIMVChatControlType.kNIMTagControlCloseAudio: break; case NIMVChatControlType.kNIMTagControlOpenVideo: break; case NIMVChatControlType.kNIMTagControlCloseVideo: break; case NIMVChatControlType.kNIMTagControlAudioToVideo: break; case NIMVChatControlType.kNIMTagControlAgreeAudioToVideo: break; case NIMVChatControlType.kNIMTagControlRejectAudioToVideo: break; case NIMVChatControlType.kNIMTagControlVideoToAudio: break; case NIMVChatControlType.kNIMTagControlBusyLine: { NIM.VChatAPI.End(); } break; case NIMVChatControlType.kNIMTagControlCamaraNotAvailable: break; case NIMVChatControlType.kNIMTagControlEnterBackground: break; case NIMVChatControlType.kNIMTagControlReceiveStartNotifyFeedback: break; case NIMVChatControlType.kNIMTagControlMp4StartRecord: break; case NIMVChatControlType.kNIMTagControlMp4StopRecord: break; } } }
private static void OnSessionCalleeAckNotify(long channel_id, string uid, int mode, bool accept) { if (accept) { DemoTrace.WriteLine("对方接听"); } else { Action a = () => { MessageBox.Show("对方拒绝接听"); }; _ownerFriendsListForm.Invoke(a); } }
private static void OnSessionPeopleStatus(long channel_id, string uid, int status) { DemoTrace.WriteLine("SessionPeopleStatus channel_id:" + channel_id.ToString() + " status:" + status.ToString() + " uid:" + uid); if (GetInstance().PeopleStatusHandler != null) { PeopleStatusEventAgrs args = new PeopleStatusEventAgrs(); args.channel_id = channel_id; args.uid = uid; args.status = status; GetInstance().PeopleStatusHandler(GetInstance(), args); } }
void OnReceiveMessage(object sender, NIMReceiveMessageEventArgs args) { DisplayReceivedMessage(args.Message.MessageContent); DemoTrace.WriteLine(args.Dump()); if (args.Message.MessageContent.SessionType == NIM.Session.NIMSessionType.kNIMSessionTypeTeam) { var tid = args.Message.MessageContent.ReceiverID; var msgs = new List <NIMIMMessage> { args.Message.MessageContent }; NIM.Team.TeamAPI.MsgAckRead(tid, msgs, (data) => { }); } }
private static void OnSessionMp4InfoStateNotify(long channel_id,int code, NIMVChatMP4State mp4_info) { string log = ""; if (mp4_info != null) { if (mp4_info.MP4_Close != null) { log += "close:channel_id:" + channel_id.ToString() + " file_path:" + mp4_info.MP4_Close.FilePath + " duration:" + mp4_info.MP4_Close.Duration; } if (mp4_info.MP4_Start != null) { log += "start:channel_id:" + channel_id.ToString() + "file_path:" + mp4_info.MP4_Start.FilePath + " duration:" + mp4_info.MP4_Start.Duration; } } DemoTrace.WriteLine("SessionMp4Info " + log); }
private static void OnSessionCalleeAckNotify(long channel_id, string uid, int mode, bool accept) { if (accept) { DemoTrace.WriteLine("对方接听"); } else { NIMDemo.VideoChatForm vchat_form = VideoChatForm.GetInstance(); if (vchat_form.VchatInfo.state == VChatState.kVChatInvite) { VideoChatInfo vchat_info = vchat_form.VchatInfo; vchat_info.state = VChatState.kVChatInviteRefuse; vchat_form.VchatInfo = vchat_info; } } }
private static void OnSessionHangupNotify(long channel_id, int code) { DemoTrace.WriteLine("OnSessionHangupNotify channel_id:" + channel_id.ToString() + " code:" + code.ToString()); EndDevices(); if (code == 200) { Action action = () => { //MessageBox.Show("已挂断"); SendCommand("e"); MainForm.VideoChatForm vform = MainForm.VideoChatForm.GetInstance(); if (vform != null) { vform.Close(); } }; _ownerFriendsListForm.Invoke(action); } }
private void OnReceivedSysNotification(object sender, NIMSysMsgEventArgs e) { if (e.Message == null || e.Message.Content == null) { return; } DemoTrace.WriteLine("系统通知:" + e.Dump()); if (e.Message.Content.MsgType == NIMSysMsgType.kNIMSysMsgTypeTeamInvite) { NIM.Team.TeamAPI.AcceptTeamInvitation(e.Message.Content.ReceiverId, e.Message.Content.SenderId, (x) => { }); } if (e.Message.Content.MsgType == NIMSysMsgType.kNIMSysMsgTypeFriendAdd) { var vt = Newtonsoft.Json.JsonConvert.DeserializeObject <FriendRequestVerify>(e.Message.Content.Attachment); //if(vt.VT == NIM.Friend.NIMVerifyType.kNIMVerifyTypeAsk) // NIM.Friend.FriendAPI.ProcessFriendRequest(e.Message.Content.SenderId, NIM.Friend.NIMVerifyType.kNIMVerifyTypeReject, "sssssss", null); } }
void ShowContextMenu(Point location, ListViewItem listItem) { ContextMenu contextMenu = new ContextMenu(); var msg = listItem.Tag as NIM.NIMIMMessage; MenuItem item1 = new MenuItem("查看详情", (s, e) => { if (msg != null) { MsgInfoForm form = new MsgInfoForm(msg); form.StartPosition = FormStartPosition.CenterParent; form.Show(); } }); MenuItem item2 = new MenuItem("清空未读数", (s, e) => { if (msg != null) { NIM.Session.SessionAPI.SetUnreadCountZero(NIMSessionType.kNIMSessionTypeP2P, msg.SenderID, (a, b, c) => { DemoTrace.WriteLine("清空未读数:" + c.ToString()); }); } }); MenuItem item3 = new MenuItem("查询最近会话", (s, e) => { if (msg != null) { NIM.Session.SessionAPI.QueryAllRecentSession((x, y) => { DemoTrace.WriteLine("total count:" + x.ToString() + " " + y.Dump()); }); } }); contextMenu.MenuItems.Add(item1); contextMenu.MenuItems.Add(item2); contextMenu.MenuItems.Add(item3); contextMenu.Show(_targetListView, location); }
private static void OnSessionConnectNotify(long channel_id, int code, string record_file, string video_record_file, long chat_time, ulong chat_rx, ulong chat_tx) { DemoTrace.WriteLine("Session Connect channel_id:" + channel_id.ToString() + " code:" + code.ToString() + " record_file:" + record_file + " video_record_file" + video_record_file + "chat_time:" + chat_time.ToString() + "chat_rx:" + chat_rx.ToString() + "chat_tx" + chat_tx.ToString()); if (code == 200) { Action a = () => { if (NIMDemo.Helper.VChatHelper.CurrentVChatType == NIMDemo.Helper.VChatType.kP2P) { MainForm.VideoChatForm vform = MainForm.VideoChatForm.GetInstance(); vform.Show(); } }; _ownerFriendsListForm.Invoke(a); StartDevices(); } else { NIM.VChatAPI.End(); } }
private void OnNetDetection(bool ret, int code, string json_extension) { DemoTrace.WriteLine(string.Format("网络测试:{0} code = {1},result = {2}", ret, code, json_extension)); }
private void OnRecallMessageCompleted(ResponseCode result, RecallNotification[] notify) { DemoTrace.WriteLine("撤回消息:" + result.ToString() + " " + notify.Dump()); }
private static void OnSessionControlRes(long channel_id, int code, int type) { DemoTrace.WriteLine("OnSessionControlRes channel_id:" + channel_id.ToString() + " status:" + type.ToString()); }
private static void OnSessionNetStatus(long channel_id, int status, string uid) { DemoTrace.WriteLine("SessionNetStatus channel_id:" + channel_id.ToString() + " status:" + status.ToString() + " uid:" + uid); }
private void OnReceiveBroadcast(NIMBroadcastMessage msg) { DemoTrace.WriteLine(msg.Dump()); }
private void OnReceiveBroadMsgs(List <NIMBroadcastMessage> msg) { DemoTrace.WriteLine(msg.Dump()); }
/// <summary> /// 撤回消息回调 /// </summary> /// <param name="result"></param> /// <param name="notify"></param> private void OnRecallMessage(ResponseCode result, RecallNotification[] notify) { DemoTrace.WriteLine("撤回消息通知", result, notify.Dump()); }
void OnQuerySessionListCompleted(int count, SesssionInfoList session) { DemoTrace.WriteLine(session.Dump()); ImageList il = new ImageList(); ListViewItem item = new ListViewItem(); }
void OnSessionChanged(object sender, SessionChangedEventArgs args) { DemoTrace.WriteLine(args.Dump()); }