Socket IO | How to get the client transport type on the serverside?

后端 未结 7 789
梦谈多话
梦谈多话 2021-01-01 23:51

I need to know what transport method a client is using for some conditional statements on the nodeJS serverside.

Does anyone know how I can get that

7条回答
  •  爱一瞬间的悲伤
    2021-01-02 00:15

    I'm sure you can find it if you dig in the internals of a client object, although without knowing why you need this I have to recommend against this kind of check for 2 reasons:

    Firstly, since it isn't in the API the developers have absolutely no responsibility to keep things backward compatible, so any given version might implement/store that information differently, which will only ripple into your own development and cause problems.

    Secondly, and more importantly, I suggest you rethink your design, the communication with the server thru socket.io is built to be transparent to the method being used. There should be no difference on either side. That's the purpose of the library, designing an app that behaves otherwise is totally orthogonal to that idea.

提交回复
热议问题