socket.io-client-swift
socket.io-client-swift copied to clipboard
How to send auth parameters ?
Our server want to read parameter like this
EIO: '4',
transport: 'polling',
t: 'NmJJKTk'
},
auth: {
public: '<>',
access: '<>',
timestamp: <>
}```
In android socket io client there is parameter Auth
But I can't find one on iOS
and solution from other similar questions doesn't work for me
(that solution won't event compile)
other options with payload also didn't work somehow
I'm using latest client
Can anyone help me please ?
I've eventually figured this out so answering my own question:
this is working code:
chatSocketManager = SocketManager(socketURL: socketURL, config: [.log(true), .compress])
chatSocketManager.defaultSocket.on(clientEvent: .connect) {data, ack in
print("socket connected")
self.chatSocketManager.defaultSocket.joinNamespace()
}
let dict = [ "access" : accessToken,
"public": publicToken,
"timestamp" : "\(timeStamp)"]
chatSocketManager.defaultSocket.connect(withPayload: dict)
withPayload automatically wraps dict into auth:dict
I've eventually figured this out so answering my own question:
this is working code:
chatSocketManager = SocketManager(socketURL: socketURL, config: [.log(true), .compress]) chatSocketManager.defaultSocket.on(clientEvent: .connect) {data, ack in print("socket connected") self.chatSocketManager.defaultSocket.joinNamespace() } let dict = [ "access" : accessToken, "public": publicToken, "timestamp" : "\(timeStamp)"] chatSocketManager.defaultSocket.connect(withPayload: dict)
withPayload automatically wraps dict into
auth:dict
do use the latest Socket pod version? After I updated pods and Xcode to version 13 I dont have: connect(withPayload: ..) anymore ? Do you have that issue
Hi @Ant-Adis here is my pod file lock :
- Socket.IO-Client-Swift (16.0.1):
- Starscream (~> 4.0)
Could you post code you're trying to compile ?
@romaHerman I had to revert pod installs and currently Im using Socket IO through Package Dependencies, version: 16.0.1 next major, with this I dont have any issues
I've eventually figured this out so answering my own question:
this is working code:
chatSocketManager = SocketManager(socketURL: socketURL, config: [.log(true), .compress]) chatSocketManager.defaultSocket.on(clientEvent: .connect) {data, ack in print("socket connected") self.chatSocketManager.defaultSocket.joinNamespace() } let dict = [ "access" : accessToken, "public": publicToken, "timestamp" : "\(timeStamp)"] chatSocketManager.defaultSocket.connect(withPayload: dict)
withPayload automatically wraps dict into
auth:dict
@romaHerman withPayload automatically wraps dict into auth:dict -> Could you please let me know where you found this information? I checked the code and couldn't find any code that wraps the dictionary into an "auth" key. Thank you! 🙇♂️
Hey @kbw2204 I haven't that was trial and error process when I was trying different options and the backend team was telling me what they have on their end since Starscream library is used under the hood for sockets maybe it's somewhere there. I don't know
Ah, I see. I can check with the backend team to confirm. Thank you for your response! 🙇♂️