PHP code example of reactorcoder / symfony2-nodesocket
1. Go to this page and download the library: Download reactorcoder/symfony2-nodesocket 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/ */
reactorcoder / symfony2-nodesocket 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
{{ 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
}