feat: add awaitable socket.emit

v1.18.x
Barış Soner Uşaklı 5 years ago
parent 6e5de39ba0
commit 4083a6e39b

@ -17,6 +17,25 @@ app.isConnected = false;
socket = io(config.websocketAddress, ioParams);
var oEmit = socket.emit;
socket.emit = function (event, data, callback) {
if (typeof data === 'function') {
callback = data;
data = null;
}
if (typeof callback === 'function') {
oEmit.apply(socket, [event, data, callback]);
return;
}
return new Promise(function (resolve, reject) {
oEmit.apply(socket, [event, data, function (err, result) {
if (err) reject(err);
else resolve(result);
}]);
});
};
if (parseInt(app.user.uid, 10) >= 0) {
addHandlers();
}

Loading…
Cancel
Save