Hi, I've broken this down as much as possible and now I'm at a loss as to why nothing happens when I use this parser. Perhaps it's me doing something silly...
My server code is as follows.
const parser = require('socket.io-json-parser');
const io = require('socket.io');
let server = io(8888, {
path: '/ws',
parser: parser
});
server.on('connection', (socket) => {
console.log('Socket Connection Connected');
socket.on('disconnect', function(){
console.log('Socket Connection Disconnected');
});
socket.on('checkPhone', (message) => {
console.log(message);
});
});
For arguments sake, this is what I'm emitting on the client side, just using the default parser:
this.socket.emit('checkPhone', JSON.stringify({phone_number: '123456'}));
If I remove the parser from the server options, then the message comes through without issue. If I use the parser in the above manner, nothing happens at all, not even an error.
Thanks in advance.
Node: 9.4.0 & 8.9.4
socket.io: 2.0.4
socket.io-json-parser: 2.1.0
EDIT:
Debug with json-parser:
engine intercepting request for path "/ws/" +2s
engine handling "GET" http request "/ws/?EIO=3&transport=polling&t=M603YX0" +0ms
engine handshaking client "AyIlfNnHwZwUZ3HiAAAC" +0ms
engine:socket sending packet "open" ({"sid":"AyIlfNnHwZwUZ3HiAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}) +0ms
engine:socket sending packet "message" ({"type":0,"nsp":"/"}) +1ms
engine:polling setting request +0ms
engine:socket flushing buffer to transport +0ms
engine:polling writing "97:0{"sid":"AyIlfNnHwZwUZ3HiAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}21:4{"type":0,"nsp":"/"}" +0ms
engine:socket executing batch send callback +0ms
socket.io:server incoming connection with id AyIlfNnHwZwUZ3HiAAAC +0ms
socket.io:client connecting to namespace / +0ms
socket.io:namespace adding socket to nsp / +1ms
socket.io:socket socket connected - writing packet +0ms
socket.io:socket joining room AyIlfNnHwZwUZ3HiAAAC +0ms
socket.io:socket packet already sent in initial handshake +0ms
Socket Connection Connected
socket.io:socket joined room AyIlfNnHwZwUZ3HiAAAC +0ms
engine intercepting request for path "/ws/" +295ms
engine handling "GET" http request "/ws/?EIO=3&transport=polling&t=M603Ybp&sid=AyIlfNnHwZwUZ3HiAAAC" +0ms
engine setting new request for existing client +0ms
engine:polling setting request +0ms
Debug without json-parser:
engine intercepting request for path "/ws/" +2s
engine handling "GET" http request "/ws/?EIO=3&transport=polling&t=M603sU5" +0ms
engine handshaking client "qAxWH0VClDsjT4e6AAAB" +0ms
engine:socket sending packet "open" ({"sid":"qAxWH0VClDsjT4e6AAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}) +0ms
engine:socket sending packet "message" (0) +0ms
engine:polling setting request +1ms
engine:socket flushing buffer to transport +0ms
engine:polling writing "97:0{"sid":"qAxWH0VClDsjT4e6AAAB","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}2:40" +0ms
engine:socket executing batch send callback +0ms
socket.io:server incoming connection with id qAxWH0VClDsjT4e6AAAB +2ms
socket.io:client connecting to namespace / +0ms
socket.io:namespace adding socket to nsp / +0ms
socket.io:socket socket connected - writing packet +1ms
socket.io:socket joining room qAxWH0VClDsjT4e6AAAB +0ms
socket.io:socket packet already sent in initial handshake +0ms
Socket Connection Connected
socket.io:socket joined room qAxWH0VClDsjT4e6AAAB +0ms
engine intercepting request for path "/ws/" +290ms
engine handling "POST" http request "/ws/?EIO=3&transport=polling&t=M603sYf&sid=qAxWH0VClDsjT4e6AAAB" +1ms
engine setting new request for existing client +0ms
engine:polling received "48:42["checkPhone","{\"phone_number\":\"123456\"}"]" +0ms
engine:socket packet +0ms
socket.io-parser decoded 2["checkPhone","{\"phone_number\":\"123456\"}"] as {"type":2,"nsp":"/","data":["checkPhone","{\"phone_number\":\"123456\"}"]} +0ms
socket.io:socket got packet {"type":2,"nsp":"/","data":["checkPhone","{\"phone_number\":\"123456\"}"]} +1ms
socket.io:socket emitting event ["checkPhone","{\"phone_number\":\"123456\"}"] +0ms
socket.io:socket dispatching an event ["checkPhone","{\"phone_number\":\"123456\"}"] +0ms
checkPhone
{"phone_number":"123456"}
engine intercepting request for path "/ws/" +0ms
engine handling "GET" http request "/ws/?EIO=3&transport=polling&t=M603sYg&sid=qAxWH0VClDsjT4e6AAAB" +0ms
engine setting new request for existing client +1ms
engine:polling setting request +0ms