@dwmt/comlink
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -0,1 +1,2 @@ | ||
const json = require('@rollup/plugin-json') | ||
module.exports = { | ||
@@ -5,3 +6,6 @@ input: 'src/Comlink.js', | ||
dir: 'dist' | ||
}, | ||
plugins: { | ||
json: json() | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
import { inherits } from 'util'; | ||
import Cookies from 'js-cookie'; | ||
@@ -26,3 +27,3 @@ import axios from 'axios'; | ||
CookieStorage.prototype = Storage.prototype; | ||
inherits(CookieStorage, Storage); | ||
@@ -41,2 +42,25 @@ CookieStorage.prototype.getItem = function (key) { | ||
function NodeStorage() { | ||
this._store = {}; | ||
} | ||
inherits(NodeStorage, Storage); | ||
NodeStorage.prototype.getItem = function (key) { | ||
return this._store[key] || null; | ||
}; | ||
NodeStorage.prototype.setItem = function (key, value, options) { | ||
this._store[key] = value; | ||
return undefined; | ||
}; | ||
NodeStorage.prototype.removeItem = function (key, options) { | ||
delete this._store[key]; | ||
}; | ||
NodeStorage.prototype.clear = function () { | ||
this._store = {}; | ||
}; | ||
var LocalStorage = typeof window !== 'undefined' ? window.localStorage : Storage; | ||
@@ -47,3 +71,4 @@ var SessionStorage = typeof window !== 'undefined' ? window.sessionStorage : Storage; | ||
SessionStorage: SessionStorage, | ||
CookieStorage: new CookieStorage() | ||
CookieStorage: new CookieStorage(), | ||
NodeStorage: new NodeStorage() | ||
}; | ||
@@ -200,2 +225,3 @@ | ||
return { | ||
type: 'http', | ||
name: options.name, | ||
@@ -221,2 +247,3 @@ protocol: options.ssl ? 'https://' : 'http://', | ||
var channel = { | ||
type: 'ws', | ||
name: options.name, | ||
@@ -263,3 +290,3 @@ protocol: options.ssl ? 'wss://' : 'ws://', | ||
if (self._channels[options.name].connection !== null) { | ||
return resolve(); | ||
return resolve(true); | ||
} | ||
@@ -283,3 +310,3 @@ | ||
resolve(); | ||
resolve(true); | ||
}); | ||
@@ -300,3 +327,3 @@ ws.addEventListener('close', function () { | ||
reject(); | ||
reject(err); | ||
}); | ||
@@ -320,3 +347,2 @@ | ||
if (tr._type === 'event') { | ||
console.log('Server event...', tr); | ||
var eventSubscribers = self._channels[options.name].listeners[tr.event]; | ||
@@ -379,2 +405,24 @@ | ||
_createClass(Client, [{ | ||
key: "connect", | ||
value: function connect() { | ||
try { | ||
var _this2 = this; | ||
var connecting = []; | ||
for (var _i = 0, _Object$keys = Object.keys(_this2._channels); _i < _Object$keys.length; _i++) { | ||
var channelName = _Object$keys[_i]; | ||
var channel = _this2._channels[channelName]; | ||
if (channel.type === 'ws' && !channel.alive) { | ||
connecting.push(channel.connect()); | ||
} | ||
} | ||
return Promise.all(connecting); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
}, { | ||
key: "channel", | ||
@@ -475,7 +523,7 @@ value: function channel(channelName) { | ||
value: function checkHeaders() { | ||
var _this = this; | ||
var _this3 = this; | ||
var headers = Object.keys(this._headers); | ||
headers.forEach(function (headerKey) { | ||
var header = _this._headers[headerKey]; | ||
var header = _this3._headers[headerKey]; | ||
@@ -522,8 +570,8 @@ if (header.type === 'automatic') { | ||
try { | ||
var _this3 = this; | ||
var _this5 = this; | ||
_this3.checkDefaultHTTPChannel(); | ||
_this5.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this3._deafultHTTPChannel; | ||
var channel = _this3._channels[channelName]; | ||
var channelName = options.channel || _this5._deafultHTTPChannel; | ||
var channel = _this5._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -574,8 +622,8 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this5 = this; | ||
var _this7 = this; | ||
_this5.checkDefaultHTTPChannel(); | ||
_this7.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this5._deafultHTTPChannel; | ||
var channel = _this5._channels[channelName]; | ||
var channelName = options.channel || _this7._deafultHTTPChannel; | ||
var channel = _this7._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -619,8 +667,8 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this7 = this; | ||
var _this9 = this; | ||
_this7.checkDefaultHTTPChannel(); | ||
_this9.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this7._deafultHTTPChannel; | ||
var channel = _this7._channels[channelName]; | ||
var channelName = options.channel || _this9._deafultHTTPChannel; | ||
var channel = _this9._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -664,8 +712,8 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this9 = this; | ||
var _this11 = this; | ||
_this9.checkDefaultHTTPChannel(); | ||
_this11.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this9._deafultHTTPChannel; | ||
var channel = _this9._channels[channelName]; | ||
var channelName = options.channel || _this11._deafultHTTPChannel; | ||
var channel = _this11._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -747,6 +795,6 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this11 = this; | ||
var _this13 = this; | ||
var channel = _this11._channels[options.channel || _this11._deafultRPCChannel]; | ||
var dialect = _this11._dialects[_dialect || _this11._defaultDialect]; | ||
var channel = _this13._channels[options.channel || _this13._deafultRPCChannel]; | ||
var dialect = _this13._dialects[_dialect || _this13._defaultDialect]; | ||
var rpcConfig = channel.rpc; | ||
@@ -804,6 +852,6 @@ | ||
try { | ||
var _this13 = this; | ||
var _this15 = this; | ||
var channelName = options.channel || _this13._deafultRPCChannel; | ||
var channel = _this13._channels[channelName]; | ||
var channelName = options.channel || _this15._deafultRPCChannel; | ||
var channel = _this15._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -818,3 +866,3 @@ var errorHandler = options.onError || channel.onError; | ||
} else { | ||
return _this13._rpc('request', path, data, options, _dialect); | ||
return _this15._rpc('request', path, data, options, _dialect); | ||
} | ||
@@ -842,6 +890,6 @@ }, function (err) { | ||
try { | ||
var _this15 = this; | ||
var _this17 = this; | ||
var channelName = options.channel || _this15._deafultRPCChannel; | ||
var channel = _this15._channels[channelName]; | ||
var channelName = options.channel || _this17._deafultRPCChannel; | ||
var channel = _this17._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -856,3 +904,3 @@ var errorHandler = options.onError || channel.onError; | ||
} else { | ||
return _this15._rpc('inform', path, data, options, _dialect); | ||
return _this17._rpc('inform', path, data, options, _dialect); | ||
} | ||
@@ -872,2 +920,13 @@ }, function (err) { | ||
} | ||
}, { | ||
key: "channels", | ||
get: function get() { | ||
var channels = Object.keys(this._channels); | ||
return channels || []; | ||
} | ||
}, { | ||
key: "headers", | ||
get: function get() { | ||
return Object.keys(this._headers); | ||
} | ||
}]); | ||
@@ -1149,8 +1208,11 @@ | ||
var version = "1.1.2"; | ||
var Comlink = { | ||
Client: Client, | ||
Server: Server, | ||
Storage: Storage$1 | ||
Storage: Storage$1, | ||
version: version | ||
}; | ||
export default Comlink; |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var util = require('util'); | ||
var Cookies = _interopDefault(require('js-cookie')); | ||
@@ -31,3 +32,3 @@ var axios = _interopDefault(require('axios')); | ||
CookieStorage.prototype = Storage.prototype; | ||
util.inherits(CookieStorage, Storage); | ||
@@ -46,2 +47,25 @@ CookieStorage.prototype.getItem = function (key) { | ||
function NodeStorage() { | ||
this._store = {}; | ||
} | ||
util.inherits(NodeStorage, Storage); | ||
NodeStorage.prototype.getItem = function (key) { | ||
return this._store[key] || null; | ||
}; | ||
NodeStorage.prototype.setItem = function (key, value, options) { | ||
this._store[key] = value; | ||
return undefined; | ||
}; | ||
NodeStorage.prototype.removeItem = function (key, options) { | ||
delete this._store[key]; | ||
}; | ||
NodeStorage.prototype.clear = function () { | ||
this._store = {}; | ||
}; | ||
var LocalStorage = typeof window !== 'undefined' ? window.localStorage : Storage; | ||
@@ -52,3 +76,4 @@ var SessionStorage = typeof window !== 'undefined' ? window.sessionStorage : Storage; | ||
SessionStorage: SessionStorage, | ||
CookieStorage: new CookieStorage() | ||
CookieStorage: new CookieStorage(), | ||
NodeStorage: new NodeStorage() | ||
}; | ||
@@ -205,2 +230,3 @@ | ||
return { | ||
type: 'http', | ||
name: options.name, | ||
@@ -226,2 +252,3 @@ protocol: options.ssl ? 'https://' : 'http://', | ||
var channel = { | ||
type: 'ws', | ||
name: options.name, | ||
@@ -268,3 +295,3 @@ protocol: options.ssl ? 'wss://' : 'ws://', | ||
if (self._channels[options.name].connection !== null) { | ||
return resolve(); | ||
return resolve(true); | ||
} | ||
@@ -288,3 +315,3 @@ | ||
resolve(); | ||
resolve(true); | ||
}); | ||
@@ -305,3 +332,3 @@ ws.addEventListener('close', function () { | ||
reject(); | ||
reject(err); | ||
}); | ||
@@ -325,3 +352,2 @@ | ||
if (tr._type === 'event') { | ||
console.log('Server event...', tr); | ||
var eventSubscribers = self._channels[options.name].listeners[tr.event]; | ||
@@ -384,2 +410,24 @@ | ||
_createClass(Client, [{ | ||
key: "connect", | ||
value: function connect() { | ||
try { | ||
var _this2 = this; | ||
var connecting = []; | ||
for (var _i = 0, _Object$keys = Object.keys(_this2._channels); _i < _Object$keys.length; _i++) { | ||
var channelName = _Object$keys[_i]; | ||
var channel = _this2._channels[channelName]; | ||
if (channel.type === 'ws' && !channel.alive) { | ||
connecting.push(channel.connect()); | ||
} | ||
} | ||
return Promise.all(connecting); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
} | ||
}, { | ||
key: "channel", | ||
@@ -480,7 +528,7 @@ value: function channel(channelName) { | ||
value: function checkHeaders() { | ||
var _this = this; | ||
var _this3 = this; | ||
var headers = Object.keys(this._headers); | ||
headers.forEach(function (headerKey) { | ||
var header = _this._headers[headerKey]; | ||
var header = _this3._headers[headerKey]; | ||
@@ -527,8 +575,8 @@ if (header.type === 'automatic') { | ||
try { | ||
var _this3 = this; | ||
var _this5 = this; | ||
_this3.checkDefaultHTTPChannel(); | ||
_this5.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this3._deafultHTTPChannel; | ||
var channel = _this3._channels[channelName]; | ||
var channelName = options.channel || _this5._deafultHTTPChannel; | ||
var channel = _this5._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -579,8 +627,8 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this5 = this; | ||
var _this7 = this; | ||
_this5.checkDefaultHTTPChannel(); | ||
_this7.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this5._deafultHTTPChannel; | ||
var channel = _this5._channels[channelName]; | ||
var channelName = options.channel || _this7._deafultHTTPChannel; | ||
var channel = _this7._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -624,8 +672,8 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this7 = this; | ||
var _this9 = this; | ||
_this7.checkDefaultHTTPChannel(); | ||
_this9.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this7._deafultHTTPChannel; | ||
var channel = _this7._channels[channelName]; | ||
var channelName = options.channel || _this9._deafultHTTPChannel; | ||
var channel = _this9._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -669,8 +717,8 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this9 = this; | ||
var _this11 = this; | ||
_this9.checkDefaultHTTPChannel(); | ||
_this11.checkDefaultHTTPChannel(); | ||
var channelName = options.channel || _this9._deafultHTTPChannel; | ||
var channel = _this9._channels[channelName]; | ||
var channelName = options.channel || _this11._deafultHTTPChannel; | ||
var channel = _this11._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -752,6 +800,6 @@ var errorHandler = options.onError || channel.onError; | ||
try { | ||
var _this11 = this; | ||
var _this13 = this; | ||
var channel = _this11._channels[options.channel || _this11._deafultRPCChannel]; | ||
var dialect = _this11._dialects[_dialect || _this11._defaultDialect]; | ||
var channel = _this13._channels[options.channel || _this13._deafultRPCChannel]; | ||
var dialect = _this13._dialects[_dialect || _this13._defaultDialect]; | ||
var rpcConfig = channel.rpc; | ||
@@ -809,6 +857,6 @@ | ||
try { | ||
var _this13 = this; | ||
var _this15 = this; | ||
var channelName = options.channel || _this13._deafultRPCChannel; | ||
var channel = _this13._channels[channelName]; | ||
var channelName = options.channel || _this15._deafultRPCChannel; | ||
var channel = _this15._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -823,3 +871,3 @@ var errorHandler = options.onError || channel.onError; | ||
} else { | ||
return _this13._rpc('request', path, data, options, _dialect); | ||
return _this15._rpc('request', path, data, options, _dialect); | ||
} | ||
@@ -847,6 +895,6 @@ }, function (err) { | ||
try { | ||
var _this15 = this; | ||
var _this17 = this; | ||
var channelName = options.channel || _this15._deafultRPCChannel; | ||
var channel = _this15._channels[channelName]; | ||
var channelName = options.channel || _this17._deafultRPCChannel; | ||
var channel = _this17._channels[channelName]; | ||
var loader = getLoader(channel, options); | ||
@@ -861,3 +909,3 @@ var errorHandler = options.onError || channel.onError; | ||
} else { | ||
return _this15._rpc('inform', path, data, options, _dialect); | ||
return _this17._rpc('inform', path, data, options, _dialect); | ||
} | ||
@@ -877,2 +925,13 @@ }, function (err) { | ||
} | ||
}, { | ||
key: "channels", | ||
get: function get() { | ||
var channels = Object.keys(this._channels); | ||
return channels || []; | ||
} | ||
}, { | ||
key: "headers", | ||
get: function get() { | ||
return Object.keys(this._headers); | ||
} | ||
}]); | ||
@@ -1154,8 +1213,11 @@ | ||
var version = "1.1.2"; | ||
var Comlink = { | ||
Client: Client, | ||
Server: Server, | ||
Storage: Storage$1 | ||
Storage: Storage$1, | ||
version: version | ||
}; | ||
module.exports = Comlink; |
{ | ||
"name": "@dwmt/comlink", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Communication library for lazy enthusiasts", | ||
@@ -48,2 +48,3 @@ "main": "dist/Comlink.js", | ||
"@dwmt/loader": "^1.0.0", | ||
"@rollup/plugin-json": "^4.0.2", | ||
"axios": "^0.19.0", | ||
@@ -50,0 +51,0 @@ "isomorphic-ws": "^4.0.1", |
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
76760
2198
6
+ Added@rollup/plugin-json@^4.0.2
+ Added@rollup/plugin-json@4.1.0(transitive)
+ Added@rollup/pluginutils@3.1.0(transitive)
+ Added@types/estree@0.0.39(transitive)
+ Addedestree-walker@1.0.1(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedrollup@2.79.2(transitive)