@nimiq/rpc
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -352,13 +352,3 @@ 'use strict'; | ||
const data = message.data; | ||
// Response handlers by id have priority to more general ones by command | ||
let callback; | ||
if (this._responseHandlers.has(data.id)) { | ||
callback = this._responseHandlers.get(data.id); | ||
} | ||
else { | ||
const command = this._waitingRequests.getCommand(data.id); | ||
if (command) { | ||
callback = this._responseHandlers.get(command); | ||
} | ||
} | ||
const callback = this._getCallback(data.id); | ||
const state = this._waitingRequests.getState(data.id); | ||
@@ -383,2 +373,15 @@ if (callback) { | ||
} | ||
_getCallback(id) { | ||
// Response handlers by id have priority to more general ones by command | ||
if (this._responseHandlers.has(id)) { | ||
return this._responseHandlers.get(id); | ||
} | ||
else { | ||
const command = this._waitingRequests.getCommand(id); | ||
if (command) { | ||
return this._responseHandlers.get(command); | ||
} | ||
} | ||
return undefined; | ||
} | ||
} | ||
@@ -487,2 +490,5 @@ class PostMessageRpcClient extends RpcClient { | ||
} | ||
else { | ||
this._rejectOnBack(); | ||
} | ||
} | ||
@@ -498,5 +504,19 @@ /* tslint:disable:no-empty */ | ||
this._waitingRequests.add(id, command, state); | ||
history.replaceState({ rpcRequestId: id }, document.title); | ||
console.debug('RpcClient REQUEST', command, args); | ||
window.location.href = url; | ||
} | ||
_rejectOnBack() { | ||
if (history.state && history.state.rpcRequestId) { | ||
const id = history.state.rpcRequestId; | ||
const callback = this._getCallback(id); | ||
const state = this._waitingRequests.getState(id); | ||
if (callback) { | ||
this._waitingRequests.remove(id); | ||
console.debug('RpcClient BACK'); | ||
const error = new Error('Request aborted'); | ||
callback.reject(error, id, state); | ||
} | ||
} | ||
} | ||
} | ||
@@ -503,0 +523,0 @@ |
@@ -349,13 +349,3 @@ class RandomUtils { | ||
const data = message.data; | ||
// Response handlers by id have priority to more general ones by command | ||
let callback; | ||
if (this._responseHandlers.has(data.id)) { | ||
callback = this._responseHandlers.get(data.id); | ||
} | ||
else { | ||
const command = this._waitingRequests.getCommand(data.id); | ||
if (command) { | ||
callback = this._responseHandlers.get(command); | ||
} | ||
} | ||
const callback = this._getCallback(data.id); | ||
const state = this._waitingRequests.getState(data.id); | ||
@@ -380,2 +370,15 @@ if (callback) { | ||
} | ||
_getCallback(id) { | ||
// Response handlers by id have priority to more general ones by command | ||
if (this._responseHandlers.has(id)) { | ||
return this._responseHandlers.get(id); | ||
} | ||
else { | ||
const command = this._waitingRequests.getCommand(id); | ||
if (command) { | ||
return this._responseHandlers.get(command); | ||
} | ||
} | ||
return undefined; | ||
} | ||
} | ||
@@ -484,2 +487,5 @@ class PostMessageRpcClient extends RpcClient { | ||
} | ||
else { | ||
this._rejectOnBack(); | ||
} | ||
} | ||
@@ -495,5 +501,19 @@ /* tslint:disable:no-empty */ | ||
this._waitingRequests.add(id, command, state); | ||
history.replaceState({ rpcRequestId: id }, document.title); | ||
console.debug('RpcClient REQUEST', command, args); | ||
window.location.href = url; | ||
} | ||
_rejectOnBack() { | ||
if (history.state && history.state.rpcRequestId) { | ||
const id = history.state.rpcRequestId; | ||
const callback = this._getCallback(id); | ||
const state = this._waitingRequests.getState(id); | ||
if (callback) { | ||
this._waitingRequests.remove(id); | ||
console.debug('RpcClient BACK'); | ||
const error = new Error('Request aborted'); | ||
callback.reject(error, id, state); | ||
} | ||
} | ||
} | ||
} | ||
@@ -500,0 +520,0 @@ |
@@ -354,13 +354,3 @@ (function (global, factory) { | ||
const data = message.data; | ||
// Response handlers by id have priority to more general ones by command | ||
let callback; | ||
if (this._responseHandlers.has(data.id)) { | ||
callback = this._responseHandlers.get(data.id); | ||
} | ||
else { | ||
const command = this._waitingRequests.getCommand(data.id); | ||
if (command) { | ||
callback = this._responseHandlers.get(command); | ||
} | ||
} | ||
const callback = this._getCallback(data.id); | ||
const state = this._waitingRequests.getState(data.id); | ||
@@ -385,2 +375,15 @@ if (callback) { | ||
} | ||
_getCallback(id) { | ||
// Response handlers by id have priority to more general ones by command | ||
if (this._responseHandlers.has(id)) { | ||
return this._responseHandlers.get(id); | ||
} | ||
else { | ||
const command = this._waitingRequests.getCommand(id); | ||
if (command) { | ||
return this._responseHandlers.get(command); | ||
} | ||
} | ||
return undefined; | ||
} | ||
} | ||
@@ -489,2 +492,5 @@ class PostMessageRpcClient extends RpcClient { | ||
} | ||
else { | ||
this._rejectOnBack(); | ||
} | ||
} | ||
@@ -500,5 +506,19 @@ /* tslint:disable:no-empty */ | ||
this._waitingRequests.add(id, command, state); | ||
history.replaceState({ rpcRequestId: id }, document.title); | ||
console.debug('RpcClient REQUEST', command, args); | ||
window.location.href = url; | ||
} | ||
_rejectOnBack() { | ||
if (history.state && history.state.rpcRequestId) { | ||
const id = history.state.rpcRequestId; | ||
const callback = this._getCallback(id); | ||
const state = this._waitingRequests.getState(id); | ||
if (callback) { | ||
this._waitingRequests.remove(id); | ||
console.debug('RpcClient BACK'); | ||
const error = new Error('Request aborted'); | ||
callback.reject(error, id, state); | ||
} | ||
} | ||
} | ||
} | ||
@@ -505,0 +525,0 @@ |
@@ -16,2 +16,3 @@ import { ResponseMessage } from './Messages'; | ||
protected _receive(message: ResponseMessage): void; | ||
protected _getCallback(id: number): ResponseHandler | undefined; | ||
} | ||
@@ -35,2 +36,3 @@ export declare class PostMessageRpcClient extends RpcClient { | ||
callAndSaveLocalState(returnURL: string, state: string | null, command: string, ...args: any[]): void; | ||
private _rejectOnBack; | ||
} |
{ | ||
"name": "@nimiq/rpc", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "RPC Client/Server", | ||
@@ -5,0 +5,0 @@ "repository": { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
95815
2208
1