@dwmt/comlink
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -119,2 +119,20 @@ import Cookies from 'js-cookie'; | ||
function _empty() {} | ||
function _awaitIgnored(value, direct) { | ||
if (!direct) { | ||
return value && value.then ? value.then(_empty) : Promise.resolve(); | ||
} | ||
} | ||
function _invoke(body, then) { | ||
var result = body(); | ||
if (result && result.then) { | ||
return result.then(then); | ||
} | ||
return then(result); | ||
} | ||
function generateUUID() { | ||
@@ -180,41 +198,46 @@ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | ||
connect: function connect() { | ||
if (self._channels[options.name].connection !== null) { | ||
return; | ||
} | ||
return new Promise(function (resolve, reject) { | ||
if (self._channels[options.name].connection !== null) { | ||
return resolve(); | ||
} | ||
var opts = []; | ||
var opts = []; | ||
if (options.auth) { | ||
var headerObject = self.getHeader(options.authHeader); | ||
opts.push(headerObject.value); | ||
} | ||
if (options.auth) { | ||
var headerObject = self.getHeader(options.authHeader); | ||
opts.push(headerObject.value); | ||
} | ||
var ws = new WebSocket(channel.protocol + channel.uri, opts); | ||
self._channels[options.name].connection = ws; | ||
ws.addEventListener('open', function () { | ||
self._channels[options.name].alive = true; | ||
}); | ||
ws.addEventListener('close', function () { | ||
self._channels[options.name].alive = false; | ||
}); | ||
ws.addEventListener('error', function () { | ||
self._channels[options.name].alive = false; | ||
}); | ||
var ws = new WebSocket(channel.protocol + channel.uri, opts); | ||
self._channels[options.name].connection = ws; | ||
ws.addEventListener('open', function () { | ||
self._channels[options.name].alive = true; | ||
console.log('Connection established'); | ||
resolve(); | ||
}); | ||
ws.addEventListener('close', function () { | ||
self._channels[options.name].alive = false; | ||
}); | ||
ws.addEventListener('error', function () { | ||
self._channels[options.name].alive = false; | ||
reject(); | ||
}); | ||
if (options.rpc) { | ||
ws.addEventListener('message', function (msg) { | ||
try { | ||
var tr = JSON.parse(msg.data); | ||
console.log("Socket message on channel ".concat(opts.name), tr); | ||
if (options.rpc) { | ||
ws.addEventListener('message', function (msg) { | ||
try { | ||
var tr = JSON.parse(msg.data); | ||
console.log("Socket message on channel ".concat(opts.name), tr); | ||
if (tr.id) { | ||
self._channels[options.name].answers[tr.id] = tr.result || { | ||
error: tr.error | ||
}; | ||
if (tr.id) { | ||
self._channels[options.name].answers[tr.id] = tr.result || { | ||
error: tr.error | ||
}; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
@@ -558,17 +581,23 @@ }; | ||
message = Object.assign({}, message, dialect["interface"], router, parameter, optioner); | ||
channel.connection.send(JSON.stringify(message)); | ||
return _await(retry(function () { | ||
return new Promise(function (resolve, reject) { | ||
if (!channel.answers[ID]) { | ||
return reject(new Error('')); | ||
return _invoke(function () { | ||
if (channel.connection === null) { | ||
return _awaitIgnored(channel.connect()); | ||
} | ||
}, function () { | ||
channel.connection.send(JSON.stringify(message)); | ||
return _await(retry(function () { | ||
return new Promise(function (resolve, reject) { | ||
if (!channel.answers[ID]) { | ||
return reject(new Error('')); | ||
} | ||
return resolve(channel.answers[ID]); | ||
}); | ||
}, rpcConfig.retryInterval, rpcConfig.maxRetries), function (answer) { | ||
if (answer.error) { | ||
throw new Error(answer.error); | ||
} | ||
return resolve(channel.answers[ID]); | ||
return answer; | ||
}); | ||
}, rpcConfig.retryInterval, rpcConfig.maxRetries), function (answer) { | ||
if (answer.error) { | ||
throw new Error(answer.error); | ||
} | ||
return answer; | ||
}); | ||
@@ -784,7 +813,7 @@ } catch (e) { | ||
function _empty() {} | ||
function _empty$1() {} | ||
function _continueIgnored(value) { | ||
if (value && value.then) { | ||
return value.then(_empty); | ||
return value.then(_empty$1); | ||
} | ||
@@ -791,0 +820,0 @@ } |
@@ -123,2 +123,20 @@ 'use strict'; | ||
function _empty() {} | ||
function _awaitIgnored(value, direct) { | ||
if (!direct) { | ||
return value && value.then ? value.then(_empty) : Promise.resolve(); | ||
} | ||
} | ||
function _invoke(body, then) { | ||
var result = body(); | ||
if (result && result.then) { | ||
return result.then(then); | ||
} | ||
return then(result); | ||
} | ||
function generateUUID() { | ||
@@ -184,41 +202,46 @@ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | ||
connect: function connect() { | ||
if (self._channels[options.name].connection !== null) { | ||
return; | ||
} | ||
return new Promise(function (resolve, reject) { | ||
if (self._channels[options.name].connection !== null) { | ||
return resolve(); | ||
} | ||
var opts = []; | ||
var opts = []; | ||
if (options.auth) { | ||
var headerObject = self.getHeader(options.authHeader); | ||
opts.push(headerObject.value); | ||
} | ||
if (options.auth) { | ||
var headerObject = self.getHeader(options.authHeader); | ||
opts.push(headerObject.value); | ||
} | ||
var ws = new WebSocket(channel.protocol + channel.uri, opts); | ||
self._channels[options.name].connection = ws; | ||
ws.addEventListener('open', function () { | ||
self._channels[options.name].alive = true; | ||
}); | ||
ws.addEventListener('close', function () { | ||
self._channels[options.name].alive = false; | ||
}); | ||
ws.addEventListener('error', function () { | ||
self._channels[options.name].alive = false; | ||
}); | ||
var ws = new WebSocket(channel.protocol + channel.uri, opts); | ||
self._channels[options.name].connection = ws; | ||
ws.addEventListener('open', function () { | ||
self._channels[options.name].alive = true; | ||
console.log('Connection established'); | ||
resolve(); | ||
}); | ||
ws.addEventListener('close', function () { | ||
self._channels[options.name].alive = false; | ||
}); | ||
ws.addEventListener('error', function () { | ||
self._channels[options.name].alive = false; | ||
reject(); | ||
}); | ||
if (options.rpc) { | ||
ws.addEventListener('message', function (msg) { | ||
try { | ||
var tr = JSON.parse(msg.data); | ||
console.log("Socket message on channel ".concat(opts.name), tr); | ||
if (options.rpc) { | ||
ws.addEventListener('message', function (msg) { | ||
try { | ||
var tr = JSON.parse(msg.data); | ||
console.log("Socket message on channel ".concat(opts.name), tr); | ||
if (tr.id) { | ||
self._channels[options.name].answers[tr.id] = tr.result || { | ||
error: tr.error | ||
}; | ||
if (tr.id) { | ||
self._channels[options.name].answers[tr.id] = tr.result || { | ||
error: tr.error | ||
}; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
@@ -562,17 +585,23 @@ }; | ||
message = Object.assign({}, message, dialect["interface"], router, parameter, optioner); | ||
channel.connection.send(JSON.stringify(message)); | ||
return _await(retry(function () { | ||
return new Promise(function (resolve, reject) { | ||
if (!channel.answers[ID]) { | ||
return reject(new Error('')); | ||
return _invoke(function () { | ||
if (channel.connection === null) { | ||
return _awaitIgnored(channel.connect()); | ||
} | ||
}, function () { | ||
channel.connection.send(JSON.stringify(message)); | ||
return _await(retry(function () { | ||
return new Promise(function (resolve, reject) { | ||
if (!channel.answers[ID]) { | ||
return reject(new Error('')); | ||
} | ||
return resolve(channel.answers[ID]); | ||
}); | ||
}, rpcConfig.retryInterval, rpcConfig.maxRetries), function (answer) { | ||
if (answer.error) { | ||
throw new Error(answer.error); | ||
} | ||
return resolve(channel.answers[ID]); | ||
return answer; | ||
}); | ||
}, rpcConfig.retryInterval, rpcConfig.maxRetries), function (answer) { | ||
if (answer.error) { | ||
throw new Error(answer.error); | ||
} | ||
return answer; | ||
}); | ||
@@ -788,7 +817,7 @@ } catch (e) { | ||
function _empty() {} | ||
function _empty$1() {} | ||
function _continueIgnored(value) { | ||
if (value && value.then) { | ||
return value.then(_empty); | ||
return value.then(_empty$1); | ||
} | ||
@@ -795,0 +824,0 @@ } |
{ | ||
"name": "@dwmt/comlink", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Communication library for lazy enthusiasts", | ||
@@ -5,0 +5,0 @@ "main": "dist/Comlink.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
52595
1568
0