socketio / socket.io-client-swift

Other
5.22k stars 843 forks source link

Sending header parameters only on initial connection. #911

Closed yilmazalican closed 6 years ago

yilmazalican commented 6 years ago

Hello. I'm designing a chat app in ios. i've designed a singleton class for the manager and socket. But the manager's extraHeaders options called on initial connection. Even changing the config of the manager to a new one does not effects.

class APISocket {
    private let manager = SocketManager(socketURL: URL(string:"http://172.27.101.123:4000")!)
    static let shared = APISocket()
    let socket:SocketIOClient
    private init(){
        self.socket = manager.defaultSocket
    }

    func establishConnection(token:String){
        if(self.socket.status != .connected){
            self.manager.config = SocketIOClientConfiguration(arrayLiteral: .compress,.connectParams(["Authorization": token]))
            self.socket.connect()
        }
    }

    func disconnectSocket(){
        if(self.socket.status == .connected){
            self.socket.disconnect()
        }
    }
nuclearace commented 6 years ago

Yes.. Unless you force polling, headers are only sent on the initial connection. Otherwise a websocket connection is established and they aren't sent again.

archerhan commented 6 years ago

Oh dude, this saved me!