static void Main(string[] args) { try { // Create a message actionClient to receive events on ActionClient = new AriClient(new StasisEndpoint("192.168.3.16", 8088, "username", "test"), AppName); ActionClient.OnStasisStartEvent += c_OnStasisStartEvent; ActionClient.OnStasisEndEvent += c_OnStasisEndEvent; ActionClient.Connect(); // Create simple bridge SimpleBridge = ActionClient.Bridges.Create("mixing", Guid.NewGuid().ToString(), AppName); // subscribe to bridge events ActionClient.Applications.Subscribe(AppName, "bridge:" + SimpleBridge.Id); // start MOH on bridge ActionClient.Bridges.StartMoh(SimpleBridge.Id, "default"); var done = false; while (!done) { var lastKey = Console.ReadKey(); switch(lastKey.KeyChar.ToString()) { case "*": done = true; break; case "1": ActionClient.Bridges.StopMoh(SimpleBridge.Id); break; case "2": ActionClient.Bridges.StartMoh(SimpleBridge.Id, "default"); break; case "3": // Mute all channels on bridge var bridgeMute = ActionClient.Bridges.Get(SimpleBridge.Id); foreach (var chan in bridgeMute.Channels) ActionClient.Channels.Mute(chan, "in"); break; case "4": // Unmute all channels on bridge var bridgeUnmute = ActionClient.Bridges.Get(SimpleBridge.Id); foreach (var chan in bridgeUnmute.Channels) ActionClient.Channels.Unmute(chan, "in"); break; } } ActionClient.Bridges.Destroy(SimpleBridge.Id); ActionClient.Disconnect(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
static void Main(string[] args) { try { endPoint = new StasisEndpoint("ipaddress", 8088, "username", "password"); // Create a message actionClient to receive events on actionClient = new AriClient(endPoint, "playrec_test"); actionClient.OnStasisStartEvent += c_OnStasisStartEvent; actionClient.OnStasisEndEvent += c_OnStasisEndEvent; actionClient.OnRecordingFinishedEvent += ActionClientOnRecordingFinishedEvent; actionClient.Connect(); bool done = false; while (!done) { var lastKey = Console.ReadKey(); switch (lastKey.KeyChar.ToString()) { case "*": done = true; break; } } actionClient.Disconnect(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
/// <summary> /// Connecto to Asterisk ARI and WebSocket events /// </summary> /// <param name="server">IP or host name of asterisk</param> /// <param name="port">Port ej: 8088</param> /// <param name="usu">ARI user</param> /// <param name="pass">ARI password</param> public void Connect(string server, int port, string usu, string pass) { source = server; //CREO EL CLIENTE pbx = new AriClient(new StasisEndpoint(server, port, usu, pass), appName); //USEREVENT para el login -> en desuso //pbx.OnChannelUsereventEvent += Pbx_OnChannelUsereventEvent; //SUBSCRIBO A EVENTOS pbx.OnUnhandledEvent += Pbx_OnUnhandledEvent; pbx.OnStasisStartEvent += Pbx_OnStasisStartEvent; pbx.OnStasisEndEvent += Pbx_OnStasisEndEvent; //CONECTO EL CLIENTE, true para habilitar reconexion, e intento cada 5 seg try { Log.Logger.Debug("Conectando login provider en: " + server); pbx.EventDispatchingStrategy = EventDispatchingStrategy.DedicatedThread; pbx.Connect(true, 5); //Thread.Sleep(1000); //pbx.Applications.Subscribe(appName, "endpoint:SIP"); //pbx.Applications.Subscribe(appName, "deviceState:"); } catch (Exception ex) { throw new Exception("Error al conectar con asterisk", ex); } }
private static void RunDemo() { try { Client = new AriClient( new StasisEndpoint("127.0.0.1", 8088, "username", "test"), AppConfig.AppName); Conference.Conferences.Add(new Conference(Client, Guid.NewGuid(), "test")); Client.OnStasisStartEvent += c_OnStasisStartEvent; Client.OnStasisEndEvent += c_OnStasisEndEvent; Client.Connect(); // Start REST WebApp.Start <Startup>(url: AppConfig.RestAddress); Console.WriteLine("Loaded...waiting for connections."); // Wait Console.ReadKey(); // Destroy all the conferences and their bridges Conference.Conferences.ForEach(async x => await x.DestroyConference()); Conference.Conferences = null; } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
private static void Main(string[] args) { try { // Create a message client to receive events on Client = new AriClient(new StasisEndpoint("127.0.0.1", 8088, "username", "test"), AppConfig.AppName); Conference.Conferences.Add(new Conference(Client, Guid.NewGuid(), "test")); Client.OnStasisStartEvent += c_OnStasisStartEvent; Client.OnStasisEndEvent += c_OnStasisEndEvent; Client.Connect(); // Start REST WebApp.Start<Startup>(url: AppConfig.RestAddress); Console.WriteLine("Loaded... waiting for connections"); // Wait Console.ReadKey(); // Destroy all the conferences and their bridges Conference.Conferences.ForEach(x => x.DestroyConference()); Conference.Conferences = null; } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
private static void Main(string[] args) { try { // Create a new Ari Connection ActionClient = new AriClient( new StasisEndpoint("127.0.0.1", 8088, "username", "test"), "HelloWorld"); ActionClient.Connect(); // List Recordings var recordings = ActionClient.Recordings.ListStored(); recordings.ForEach(x => Console.WriteLine($"Recording Name: {x.Name}, {x.Format}")); // Download the first Recording var recording = recordings.First(); Console.WriteLine($"Downloading recording {recording.Name}"); using (var file = File.Create(Path.GetTempFileName())) { var buffer = ActionClient.Recordings.GetStoredFile(recording.Name); file.Write(buffer, 0, buffer.Length); file.Flush(); } Console.WriteLine("Press any key to close..."); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
public void DoWork() { ActionClient = new AriClient(new StasisEndpoint("10.100.3.44", 8088, "asterisk", "heslox"), "wcf-service"); ActionClient.OnStasisStartEvent += ActionClient_OnStasisStartEvent; ActionClient.OnStasisEndEvent += ActionClient_OnStasisEndEvent; ActionClient.Connect(); }
/// <summary> /// Connecto to Asterisk ARI and WebSocket events /// </summary> /// <param name="server">IP or host name of asterisk</param> /// <param name="port">Port ej: 8088</param> /// <param name="usu">ARI user</param> /// <param name="pass">ARI password</param> public void Connect(string server, int port, string usu, string pass) { source = server; //CREO EL CLIENTE pbx = new AriClient(new StasisEndpoint(server, port, usu, pass), appName); //SUBSCRIBO A EVENTOS ARI pbx.OnEndpointStateChangeEvent += Pbx_OnEndpointStateChangeEvent; pbx.OnDeviceStateChangedEvent += Pbx_OnDeviceStateChangedEvent; pbx.OnPeerStatusChangeEvent += Pbx_OnPeerStatusChangeEvent; //SUBCRIBO A EVENTOS ActorStateProxy actorStateProxy.AttachMember += ActorStateProxy_AttachMember; actorStateProxy.DetachMember += ActorStateProxy_DetachMember; //pbx.OnUnhandledEvent += Pbx_OnUnhandledEvent; //CONECTO EL CLIENTE, true para habilitar reconexion, e intento cada 5 seg try { Log.Logger.Debug("Conectando state provider en: " + server); pbx.EventDispatchingStrategy = EventDispatchingStrategy.DedicatedThread; pbx.Connect(true, 5); Thread.Sleep(1000); //obtengo los endpoints (devices) List <Endpoint> endpoints = pbx.Endpoints.ListByTech("SIP"); foreach (Endpoint endpoint in endpoints) { Device device = new Device(); device.Id = endpoint.Technology + "/" + endpoint.Resource; device.EndpointState = endpoint.State; deviceCache.AddDevice(device); } //obtengo el estado de los dispositivod?? no se bien que devuelve esto... por ahora lo comento //List<DeviceState> devStates = pbx.DeviceStates.List(); //foreach (DeviceState state in devStates) { // deviceCache.UpdateDeviceState(state.Name, state.State); //} pbx.Applications.Subscribe(appName, "endpoint:SIP"); pbx.Applications.Subscribe(appName, "deviceState:"); //una vez que inicializo pongo a recibir eventos al actorStateProxy, de aca me llegan los attach u detach actorStateProxy.Start(); } catch (Exception ex) { throw new Exception("Error al conectar con asterisk", ex); } }
public ARIMain(StasisEndpoint endpoint, string app, ISSSO _ssso) { ariClient = new AriClient(endpoint, app); ariClient.Connect(); ssso = _ssso; ariClient.OnStasisStartEvent += AriClient_OnStasisStartEvent; ariClient.OnChannelHangupRequestEvent += AriClient_OnChannelHangupRequestEvent; ariClient.OnChannelDtmfReceivedEvent += AriClient_OnChannelDtmfReceivedEvent; dtmfTimer = new Timer(dtmfTimerDoWork, lockObject, TimeSpan.Zero, TimeSpan.FromSeconds(1)); }
private void Start(StasisEndpoint endpoint) { try { _logger.Information("Starting Asterisk ARI!"); var ariClient = new AriClient(endpoint, AppName); ariClient.OnConnectionStateChanged += AriClientOnConnectionStateChanged; ariClient.Connect(); _ariClient = ariClient; _endpointHost = endpoint.Host; } catch (HttpRequestException ex) { _logger.Error($"Ошибка подключения к Asterisk ARI. Host: {endpoint.Host}:{endpoint.Port}, Endpoint: {endpoint.AriEndPoint}", ex); throw; } }
private static void Main(string[] args) { try { // Create a new Ari Connection ActionClient = new AriClient(new StasisEndpoint("192.168.3.201", 8088, "test", "test"), "HelloWorld"); // Hook into required events ActionClient.OnStasisStartEvent += c_OnStasisStartEvent; ActionClient.OnChannelDtmfReceivedEvent += ActionClientOnChannelDtmfReceivedEvent; ActionClient.OnConnectionStateChanged += ActionClientOnConnectionStateChanged; ActionClient.Connect(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
/// <summary> /// Connecto to Asterisk ARI and WebSocket events /// </summary> /// <param name="server">IP or host name of asterisk</param> /// <param name="port">Port ej: 8088</param> /// <param name="usu">ARI user</param> /// <param name="pass">ARI password</param> public void Connect(string server, int port, string usu, string pass) { source = server; //CREO EL CLIENTE pbx = new AriClient(new StasisEndpoint(server, port, usu, pass), appName); pbx.EventDispatchingStrategy = EventDispatchingStrategy.DedicatedThread; //SUBSCRIBO A EVENTOS pbx.OnStasisStartEvent += Pbx_OnStasisStartEvent; //Se dispara cuando un canal ejecuta la app stasis en el dialplan. el canal queda ahi a la espera de ser manejado pbx.OnStasisEndEvent += Pbx_OnStasisEndEvent; //el canal abandonó la app stasis (no quiere decir que cortó) pbx.OnChannelHangupRequestEvent += Pbx_OnChannelHangupRequestEvent; //Se solicito terminar el canal (posee la causa ej: normal clearing) pbx.OnChannelStateChangeEvent += Pbx_OnChannelStateChangeEvent; //cambió el estado del canal ej: down->up->ringing. No se si lo voy a usar pbx.OnChannelDestroyedEvent += Pbx_OnChannelDestroyedEvent; //el canal fué terminado, sehizo efectivo el hangup pbx.OnChannelHoldEvent += Pbx_OnChannelHoldEvent; //el canal se puso onhold pbx.OnChannelUnholdEvent += Pbx_OnChannelUnholdEvent; pbx.OnBridgeAttendedTransferEvent += Pbx_OnBridgeAttendedTransferEvent; pbx.OnBridgeBlindTransferEvent += Pbx_OnBridgeBlindTransferEvent; //CONECTO EL CLIENTE, true para habilitar reconexion, e intento cada 5 seg try { lock (_locker) { Log.Logger.Debug("Conectando call manager en: " + server); pbx.Connect(true, 5); if (pbx.Connected) { List <Bridge> brs = pbx.Bridges.List(); foreach (Bridge b in brs) { bridgesList.AddNewBridge(b); } } } } catch (Exception ex) { throw new Exception("Error al conectar con asterisk", ex); } }
private static void Main(string[] args) { try { // Create a new Ari Connection ActionClient = new AriClient( new StasisEndpoint("192.168.3.201", 8088, "test", "test"), "HelloWorld"); // Hook into required events ActionClient.OnStasisStartEvent += c_OnStasisStartEvent; ActionClient.OnChannelDtmfReceivedEvent += ActionClientOnChannelDtmfReceivedEvent; ActionClient.OnConnectionStateChanged += ActionClientOnConnectionStateChanged; ActionClient.Connect(); Console.ReadKey(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
static void Main(string[] args) { try { // Create a message actionClient to receive events on ActionClient = new AriClient(new StasisEndpoint("192.168.3.16", 8088, "username", "test"), AppName); ActionClient.OnStasisStartEvent += c_OnStasisStartEvent; ActionClient.OnStasisEndEvent += c_OnStasisEndEvent; ActionClient.Connect(); // Create simple bridge SimpleBridge = ActionClient.Bridges.Create("mixing", Guid.NewGuid().ToString(), AppName); // subscribe to bridge events ActionClient.Applications.Subscribe(AppName, "bridge:" + SimpleBridge.Id); // start MOH on bridge ActionClient.Bridges.StartMoh(SimpleBridge.Id, "default"); var done = false; while (!done) { var lastKey = Console.ReadKey(); switch (lastKey.KeyChar.ToString()) { case "*": done = true; break; case "1": ActionClient.Bridges.StopMoh(SimpleBridge.Id); break; case "2": ActionClient.Bridges.StartMoh(SimpleBridge.Id, "default"); break; case "3": // Mute all channels on bridge var bridgeMute = ActionClient.Bridges.Get(SimpleBridge.Id); foreach (var chan in bridgeMute.Channels) { ActionClient.Channels.Mute(chan, "in"); } break; case "4": // Unmute all channels on bridge var bridgeUnmute = ActionClient.Bridges.Get(SimpleBridge.Id); foreach (var chan in bridgeUnmute.Channels) { ActionClient.Channels.Unmute(chan, "in"); } break; } } ActionClient.Bridges.Destroy(SimpleBridge.Id); ActionClient.Disconnect(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.ReadKey(); } }
public void Start() { _client.Connect(); }