theturtle32 / WebSocket-Node

A WebSocket Implementation for Node.JS (Draft -08 through the final RFC 6455)
Apache License 2.0
3.75k stars 604 forks source link

protocol specification issue #269

Open d3x0r opened 7 years ago

d3x0r commented 7 years ago

while I did see just now, on npm package page "No API for user-provided protocol extensions."

there is some support for it.

however; you drop everything to lower case, and force me to think in your terms because you don't provide a reverse map always (or the wrong value, which should be the reverse mapped value).


on( 'request', (req)=> {
  req.resource,   //      '/gameState'
  req.requestedProtocols,    //  [ 'gundb' ]
  req.protocolFullCaseMap[req.requestedProtocols[0]]   // correctly cased 'gunDb'
  req.accept( req.requestedProtocols[0], null );    // have to pass lower case version
}

on( 'connect', (conn)=>{
    conn.protocol  
} )

resource is a useful, switable value, but is lost to the 'connect' event (it's not part of connection) you do pass protocol as part of the connection, but the protocol there is what was sent in the accept.

if I specify a single string protocol for the client, I receive an array that is one element; this is okay, for consistency. The strings in the array 'requestedProtocols' are always lower case. In order to get the correct capical case I have to pass it through protocolFullCaseMap.

When I accept() the connection I have to pass the lower case version, and the library apparenlty send the correctly cased one out. The 'connect' event receives the lower case version.

I also do not see a way to pass information between 'request' and 'connect' other than the selected protocol(?).... like the req object has no relation to the conn object

I don't think there's a guarantee that I will get a 'connect' for a webSockServer object always, after a 'request' that does an accept, before another 'request' ? or - is it possible to get two 'request' events without a 'connect' (assuming the request does an accept)

ibc commented 7 years ago

I don't think there's a guarantee that I will get a 'connect' for a webSockServer object always, after a 'request' that does an accept?

Yes, there is.

before another 'request' ?

Who cares? Of course you can get different WS connection requests at the same time.

Please, be specific in the issue you are requesting.

d3x0r commented 7 years ago

in the first case; I meant 'immediately' and/or not before another 'request'

I have to wait until 'connect' to attach on( 'message' ) so I don't know which handlers I should be using in connect, because I don't get the 'resource' from the 'request'

I can save the resource in the webSocketServer object from the 'request' and for the 'connect' to receive the resource; but, if connect doesn't finish before another request, then another request would of course overwrite that... I remember vaguely in the connection is the remote address; which could let me use that as a key in a map or something; but then multiple browsers from behind the same firewall connecting at the same time wouldn't be identifiable as to which 'request' this 'connect' was in response to.