@adt/json-rpc-transport-providers
Advanced tools
Comparing version 0.0.1-SNAPSHOT.5 to 0.0.1-SNAPSHOT.8
@@ -137,3 +137,3 @@ 'use strict'; | ||
* @param {Function} o.onMessage Callback with message argument which must be invoked when message arrives | ||
* @param {Function} o.onDisconnect Callback which must be invoked when message arrives | ||
* @param {Function} o.onDisconnect Callback which must be invoked on disconnection | ||
* @param {Function} o.onError Callback which must be invoked when error occurs | ||
@@ -268,3 +268,3 @@ * @returns {DummyTransportProvider} | ||
* @param {Number} [c.reconnectAfter=5000] Reconnect timeout in milliseconds | ||
* @param {Function} [c.onMessage=function(){]] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.onMessage=function()] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.serializer] Message serializer function (any) => string|ByteArray. By default it returns message as is | ||
@@ -277,4 +277,2 @@ * @param {Function} [c.deserializer] Message deserializer function (string|ByteArray) => any. By default it returns message as is | ||
// TODO: Tutaj sprawdzenie parametrów wejściowych i zapisanie ich do wewnętrznego configa | ||
if (typeof c === "undefined" || c === null) { | ||
@@ -412,3 +410,119 @@ throw Error("Missing configuration object"); | ||
/** | ||
* PostMessage Transport Provider | ||
* @param {Object} c Configuration object | ||
* @param {String} c.endpoint Target element to send and receive messages (window, iframe, Worker, SharedWorker port etc) | ||
* @param {Function} [c.onMessage=function()] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.serializer] Message serializer function (any) => string|ByteArray. By default it returns message as is | ||
* @param {Function} [c.deserializer] Message deserializer function (string|ByteArray) => any. By default it returns message as is | ||
* @constructor | ||
*/ | ||
function PostMessageTransportProvider(c) { | ||
if (typeof c === "undefined" || c === null) { | ||
throw Error("Missing configuration object"); | ||
} | ||
if ("endpoint" in c === false) { | ||
throw Error("Required param 'endpoint' is not defined"); | ||
} | ||
var config = {}; | ||
config.receiver = c.receiver; | ||
if ("onMessage" in c) { | ||
if (typeof c.onMessage !== "function") { | ||
throw Error("onMessage callback is not a function"); | ||
} else { | ||
config.onMessage = c.onMessage; | ||
} | ||
} else { | ||
// By default call empty function when message arrives | ||
// Sometimes we need only sending, so we don't force users to set this callback | ||
config.onMessage = function () {}; | ||
} | ||
if ("serializer" in c) { | ||
if (typeof c.serializer !== "function") { | ||
throw Error("Serializer is not a function"); | ||
} | ||
config.serializer = c.serializer; | ||
} else { | ||
config.serializer = function (req) { | ||
return req; | ||
}; | ||
} | ||
if ("deserializer" in c) { | ||
if (typeof c.deserializer !== "function") { | ||
throw Error("Deserializer is not a function"); | ||
} | ||
config.deserializer = c.deserializer; | ||
} else { | ||
config.deserializer = function (req) { | ||
return req; | ||
}; | ||
} | ||
// By default call empty function | ||
config.onDisconnect = function () {}; | ||
function onEndpointMessage(msg) { | ||
config.onMessage(config.deserializer(msg)); | ||
} | ||
var onEndpointMessageIsBinded = false; | ||
var onEndpointMessageBinded = onEndpointMessage.bind(this); | ||
return Object.create(PostMessageTransportProvider.prototype, { | ||
/** | ||
* Assigns message listener to receiver | ||
* @return Promise | ||
*/ | ||
connect: { value: function value() { | ||
return new Promise(function (resolve) { | ||
config.endpoint.addEventListener("message", onEndpointMessageBinded); | ||
onEndpointMessageIsBinded = true; | ||
resolve(); | ||
}); | ||
} }, | ||
send: { value: function value(req) { | ||
config.endpoint.postMessage(req); | ||
} }, | ||
disconnect: { value: function value() { | ||
if (onEndpointMessageIsBinded === true) { | ||
config.endpoint.removeEventListener("message", onEndpointMessageBinded); | ||
onEndpointMessageIsBinded = false; | ||
} | ||
} }, | ||
isConnected: { value: function value() { | ||
return onEndpointMessageBinded; | ||
} }, | ||
onMessage: { value: function value(callback) { | ||
return config.onMessage = callback; | ||
}, writable: true }, | ||
onDisconnect: { value: function value(callback) { | ||
return config.onDisconnect = callback; | ||
}, writable: true }, | ||
onError: { value: undefined, writable: true } | ||
}); | ||
} | ||
exports.DummyTransportProvider = DummyTransportProvider; | ||
exports.WebSocketTransportProvider = WebSocketTransportProvider; | ||
exports.PostMessageTransportProvider = PostMessageTransportProvider; |
@@ -133,3 +133,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
* @param {Function} o.onMessage Callback with message argument which must be invoked when message arrives | ||
* @param {Function} o.onDisconnect Callback which must be invoked when message arrives | ||
* @param {Function} o.onDisconnect Callback which must be invoked on disconnection | ||
* @param {Function} o.onError Callback which must be invoked when error occurs | ||
@@ -264,3 +264,3 @@ * @returns {DummyTransportProvider} | ||
* @param {Number} [c.reconnectAfter=5000] Reconnect timeout in milliseconds | ||
* @param {Function} [c.onMessage=function(){]] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.onMessage=function()] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.serializer] Message serializer function (any) => string|ByteArray. By default it returns message as is | ||
@@ -273,4 +273,2 @@ * @param {Function} [c.deserializer] Message deserializer function (string|ByteArray) => any. By default it returns message as is | ||
// TODO: Tutaj sprawdzenie parametrów wejściowych i zapisanie ich do wewnętrznego configa | ||
if (typeof c === "undefined" || c === null) { | ||
@@ -408,2 +406,117 @@ throw Error("Missing configuration object"); | ||
export { DummyTransportProvider, WebSocketTransportProvider }; | ||
/** | ||
* PostMessage Transport Provider | ||
* @param {Object} c Configuration object | ||
* @param {String} c.endpoint Target element to send and receive messages (window, iframe, Worker, SharedWorker port etc) | ||
* @param {Function} [c.onMessage=function()] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.serializer] Message serializer function (any) => string|ByteArray. By default it returns message as is | ||
* @param {Function} [c.deserializer] Message deserializer function (string|ByteArray) => any. By default it returns message as is | ||
* @constructor | ||
*/ | ||
function PostMessageTransportProvider(c) { | ||
if (typeof c === "undefined" || c === null) { | ||
throw Error("Missing configuration object"); | ||
} | ||
if ("endpoint" in c === false) { | ||
throw Error("Required param 'endpoint' is not defined"); | ||
} | ||
var config = {}; | ||
config.receiver = c.receiver; | ||
if ("onMessage" in c) { | ||
if (typeof c.onMessage !== "function") { | ||
throw Error("onMessage callback is not a function"); | ||
} else { | ||
config.onMessage = c.onMessage; | ||
} | ||
} else { | ||
// By default call empty function when message arrives | ||
// Sometimes we need only sending, so we don't force users to set this callback | ||
config.onMessage = function () {}; | ||
} | ||
if ("serializer" in c) { | ||
if (typeof c.serializer !== "function") { | ||
throw Error("Serializer is not a function"); | ||
} | ||
config.serializer = c.serializer; | ||
} else { | ||
config.serializer = function (req) { | ||
return req; | ||
}; | ||
} | ||
if ("deserializer" in c) { | ||
if (typeof c.deserializer !== "function") { | ||
throw Error("Deserializer is not a function"); | ||
} | ||
config.deserializer = c.deserializer; | ||
} else { | ||
config.deserializer = function (req) { | ||
return req; | ||
}; | ||
} | ||
// By default call empty function | ||
config.onDisconnect = function () {}; | ||
function onEndpointMessage(msg) { | ||
config.onMessage(config.deserializer(msg)); | ||
} | ||
var onEndpointMessageIsBinded = false; | ||
var onEndpointMessageBinded = onEndpointMessage.bind(this); | ||
return Object.create(PostMessageTransportProvider.prototype, { | ||
/** | ||
* Assigns message listener to receiver | ||
* @return Promise | ||
*/ | ||
connect: { value: function value() { | ||
return new Promise(function (resolve) { | ||
config.endpoint.addEventListener("message", onEndpointMessageBinded); | ||
onEndpointMessageIsBinded = true; | ||
resolve(); | ||
}); | ||
} }, | ||
send: { value: function value(req) { | ||
config.endpoint.postMessage(req); | ||
} }, | ||
disconnect: { value: function value() { | ||
if (onEndpointMessageIsBinded === true) { | ||
config.endpoint.removeEventListener("message", onEndpointMessageBinded); | ||
onEndpointMessageIsBinded = false; | ||
} | ||
} }, | ||
isConnected: { value: function value() { | ||
return onEndpointMessageBinded; | ||
} }, | ||
onMessage: { value: function value(callback) { | ||
return config.onMessage = callback; | ||
}, writable: true }, | ||
onDisconnect: { value: function value(callback) { | ||
return config.onDisconnect = callback; | ||
}, writable: true }, | ||
onError: { value: undefined, writable: true } | ||
}); | ||
} | ||
export { DummyTransportProvider, WebSocketTransportProvider, PostMessageTransportProvider }; |
@@ -145,3 +145,3 @@ (function (global, factory) { | ||
* @param {Function} o.onMessage Callback with message argument which must be invoked when message arrives | ||
* @param {Function} o.onDisconnect Callback which must be invoked when message arrives | ||
* @param {Function} o.onDisconnect Callback which must be invoked on disconnection | ||
* @param {Function} o.onError Callback which must be invoked when error occurs | ||
@@ -276,3 +276,3 @@ * @returns {DummyTransportProvider} | ||
* @param {Number} [c.reconnectAfter=5000] Reconnect timeout in milliseconds | ||
* @param {Function} [c.onMessage=function(){]] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.onMessage=function()] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.serializer] Message serializer function (any) => string|ByteArray. By default it returns message as is | ||
@@ -285,4 +285,2 @@ * @param {Function} [c.deserializer] Message deserializer function (string|ByteArray) => any. By default it returns message as is | ||
// TODO: Tutaj sprawdzenie parametrów wejściowych i zapisanie ich do wewnętrznego configa | ||
if (typeof c === "undefined" || c === null) { | ||
@@ -420,4 +418,120 @@ throw Error("Missing configuration object"); | ||
/** | ||
* PostMessage Transport Provider | ||
* @param {Object} c Configuration object | ||
* @param {String} c.endpoint Target element to send and receive messages (window, iframe, Worker, SharedWorker port etc) | ||
* @param {Function} [c.onMessage=function()] Callback with message argument which must be invoked when message arrives. By default its empty function | ||
* @param {Function} [c.serializer] Message serializer function (any) => string|ByteArray. By default it returns message as is | ||
* @param {Function} [c.deserializer] Message deserializer function (string|ByteArray) => any. By default it returns message as is | ||
* @constructor | ||
*/ | ||
function PostMessageTransportProvider(c) { | ||
if (typeof c === "undefined" || c === null) { | ||
throw Error("Missing configuration object"); | ||
} | ||
if ("endpoint" in c === false) { | ||
throw Error("Required param 'endpoint' is not defined"); | ||
} | ||
var config = {}; | ||
config.receiver = c.receiver; | ||
if ("onMessage" in c) { | ||
if (typeof c.onMessage !== "function") { | ||
throw Error("onMessage callback is not a function"); | ||
} else { | ||
config.onMessage = c.onMessage; | ||
} | ||
} else { | ||
// By default call empty function when message arrives | ||
// Sometimes we need only sending, so we don't force users to set this callback | ||
config.onMessage = function () {}; | ||
} | ||
if ("serializer" in c) { | ||
if (typeof c.serializer !== "function") { | ||
throw Error("Serializer is not a function"); | ||
} | ||
config.serializer = c.serializer; | ||
} else { | ||
config.serializer = function (req) { | ||
return req; | ||
}; | ||
} | ||
if ("deserializer" in c) { | ||
if (typeof c.deserializer !== "function") { | ||
throw Error("Deserializer is not a function"); | ||
} | ||
config.deserializer = c.deserializer; | ||
} else { | ||
config.deserializer = function (req) { | ||
return req; | ||
}; | ||
} | ||
// By default call empty function | ||
config.onDisconnect = function () {}; | ||
function onEndpointMessage(msg) { | ||
config.onMessage(config.deserializer(msg)); | ||
} | ||
var onEndpointMessageIsBinded = false; | ||
var onEndpointMessageBinded = onEndpointMessage.bind(this); | ||
return Object.create(PostMessageTransportProvider.prototype, { | ||
/** | ||
* Assigns message listener to receiver | ||
* @return Promise | ||
*/ | ||
connect: { value: function value() { | ||
return new Promise(function (resolve) { | ||
config.endpoint.addEventListener("message", onEndpointMessageBinded); | ||
onEndpointMessageIsBinded = true; | ||
resolve(); | ||
}); | ||
} }, | ||
send: { value: function value(req) { | ||
config.endpoint.postMessage(req); | ||
} }, | ||
disconnect: { value: function value() { | ||
if (onEndpointMessageIsBinded === true) { | ||
config.endpoint.removeEventListener("message", onEndpointMessageBinded); | ||
onEndpointMessageIsBinded = false; | ||
} | ||
} }, | ||
isConnected: { value: function value() { | ||
return onEndpointMessageBinded; | ||
} }, | ||
onMessage: { value: function value(callback) { | ||
return config.onMessage = callback; | ||
}, writable: true }, | ||
onDisconnect: { value: function value(callback) { | ||
return config.onDisconnect = callback; | ||
}, writable: true }, | ||
onError: { value: undefined, writable: true } | ||
}); | ||
} | ||
exports.DummyTransportProvider = DummyTransportProvider; | ||
exports.WebSocketTransportProvider = WebSocketTransportProvider; | ||
exports.PostMessageTransportProvider = PostMessageTransportProvider; | ||
@@ -424,0 +538,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "@adt/json-rpc-transport-providers", | ||
"version": "0.0.1-SNAPSHOT.5", | ||
"version": "0.0.1-SNAPSHOT.8", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "dist/JsonRpcTransportProviders.cjs.js", |
@@ -5,4 +5,2 @@ # JsonRpcTransportProviders | ||
# !!! WARNING !!! NOT PRODUCTION READY | ||
## Available providers | ||
@@ -12,2 +10,3 @@ | ||
- WebsocketTransportProvider | ||
- PostMessageTransportProvider | ||
@@ -14,0 +13,0 @@ ## Writing own providers |
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
50628
1234
18