private void txtExt_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (!this.connectState) { MessageBox.Show("Not connected to pbx server", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.callDir == CallDirection.None || this.callDir == CallDirection.Outbound) { var extension = txtExt.Text; if (callState || callRinging) { phone.TerminateCall(call); callState = false; } else { if (string.IsNullOrEmpty(extension)) { MessageBox.Show("Extension cannot be empty", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { callerIdentity = new CallerIdentity(extension); updateLog("Calling " + callerIdentity.Number); callRinging = true; phone.MakeCall(callerIdentity.Number); } } } } else { string code = e.KeyData.ToString(); dtdt.playKeyCode(code); if (callState) { phone.SendDTMFs(call, dtdt.getNumber(code)); } Console.WriteLine(e.KeyData.ToString()); } }
private void button2_Click(object sender, EventArgs e) { string extension = txtExt.Text; Console.WriteLine(callDir); System.Diagnostics.Debug.WriteLine("di clik"); if (this.callDir == CallDirection.None || this.callDir == CallDirection.Outbound) { Console.WriteLine(callState); if (callState || callRinging) { phone.TerminateCall(call); callState = false; } else { if (string.IsNullOrEmpty(extension)) { MessageBox.Show("Extension cannot be empty", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { callerIdentity = new CallerIdentity(extension); updateLog("Calling " + callerIdentity.Number); callRinging = true; //phone.MakeCall(callerIdentity.Number); } } } else if (callDir == CallDirection.Inbound && callState == false) { phone.ReceiveCall(call); callState = true; } else if (callDir == CallDirection.Inbound && callState == true) { callState = false; phone.TerminateCall(call); } }
private void connect() { if (string.IsNullOrEmpty(ippbx.hosts) || string.IsNullOrEmpty(ippbx.extension) || string.IsNullOrEmpty(ippbx.password)) { MessageBox.Show("IPPBX parameter not complete", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { invokeUpdateLog("Registering ..."); string pwd = Common.passwordToAsterixs(ippbx.password); invokeUpdateLog("Extension:" + ippbx.extension + " password:"******" hosts:" + ippbx.hosts); account = new Account(ippbx.extension, ippbx.password, ippbx.hosts); phone = new Phone(account); phone.PhoneConnectedEvent += delegate() { invokeUpdateLog("connected"); ws.send("register|success"); Properties.Settings.Default["pbx_hosts"] = ippbx.hosts; Properties.Settings.Default["pbx_extension"] = ippbx.extension; Properties.Settings.Default["pbx_password"] = ippbx.password; Properties.Settings.Default["pbx_caller"] = ippbx.hosts; Properties.Settings.Default.Save(); invokeUpdateTelepohyInfo(); }; phone.PhoneDisconnectedEvent += delegate() { invokeUpdateLog("Disconnected"); ws.send("register|disconnect"); }; phone.CallCompletedEvent += delegate(Call call) { callRinging = false; callDir = CallDirection.None; if (recorder != null) { recorder.stopRecordInput(); recorder.stopRecordOutput(); } invokeUpdateLog("Call complete"); callerIdentity = null; ws.send("call|completed"); notifyIcon1.BalloonTipTitle = "Call Completed"; notifyIcon1.BalloonTipText = "Call completed"; notifyIcon1.ShowBalloonTip(10000000); ringer.Stop(); }; phone.CallActiveEvent += delegate(Call call) { ringer.Stop(); callState = true; callRinging = false; this.call = call; if (this.callerIdentity != null && (this.callerIdentity.Extension != null && this.callerIdentity.Extension.Equals("") == false)) { phone.SendDTMFs(call, callerIdentity.Extension); } invokeUpdateLog("On Call"); if (callDir == CallDirection.Inbound) { recorder = new Recorder(inboundCallerId); } else { recorder = new Recorder(txtExt.Text); } recorder.startRecordInput(); recorder.startRecordOutput(); recorder.CombineComplete += (s, e) => { Recording recording = recorder.getRecording(); if (callDir == CallDirection.Inbound) { recording.Direction = Recording.RecDirection.Inbound; } else { recording.Direction = Recording.RecDirection.Outbound; } recording.Status = Recording.RecStatUpload.Unuploaded; invokeUpdateLog("Recording : " + recording.Filename); ws.send("recording|" + recording.Filename); collection.Insert(recording); }; ws.send("call|active"); }; phone.LoadEvent += delegate(Call call) { callRinging = true; this.call = call; invokeUpdateLog("Ringging"); ws.send("call|ringing"); }; phone.IncomingCallEvent += delegate(Call call) { this.call = call; callRinging = true; callDir = CallDirection.Inbound; callState = false; inboundCallerId = Common.getExtensionNumberFromCall(call.GetFrom()); invokeUpdateLog("Incoming Call from " + inboundCallerId); ws.send("call|incoming|" + inboundCallerId); notifyIcon1.BalloonTipTitle = "Incoming Call"; notifyIcon1.BalloonTipText = "Incoming call from " + inboundCallerId; notifyIcon1.ShowBalloonTip(1); ringer.Play(); }; phone.Connect(); this.connectState = true; if (button2.InvokeRequired) { lblExt.Invoke(new MethodInvoker(delegate { button2.Enabled = true; })); } else { button2.Enabled = true; } } }