@nimiq/rpc
Advanced tools
Comparing version 0.1.0-beta.2 to 0.1.0-beta.3
@@ -482,2 +482,25 @@ 'use strict'; | ||
} | ||
class ReceiveOnlyPostMessageRpcClient extends PostMessageRpcClient { | ||
constructor(targetWindow, allowedOrigin, requestId) { | ||
super(targetWindow, allowedOrigin); | ||
this._requestId = requestId; | ||
} | ||
async listenFor(command) { | ||
if (!this._connected) | ||
throw new Error('Client is not connected, call init first'); | ||
return new Promise((resolve, reject) => { | ||
// Store the request resolvers | ||
this._responseHandlers.set(this._requestId, { resolve, reject }); | ||
this._waitingRequests.add(this._requestId, command); | ||
// Periodically check if recepient window is still open | ||
const checkIfServerWasClosed = () => { | ||
if (this._target.closed) { | ||
reject(new Error('Window was closed')); | ||
} | ||
setTimeout(checkIfServerWasClosed, 500); | ||
}; | ||
setTimeout(checkIfServerWasClosed, 500); | ||
}); | ||
} | ||
} | ||
class RedirectRpcClient extends RpcClient { | ||
@@ -699,2 +722,3 @@ constructor(targetURL, allowedOrigin) { | ||
exports.PostMessageRpcClient = PostMessageRpcClient; | ||
exports.ReceiveOnlyPostMessageRpcClient = ReceiveOnlyPostMessageRpcClient; | ||
exports.RedirectRpcClient = RedirectRpcClient; | ||
@@ -704,1 +728,2 @@ exports.RpcServer = RpcServer; | ||
exports.UrlRpcEncoder = UrlRpcEncoder; | ||
exports.RandomUtils = RandomUtils; |
@@ -479,2 +479,25 @@ class RandomUtils { | ||
} | ||
class ReceiveOnlyPostMessageRpcClient extends PostMessageRpcClient { | ||
constructor(targetWindow, allowedOrigin, requestId) { | ||
super(targetWindow, allowedOrigin); | ||
this._requestId = requestId; | ||
} | ||
async listenFor(command) { | ||
if (!this._connected) | ||
throw new Error('Client is not connected, call init first'); | ||
return new Promise((resolve, reject) => { | ||
// Store the request resolvers | ||
this._responseHandlers.set(this._requestId, { resolve, reject }); | ||
this._waitingRequests.add(this._requestId, command); | ||
// Periodically check if recepient window is still open | ||
const checkIfServerWasClosed = () => { | ||
if (this._target.closed) { | ||
reject(new Error('Window was closed')); | ||
} | ||
setTimeout(checkIfServerWasClosed, 500); | ||
}; | ||
setTimeout(checkIfServerWasClosed, 500); | ||
}); | ||
} | ||
} | ||
class RedirectRpcClient extends RpcClient { | ||
@@ -694,2 +717,2 @@ constructor(targetURL, allowedOrigin) { | ||
export { RpcClient, PostMessageRpcClient, RedirectRpcClient, RpcServer, State, ResponseStatus, UrlRpcEncoder }; | ||
export { RpcClient, PostMessageRpcClient, ReceiveOnlyPostMessageRpcClient, RedirectRpcClient, RpcServer, State, ResponseStatus, UrlRpcEncoder, RandomUtils }; |
@@ -484,2 +484,25 @@ (function (global, factory) { | ||
} | ||
class ReceiveOnlyPostMessageRpcClient extends PostMessageRpcClient { | ||
constructor(targetWindow, allowedOrigin, requestId) { | ||
super(targetWindow, allowedOrigin); | ||
this._requestId = requestId; | ||
} | ||
async listenFor(command) { | ||
if (!this._connected) | ||
throw new Error('Client is not connected, call init first'); | ||
return new Promise((resolve, reject) => { | ||
// Store the request resolvers | ||
this._responseHandlers.set(this._requestId, { resolve, reject }); | ||
this._waitingRequests.add(this._requestId, command); | ||
// Periodically check if recepient window is still open | ||
const checkIfServerWasClosed = () => { | ||
if (this._target.closed) { | ||
reject(new Error('Window was closed')); | ||
} | ||
setTimeout(checkIfServerWasClosed, 500); | ||
}; | ||
setTimeout(checkIfServerWasClosed, 500); | ||
}); | ||
} | ||
} | ||
class RedirectRpcClient extends RpcClient { | ||
@@ -701,2 +724,3 @@ constructor(targetURL, allowedOrigin) { | ||
exports.PostMessageRpcClient = PostMessageRpcClient; | ||
exports.ReceiveOnlyPostMessageRpcClient = ReceiveOnlyPostMessageRpcClient; | ||
exports.RedirectRpcClient = RedirectRpcClient; | ||
@@ -706,2 +730,3 @@ exports.RpcServer = RpcServer; | ||
exports.UrlRpcEncoder = UrlRpcEncoder; | ||
exports.RandomUtils = RandomUtils; | ||
@@ -708,0 +733,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
export * from './RpcClient'; | ||
export * from './RpcServer'; | ||
export * from './UrlRpcEncoder'; | ||
export * from './RandomUtils'; |
@@ -19,5 +19,5 @@ import { ResponseMessage } from './Messages'; | ||
export declare class PostMessageRpcClient extends RpcClient { | ||
private readonly _target; | ||
protected readonly _target: Window; | ||
protected _connected: boolean; | ||
private readonly _receiveListener; | ||
private _connected; | ||
constructor(targetWindow: Window, allowedOrigin: string); | ||
@@ -29,2 +29,7 @@ init(): Promise<void>; | ||
} | ||
export declare class ReceiveOnlyPostMessageRpcClient extends PostMessageRpcClient { | ||
private _requestId; | ||
constructor(targetWindow: Window, allowedOrigin: string, requestId: number); | ||
listenFor(command: string): Promise<any>; | ||
} | ||
export declare class RedirectRpcClient extends RpcClient { | ||
@@ -31,0 +36,0 @@ private readonly _target; |
{ | ||
"name": "@nimiq/rpc", | ||
"version": "0.1.0-beta.2", | ||
"version": "0.1.0-beta.3", | ||
"description": "RPC Client/Server", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
101125
2306