public async Task <PlayResult> Play(string file, Leg leg = Leg.ALeg, string terminator = null) { if (!CanPlayBackAudio) { return(new PlayResult(null)); } if (terminator != null && lastEvent.GetVariable("playback_terminators") != terminator) { await SetChannelVariable("playback_terminators", terminator).ConfigureAwait(false); } var bLegUUID = lastEvent.GetHeader(HeaderNames.OtherLegUniqueId); if (leg == Leg.ALeg || bLegUUID == null) { return(await eventSocket.Play(UUID, file, new PlayOptions()).ConfigureAwait(false)); } switch (leg) { case Leg.Both: return((await Task.WhenAll( eventSocket.Play(UUID, file, new PlayOptions()), eventSocket.Play(bLegUUID, file, new PlayOptions())) .ConfigureAwait(false)).First <PlayResult>()); case Leg.BLeg: return(await eventSocket.Play(bLegUUID, file, new PlayOptions()).ConfigureAwait(false)); default: throw new NotSupportedException("Leg {0} is not supported".Fmt(leg)); } }
public async Task Play(string file, Leg leg = Leg.ALeg, bool mix = false, string terminator = null) { if (!IsAnswered) { return; } if (terminator != null && lastEvent.GetVariable("playback_terminators") != terminator) { await SetChannelVariable("playback_terminators", terminator).ConfigureAwait(false); } if (leg == Leg.ALeg || !IsBridged) { await eventSocket.Play(UUID, file, new PlayOptions()).ConfigureAwait(false); return; } // uuid displace only works on one leg switch (leg) { case Leg.Both: await Task.WhenAll( eventSocket.ExecuteApplication(UUID, "displace_session", "{0} {1}{2}".Fmt(file, mix ? "m" : string.Empty, "w"), false, false), eventSocket.ExecuteApplication(lastEvent.Headers[HeaderNames.OtherLegUniqueId], "displace_session", "{0} {1}{2}".Fmt(file, mix ? "m" : string.Empty, "w"), false, false)) .ConfigureAwait(false); break; case Leg.ALeg: await eventSocket.ExecuteApplication(UUID, "displace_session", "{0} {1}{2}".Fmt(file, mix ? "m" : string.Empty, "w"), false, false).ConfigureAwait(false); break; case Leg.BLeg: await eventSocket.ExecuteApplication(UUID, "displace_session", "{0} {1}{2}".Fmt(file, mix ? "m" : string.Empty, "r"), false, false).ConfigureAwait(false); break; default: throw new NotSupportedException("Leg {0} is not supported".Fmt(leg)); } }