created working session and client handler w/ websocket
This commit is contained in:
@@ -21,6 +21,8 @@ class AppKernel extends Kernel
|
||||
new FOS\UserBundle\FOSUserBundle(),
|
||||
new Gos\Bundle\WebSocketBundle\GosWebSocketBundle(),
|
||||
new Gos\Bundle\PubSubRouterBundle\GosPubSubRouterBundle(),
|
||||
new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
|
||||
new Snc\RedisBundle\SncRedisBundle(),
|
||||
|
||||
new Jotunheimr\AdminBundle\JotunheimrAdminBundle(),
|
||||
new Jotunheimr\UserBundle\JotunheimrUserBundle(),
|
||||
|
||||
@@ -29,7 +29,8 @@ framework:
|
||||
trusted_proxies: ~
|
||||
session:
|
||||
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
|
||||
handler_id: session.handler.native_file
|
||||
# handler_id: session.handler.native_file
|
||||
handler_id: session.handler.pdo
|
||||
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
|
||||
fragments: ~
|
||||
http_method_override: true
|
||||
|
||||
@@ -8,7 +8,7 @@ security:
|
||||
|
||||
providers:
|
||||
fos_userbundle:
|
||||
id: fos_user.user_provider.username
|
||||
id: fos_user.user_provider.username_email
|
||||
|
||||
firewalls:
|
||||
main:
|
||||
@@ -17,8 +17,6 @@ security:
|
||||
provider: fos_userbundle
|
||||
csrf_token_generator: security.csrf.token_manager
|
||||
default_target_path: /admin
|
||||
# if you are using Symfony < 2.8, use the following config instead:
|
||||
# csrf_provider: form.csrf_provider
|
||||
|
||||
logout: true
|
||||
anonymous: true
|
||||
@@ -28,3 +26,4 @@ security:
|
||||
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
||||
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
|
||||
- { path: ^/admin, role: ROLE_SUPER_ADMIN }
|
||||
# - { path: ^/, role: ROLE_SUPER_ADMIN }
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"symfony/symfony": "3.1.*",
|
||||
"doctrine/orm": "^2.5",
|
||||
"doctrine/doctrine-bundle": "^1.6",
|
||||
"doctrine/doctrine-cache-bundle": "^1.2",
|
||||
"doctrine/doctrine-cache-bundle": "^1.3",
|
||||
"symfony/swiftmailer-bundle": "^2.3",
|
||||
"symfony/monolog-bundle": "^2.8",
|
||||
"symfony/polyfill-apcu": "^1.0",
|
||||
@@ -31,7 +31,9 @@
|
||||
"gos/web-socket-bundle": "^1.8",
|
||||
"friendsofsymfony/user-bundle": "~2.0@dev",
|
||||
"doctrine/doctrine-migrations-bundle": "^1.0",
|
||||
"symfony/assetic-bundle": "^2.8"
|
||||
"symfony/assetic-bundle": "^2.8",
|
||||
"predis/predis": "^1.0",
|
||||
"snc/redis-bundle": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"sensio/generator-bundle": "^3.0",
|
||||
|
||||
137
composer.lock
generated
137
composer.lock
generated
@@ -4,8 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "c2ead293f3b494da909a8b7dceff7c40",
|
||||
"content-hash": "267bd32d13cbb40c3078bde5258afa5b",
|
||||
"hash": "7c1e046373c318178e58c9617d9c6931",
|
||||
"content-hash": "b09b605e8d336a4e0bf774ce6f486957",
|
||||
"packages": [
|
||||
{
|
||||
"name": "doctrine/annotations",
|
||||
@@ -961,12 +961,12 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/FriendsOfSymfony/FOSUserBundle.git",
|
||||
"reference": "9c64d6fa7ae264828b2ec98aca847840b200bd56"
|
||||
"reference": "4393a98891a03fb7628c546aee4e5ced699c83de"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/FriendsOfSymfony/FOSUserBundle/zipball/9c64d6fa7ae264828b2ec98aca847840b200bd56",
|
||||
"reference": "9c64d6fa7ae264828b2ec98aca847840b200bd56",
|
||||
"url": "https://api.github.com/repos/FriendsOfSymfony/FOSUserBundle/zipball/4393a98891a03fb7628c546aee4e5ced699c83de",
|
||||
"reference": "4393a98891a03fb7628c546aee4e5ced699c83de",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1030,7 +1030,7 @@
|
||||
"keywords": [
|
||||
"User management"
|
||||
],
|
||||
"time": "2016-10-14 20:44:45"
|
||||
"time": "2016-10-17 07:51:36"
|
||||
},
|
||||
{
|
||||
"name": "gos/pnctl-event-loop-emitter",
|
||||
@@ -1929,16 +1929,16 @@
|
||||
},
|
||||
{
|
||||
"name": "paragonie/random_compat",
|
||||
"version": "v2.0.2",
|
||||
"version": "v2.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/paragonie/random_compat.git",
|
||||
"reference": "088c04e2f261c33bed6ca5245491cfca69195ccf"
|
||||
"reference": "c0125896dbb151380ab47e96c621741e79623beb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/088c04e2f261c33bed6ca5245491cfca69195ccf",
|
||||
"reference": "088c04e2f261c33bed6ca5245491cfca69195ccf",
|
||||
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/c0125896dbb151380ab47e96c621741e79623beb",
|
||||
"reference": "c0125896dbb151380ab47e96c621741e79623beb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1973,7 +1973,57 @@
|
||||
"pseudorandom",
|
||||
"random"
|
||||
],
|
||||
"time": "2016-04-03 06:00:07"
|
||||
"time": "2016-10-17 15:23:22"
|
||||
},
|
||||
{
|
||||
"name": "predis/predis",
|
||||
"version": "v1.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nrk/predis.git",
|
||||
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
|
||||
"reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.9"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.8"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Allows access to Webdis when paired with phpiredis",
|
||||
"ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Predis\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniele Alessandri",
|
||||
"email": "suppakilla@gmail.com",
|
||||
"homepage": "http://clorophilla.net"
|
||||
}
|
||||
],
|
||||
"description": "Flexible and feature-complete Redis client for PHP and HHVM",
|
||||
"homepage": "http://github.com/nrk/predis",
|
||||
"keywords": [
|
||||
"nosql",
|
||||
"predis",
|
||||
"redis"
|
||||
],
|
||||
"time": "2016-06-16 16:22:20"
|
||||
},
|
||||
{
|
||||
"name": "psr/cache",
|
||||
@@ -2355,6 +2405,71 @@
|
||||
"description": "A security checker for your composer.lock",
|
||||
"time": "2016-09-23 18:09:57"
|
||||
},
|
||||
{
|
||||
"name": "snc/redis-bundle",
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/snc/SncRedisBundle.git",
|
||||
"reference": "b8aa1a966b32c4fba6b7dac4532d5eeb1d890afb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/snc/SncRedisBundle/zipball/b8aa1a966b32c4fba6b7dac4532d5eeb1d890afb",
|
||||
"reference": "b8aa1a966b32c4fba6b7dac4532d5eeb1d890afb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"symfony/framework-bundle": "^2.7 || ^3.0",
|
||||
"symfony/yaml": "^2.7 || ^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/cache": "1.*",
|
||||
"phpunit/phpunit": "4.8.*",
|
||||
"predis/predis": "^1.0",
|
||||
"symfony/console": "^2.7 || ^3.0",
|
||||
"symfony/phpunit-bridge": "^2.7 || ^3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"monolog/monolog": "If you want to use the monolog redis handler.",
|
||||
"predis/predis": "If you want to use predis.",
|
||||
"symfony/console": "If you want to use commands to interact with the redis database"
|
||||
},
|
||||
"type": "symfony-bundle",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Snc\\RedisBundle\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Henrik Westphal",
|
||||
"email": "henrik.westphal@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Community contributors",
|
||||
"homepage": "https://github.com/snc/SncRedisBundle/contributors"
|
||||
}
|
||||
],
|
||||
"description": "A Redis bundle for Symfony",
|
||||
"homepage": "https://github.com/snc/SncRedisBundle",
|
||||
"keywords": [
|
||||
"nosql",
|
||||
"redis",
|
||||
"symfony"
|
||||
],
|
||||
"time": "2016-06-17 11:50:26"
|
||||
},
|
||||
{
|
||||
"name": "swiftmailer/swiftmailer",
|
||||
"version": "v5.4.3",
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Mine\SeekerBundle\EventListener;
|
||||
|
||||
use Gos\Bundle\WebSocketBundle\Event\ClientEvent;
|
||||
use Gos\Bundle\WebSocketBundle\Event\ClientErrorEvent;
|
||||
use Gos\Bundle\WebSocketBundle\Event\ServerEvent;
|
||||
use Gos\Bundle\WebSocketBundle\Event\ClientRejectedEvent;
|
||||
|
||||
class AcmeClientEventListener
|
||||
{
|
||||
/**
|
||||
* Called whenever a client connects
|
||||
*
|
||||
* @param ClientEvent $event
|
||||
*/
|
||||
public function onClientConnect(ClientEvent $event)
|
||||
{
|
||||
$conn = $event->getConnection();
|
||||
|
||||
echo $conn->resourceId . " connected" . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a client disconnects
|
||||
*
|
||||
* @param ClientEvent $event
|
||||
*/
|
||||
public function onClientDisconnect(ClientEvent $event)
|
||||
{
|
||||
$conn = $event->getConnection();
|
||||
|
||||
echo $conn->resourceId . " disconnected" . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a client errors
|
||||
*
|
||||
* @param ClientErrorEvent $event
|
||||
*/
|
||||
public function onClientError(ClientErrorEvent $event)
|
||||
{
|
||||
$conn = $event->getConnection();
|
||||
$e = $event->getException();
|
||||
|
||||
echo "connection error occurred: " . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever server start
|
||||
*
|
||||
* @param ServerEvent $event
|
||||
*/
|
||||
public function onServerStart(ServerEvent $event)
|
||||
{
|
||||
$event = $event->getEventLoop();
|
||||
|
||||
echo 'Server was successfully started !' . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever client is rejected by application
|
||||
*
|
||||
* @param ClientRejectedEvent $event
|
||||
*/
|
||||
public function onClientRejected(ClientRejectedEvent $event)
|
||||
{
|
||||
$origin = $event->getOrigin;
|
||||
|
||||
echo 'connection rejected from ' . $origin . PHP_EOL;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,44 @@
|
||||
# PDO Session Handler Configuration !!!!! --> moved to main config.yml
|
||||
#framework:
|
||||
# session:
|
||||
# handler_id: session.handler.pdo
|
||||
|
||||
# Doctrine cache
|
||||
doctrine_cache:
|
||||
providers:
|
||||
redis_cache:
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 3
|
||||
websocket_cache_client:
|
||||
type: redis
|
||||
alias: gos_web_socket.client_storage.driver.redis
|
||||
|
||||
# SNC
|
||||
snc_redis:
|
||||
clients:
|
||||
cache:
|
||||
type: predis
|
||||
alias: cache
|
||||
dsn: redis://localhost/2
|
||||
logging: "%kernel.debug%"
|
||||
options:
|
||||
profile: 2.2
|
||||
connection_timeout: 10
|
||||
read_write_timeout: 30
|
||||
|
||||
# Web Socket Configuration
|
||||
gos_web_socket:
|
||||
# for user ex.: var _WS_URI = "ws://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}";
|
||||
shared_config: false
|
||||
server:
|
||||
port: 8080 # The port the socket server will listen on
|
||||
host: 127.0.0.1 # The host IP to bind to
|
||||
host: 0.0.0.0
|
||||
port: 8080
|
||||
router:
|
||||
resources:
|
||||
- "@MineSeekerBundle/Resources/config/pubsub/routing.yml"
|
||||
client:
|
||||
firewall: secured_area # Can be an array of firewalls
|
||||
firewall: main
|
||||
session_handler: "@session.handler.pdo"
|
||||
# storage:
|
||||
# driver: "@gos_web_socket.client_storage.driver.predis"
|
||||
# driver: "@gos_web_socket.server.in_memory.client_storage.driver"
|
||||
# ttl: 28800 # (optionally) time to live if you use redis driver
|
||||
# prefix: client # (optionally) prefix if you use redis driver, create key "client:1" instead key "1"
|
||||
|
||||
# PDO Session Handler Configuration
|
||||
framework:
|
||||
session:
|
||||
handler_id: session.handler.pdo
|
||||
#
|
||||
storage:
|
||||
driver: "@gos_web_socket.client_storage.driver.predis"
|
||||
decorator: "@gos_web_socket.client_storage.doctrine.decorator"
|
||||
|
||||
@@ -1,27 +1,48 @@
|
||||
services:
|
||||
# mine_seeker.example:
|
||||
# class: Mine\SeekerBundle\Example
|
||||
# arguments: ["@service_id", "plain_value", %parameter%]
|
||||
|
||||
pdo:
|
||||
class: PDO
|
||||
arguments:
|
||||
dsn: "mysql:host=%database_host%;dbname=%database_name%"
|
||||
user: "%database_user%"
|
||||
passwd: "%database_password%"
|
||||
calls:
|
||||
- [ setAttribute, [3, 2] ] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION
|
||||
|
||||
session.handler.pdo:
|
||||
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
|
||||
arguments:
|
||||
- "mysql:dbname=%database_name%"
|
||||
- { db_table: sessions, db_username: myuser, db_password: mypassword }
|
||||
public: false
|
||||
arguments: ["@pdo", {lock_mode: 0}]
|
||||
|
||||
# gos_web_scocket.client_storage.driver.predis:
|
||||
# class: Gos\Bundle\WebSocketBundle\Client\Driver\PredisDriver
|
||||
# arguments:
|
||||
# - "@cache.adapter.redis"
|
||||
# config.yml --> gos_web_socket > storage > client > driver
|
||||
gos_web_socket.client_storage.driver.predis:
|
||||
class: Gos\Bundle\WebSocketBundle\Client\Driver\PredisDriver
|
||||
arguments:
|
||||
- "@snc_redis.cache"
|
||||
|
||||
# config.yml --> gos_web_socket > storage > client > decorator
|
||||
gos_web_socket.client_storage.doctrine.decorator:
|
||||
class: Gos\Bundle\WebSocketBundle\Client\Driver\DoctrineCacheDriverDecorator
|
||||
arguments:
|
||||
- "@doctrine_cache.providers.doctrine.orm.default_result_cache"
|
||||
|
||||
acme_hello.topic_sample_service:
|
||||
class: Mine\SeekerBundle\Topic\AcmeTopic
|
||||
tags:
|
||||
- { name: gos_web_socket.topic }
|
||||
# arguments:
|
||||
# - { clientManipulator: "@gos_web_socket.websocket.client_manipulator" }
|
||||
arguments:
|
||||
clientManipulator: "@gos_web_socket.websocket.client_manipulator"
|
||||
|
||||
acme_hello.rpc_sample_service:
|
||||
class: Mine\SeekerBundle\Rpc\AcmeRpc
|
||||
tags:
|
||||
- { name: gos_web_socket.rpc }
|
||||
|
||||
gos_web_socket_server.client_event.listener:
|
||||
class: Mine\SeekerBundle\EventListener\AcmeClientEventListener
|
||||
tags:
|
||||
- { name: kernel.event_listener, event: 'gos_web_socket.client_connected', method: onClientConnect }
|
||||
- { name: kernel.event_listener, event: 'gos_web_socket.client_disconnected', method: onClientDisconnect }
|
||||
- { name: kernel.event_listener, event: 'gos_web_socket.client_error', method: onClientError }
|
||||
- { name: kernel.event_listener, event: 'gos_web_socket.server_launched', method: onServerStart }
|
||||
- { name: kernel.event_listener, event: 'gos_web_socket.client_rejected', method: onClientRejected }
|
||||
|
||||
@@ -4,7 +4,7 @@ import GridControl from './grid/grid-control';
|
||||
class MineSeeker extends React.Component {
|
||||
/** after rendering */
|
||||
componentDidMount() {
|
||||
var websocket = WS.connect("ws://127.0.0.1:8080");
|
||||
var websocket = WS.connect("ws://mine.dev:8080");
|
||||
|
||||
/** session is an Autobahn JS WAMP session. */
|
||||
websocket.on("socket/connect", function (session) {
|
||||
@@ -46,7 +46,8 @@ class MineSeeker extends React.Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<GridControl ref="gridControl"/>
|
||||
<div></div>
|
||||
// <GridControl ref="gridControl"/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Mine\SeekerBundle\Topic;
|
||||
|
||||
//use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface;
|
||||
use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface;
|
||||
use Gos\Bundle\WebSocketBundle\Topic\TopicInterface;
|
||||
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
|
||||
use Ratchet\ConnectionInterface;
|
||||
@@ -10,15 +10,18 @@ use Ratchet\Wamp\Topic;
|
||||
|
||||
class AcmeTopic implements TopicInterface
|
||||
{
|
||||
// protected $clientManipulator;
|
||||
//
|
||||
// /**
|
||||
// * @param ClientManipulatorInterface $clientManipulator
|
||||
// */
|
||||
// public function __construct(ClientManipulatorInterface $clientManipulator)
|
||||
// {
|
||||
// $this->clientManipulator = $clientManipulator;
|
||||
// }
|
||||
/** @var ClientManipulatorInterface */
|
||||
protected $clientManipulator;
|
||||
|
||||
/**
|
||||
* AcmeTopic constructor.
|
||||
*
|
||||
* @param $clientManipulator ClientManipulatorInterface
|
||||
*/
|
||||
public function __construct(ClientManipulatorInterface $clientManipulator)
|
||||
{
|
||||
$this->clientManipulator = $clientManipulator;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will receive any Subscription requests for this topic.
|
||||
@@ -30,12 +33,12 @@ class AcmeTopic implements TopicInterface
|
||||
*/
|
||||
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||
{
|
||||
// $user = $this->clientManipulator->getClient($connection);
|
||||
$user = "";
|
||||
//this will broadcast the message to ALL subscribers of this topic.
|
||||
/** this will broadcast the message to ALL subscribers of this topic. */
|
||||
$user = $this->clientManipulator->getClient($connection);
|
||||
dump($user);
|
||||
$topic->broadcast([
|
||||
'msg' => $connection->resourceId . " has joined " . $topic->getId(),
|
||||
'user' => $user
|
||||
'user' => $this->getName()
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -49,7 +52,9 @@ class AcmeTopic implements TopicInterface
|
||||
*/
|
||||
public function onUnSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
|
||||
{
|
||||
//this will broadcast the message to ALL subscribers of this topic.
|
||||
/** this will broadcast the message to ALL subscribers of this topic. */
|
||||
$user = $this->clientManipulator->getClient($connection);
|
||||
dump($user);
|
||||
$topic->broadcast(['msg' => $connection->resourceId . " has left " . $topic->getId()]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user