Example #1
1
<?php

/**
 * This file is part of the Elephant.io package
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 *
 * @copyright Wisembly
 * @license   http://www.opensource.org/licenses/MIT-License MIT License
 */
use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version1X;
require __DIR__ . '/../../../../vendor/autoload.php';
ini_set('display_errors', 1);
//$client = new Client(new Version1X('http://localhost:1337'));
$userId = 6;
$client = new Client(new Version1X('https://chat.vdomax.com:1314'));
$client->initialize();
$client->emit('Authenticate', ['userId' => $userId]);
// $client->on('Authenticate:Success', function($msg){
// 	print_r($msg);
// });
//$client->emit('broadcast', ['foo' => 'bar']);
$client->emit('notify', $_GET);
$client->close();
Example #2
0
 public function do_emit_message($message)
 {
     if (!$this->socket) {
         $this->do_create_socket();
     }
     $this->socket->emit('message', json_encode(['message' => $message, 'clientID' => $_REQUEST['data-socket']]));
 }
 public function sendMsg()
 {
     $room = request()->input('room');
     $msg = request()->input('msg');
     $url = url('/') . ":8080";
     $client = new Client(new Version1X($url));
     $client->initialize();
     if (trim($room) == '') {
         $client->emit('msgChatAllFromPHP', [$msg]);
     } else {
         $data = json_encode(['room' => $room, 'msg' => $msg]);
         $client->emit('msgChatGameFromPHP', [$data]);
     }
     $client->close();
     return redirect('integration_elephant_io');
 }
Example #4
0
 public function sendToken($token)
 {
     $client = new Client(new Version1X('http://localhost:8888'));
     $client->initialize();
     $client->emit('activeToken', ['tokenKey' => $token]);
     $client->close();
 }
Example #5
0
 public function send($event, array $message, $namespace = null)
 {
     $client = new Client(new IO($this->get_url));
     $client->initialize();
     if ($namespace) {
         $client->of($namespace);
     }
     $client->emit($event, $message);
     $client->close();
 }
 public static function emit($node, $message)
 {
     try {
         $url = config('emitter.host') . ':' . config('emitter.port');
         $client = new Client(new Version1X($url));
         $client->initialize();
         $client->emit($node, $message);
         $client->close();
     } catch (ServerConnectionFailureException $ex) {
         //\Log::alert('failed to connect socket io stream on '.$url);
         return false;
     }
     return true;
 }
Example #7
0
<?php

/**
 * This file is part of the Elephant.io package
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 *
 * @copyright Wisembly
 * @license   http://www.opensource.org/licenses/MIT-License MIT License
 */
use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version1X;
require __DIR__ . '/../../../../vendor/autoload.php';
$client = new Client(new Version1X('http://localhost:1337'));
$client->initialize();
$client->emit('broadcast', ['foo' => 'bar']);
$client->close();
Example #8
0
<?php

/**
 * This file is part of the Elephant.io package
 *
 * For the full copyright and license information, please view the LICENSE file
 * that was distributed with this source code.
 *
 * @copyright Wisembly
 * @license   http://www.opensource.org/licenses/MIT-License MIT License
 */
use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version0X;
require __DIR__ . '/../../../../vendor/autoload.php';
$client = new Client(new Version0X('http://localhost:1337'));
$client->initialize();
$client->emit('action', ['foo' => 'bar']);
$client->close();
Example #9
0
}
if (isset($_POST['join_server'])) {
    $ip = $_POST['servers'];
    setcookie('server_cookie', $ip, time() + 86400 * 30, '/');
    $username = $_COOKIE["user_cookie"];
    // If the selected server IS a turing server, use ElephantIO to pass the username and chip amount
    if (strpos($ip, 'http://192.168.1.101:') !== FALSE) {
        $client = new Client(new Version1X($ip));
        // This does not like it if you include the backslash at the end of the address!
        $sql = 'SELECT chipamount FROM users WHERE username = :username';
        $stmt = $db->prepare($sql);
        $stmt->bindParam(':username', $username);
        $stmt->execute();
        $chipAmount = $stmt->fetchColumn();
        $client->initialize();
        $client->emit('linkUsername', [$username, $chipAmount]);
        $client->emit('linkChipAmount', [$chipAmount]);
        $client->emit('disconnectLink', []);
        $client->close();
    }
    ?>
  <script>
    window.open("<?php 
    echo $ip;
    ?>
", '_blank','width=780,height=670');
  </script>
  <?php 
}
?>
<style>
Example #10
0
<?php

require __DIR__ . '/../lib/ElephantIO/Client.php';
use ElephantIO\Client as ElephantIOClient;
$elephant = new ElephantIOClient('http://localhost:8000', 'socket.io', 1, false, true, true);
$elephant->init();
$elephant->emit('action', 'foo');
$elephant->close();
echo 'tryin to send `foo` to the event called action';