E
E
EpicUsaMan2016-12-02 09:10:47
JavaScript
EpicUsaMan, 2016-12-02 09:10:47

Socketio dynamic namespace?

Is there a user friendly interface to quickly switch between namespaces in socket.io?
To do something like

//client side
var socket = io("http://addr");

socket.of("/finance").on("buy", function(msg) {
console.log(msg);
});

socket.of("/history").on("new", function(msg) {
console.log(msg);
});

$("#history").click(function() {
socket.namespace("/history");
});

$("#finance").click(function() {
socket.namespace("/finance");
});

//server side
var io = require('socket.io').listen(9090);
io.of("/finance").on("connection", function(socket) {
socket.emit("buy", {data: "abc"});
});

Basically the complexity for the client side, because I want to describe namespaces separately.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pshkll, 2016-12-02
@Pshkll

var socket = io('/my-namespace');
socket.io/docs/rooms-and-namespaces/#custom-namespaces

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question