protected function stopRouter() { $this->assertInstanceOf('Thruway\\Peer\\Router', $this->router); $this->assertInstanceOf('React\\EventLoop\\Timer\\Timer', $this->currentTimer); $this->currentTimer->cancel(); $this->router->stop(false); }
public function start() { $this->loop = \WyriHaximus\Ratchet\loopResolver(); $router = new Router($this->loop); $router->addInternalClient(new InternalClient('first', $this->loop)); $router->addTransportProvider(new RatchetTransportProvider(Configure::read('WyriHaximus.Ratchet.Connection.Websocket.address'), Configure::read('WyriHaximus.Ratchet.Connection.Websocket.port'))); //$router->getRealmManager()->setDefaultAuthorizationManager(new AllPermissiveAuthorizationManager()); EventManager::instance()->dispatch(WebsocketStartEvent::create($this->loop)); $router->start(false); $this->loop->run(); }
/** * @param ConstructEvent $event */ public function construct(ConstructEvent $event) { $router = new Router($event->getLoop()); foreach (Configure::read('WyriHaximus.Ratchet.realms') as $realm => $config) { $router->addInternalClient(new InternalClient($realm, $event->getLoop())); } $router->addTransportProvider(new RatchetTransportProvider(Configure::read('WyriHaximus.Ratchet.internal.address'), Configure::read('WyriHaximus.Ratchet.internal.port'))); //$router->getRealmManager()->setDefaultAuthorizationManager(new AllPermissiveAuthorizationManager()); EventManager::instance()->dispatch(WebsocketStartEvent::create($event->getLoop())); $router->start(false); }
<?php /** * This requires "facebook/php-sdk-v4" : "4.0.*" */ require '../../bootstrap.php'; require 'FacebookAuthProvider.php'; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $router = new Router(); $authMgr = new \Thruway\Authentication\AuthenticationManager(); $router->setAuthenticationManager($authMgr); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authMgr)); $authProvClient = new FacebookAuthProvider(['*'], 'YOUR_APP_ID', 'YOUR_APP_SECRET'); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authProvClient)); $transportProvider = new RatchetTransportProvider("127.0.0.1", 9090); $router->addTransportProvider($transportProvider); $router->start();
<?php require_once __DIR__ . '/../../bootstrap.php'; require_once __DIR__ . '/UserDb.php'; use Thruway\Authentication\WampCraAuthProvider; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $router = new Router(); // setup some users to auth against $userDb = new UserDb(); $userDb->add('peter', 'secret1', 'salt123'); $userDb->add('joe', 'secret2', "mmm...salt"); /** * The AuthenticationManager is both an internal client and also responsible * for handling all authentication for the router. * * When authentication is needed, the router consults the AuthenticationManager * which will consult registered Authentication Providers to do the actual authentication. * * The Authentication providers and the AuthenticationManager communicate through WAMP * in the thruway.auth realm. */ $authMgr = new \Thruway\Authentication\AuthenticationManager(); $router->registerModule($authMgr); $authProvClient = new WampCraAuthProvider(["realm1"]); $authProvClient->setUserDb($userDb); $router->addInternalClient($authProvClient); $router->registerModule(new RatchetTransportProvider("127.0.0.1", 9090)); $router->start();
public function setInternalClient(ThruwayClientInterface $client) { $this->router->addInternalClient($client); $this->client = $client; }
<?php require_once __DIR__ . '/bootstrap.php'; require_once __DIR__ . '/Clients/InternalClient.php'; require_once __DIR__ . '/Clients/SimpleAuthProviderClient.php'; require_once __DIR__ . '/Clients/AbortAfterHelloAuthProviderClient.php'; require_once __DIR__ . '/Clients/DisclosePublisherClient.php'; use Thruway\Logging\Logger; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; //Logger::set(new \Psr\Log\NullLogger()); $timeout = isset($argv[1]) ? $argv[1] : 0; $router = new Router(); $loop = $router->getLoop(); $authMgr = new \Thruway\Authentication\AuthenticationManager(); $router->setAuthenticationManager($authMgr); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authMgr)); //Provide authentication for the realm: 'testSimpleAuthRealm' $authProvClient = new SimpleAuthProviderClient(["testSimpleAuthRealm", "authful_realm"]); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authProvClient)); // provide aborting auth provider $authAbortAfterHello = new AbortAfterHelloAuthProviderClient(["abortafterhello"]); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authAbortAfterHello)); //////////////////// // Test stuff for Authorization $authorizationManager = new \Thruway\Authentication\AuthorizationManager('authorizing_realm'); $authorizingRealm = new \Thruway\Realm('authorizing_realm'); $authorizingRealm->setAuthorizationManager($authorizationManager); $router->getRealmManager()->addRealm($authorizingRealm); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authorizationManager)); // Create a realm with Authentication also
/** * Issue 53 - publishing inside of subscription event callback * prevents other internal clients from receiving the published event * * @depends testStart * @param \Thruway\Peer\Router $router */ public function testIssue53(\Thruway\Peer\Router $router) { $this->_callCount = 0; $transport1 = $this->getMockBuilder('\\Thruway\\Transport\\TransportInterface')->getMock(); $transport2 = $this->getMockBuilder('\\Thruway\\Transport\\TransportInterface')->getMock(); $transport2->expects($this->exactly(3))->method('sendMessage')->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\WelcomeMessage')], [$this->isInstanceOf('\\Thruway\\Message\\SubscribedMessage')], [$this->isInstanceOf('\\Thruway\\Message\\EventMessage')]); $transportPublisher = $this->getMockBuilder('\\Thruway\\Transport\\TransportInterface')->getMock(); $session1 = new \Thruway\Session($transport1); $session2 = new \Thruway\Session($transport2); $sessionPublisher = new \Thruway\Session($transportPublisher); $transport1->expects($this->exactly(3))->method('sendMessage')->withConsecutive([$this->isInstanceOf('\\Thruway\\Message\\WelcomeMessage')], [$this->isInstanceOf('\\Thruway\\Message\\SubscribedMessage')], [$this->callback(function ($arg) use($router, $transport1, $session1) { $this->assertInstanceOf('\\Thruway\\Message\\EventMessage', $arg); // publish while in the callback $publishMsg = new \Thruway\Message\PublishMessage(12346, (object) [], 'com.example.nowhere'); $session1->dispatchMessage($publishMsg); $this->_callCount = $this->_callCount + 1; return true; })]); $router->getEventDispatcher()->dispatch("connection_open", new \Thruway\Event\ConnectionOpenEvent($session1)); $router->getEventDispatcher()->dispatch("connection_open", new \Thruway\Event\ConnectionOpenEvent($session2)); $router->getEventDispatcher()->dispatch("connection_open", new \Thruway\Event\ConnectionOpenEvent($sessionPublisher)); // send in a few hellos $helloMsg = new \Thruway\Message\HelloMessage("realm_issue53", (object) []); $session1->dispatchMessage($helloMsg); $session2->dispatchMessage($helloMsg); $sessionPublisher->dispatchMessage($helloMsg); // subscribe $subscribeMsg = new \Thruway\Message\SubscribeMessage(\Thruway\Common\Utils::getUniqueId(), (object) [], "com.example.issue53"); $session1->dispatchMessage($subscribeMsg); $session2->dispatchMessage($subscribeMsg); // publish to the topic from the publishing transport $publishMsg = new \Thruway\Message\PublishMessage(12345, (object) [], 'com.example.issue53'); $sessionPublisher->dispatchMessage($publishMsg); }
<?php use SlackWamp\SlackClient; use Thruway\Peer\Router; use Thruway\Transport\PawlTransportProvider; use Thruway\Transport\RatchetTransportProvider; require '../vendor/autoload.php'; $token = 'your_slack_token'; //your slack token https://my.slack.com/services/new/bot $realm = 'realm1'; // WAMP Realm $uri = 'ws://127.0.0.1:9090/'; // WAMP Router URI $router = new Router(); $router->addTransportProvider(new RatchetTransportProvider("127.0.0.1", 9090)); $client = new SlackClient($token, $realm, $router->getLoop()); $client->addTransportProvider(new PawlTransportProvider($uri)); $client->start(false); $router->start();
<?php require "../bootstrap.php"; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $manager = new \Thruway\Manager\ManagerClient(); $loop = \React\EventLoop\Factory::create(); //$loop->addTimer(2, array($manager, "testSubscribe")); $router = new Router($loop, $manager); $transportProvider = new RatchetTransportProvider("127.0.0.1", 9090); $internalClientTransportProvider = new \Thruway\Transport\InternalClientTransportProvider($manager); $router->addTransportProvider($transportProvider); $router->addTransportProvider($internalClientTransportProvider); $router->start();
<?php require '../bootstrap.php'; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $router = new Router(); $transportProvider = new RatchetTransportProvider("127.0.0.1", 9090); $router->addTransportProvider($transportProvider); $router->getManager()->setQuiet(true); $router->start();
<?php require 'bootstrap.php'; require 'Clients/InternalClient.php'; require 'Clients/SimpleAuthProviderClient.php'; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $mgr = new \Thruway\Manager\ManagerDummy(); $mgr->setLogger(new \Thruway\ConsoleLogger()); $router = new Router(null, $mgr); $loop = $router->getLoop(); $authMgr = new \Thruway\Authentication\AuthenticationManager(); $router->setAuthenticationManager($authMgr); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authMgr)); //Provide authentication for the realm: 'testSimpleAuthRealm' $authProvClient = new SimpleAuthProviderClient(["testSimpleAuthRealm"]); $router->addTransportProvider(new \Thruway\Transport\InternalClientTransportProvider($authProvClient)); $transportProvider = new RatchetTransportProvider("127.0.0.1", 8080); $router->addTransportProvider($transportProvider); $theInternalClient = new InternalClient('testRealm', $loop); $theInternalClient->setRouter($router); $internalTransportProvider = new Thruway\Transport\InternalClientTransportProvider($theInternalClient); $router->addTransportProvider($internalTransportProvider); $router->start();
require_once __DIR__ . '/bootstrap.php'; require_once __DIR__ . '/Clients/InternalClient.php'; require_once __DIR__ . '/Clients/SimpleAuthProviderClient.php'; require_once __DIR__ . '/Clients/AbortAfterAuthenticateWithDetailsAuthProviderClient.php'; require_once __DIR__ . '/Clients/AbortAfterHelloAuthProviderClient.php'; require_once __DIR__ . '/Clients/AbortAfterHelloWithDetailsAuthProviderClient.php'; require_once __DIR__ . '/Clients/DisclosePublisherClient.php'; require_once __DIR__ . '/Clients/QueryParamAuthProviderClient.php'; require_once __DIR__ . '/UserDb.php'; use Thruway\Logging\Logger; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; //Logger::set(new \Psr\Log\NullLogger()); $timeout = isset($argv[1]) ? $argv[1] : 0; $router = new Router(); $loop = $router->getLoop(); //Create a WebSocket connection that listens on localhost port 8090 //$router->addTransportProvider(new RatchetTransportProvider("127.0.0.1", 8090)); $router->registerModules([new \Thruway\Authentication\AuthenticationManager(), new \Thruway\Authentication\AuthorizationManager('authorizing_realm'), new \Thruway\Authentication\AuthorizationManager("authful_realm"), new InternalClient('testRealm'), new DisclosePublisherClient('testSimpleAuthRealm'), new \Thruway\Subscription\StateHandlerRegistry('state.test.realm'), new RatchetTransportProvider("127.0.0.1", 8090), new \Thruway\Transport\RawSocketTransportProvider()]); //Provide authentication for the realm: 'testSimpleAuthRealm' $router->addInternalClient(new SimpleAuthProviderClient(["testSimpleAuthRealm", "authful_realm"])); // provide aborting auth provider $router->addInternalClient(new AbortAfterHelloAuthProviderClient(["abortafterhello"])); $router->addInternalClient(new AbortAfterHelloWithDetailsAuthProviderClient(["abortafterhellowithdetails"])); $router->addInternalClient(new AbortAfterAuthenticateWithDetailsAuthProviderClient(["aaawd"])); $router->addInternalClient(new QueryParamAuthProviderClient(["query_param_auth_realm"])); //////////////////////// //WAMP-CRA Authentication // setup some users to auth against $userDb = new UserDb();
<?php require "../bootstrap.php"; require 'SimpleAuthProviderClient.php'; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $router = new Router(); $router->registerModule(new \Thruway\Authentication\AuthenticationManager()); //Provide authentication for the realm: 'somerealm' $authProvClient = new SimpleAuthProviderClient(["somerealm"]); $router->addInternalClient($authProvClient); $router->registerModule(new RatchetTransportProvider("127.0.0.1", 9090)); $router->start();
<?php require "../bootstrap.php"; use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $router = new Router(); $router->registerModule(new RatchetTransportProvider("127.0.0.1", 9090)); $router->start();
<?php if (file_exists(__DIR__ . '/../../../autoload.php')) { require __DIR__ . '/../../../autoload.php'; } else { require __DIR__ . '/../vendor/autoload.php'; } use Thruway\Peer\Router; use Thruway\Transport\RatchetTransportProvider; $router = new Router(); $transportProvider = new RatchetTransportProvider("0.0.0.0", 6661); $router->addTransportProvider($transportProvider); $router->start();
/** * Invalid Empty Realm Name * * @depends testStart * @param \Thruway\Peer\Router $router * @return array */ public function testInvalidRealm(\Thruway\Peer\Router $router) { $transport = $this->getMock('Thruway\\Transport\\TransportInterface'); // Configure the stub. $transport->expects($this->any())->method('getTransportDetails')->will($this->returnValue(["type" => "ratchet", "transportAddress" => "127.0.0.1"])); $transport->expects($this->once())->method('sendMessage')->with($this->callback(function (\Thruway\Message\AbortMessage $msg) { $this->assertInstanceOf('\\Thruway\\Message\\AbortMessage', $msg); $this->assertEquals('wamp.error.no_such_realm', $msg->getResponseURI()); return $msg instanceof Thruway\Message\AbortMessage; }))->will($this->returnValue(null)); //Simulate onOpen $router->onOpen($transport); //Simulate a HelloMessage with an empty Realm $helloMessage = new \Thruway\Message\HelloMessage("", []); $router->onMessage($transport, $helloMessage); }