<?php /** * nRelay demo - Server Side */ session_start(); require __DIR__ . "/../vendor/autoload.php"; // Configuration of the nRelay server include __DIR__ . "/config.inc.php"; try { // Start new nRelay instance $s = new nRelay(NRLY_HOST, NRLY_PASS); // Get a userAccess on the channel 'demo' to pass to the views $userAccessHash = $s->allow(session_id(), "demo"); // Clean the object unset($s); } catch (Exception $e) { die("nRelay Error: nRelay Bridge seems to be offline."); } // Assign Template values $assignAry['{$NLRY_HOST}'] = NRLY_HOST; $assignAry['{$USER_HASH}'] = $userAccessHash; // Here is maybe the world's smallest template engine ! $html = file_get_contents(__DIR__ . "/assets/index.tpl"); foreach ($assignAry as $key => $value) { $html = str_replace($key, $value, $html); } // Send HTML to browser. echo $html;
<?php /** * nRelay Server - Server Broadcast Demo */ session_start(); require __DIR__ . "/../vendor/autoload.php"; include __DIR__ . "/config.inc.php"; // Bad call if (!isset($_GET['MSG']) || trim($_GET['MSG']) == "") { die("{result:false, error:'Message Could not be empty !'}"); } try { // Connect to the nRelay Server $s = new nRelay(NRLY_HOST, NRLY_SECRET); // Push the message to the "demo" channel with the action "say" $s->push($session_id(), "demo", "say", $msg); // Clean the object unset($s); } catch (Exception $e) { die("{result:false, error:'Socket Connexion error:<br /><b>" . $e->getMessage() . "</b>'}"); } // Everything is good echo "{result:true}";