Comparing version 0.0.3 to 0.0.4
@@ -17,8 +17,8 @@ | ||
Socket.prototype.emitAsync = function emitAsync(event, payload) { | ||
return new Promise((resolve, reject) => { | ||
return this.emit(event, payload, (...args) => { | ||
return new Promise(function(resolve, reject) { | ||
return this.emit(event, payload, function(...args) { | ||
if (args[0]) return reject(new Error(args[0])); | ||
return resolve.apply(null, args); | ||
}); | ||
}); | ||
}.bind(this)); | ||
}; | ||
@@ -31,3 +31,3 @@ | ||
const onDisconnect = () => { | ||
const onDisconnect = function() { | ||
clearTimeout(timeout); | ||
@@ -37,4 +37,4 @@ reject(new Error('Socket disconnected')); | ||
return new Promise((resolve, reject) => { | ||
this.emit(options.event, { method, data }, (res) => { | ||
return new Promise(function(resolve, reject) { | ||
this.emit(options.event, { method, data }, function(res) { | ||
clearTimeout(timeout); | ||
@@ -46,9 +46,9 @@ this.removeListener('disconnect', onDisconnect); | ||
resolve(res.data); | ||
}); | ||
}); | ||
}.bind(this)); | ||
}.bind(this)); | ||
timeout = setTimeout(() => { | ||
timeout = setTimeout(function() { | ||
this.removeListener('disconnect', onDisconnect); | ||
reject(new Error(`Socket request timeout: Exceeded ${options.timeout} msec`)); | ||
}, options.timeout); | ||
}.bind(this), options.timeout); | ||
@@ -62,12 +62,12 @@ this.once("disconnect", onDisconnect); | ||
this.on(options.event, (req, ack) => { | ||
this.on(options.event, function(req, ack) { | ||
if (req.method !== method) return; | ||
const res = (data) => { | ||
const res = function(data) { | ||
ack({ data }); | ||
}; | ||
res.error = (err) => { | ||
res.error = function(err) { | ||
ack({ error: JSON.stringify(err, replaceErrors)}); | ||
}; | ||
callback(req.data, res); | ||
}); | ||
}.bind(this)); | ||
}; | ||
@@ -74,0 +74,0 @@ |
28
index.js
@@ -17,8 +17,8 @@ | ||
Socket.prototype.emitAsync = function emitAsync(event, payload) { | ||
return new Promise((resolve, reject) => { | ||
return this.emit(event, payload, (...args) => { | ||
return new Promise(function (resolve, reject) { | ||
return this.emit(event, payload, function (...args) { | ||
if (args[0]) return reject(new Error(args[0])); | ||
return resolve.apply(null, args); | ||
}); | ||
}); | ||
}.bind(this)); | ||
}; | ||
@@ -31,3 +31,3 @@ | ||
const onDisconnect = () => { | ||
const onDisconnect = function() { | ||
clearTimeout(timeout); | ||
@@ -37,4 +37,4 @@ reject(new Error('Socket disconnected')); | ||
return new Promise((resolve, reject) => { | ||
this.emit(options.event, { method, data }, (res) => { | ||
return new Promise(function(resolve, reject) { | ||
this.emit(options.event, { method, data }, function(res) { | ||
clearTimeout(timeout); | ||
@@ -46,9 +46,9 @@ this.removeListener('disconnect', onDisconnect); | ||
resolve(res.data); | ||
}); | ||
}); | ||
}.bind(this)); | ||
}.bind(this)); | ||
timeout = setTimeout(() => { | ||
timeout = setTimeout(function() { | ||
this.removeListener('disconnect', onDisconnect); | ||
reject(new Error(`Socket request timeout: Exceeded ${options.timeout} msec`)); | ||
}, options.timeout); | ||
}.bind(this), options.timeout); | ||
@@ -62,12 +62,12 @@ this.once("disconnect", onDisconnect); | ||
this.on(options.event, (req, ack) => { | ||
this.on(options.event, function(req, ack) { | ||
if (req.method !== method) return; | ||
const res = (data) => { | ||
const res = function(data) { | ||
ack({ data }); | ||
}; | ||
res.error = (err) => { | ||
res.error = function(err) { | ||
ack({ error: JSON.stringify(err, replaceErrors)}); | ||
}; | ||
callback(req.data, res); | ||
}); | ||
}.bind(this)); | ||
}; | ||
@@ -74,0 +74,0 @@ |
{ | ||
"name": "usockets", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Universal socket.io wrapper with promise and request/response support", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10745