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
Server fails with error after client emitted event #2
Comments
Thanks for submitting a bug report. It's crazy because I see nothing wrong with your code, and when I tested it, it worked properly. One thing I noticed was your error message: The following code will fail, for example: const socket = new WebSocketWrapper(new WebSocket('ws://localhost:3000'))
var obj = {};
obj.hello = "world";
obj.myself = obj; // Don't do this!
socket.emit('echo-me', obj) |
If you're still having trouble, you are welcome to post back here with more code, and I'd be happy to help. It's cool to see others using this lib. Best of luck! Closing this issue for now. Please feel free to re-open if needed. EDIT: The source of this issue is documented below: wss.on("connection", (rawSocket) => {
const socket = new WebSocketWrapper(rawSocket)
// The following line it what is causing this Error
socket.name = `Socket${Math.random()}`;
socket.on('echo', (data) => {
console.log('Echo', data, socket.name)
})
}); |
@bminer Thanks for looking into this! In fact I didn't pass anything to |
Sure thing. If you'd like to send me more code, I can try to point you in the right direction. I'm at a loss at the moment. If you'd prefer, we can take this "offline". My email address is here: https://github.com/bminer |
@bminer I hid some information which I thought was irrelevant to the issue. Here is the repro I made: OEvgeny/ws-wrapper-example Please take a look at this line which causes original issue. It was a bit surprising to me 😄 |
Also I noticed there are no any tests yet. If you have any preferences just let me know. But I'm not sure I'll have any time to contribute in near future. |
Thanks for posting. I didn't realize it was the server that was crashing with a TypeError. Sorry for glossing over that detail. When you set the The best solution to this problem is to use the const WebSocketServer = require('ws').Server
const WebSocketWrapper = require('ws-wrapper')
const wss = new WebSocketServer({port: 3000})
wss.on('connection', (rawSocket) => {
const socket = new WebSocketWrapper(rawSocket)
// Use `set` method to store custom data on the Socket (this is always safe)
socket.set('name', `Socket${Math.random()}`)
socket.on('echo', (data) => {
console.log('Echo', data, socket.name)
socket.emit('echo', data)
})
}); |
A few side notes (not related to this issue):
|
Thanks for the information. All of these tips are very useful! As for original issue I have an idea. Looks like it is possible to make produced by WebSocketWrapper constructor object frozen. Which will make error message more cleaner. |
Really good idea. I will open an issue for that! |
I faced with strange issue using
ws-wrapper
. After client emits something server just fails with this error:Client (in browser)
Server
As you can see server just emits nothing.
I'm trying to isolate issue to give you a cleaner reproduction. For some reason I can't reproduce it with node clients.
The text was updated successfully, but these errors were encountered: