Generic Request/Response wrapper
const RequestResponseWrapper = require('@rainder/request-response-wrapper');
const wrapper = new class extends RequestResponseWrapper {
//implement a custom logic of writing data to the socket connection
send(data, connection) {
return connection.write(data);
}
// process request and return response
// .send(response) will be called on the same connection
onRequest(data) {
return Promise.resolve('response');
}
onPush(data) {
processPush(data);
}
}
socketServer.on('data', (data, connection) => {
wrapper.receive(data, connection);
});
See sample.js for example