socket.io-client-swift icon indicating copy to clipboard operation
socket.io-client-swift copied to clipboard

Extract namespace and query parameters from SocketManager URL

Open alemannosara opened this issue 5 years ago • 5 comments

Hello,
I am trying to create an iOS app based on a Javascript web app. To initialize the connection in Javascript, I do: var socket = io("https://[...]/namespace?auth=[token]");.
I have tried to init the connection the same way in Swift: let manager = SocketManager(socketURL: URL(string: string)!, config: [.log(true)]), where string corresponds to the URL "https://[...]/namespace?auth=[token]". However, it seems that the library does not parse it such that

  • the path becomes the namespace;
  • the query parameters, like auth, become the connection parameters;

as in Javascript.

A potential solution is the following:

let manager = SocketManager(socketURL: URL(string: string)!, config: [.log(true), .connectParams(["auth": token])])
let socket = manager.socket(forNamespace: namespace)

However, in my case, the namespace depends on the path, which for technical reasons is not always the same. I was wondering whether and how I could integrate it with the query parameters in the URL, as in Javascript, to avoid manual parsing in the app.

Thank you in advance for your help !

alemannosara avatar Jun 29 '20 14:06 alemannosara

I am getting the same issue. please help me!

datpham96 avatar Jun 30 '20 03:06 datpham96

you folow https://stackoverflow.com/questions/48675629/swift-socket-io-connects-to-server-but-manager-and-engine-are-being-released @alemannosara

datpham96 avatar Jun 30 '20 06:06 datpham96

you folow https://stackoverflow.com/questions/48675629/swift-socket-io-connects-to-server-but-manager-and-engine-are-being-released @alemannosara

Thank you for the hint !
I am using socket.io to build up an API, without any view being loaded. The connection is alive and the engine is not released in my case. The main problem is that the server does not handle the events as it should due to the missing connection parameters (token) and namespace. Therefore, for now, I have to parse the URL.

alemannosara avatar Jun 30 '20 07:06 alemannosara

I had the same problem and spent significant time figuring out why I don't receive any data. It would be nice for the library to parse the supplied URL automatically like other socket.io clients do (java implementation for example). Or at least mention it and ideally add an example of it to the docs.

algrid avatar Oct 17 '23 13:10 algrid

Hello, I am trying to create an iOS app based on a Javascript web app. To initialize the connection in Javascript, I do: var socket = io("https://[...]/namespace?auth=[token]");. I have tried to init the connection the same way in Swift: let manager = SocketManager(socketURL: URL(string: string)!, config: [.log(true)]), where string corresponds to the URL "https://[...]/namespace?auth=[token]". However, it seems that the library does not parse it such that

  • the path becomes the namespace;
  • the query parameters, like auth, become the connection parameters;

as in Javascript.

A potential solution is the following:

let manager = SocketManager(socketURL: URL(string: string)!, config: [.log(true), .connectParams(["auth": token])])
let socket = manager.socket(forNamespace: namespace)

However, in my case, the namespace depends on the path, which for technical reasons is not always the same. I was wondering whether and how I could integrate it with the query parameters in the URL, as in Javascript, to avoid manual parsing in the app.

Thank you in advance for your help !

Thank you for your help, works for me! Just don't forget to include .path("/wss") in configuration, while creating instance of socket manager

iOSdev-klimov avatar Mar 15 '24 05:03 iOSdev-klimov