public function connect($address, array $streamOptions = [], $httpOptions = [])
    {
        $components = parse_url($address);
        $scheme = $components['scheme'];
        $host = $components['host'];
        $port = $components['port'];
        $path = $components['path'];
        $query = $components['query'];
        $queryParts = [];
        parse_str($query, $queryParts);

        $this->stasisApplicationName = $queryParts['app'];
        $apiKey = $queryParts['api_key'];
        list($username, $password) = explode(':', $apiKey);

        $config = [
            'base_uri' => ($scheme === 'wss' ? 'https://' : 'http://').$host.':'.$port.dirname($path).'/',
            'auth' => [$username, $password],
            'verify' => false
        ];
        $config = array_merge($config, $httpOptions);
        
        $this->endpoint = new Client($config);

        $this->wsClient = new WebSocket($address, $this->eventLoop, $this->logger, $streamOptions);

        $this->wsClient->on("message", function (WebSocketMessage $rawMessage) {
            $message = new Message($rawMessage->getData());

            $eventType = '\\phparia\\Events\\'.$message->getType();
            if (class_exists($eventType)) {
                $event = new $eventType($this, $rawMessage->getData());
            } else {
                $this->logger->warn("Event: '$eventType' not implemented");

                // @todo Create a generic event for any that are not implemented

                return;
            }

            // Emit the specific event (just to get it back to where it came from)
            if ($event instanceof IdentifiableEventInterface) {
                $this->logger->notice("Emitting ID event: {$event->getEventId()}");
                $this->wsClient->emit($event->getEventId(), array('event' => $event));
            }

            // Emit the general event
            $this->logger->notice("Emitting event: {$message->getType()}");
            $this->wsClient->emit($message->getType(), array('event' => $event));
        });
    }
public function connect($address, array $streamOptions = [], $httpOptions = [])
    {
        $components = parse_url($address);
        $scheme = $components['scheme'];
        $host = $components['host'];
        $port = $components['port'];
        $path = $components['path'];
        $query = $components['query'];
        $queryParts = [];
        parse_str($query, $queryParts);

        $this->stasisApplicationName = $queryParts['app'];
        $apiKey = $queryParts['api_key'];
        list($username, $password) = explode(':', $apiKey);

        $config = [
            'base_uri' => ($scheme === 'wss' ? 'https://' : 'http://').$host.':'.$port.dirname($path).'/',
            'auth' => [$username, $password],
            'verify' => false
        ];
        $config = array_merge($config, $httpOptions);
        
        $this->endpoint = new Client($config);

        $this->wsClient = new WebSocket($address, $this->eventLoop, $this->logger, $streamOptions);

        $this->wsClient->on("message", function (WebSocketMessage $rawMessage) {
            $message = new Message($rawMessage->getData());

            $eventType = '\\phparia\\Events\\'.$message->getType();
            if (class_exists($eventType)) {
                $event = new $eventType($this, $rawMessage->getData());
            } else {
                $this->logger->warn("Event: '$eventType' not implemented");

                // @todo Create a generic event for any that are not implemented

                return;
            }

            // Emit the specific event (just to get it back to where it came from)
            if ($event instanceof IdentifiableEventInterface) {
                $this->logger->notice("Emitting ID event: {$event->getEventId()}");
                $this->wsClient->emit($event->getEventId(), array('event' => $event));
            }

            // Emit the general event
            $this->logger->notice("Emitting event: {$message->getType()}");
            $this->wsClient->emit($message->getType(), array('event' => $event));
        });
    }
public function connect ( $ address , array $ streamOptions = [ ] , $ httpOptions = [ ] ) { $ components = parse_url ( $ address ) ; $ scheme = $ components [ 'scheme' ] ; $ host = $ components [ 'host' ] ; $ port = $ components [ 'port' ] ; $ path = $ components [ 'path' ] ; $ query = $ components [ 'query' ] ; $ queryParts = [ ] ; parse_str ( $ query , $ queryParts ) ; $ this -> stasisApplicationName = $ queryParts [ 'app' ] ; $ apiKey = $ queryParts [ 'api_key' ] ; list ( $ username , $ password ) = explode ( ':' , $ apiKey ) ; $ config = [ 'base_uri' => ( $ scheme === 'wss' ? 'https://' : 'http://' ) . $ host . ':' . $ port . dirname ( $ path ) . '/' , 'auth' => [ $ username , $ password ] , 'verify' => false ] ; $ config = array_merge ( $ config , $ httpOptions ) ; $ this -> endpoint = new Client ( $ config ) ; $ this -> wsClient = new WebSocket ( $ address , $ this -> eventLoop , $ this -> logger , $ streamOptions ) ; $ this -> wsClient -> on ( "message" , function ( WebSocketMessage $ rawMessage ) { $ message = new Message ( $ rawMessage -> getData ( ) ) ; $ eventType = '\\phparia\\Events\\' . $ message -> getType ( ) ; if ( class_exists ( $ eventType ) ) { $ event = new $ eventType ( $ this , $ rawMessage -> getData ( ) ) ; } else { $ this -> logger -> warn ( "Event: '$eventType' not implemented" ) ; // @todo Create a generic event for any that are not implemented return ; } // Emit the specific event (just to get it back to where it came from) if ( $ event instanceof IdentifiableEventInterface ) { $ this -> logger -> notice ( "Emitting ID event: {$event->getEventId()}" ) ; $ this -> wsClient -> emit ( $ event -> getEventId ( ) , array ( 'event' => $ event ) ) ; } // Emit the general event $ this -> logger -> notice ( "Emitting event: {$message->getType()}" ) ; $ this -> wsClient -> emit ( $ message -> getType ( ) , array ( 'event' => $ event ) ) ; } ) ; }
Connect to ARI.

@param string $address Example ws://localhost:8088/ari/events?api_key=username:password&app=stasis_app_name
@param array $streamOptions Such as ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]];
@param array $httpOptions Such as ['verify' => false];
Connect to ARI .