/// <summary> /// Plays the provided audio source to the A-Leg. /// Dispose the returned token to cancel playback. /// </summary> /// <param name="file">The audio source.</param> /// <returns>An <seealso cref="IDisposable"/> which can be disposed to stop the audio.</returns> public async Task <IDisposable> PlayUntilCancelled(string file) { if (!CanPlayBackAudio) { Log.Warn(() => "Channel [{0}] attempted to play hold music when not answered".Fmt(UUID)); return(Task.FromResult(new DisposableAction())); } // essentially, we'll do a playback application call without waiting for the ChannelExecuteComplete event // the caller can .Dispose() the returned token to do a uuid_break on the channel to kill audio. await eventSocket.SendCommand(string.Format("sendmsg {0}\ncall-command: execute\nexecute-app-name: playback\nexecute-app-arg:{1}\nloops:-1", UUID, file)); var cancellation = new DisposableAction( async() => { if (!CanPlayBackAudio) { return; } try { await eventSocket.Api("uuid_break", UUID); } catch (Exception ex) { Log.ErrorException("Error calling 'api uuid_break {0}'".Fmt(UUID), ex); } }); return(cancellation); }
public static Task <CommandReply> SendEvent( this EventSocket eventSocket, string eventName, IDictionary <string, string> headers = null) { if (eventName == null) { throw new ArgumentNullException("eventName"); } if (headers == null) { headers = new Dictionary <string, string>(); } var headersString = headers.Aggregate( StringBuilderPool.Allocate(), (sb, kvp) => { sb.AppendFormat("{0}: {1}", kvp.Key, kvp.Value); sb.Append("\n"); return(sb); }, StringBuilderPool.ReturnAndFree); return(eventSocket.SendCommand("sendevent {0}\n{1}".Fmt(eventName, headersString))); }
public static Task <CommandReply> FilterDelete(this EventSocket eventSocket, string header) { if (header == null) { throw new ArgumentNullException("header"); } return(eventSocket.SendCommand("filter delete {0}".Fmt(header))); }
public static Task <CommandReply> Hangup( this EventSocket eventSocket, string uuid, HangupCause hangupCause = HangupCause.NormalClearing) { if (uuid == null) { throw new ArgumentNullException("uuid"); } return (eventSocket.SendCommand( "sendmsg {0}\ncall-command: hangup\nhangup-cause: {1}".Fmt(uuid, hangupCause.ToString().ToUpperWithUnderscores()))); }
public static Task <CommandReply> Filter(this EventSocket eventSocket, string header, string value) { if (header == null) { throw new ArgumentNullException("header"); } if (value == null) { throw new ArgumentNullException("value"); } return(eventSocket.SendCommand("filter {0} {1}".Fmt(header, value))); }
public static Task <CommandReply> DivertEventsOff(this EventSocket eventSocket) { return(eventSocket.SendCommand("divert_events off")); }
public static Task <CommandReply> NoEvents(this EventSocket eventSocket) { return(eventSocket.SendCommand("noevents")); }
public static Task <CommandReply> NoLog(this EventSocket eventSocket) { return(eventSocket.SendCommand("nolog")); }
public static Task <CommandReply> FsLog(this EventSocket eventSocket, string logLevel) { return(eventSocket.SendCommand("log " + logLevel)); }
public Task <CommandReply> SendCommand(string command) { return(eventSocket.SendCommand(command)); }