Ejemplo n.º 1
1
function go($message)
{
    $S = anyC::getFirst("Websocket", "WebsocketUseFor", "fheME");
    $realm = $S->A("WebsocketRealm");
    spl_autoload_unregister("phynxAutoloader");
    require Util::getRootPath() . 'PWS/Thruway/vendor/autoload.php';
    if (!class_exists("ClientPhimAuthenticator", false)) {
        Thruway\Logging\Logger::set(new Psr\Log\NullLogger());
        class ClientPhimAuthenticator implements Thruway\Authentication\ClientAuthenticationInterface
        {
            private $authID;
            private $key;
            private $realm;
            function __construct($realm, $authID, $key)
            {
                $this->authID = $authID;
                $this->key = $key;
                $this->realm = $realm;
            }
            public function getAuthId()
            {
                return $this->authID;
            }
            public function setAuthId($authid)
            {
            }
            public function getAuthMethods()
            {
                return ["phimAuth_" . $this->realm];
            }
            public function getAuthenticateFromChallenge(Thruway\Message\ChallengeMessage $msg)
            {
                return new \Thruway\Message\AuthenticateMessage($this->key);
            }
        }
    }
    $connection = new \Thruway\Connection(["realm" => $realm, "url" => "ws" . ($S->A("WebsocketSecure") ? "s" : "") . "://" . $S->A("WebsocketServer") . ":" . $S->A("WebsocketServerPort") . "/"]);
    $client = $connection->getClient();
    $client->addClientAuthenticator(new ClientPhimAuthenticator($realm, "phimUser", $S->A("WebsocketToken")));
    $connection->on('open', function (\Thruway\ClientSession $session) use($connection, $message) {
        $session->publish('it.furtmeier.fheme', [json_encode($message, JSON_UNESCAPED_UNICODE)], [], ["acknowledge" => true])->then(function () use($connection) {
            $connection->close();
        }, function ($connection) {
            $connection->close();
        });
    });
    $connection->open();
    #spl_autoload_unregister(array("ThruwayLoader", "alienClassLoader"));
    #spl_autoload_register("phynxAutoloader");
}
Ejemplo n.º 2
0
 private function go($message, $to)
 {
     $S = anyC::getFirst("Websocket", "WebsocketUseFor", "phim");
     $realm = $S->A("WebsocketRealm");
     spl_autoload_unregister("phynxAutoloader");
     require Util::getRootPath() . 'PWS/Thruway/vendor/autoload.php';
     require_once __DIR__ . '/ClientPhimAuthenticator.php';
     Thruway\Logging\Logger::set(new Psr\Log\NullLogger());
     $connection = new \Thruway\Connection(["realm" => $realm, "url" => "ws" . ($S->A("WebsocketSecure") ? "s" : "") . "://" . $S->A("WebsocketServer") . ":" . $S->A("WebsocketServerPort") . "/"]);
     $client = $connection->getClient();
     $client->addClientAuthenticator(new ClientPhimAuthenticator($realm, "phimUser", $S->A("WebsocketToken")));
     $connection->on('open', function (\Thruway\ClientSession $session) use($connection, $message, $to) {
         $session->publish('it.furtmeier.phim_' . $to, [json_encode($message, JSON_UNESCAPED_UNICODE)], [], ["acknowledge" => true])->then(function () use($connection) {
             $connection->close();
         }, function ($connection) {
             $connection->close();
         });
     });
     $connection->open();
     /*$client = new Thruway\Peer\Client($realm);
     		$client->addClientAuthenticator(new ClientPhimAuthenticator($realm, "phimUser", $S->A("WebsocketToken")));
     		
     		$client->addTransportProvider(new Thruway\Transport\PawlTransportProvider("ws".($S->A("WebsocketSecure") ? "s" : "")."://".$S->A("WebsocketServer").":".$S->A("WebsocketServerPort")."/"));
     
     		$client->on('open', function (Thruway\ClientSession $session) use ($message, $to) {
     
     			$session->publish('it.furtmeier.phim_'.$to, [json_encode($message, JSON_UNESCAPED_UNICODE)], [], ["acknowledge" => true])->then(
     				function () {
     					echo "Publish Acknowledged!\n";
     					die();
     				},
     				function ($error) {
     					// publish failed
     					echo "Publish Error {$error}\n";
     				}
     			);
     
     			//$session->close();
     		});
     
     
     		$client->start();*/
 }