You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use this library with a subprotocol where the client and server have their own sequence ID. Both peers should be able to send requests and receive corresponding responses.
The problem I encounter:
The subprotocol is based on request-response pattern.
Imagine both peers use their own sequenceId to number their requests and both peers start with sequenceId = 1.
So it is possible, that both peers send a request with the same sequence ID at the same time. Now the client considers the request of the server as the response of its request and the real response of the server is dismissed.
This happens because the assignment of messages is only based on the sequence ID.
Feature Request:
Give the caller the opportunity to save additional data to every request so the assignment of messages is not only based on the sequence ID but on additional data.
Example:
Request opcode
Possible response opcodes
login
ack, nak
getProperties
properties, nak
...
...
If I send a login command and it gets the sequenceId = 34, I can save the possible response opcodes as additional data for that request and when I get a response matched by the sequenceId I can validate the response by checking if the response opcode matches ack or nak.
constwsp=newWebSocketAsPromised(wsUrl,{packMessage: data=>JSON.stringify(data),unpackMessage: data=>JSON.parse(data),attachRequestId: (data,requestId)=>Object.assign({id: requestId},data),// attach requestId to message as `id` fieldextractRequestId: data=>data&&data.id,// read requestId from message `id` fieldisPossibleResponse: (data,additionalData)=>additionalData.possibleResponses.includes(data.opcode)// <--- new parameter});wsp.sendRequest({foo: 'bar'},{requestId: 42,additionalData: {possibleResponses: ['ack','nak']}});
I want to use this library with a subprotocol where the client and server have their own sequence ID. Both peers should be able to send requests and receive corresponding responses.
The problem I encounter:
The subprotocol is based on request-response pattern.
Imagine both peers use their own
sequenceId
to number their requests and both peers start withsequenceId = 1
.So it is possible, that both peers send a request with the same sequence ID at the same time. Now the client considers the request of the server as the response of its request and the real response of the server is dismissed.
This happens because the assignment of messages is only based on the sequence ID.
Feature Request:
Give the caller the opportunity to save additional data to every request so the assignment of messages is not only based on the sequence ID but on additional data.
Example:
login
ack
,nak
getProperties
properties
,nak
If I send a
login
command and it gets thesequenceId = 34
, I can save the possible response opcodes as additional data for that request and when I get a response matched by thesequenceId
I can validate the response by checking if the response opcode matchesack
ornak
.I worked a bit on this idea in the following fork: https://github.com/PMalte/websocket-as-promised/tree/feature/bidirectional-subprotocols
The text was updated successfully, but these errors were encountered: