Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Can't connect to namespace on specified socket #1029

Closed
1 task done
NagRock opened this issue Nov 24, 2016 · 1 comment
Closed
1 task done

Can't connect to namespace on specified socket #1029

NagRock opened this issue Nov 24, 2016 · 1 comment

Comments

@NagRock
Copy link

NagRock commented Nov 24, 2016

You want to:

  • report a bug

Current behaviour

As documentation says, to connect to namespace i should use:
var socket = io('/my-namespace');

But since io (or connect) method is global I can't specify on which socket I want to connect to namespace. For example:

var firstSocket = io('localhost');
var secondSocket = io('localhost');
var namespace = io('localhost/myNamespace');

I can't define if myNamespace connection should go through first or second socket.

Expected behaviour

I think it should be like that:

var firstSocket = io('localhost');
var secondSocket = io('localhost');
var firstSocketNamespace = firstSocket.connectNamespace('myNamespace');
var secondSocketNamespace = secondSocket.connectNamespace('myNamespace');

@darrachequesne
Copy link
Member

For future readers:

const io = require("socket.io-client");

const socket = io("ws://example.com/my-namespace", {
  reconnectionDelayMax: 10000,
  query: {
    "my-key": "my-value"
  },
  auth: {
    token: "123"
  }
});

is the short form of:

const { Manager } = require("socket.io-client");

const manager = new Manager("ws://example.com", {
  reconnectionDelayMax: 10000,
  query: {
    "my-key": "my-value"
  }
});

const socket = manager.socket("/my-namespace", {
  auth: {
    token: "123"
  }
});

The latter makes the creation of the Manager (which manages the low-level connection) explicit.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants