Private
Public Access
1
0

working websocket client and server w/o session handling and storage

This commit is contained in:
2016-10-18 15:58:53 +02:00
parent 8578a94caf
commit fbfbe5a13b
9 changed files with 229 additions and 15 deletions

View File

@@ -0,0 +1,24 @@
# 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
router:
resources:
- "@MineSeekerBundle/Resources/config/pubsub/routing.yml"
client:
firewall: secured_area # Can be an array of firewalls
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
#

View File

@@ -0,0 +1,14 @@
# Topic Configuration
acme_topic:
channel: acme/channel
handler:
callback: 'acme.topic' #related to the getName() of your topic
# Remote Procedure Call Configuration
acme_rpc:
channel: sample/{method}
handler:
callback: 'acme.rpc' #related to the getName() or your RPC service
requirements:
method:
path: "[a-z_]+"

View File

@@ -2,3 +2,26 @@ services:
# mine_seeker.example:
# class: Mine\SeekerBundle\Example
# arguments: ["@service_id", "plain_value", %parameter%]
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 }
# gos_web_scocket.client_storage.driver.predis:
# class: Gos\Bundle\WebSocketBundle\Client\Driver\PredisDriver
# arguments:
# - "@cache.adapter.redis"
acme_hello.topic_sample_service:
class: Mine\SeekerBundle\Topic\AcmeTopic
tags:
- { name: gos_web_socket.topic }
# arguments:
# - { clientManipulator: "@gos_web_socket.websocket.client_manipulator" }
acme_hello.rpc_sample_service:
class: Mine\SeekerBundle\Rpc\AcmeRpc
tags:
- { name: gos_web_socket.rpc }

View File

@@ -2,14 +2,47 @@ import React from 'react';
import GridControl from './grid/grid-control';
class MineSeeker extends React.Component {
// /** after rendering */
// componentDidMount() {
// this.connection = new WebSocket('ws://127.0.0.1:8080');
//
// this.connection.onmessage = evt => {
// // console.log(evt.data);
// };
// }
/** after rendering */
componentDidMount() {
var websocket = WS.connect("ws://127.0.0.1:8080");
/** session is an Autobahn JS WAMP session. */
websocket.on("socket/connect", function (session) {
console.info("Successfully Connected!");
session.subscribe("acme/channel", function(uri, payload){
console.log("Received message", payload.msg);
});
// session.call("sample/sum", {"term1": 2, "term2": 5}).then(
// function (result) {
// console.log("RPC Valid!", result);
// },
// function (error, desc) {
// console.log("RPC Error", error, desc);
// }
// );
session.publish("acme/channel", {msg: "This is a message!"});
// session.publish("acme/channel", {msg: "I'm leaving, I will not see the next message"});
//
// session.unsubscribe("acme/channel");
//
// session.publish("acme/channel", {msg: "I won't see this"});
//
// session.subscribe("acme/channel", function (uri, payload) {
// console.log("Received message", payload.msg);
// });
//
// session.publish("acme/channel", {msg: "I'm back!"});
});
/** error provides us with some insight into the disconnection: error.reason and error.code */
websocket.on("socket/disconnect", function (error) {
console.info("Disconnected for " + error.reason + " with code " + error.code);
});
}
render() {
return (

View File

@@ -13,6 +13,7 @@
{% block javascripts %}
{{ parent() }}
{{ ws_client() }}
<script type="text/javascript" src="{{ asset('js/index.js') }}"></script>
{% endblock %}