I just ran into this issue using some older example. Here is the answer I found: Migrating 0.6 to 0.7+, which I reproduce below.
In v0.6, socket.send
would automatically convert an object like {a: 'b'}
to JSON. You would send data to a client with:
socket.send({a: 'b'});
While this is cool, it poses a fundamental problem. JSON not only encodes objects, but also strings, numbers, etc! So, the API is more clear if you explicitly state you want to pass JSON (since there's a performance penalty associated with encoding/decoding JSON).
In v0.7, use the json
flag:
socket.json.send({a: 'b'});
Now you can also emit and receive custom events between the browser and server:
socket.emit('my_event', {a: 'b'});
Arguments for events get encoded in JSON automatically for you.