private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams) { Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State); Task.Run(() => { try { call.Answer(); } catch (Exception exc) { Logger.LogError(exc, "Answer failed"); sCompleted.Set(); return; } try { call.OnRecordStateChange += OnCallRecordStateChange; call.Record(new CallRecord() { Audio = new CallRecord.AudioParams() { // Default parameters } }); } catch (Exception exc) { Logger.LogError(exc, "StartRecord failed"); sCompleted.Set(); return; } }); }
private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams) { Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State); Task.Run(() => { try { call.Answer(); } catch (Exception exc) { Logger.LogError(exc, "Answer failed"); sCompleted.Set(); return; } try { call.OnPlayStateChange += OnCallPlayStateChange; call.PlayTTS( new CallMedia.TTSParams() { Text = "i'm a little teapot", }); } catch (Exception exc) { Logger.LogError(exc, "PlayTTS failed"); sCompleted.Set(); return; } }); }
private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams) { Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State); Task.Run(() => { try { call.Answer(); } catch (Exception exc) { Logger.LogError(exc, "Answer failed"); sCompleted.Set(); return; } Thread.Sleep(1000); try { call.OnCollect += OnCallCollect; PlayTTSAndCollectAction action = call.PlayTTSAndCollect( new CallMedia.TTSParams() { Text = "i'm a little teapot, short and stout. Here is my handle, here is my spout.", }, new CallCollect() { Digits = new CallCollect.DigitsParams() { Max = 1 } }); Thread.Sleep(2000); action.Stop(); call.PlayTTS(new CallMedia.TTSParams() { Text = "Stopped" }); Thread.Sleep(1000); call.Hangup(); sSuccessful = true; sCompleted.Set(); } catch (Exception exc) { Logger.LogError(exc, "PlayTTSAndCollect failed"); sCompleted.Set(); return; } }); }
private void OnEvent_CallingCallReceive(Client client, BroadcastParams broadcastParams, CallEventParams callEventParams) { CallEventParams.ReceiveParams receiveParams = null; try { receiveParams = callEventParams.ParametersAs <CallEventParams.ReceiveParams>(); } catch (Exception exc) { Logger.LogWarning(exc, "Failed to parse ReceiveParams"); return; } // @note A received call should only ever receive one receive event regardless of the state of the call, but we act as though // we could receive multiple just for sanity here, but the callbacks will still only be called when first created, which makes // this effectively a no-op on additional receive events Call call = null; Call tmp = null; switch (receiveParams.Device.Type) { case CallDevice.DeviceType.phone: { CallDevice.PhoneParams phoneParams = null; try { phoneParams = receiveParams.Device.ParametersAs <CallDevice.PhoneParams>(); } catch (Exception exc) { Logger.LogWarning(exc, "Failed to parse PhoneParams"); return; } // If the call already exists under the real call id simply obtain the call, otherwise create a new call call = mCalls.GetOrAdd(receiveParams.CallID, k => (tmp = new PhoneCall(this, receiveParams.NodeID, receiveParams.CallID) { To = phoneParams.ToNumber, From = phoneParams.FromNumber, Timeout = phoneParams.Timeout, // Capture the state, it may not always be created the first time we see the call State = receiveParams.CallState, })); break; } // @TODO: sip and webrtc default: Logger.LogWarning("Unknown device type: {0}", receiveParams.Device.Type); return; } if (tmp == call) { OnCallCreated?.Invoke(this, call); OnCallReceived?.Invoke(this, call, receiveParams); } }
private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams) { Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State); Task.Run(() => { try { call.Answer(); } catch (Exception exc) { Logger.LogError(exc, "Answer failed"); sCompleted.Set(); } }); }
private static void CallingAPI_OnCallReceived(CallingAPI api, Call call, CallEventParams.ReceiveParams receiveParams) { // This is called when the client is informed that a new inbound call has been created Logger.LogInformation("OnCallReceived: {0}, {1}", call.CallID, call.State); // Answer the inbound call try { call.Answer(); } catch (Exception exc) { Logger.LogError(exc, "CallAnswer failed"); return; } Call callB = null; try { // The top level list of the devices represents entries that will be called in serial, // one at a time. The inner list of devices represents a set of devices to call in // parallel with each other. Ultimately only one device wins by answering first. callB = call.Connect(new List <List <CallDevice> > { new List <CallDevice> { new CallDevice { Type = CallDevice.DeviceType.phone, Parameters = new CallDevice.PhoneParams { ToNumber = sCallToNumber, FromNumber = sCallFromNumber, } } } }); } catch (Exception exc) { Logger.LogError(exc, "Connect failed"); return; } // Wait upto 15 seconds for the connected side to end then hangup callB.WaitForState(TimeSpan.FromSeconds(15), CallState.ended); call.Hangup(); }