private void MainWindow_Load(object sender, EventArgs e) { callManager.CallsChanged += callsChangedHandle; callManager.PropertyChanged += OnCallManagerPropertyChangedHandle; eventMonitor.MonitorEvent += monitorEventHandle; eventMonitor.Dispatcher = this; deviceManager.DevicesChanged += deviceChangedHandle; LAL.GetDevices(); gvCalls.AutoGenerateColumns = false; }
private void Hangup(int callHandle) { var call = callManager.GetCall(callHandle); if (null != call) { if (!LAL.Hangup(call)) { MessageBox.Show(this, "挂断失败!", "消息框", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Resume(int callHandle) { var call = callManager.GetCall(callHandle); if (null != call) { if (!LAL.Resume(call)) { MessageBox.Show(this, "接听保持恢复失败!", "消息框", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void Hold(int callHandle) { var call = callManager.GetCall(callHandle); if (null != call) { if (!LAL.Hold(call)) { MessageBox.Show(this, "接听保持失败!", "消息框", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Answer(int callHandle) { var call = callManager.GetCall(callHandle); if (null != call) { if (!LAL.Answer(call, call.CallMode, true)) { MessageBox.Show(this, "接听失败!", "消息框", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void onCallWindowClosedHandle(object sender, EventArgs args) { var callWindow = sender as CallWindow; if (null != callWindow) { var wnds = callWindows.Where(c => c.Value == callWindow).ToList(); foreach (var wnd in wnds) { var call = callManager.GetCall(wnd.Key); if (null != call) { LAL.Hangup(call); callManager.RemoveCall(call); } callWindows.Remove(wnd.Key); } } }
private void OnDisposed(object sender, EventArgs e) { try { switch (_channel.ChannelType) { case ChannelType.Local: { var isOK = LAL.DetachStreamFromWindow(MediaTypeEnum.PLCM_MF_STREAM_LOCAL, _channel.ChannelID, _channel.Call.CallHandle); if (!isOK) { MessageBox.Show("本地视频卸载失败"); } } break; case ChannelType.Remote: { var isOK = LAL.DetachStreamFromWindow(MediaTypeEnum.PLCM_MF_STREAM_REMOTE, _channel.ChannelID, _channel.Call.CallHandle); if (!isOK) { MessageBox.Show("远程视频卸载失败"); } } break; case ChannelType.Content: { var isOK = LAL.DetachStreamFromWindow(MediaTypeEnum.PLCM_MF_STREAM_CONTENT, _channel.ChannelID, _channel.Call.CallHandle); if (!isOK) { MessageBox.Show("共享视频卸载失败"); } } break; } } catch (Exception ex) { } }
private void btnLogin_Click(object sender, EventArgs e) { #region Valid var sipServer = txtServer.Text.Trim(); if (string.IsNullOrEmpty(sipServer)) { txtServer.Focus(); MessageBox.Show(this, "Sip服务地址必须", "消息通知", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var userName = txtUserName.Text.Trim(); if (string.IsNullOrEmpty(userName)) { txtUserName.Focus(); MessageBox.Show(this, "用户名必须", "消息通知", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var pwd = txtPassword.Text.Trim(); if (string.IsNullOrEmpty(pwd)) { txtPassword.Focus(); MessageBox.Show(this, "密码必须", "消息通知", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } #endregion if (!LAL.Initialize()) { MessageBox.Show(this, "初始化失败!", "消息通知", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!LAL.RegisterClient(sipServer, userName, pwd)) { MessageBox.Show(this, "登录失败!", "消息通知", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { btnLogin.Enabled = false; } }
private void CallWindow_FormClosing(object sender, FormClosingEventArgs e) { bool canDirectClose = false; switch (_call.CallState) { case CallStateEnum.SIP_UNKNOWN: case CallStateEnum.SIP_CALL_CLOSED: case CallStateEnum.NULL_CALL: canDirectClose = true; break; case CallStateEnum.SIP_INCOMING_INVITE: case CallStateEnum.SIP_INCOMING_CONNECTED: case CallStateEnum.SIP_CALL_HOLD: case CallStateEnum.SIP_CALL_HELD: case CallStateEnum.SIP_CALL_DOUBLE_HOLD: case CallStateEnum.SIP_OUTGOING_TRYING: case CallStateEnum.SIP_OUTGOING_RINGING: case CallStateEnum.SIP_OUTGOING_CONNECTED: canDirectClose = false; break; } if (!canDirectClose) { Action okAction = () => { LAL.Hangup(_call); e.Cancel = false; }; Action cancelAction = () => { e.Cancel = true; }; UXMessageMask.ShowMessage(this, true, "当前通话连通中.\r\n确认要关闭退出吗?", MessageBoxButtonsType.OKCancel, MessageBoxIcon.Question , okAction, cancelAction); } }
public void handleEvent(Call call) { switch (call.CallEventState) { case CallEventStateEnum.UNKNOWN: { } break; case CallEventStateEnum.INCOMING_INVITE: /* UAS received an incoming call. */ { deviceManager.StopSound(); deviceManager.PlaySound(DeviceManager.IncomingSound, true, 2000); var msg = string.Format("【{0}】呼入中,是否接听?", this._call.RemoteDisplayName); Action answerAction = () => { LAL.Hold(true); LAL.Hangup(true); deviceManager.StopSound(); LAL.Answer(this._call, CallModeEnum.PLCM_MFW_AUDIOVIDEO_CALL, true); }; Action hangupAction = () => { LAL.Hangup(this._call); }; UXMessageMask.ShowMessage(this, false, msg, MessageBoxButtonsType.AnswerHangup, MessageBoxIcon.Question , answerAction, hangupAction); } break; case CallEventStateEnum.INCOMING_CLOSED: /* UAS received the call terminated. */ { deviceManager.StopSound(); deviceManager.PlaySound(DeviceManager.ClosedSound, false, 0); Action okAction = () => { this.Close(); }; UXMessageMask.ShowMessage(this, false, "呼叫已经关闭!", MessageBoxButtonsType.OK, MessageBoxIcon.Information , okAction); } break; case CallEventStateEnum.INCOMING_CONNECTED: /* UAS received the call connected. */ { deviceManager.StopSound(); ViewRender(); UXMessageMask.HideMessage(this); } break; case CallEventStateEnum.INCOMING_HOLD: break; /* The call is holding by local site. */ case CallEventStateEnum.INCOMING_HELD: break; /* The call is holding by far site. */ case CallEventStateEnum.INCOMING_DOUBLE_HOLD: break; /* The call is holding by both far site and local site. */ case CallEventStateEnum.INCOMING_CALL_FARSITE_MIC_MUTE: /* Far site has muted micphone. */ { } break; case CallEventStateEnum.INCOMING_CALL_FARSITE_MIC_UNMUTE: /* Far site has unmuted micphone. */ { } break; case CallEventStateEnum.INCOMING_CONTENT: { } break; case CallEventStateEnum.CONTENT_SENDING: { log.Info("CONTENT_SENDING"); } break; case CallEventStateEnum.CONTENT_CLOSED: { var contentChannel = _call.Channels.FirstOrDefault(c => c.ChannelType == ChannelType.Content); if (null != contentChannel) { this._call.RemoveChannel(contentChannel.ChannelID); } // LAL.detachStreamFromWindow(MediaType.PLCM_MF_STREAM_CONTENT, 0, LAL.getActiveCall().getCallHandle()); /*detach content window*/ } break; case CallEventStateEnum.CONTENT_UNSUPPORTED: break; case CallEventStateEnum.CONTENT_IDLE: break; case CallEventStateEnum.OUTGOING_RINGING: /* UAC received far site is ringing.*/ { deviceManager.StopSound(); deviceManager.PlaySound(DeviceManager.RingingSound, true, 2000); Action hangupAction = () => { this.Close(); }; UXMessageMask.ShowMessage(this, false, "当前正呼叫中...", MessageBoxButtonsType.Hangup, MessageBoxIcon.Information , hangupAction); } break; case CallEventStateEnum.OUTGOING_FAILURE: /* from CC */ { deviceManager.StopSound(); Action okAction = () => { this.Close(); }; UXMessageMask.ShowMessage(this, false, "呼叫失敗!", MessageBoxButtonsType.OK, MessageBoxIcon.Error , okAction); } break; case CallEventStateEnum.OUTGOING_CONNECTED: /* from CC */ { deviceManager.StopSound(); ViewRender(); UXMessageMask.HideMessage(this); } break; case CallEventStateEnum.LOCAL_RESOLUTION_CHANGED: break; case CallEventStateEnum.REMOTE_RESOLUTION_CHANGED: break; case CallEventStateEnum.SIP_REGISTER_SUCCESS: break; /* Register to sip server succeed. */ case CallEventStateEnum.SIP_REGISTER_FAILURE: break; /* Register to sip server failed. */ case CallEventStateEnum.SIP_UNREGISTERED: break; /* Unregister to sip server. */ case CallEventStateEnum.NETWORK_CHANGED: break; /* Network changed or lost.*/ case CallEventStateEnum.CALL_AUDIO_ONLY_TRUE: break; /* The call is audio only.*/ case CallEventStateEnum.CALL_AUDIO_ONLY_FALSE: break; /* The call is not audio only.*/ case CallEventStateEnum.MFW_INTERNAL_TIME_OUT: break; //SVC case CallEventStateEnum.REFRESH_ACTIVE_SPEAKER: { // ViewRender(); //重新布局 } break; case CallEventStateEnum.REFRESH_LAYOUT: { this._call.ClearRemoteChannels(); } break; case CallEventStateEnum.CHANNEL_STATUS_UPDATE: break; case CallEventStateEnum.DISPLAYNAME_UPDATE: break; case CallEventStateEnum.CALL_MODE_UPGRADE_REQ: break; case CallEventStateEnum.DEVICE_VIDEOINPUT: break; case CallEventStateEnum.CERTIFICATE_VERIFY: break; case CallEventStateEnum.TRANSCODER_FINISH: break; case CallEventStateEnum.ICE_STATUS_CHANGED: break; case CallEventStateEnum.AUTODISCOVERY_SUCCESS: break; case CallEventStateEnum.AUTODISCOVERY_FAILURE: break; case CallEventStateEnum.AUTODISCOVERY_ERROR: break; case CallEventStateEnum.SIP_CALL_TRYING: { deviceManager.StopSound(); deviceManager.PlaySound(DeviceManager.RingingSound, true, 2000); Action hangupAction = () => { LAL.Hangup(this._call); }; UXMessageMask.ShowMessage(this, false, "呼叫中...", MessageBoxButtonsType.Hangup, MessageBoxIcon.Information , hangupAction); } break; } }
private void btnVideoCall_Click(object sender, EventArgs e) { var callAddr = txtCallee.Text.Trim(); if (string.IsNullOrEmpty(callAddr)) { MessageBox.Show("被呼叫方必须"); return; } LAL.Hold(true); log.Info("[MainWindow]Dial a call " + CallModeEnum.PLCM_MFW_AUDIOVIDEO_CALL); var errno = LAL.Dial(callAddr, CallModeEnum.PLCM_MFW_AUDIOVIDEO_CALL); var msg = string.Empty; switch (errno) { case ErrorNumberEnum.PLCM_SAMPLE_OK: break; case ErrorNumberEnum.PLCM_MFW_ERR_CALL_INVALID_FORMAT: msg = "Place call failed. Your input is in wrong format or contains illegal characters."; break; case ErrorNumberEnum.PLCM_MFW_ERR_CALL_IN_REGISTERING: msg = "Place call failed. Registering to server, please try again after your registration is completed"; break; case ErrorNumberEnum.PLCM_MFW_ERR_CALL_EXCEED_MAXIMUM_CALLS: msg = "Place call failed. Total Call Number Exceeds Maximum Allowable Value."; break; case ErrorNumberEnum.PLCM_MFW_ERR_ENCRYPTION_CONFIG: msg = "Place call failed. Encryption settings do not match."; break; case ErrorNumberEnum.PLCM_MFW_ERR_CALL_NO_CONNECT: msg = "Place call failed. No local network connection."; break; case ErrorNumberEnum.PLCM_MFW_ERR_CALL_HOST_UNKNOWN: msg = "Place call failed. Your input can not be parsed into a valid address."; break; case ErrorNumberEnum.PLCM_MFW_ERR_CALL_EXIST: msg = "Place call failed. The call of the far site already exist."; break; case ErrorNumberEnum.PLCM_MFW_ERR_GENERIC: msg = "Place call failed. PLCM_MFW_ERR_GENERIC"; break; default: msg = "Place call failed." + errno.ToString(); break; } if (!string.IsNullOrEmpty(msg)) { if (MessageBox.Show(this, msg, "消息通知", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) { } } }
private void RenderVedio() { try { var hwnd = pnlVideo.Handle; if (_channel.IsVideo) { switch (_channel.ChannelType) { case ChannelType.Local: { var isOK = LAL.AttachStreamToWindow(hwnd, _channel.Call.CallHandle, MediaTypeEnum.PLCM_MF_STREAM_LOCAL, _channel.ChannelID, this.pnlVideo.Width, this.pnlVideo.Height - 40); if (!isOK) { MessageBox.Show("本地视频附加失败"); } } break; case ChannelType.Remote: { var isOK = LAL.AttachStreamToWindow(hwnd, _channel.Call.CallHandle, MediaTypeEnum.PLCM_MF_STREAM_REMOTE, _channel.ChannelID, this.pnlVideo.Width, this.pnlVideo.Height - 40); if (!isOK) { MessageBox.Show("远程视频附加失败"); } } break; case ChannelType.Content: { var isOK = LAL.AttachStreamToWindow(hwnd, _channel.Call.CallHandle, MediaTypeEnum.PLCM_MF_STREAM_CONTENT, _channel.ChannelID, this.pnlVideo.Width, this.pnlVideo.Height - 40); if (!isOK) { MessageBox.Show("共享视频附加失败"); } } break; } } else //音频 { switch (_channel.ChannelType) { case ChannelType.Local: { var isOK = LAL.DetachStreamFromWindow(MediaTypeEnum.PLCM_MF_STREAM_LOCAL, _channel.ChannelID, _channel.Call.CallHandle); if (!isOK) { MessageBox.Show("本地视频卸载失败"); } } break; case ChannelType.Remote: { var isOK = LAL.DetachStreamFromWindow(MediaTypeEnum.PLCM_MF_STREAM_REMOTE, _channel.ChannelID, _channel.Call.CallHandle); if (!isOK) { MessageBox.Show("远程视频卸载失败"); } } break; case ChannelType.Content: { var isOK = LAL.DetachStreamFromWindow(MediaTypeEnum.PLCM_MF_STREAM_CONTENT, _channel.ChannelID, _channel.Call.CallHandle); if (!isOK) { MessageBox.Show("共享视频卸载失败"); } } break; } } } catch (Exception ex) { } }