protected override void OnClosed(bool p_result) { Inst = null; // 未挂断时,请求挂断 if (!p_result) { AtMsg.HangUp(Kit.UserID, _detail.OtherID, false); } var js = @"if(element.PeerConnection) element.PeerConnection.Close();"; this.ExecuteJavascript(js); if (_timer != null) { _timer.Dispose(); _timer = null; TimeSpan span = DateTime.Now - _startTime; string msg = string.Format("通话时长 {0:mm:ss}", new DateTime(span.Ticks)); _detail.SendMsg(msg); } else { _detail.SendMsg("取消通话"); } }
public async Task ShowDlg(ChatDetail p_detail) { _detail = p_detail; _tbInfo.Text = $"准备呼叫 [{p_detail.Other.Name}]..."; if (Kit.IsPhoneUI) { HideTitleBar = true; } else { IsPinned = true; SetSize(600, -60); } var task = ShowAsync(); // 确认设备权限 if (!await ExistMediaDevice()) { Close(true); Kit.Warn("打开摄像头或麦克风出错!"); return; } // 确认在线 int retry = 1; while (true) { bool suc = await AtMsg.RequestRtcConnection(Kit.UserID, p_detail.OtherID); if (suc) { break; } // 不在线重试 if (retry++ > 4) { Close(true); Kit.Warn($"等待已超时,[{p_detail.Other.Name}] 未接受邀请!"); return; } await Task.Delay(TimeSpan.FromSeconds(5)); _tbInfo.Text = $"正在第 {retry} 次呼叫 [{p_detail.Other.Name}]..."; } _tbInfo.Text = $"正在等待 [{p_detail.Other.Name}] 接受邀请..."; await task; }
async void OnAccept(object sender, RoutedEventArgs e) { // 确认设备权限 if (!await VideoCaller.ExistMediaDevice()) { Close(true); Kit.Warn("打开摄像头或麦克风出错!"); await AtMsg.RefuseRtcConnection(Kit.UserID, _other.ID); return; } _tbInfo.Text = $"已接受 [{_other.Name}] 的邀请..."; await AtMsg.AcceptRtcConnection(Kit.UserID, _other.ID); _gridBtn.Visibility = Visibility.Collapsed; _btnEnd.Visibility = Visibility.Visible; }
/// <summary> /// 撤回发出的消息 /// </summary> /// <param name="p_letter">待撤消息</param> /// <returns></returns> public static async Task <bool> SendUndoLetter(Letter p_letter) { if (p_letter == null) { return(false); } LetterInfo li = new LetterInfo { ID = p_letter.MsgID, SenderID = Kit.UserID, SenderName = Kit.UserName, LetterType = LetterType.Undo, SendTime = Kit.Now }; await AtMsg.SendLetter(p_letter.OtherID, li); AtState.Exec($"delete from Letter where ID={p_letter.ID}"); return(true); }
protected override void OnClosed(bool p_result) { Inst = null; // 未挂断时,请求挂断 if (!p_result) { AtMsg.HangUp(Kit.UserID, _other.ID, true); } var js = @"if(element.PeerConnection) element.PeerConnection.Close();"; this.ExecuteJavascript(js); if (_timer != null) { _timer.Dispose(); _timer = null; } }
/// <summary> /// 发送聊天信息 /// </summary> /// <param name="p_recvID"></param> /// <param name="p_recvName"></param> /// <param name="p_content"></param> /// <param name="p_type"></param> /// <returns></returns> public static async Task <Letter> SendLetter( long p_recvID, string p_recvName, string p_content, LetterType p_type) { Throw.IfNullOrEmpty(p_content); LetterInfo li = new LetterInfo { ID = Kit.NewGuid, SenderID = Kit.UserID, SenderName = Kit.UserName, LetterType = p_type, Content = p_content, SendTime = Kit.Now }; bool isOnline = await AtMsg.SendLetter(p_recvID, li); // 本地记录 Letter l = new Letter( LoginID: Kit.UserID, MsgID: li.ID, OtherID: p_recvID, OtherName: p_recvName, OtherIsOnline: isOnline, IsReceived: false, Unread: false, LetterType: p_type, Content: p_content, STime: li.SendTime); // 自增主键插入后自动赋值 await AtState.Save(l, false); NewLetter?.Invoke(l); return(l); }
void OnIceCandidate(object sender, HtmlCustomEventArgs e) { AtMsg.SendIceCandidate(Kit.UserID, _detail.OtherID, e.Detail, false); }
void OnOffer(object sender, HtmlCustomEventArgs e) { _tbInfo.Text = $"正在呼叫 [{_detail.Other.Name}]..."; AtMsg.SendRtcOffer(Kit.UserID, _detail.OtherID, e.Detail); }
void OnIceCandidate(object sender, HtmlCustomEventArgs e) { AtMsg.SendIceCandidate(Kit.UserID, _other.ID, e.Detail, true); }
async void OnAnswer(object sender, HtmlCustomEventArgs e) { await AtMsg.SendRtcAnswer(Kit.UserID, _other.ID, e.Detail); }
void OnRefuse(object sender, RoutedEventArgs e) { Close(true); AtMsg.RefuseRtcConnection(Kit.UserID, _other.ID); }