PHP code example of tiitoo / symfony3-nodesjssocket

1. Go to this page and download the library: Download tiitoo/symfony3-nodesjssocket library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tiitoo / symfony3-nodesjssocket example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Reactorcoder\Symfony2NodesocketBundle\ReactorcoderSymfony2NodesocketBundle(),
        );

        // ...
    }

    // ...
}

reactorcoder_symfony2_nodesocket:
    host:   [yourhostname]                  # domain.ltd
    port:   [your port for node socket]     # 3001
    origin: [yourhostname]:*                # domain.ltd:*
    allowedServers: [127.0.0.1]             # separate with comma to add hosts
    dbOptions: null                         # 
    checkClientOrigin: null                 #
    sessionVarName: null                    #
    socketLogFile:  null                    # A log path file for process ID
    pidFile: null                           # runtime PID file

<head>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    {{ codereactor_nodesocket_css() }}
    {{ codereactor_nodesocket_header_js() }}
</head>

{{ codereactor_nodesocket_body_js() }}

    {{ codereactor_nodesocket_body_js() }}

    <script type="text/javascript">

        var socket = new NodeSocket();
        socket.debug(true);

        socket.onConnect(function () {
                console.log('Connection to socket successfully');
        });

        socket.onDisconnect(function () {
                console.log('On lost connection');
        });

        socket.on('message', function (data) {
                console.log('An event emit. Input data:');
                // Here you receive data from emits
                console.log(data);
        });

    </script>

use Reactorcoder\Symfony2NodesocketBundle\Library\php\NodeSocket as NodeSocket;

class DefaultController extends Controller
{
    $nodesocket = new NodeSocket;

    $event = $this->get('service_nodesocket')->getFrameFactory()->createAuthenticationFrame();
    $event->setUserId((int)1);  // Current UserID after login
    $event->send();

    return $this->render(...);  // This should be load assets from Step 6
}

    $event = $this->get('service_nodesocket')->getFrameFactory()->createEventFrame();
    $event->setEventName('message');
    $event['url'] = "uri";
    $event['time'] = date("d.m.Y H:i");
    $event['message'] = 'Hello';
    $event->send();

    $nodesocket = new NodeSocket;

    $event = $this->get('service_nodesocket')->getFrameFactory()->createEventFrame();
    $event->setUserId((int)2); // Send to another user
    $event->setEventName('message');
    $event['url'] = "uri";
    $event['time'] = date("d.m.Y H:i");
    $event['message'] = 'Hello';
    $event->send();