New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom id_key function #29
Comments
Hi, David! Thank you for the good issue! If I understand well, it can be accomplished by either by
Also, I'd say that the API for this is quite full and would probably become over-complex if add some ability to identify a message that was sent that way. It's now just |
Hey. I did a smart workaround by playing with the encode/decode functions and adding a string with _ that I can then split. My API has 2 methods: full checks (super slow) and partial checks (kind of slow) I have a class that has this variable:
my encode/decode has this logic:
And i have these helper functions:
Then on the await of the send i do this logic:
This is working. The hardest part of this is that your encode/decode and send logic really MUST have the packNumbers id you generate so I had to come up with a way to keep that value on the decode else I would never get the data back (and you have no logging in these cases so I had to understand your source code to see what was wrong). I have another question though: Is it possible to get a specific timeout per send request, and not just a global timeout. Also I am not sure if this is a problem with your framework or my backend server, but its seems that he always replies to the requests sequentially. But your code should work regardless right? |
There is something wrong with the connections which Im having a hard time understanding. So this is the relevant part of my config:
Now check out these logs: 1 - sent request (very large payload) a LOT of time passes and nothing happens. (*) This is the interesting part, I received the message from request #1 I want to always receive the requests but I don't want to keep reconnecting when I don't have anything to send. |
Also, it's interesting to debug this in network tab in developer tools to see actual messages and their timings. So, you totally have no access to the server response ? To track them without any quirks. The library works fully asynchronously: regardless of outgoing messages order, they stay and wait for their responses together without any order, but you can manually stop them by your code, sort of: const data1 = await wsp.send(request1)
const data2 = await wsp.send(request2) // this won't work if previous is stuck. The idea of customizing config per message is interesting. Gonna think of it today, - maybe will add it and let you know! |
i cannot use ping because the server is not expecting an empty message. The network tab for web sockets only shows the first request, everything else is then hidden. I tried doing like this in the code: Are you sending requests before the web socket being open? Because that can cause problems from what I read on stackoverflow. |
if the connection closes (not by the user but just because) i believe it should just automatically open it again. I have some users that just decide to keep the page open for hours. But they are not really using anything.In that case doesn't it make sense to always reconnect right? I hate web sockets. |
The message can contain something.
Weird browser behaviour. Try another or check settings etc. After click on a WS connection it should show self-refreshing list of messages.
|
If you triggered Also, I was a bit wrong about Again about that case with messages tracking, you really have no access to server side to track them anyhow ? Also this lib is designed to fall in 💘 with them c: They are really cool if used properly. UPD: when |
But when the connection gets automatically disconnected. if i want to send a new request, shouldn't thee connection be automatically (by the framework) as well? |
Use |
Im trying to use ready but it doesnt work when the connection was closed (not by me) |
I see now o my previous client, before every send he checks if the connection is closed, and if it is he creates a new one. I can do something similar with a class getter and get the "wsp" instance and create a new one if the socket was closed |
Could you please tell what shows if write |
it seems you probably delete the socket reference when an on close happeens? There are two use cases here: The API user really wants to close the connection. I think its not so clear separation between these two use cases in the code and this is why this happens. |
https://github.com/houd1ni/WebsocketPromisify/blob/master/src/connectLib.ts#L56 here you should only set this stuff to null if it was force_close to true right? |
Im not sure if you saw this but the this.log('send') is not totally accurate, Thank you so much for taking your time in talking to me. |
Also the reconnect() timeout really isnt doing anything. I was expecting the following flow: close connection
but in the code you are listening to the socket 'close' option and you automatically reconnect and then add a timeout. Which is a bit counterintuitive (to me at least) that I was expecting. |
If close happens, this means,
It's too far from this issue topic, but why simply use
It will reconnect by itself. To be safe, just use
What is confusing exactly ?
What do you mean ?
You are right, - it's more like interval. Will change the corresponding documentation. Thanks! Btw, setting it to So, we have some suggestions: Reconnect by send() itself instead of manually check by
|
Reconnect by send() itself instead of manually check by ready(). Even by manually checking ready() it doesnt work. => send a message via websocket Make some configurable option that makes send() returning an object with additional data. |
This will be updated after #37 is done. |
Hey!
I am trying to use your framework but I already have my own custom id_key function which I NEED to use.
I basically use a spellchecker!
Imagine this flow:
text change #1 => websocket id_key 1
text change #2 => websocket id_key 2
websocket id_key 2 response
websocket id_key 1 response
Without any ability to manage my id_key the id_key 1 response is what is going to be saved on the interface. Which is wrong because it is outdated. It happens a lot of times that the server is slow and unpredictable to respond.
Therefore I need a way to discard "old" responses that I dont want.
I did this before by creating my own id_key with a simple JS date.toString().
But it can get even more wacky and crazy because I have several independent sentences that have different errors like so:
text change #1 on sentence #1 => websocket id_key 11
text change #2 on sentence #1 => websocket id_key 21
text change #1 on sentence #2 => websocket id_key 12
websocket id_key 21 response => i want this response
websocket id_key 12 response => i also want this one because it is from a different sentence
So I need a way to manage this complexity, and the way I do this is to have my very own custom identifier that i send to the server so that I can compare.
With your framework I need to use your message_id value that comes from the encode function and I have no way of managing this.
Can you help me out here?
Do you have any suggestions or alternatives that could help me with my use case?
TLDR: How can I ignore specific request responses based that are "older" that I no longer want to act on their response.
Im willing to talk a bit more if you think this kind of problem is interesting to you or If I am completely misunderstanding your framework.
The text was updated successfully, but these errors were encountered: