@push-rpc/core
Advanced tools
Comparing version 1.0.27 to 1.0.28
@@ -26,5 +26,6 @@ import { Middleware, RpcConnectionContext } from "./rpc"; | ||
messageParser(data: any): any[]; | ||
keepAlivePeriod: number; | ||
pingSendTimeout: number; | ||
pongWaitTimeout: number; | ||
syncRemoteCalls: boolean; | ||
} | ||
export declare function createRpcClient<R = any>(level: any, createSocket: () => Socket, options?: Partial<RpcClientOptions>): Promise<RpcClient<R>>; |
@@ -32,3 +32,4 @@ "use strict"; | ||
messageParser: function (data) { return JSON.parse(data, utils_1.dateReviver); }, | ||
keepAlivePeriod: null, | ||
pingSendTimeout: null, | ||
pongWaitTimeout: null, | ||
syncRemoteCalls: false, | ||
@@ -39,3 +40,3 @@ }; | ||
var opts = __assign(__assign({}, defaultOptions), options); | ||
var session = new RpcSession_1.RpcSession(opts.local, level, opts.listeners, opts.createContext(), opts.localMiddleware, opts.remoteMiddleware, opts.messageParser, opts.keepAlivePeriod, opts.syncRemoteCalls); | ||
var session = new RpcSession_1.RpcSession(opts.local, level, opts.listeners, opts.createContext(), opts.localMiddleware, opts.remoteMiddleware, opts.messageParser, opts.pingSendTimeout, opts.pongWaitTimeout, opts.syncRemoteCalls); | ||
var client = { | ||
@@ -42,0 +43,0 @@ remote: session.remote, |
@@ -17,5 +17,6 @@ import { MessageType, Middleware, RpcConnectionContext, RpcContext } from "./rpc"; | ||
private messageParser; | ||
private keepAlivePeriod; | ||
private pingSendTimeout; | ||
private pongWaitTimeout; | ||
private syncRemoteCalls; | ||
constructor(local: any, remoteLevel: number, listeners: RpcSessionListeners, connectionContext: RpcConnectionContext, localMiddleware: Middleware, remoteMiddleware: Middleware, messageParser: (data: any) => any[], keepAlivePeriod: number, syncRemoteCalls: boolean); | ||
constructor(local: any, remoteLevel: number, listeners: RpcSessionListeners, connectionContext: RpcConnectionContext, localMiddleware: Middleware, remoteMiddleware: Middleware, messageParser: (data: any) => any[], pingSendTimeout: number, pongWaitTimeout: number, syncRemoteCalls: boolean); | ||
remote: any; | ||
@@ -22,0 +23,0 @@ open(socket: Socket): void; |
@@ -67,3 +67,3 @@ "use strict"; | ||
var RpcSession = /** @class */ (function () { | ||
function RpcSession(local, remoteLevel, listeners, connectionContext, localMiddleware, remoteMiddleware, messageParser, keepAlivePeriod, syncRemoteCalls) { | ||
function RpcSession(local, remoteLevel, listeners, connectionContext, localMiddleware, remoteMiddleware, messageParser, pingSendTimeout, pongWaitTimeout, syncRemoteCalls) { | ||
var _this = this; | ||
@@ -76,3 +76,4 @@ this.local = local; | ||
this.messageParser = messageParser; | ||
this.keepAlivePeriod = keepAlivePeriod; | ||
this.pingSendTimeout = pingSendTimeout; | ||
this.pongWaitTimeout = pongWaitTimeout; | ||
this.syncRemoteCalls = syncRemoteCalls; | ||
@@ -85,8 +86,8 @@ this.sendPing = function () { return __awaiter(_this, void 0, void 0, function () { | ||
_a.trys.push([0, 2, , 3]); | ||
// call will be rejected if no reply will come in keepAlivePeriod / 2, see #sendCall | ||
// call will be rejected if no reply will come in pongWaitTimeout, see #sendCall | ||
return [4 /*yield*/, this.callRemote("", "ping", "ping")]; | ||
case 1: | ||
// call will be rejected if no reply will come in keepAlivePeriod / 2, see #sendCall | ||
// call will be rejected if no reply will come in pongWaitTimeout, see #sendCall | ||
_a.sent(); | ||
this.pingTimer = setTimeout(this.sendPing, this.keepAlivePeriod); | ||
this.pingTimer = setTimeout(this.sendPing, this.pingSendTimeout); | ||
return [3 /*break*/, 3]; | ||
@@ -112,4 +113,4 @@ case 2: | ||
resubscribeTopics(this.remote); | ||
if (this.keepAlivePeriod) { | ||
this.pingTimer = setTimeout(this.sendPing, this.keepAlivePeriod); | ||
if (this.pingSendTimeout) { | ||
this.pingTimer = setTimeout(this.sendPing, this.pingSendTimeout); | ||
socket.onPong(function () { | ||
@@ -228,3 +229,3 @@ _this.listeners.messageIn("PONG"); | ||
var messageId = _a[_i]; | ||
var expireCallBefore = messageId == PING_MESSAGE_ID ? now - this.keepAlivePeriod / 2 : now - callTimeout; | ||
var expireCallBefore = messageId == PING_MESSAGE_ID ? now - this.pongWaitTimeout : now - callTimeout; | ||
if (this.runningCalls[messageId].startedAt < expireCallBefore) { | ||
@@ -231,0 +232,0 @@ var reject = this.runningCalls[messageId].reject; |
@@ -9,3 +9,4 @@ import { Middleware, RpcConnectionContext } from "./rpc"; | ||
messageParser?(data: any): any[]; | ||
keepAlivePeriod?: number; | ||
pingSendTimeout?: number; | ||
pongWaitTimeout?: number; | ||
syncRemoteCalls?: boolean; | ||
@@ -12,0 +13,0 @@ listeners?: { |
@@ -80,3 +80,4 @@ "use strict"; | ||
clientLevel: 0, | ||
keepAlivePeriod: 50 * 1000, | ||
pingSendTimeout: 50 * 1000, | ||
pongWaitTimeout: 25 * 1000, | ||
syncRemoteCalls: false, | ||
@@ -138,3 +139,3 @@ messageParser: function (data) { return JSON.parse(data, utils_1.dateReviver); }, | ||
unsubscribed: function () { return opts.listeners.unsubscribed(getTotalSubscriptions()); }, | ||
}, connectionContext, opts.localMiddleware, opts.remoteMiddleware, opts.messageParser, opts.keepAlivePeriod, opts.syncRemoteCalls); | ||
}, connectionContext, opts.localMiddleware, opts.remoteMiddleware, opts.messageParser, opts.pingSendTimeout, opts.pongWaitTimeout, opts.syncRemoteCalls); | ||
session.open(socket); | ||
@@ -141,0 +142,0 @@ if (sessions[remoteId]) { |
{ | ||
"name": "@push-rpc/core", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -30,3 +30,4 @@ import {RpcSession} from "./RpcSession" | ||
messageParser(data): any[] | ||
keepAlivePeriod: number | ||
pingSendTimeout: number | ||
pongWaitTimeout: number | ||
syncRemoteCalls: boolean | ||
@@ -51,3 +52,4 @@ } | ||
messageParser: data => JSON.parse(data, dateReviver), | ||
keepAlivePeriod: null, | ||
pingSendTimeout: null, | ||
pongWaitTimeout: null, | ||
syncRemoteCalls: false, | ||
@@ -71,3 +73,4 @@ } | ||
opts.messageParser, | ||
opts.keepAlivePeriod, | ||
opts.pingSendTimeout, | ||
opts.pongWaitTimeout, | ||
opts.syncRemoteCalls | ||
@@ -74,0 +77,0 @@ ) |
@@ -37,3 +37,4 @@ import {log} from "./logger" | ||
private messageParser: (data) => any[], | ||
private keepAlivePeriod: number, | ||
private pingSendTimeout: number, | ||
private pongWaitTimeout: number, | ||
private syncRemoteCalls: boolean | ||
@@ -50,4 +51,4 @@ ) { | ||
if (this.keepAlivePeriod) { | ||
this.pingTimer = setTimeout(this.sendPing, this.keepAlivePeriod) | ||
if (this.pingSendTimeout) { | ||
this.pingTimer = setTimeout(this.sendPing, this.pingSendTimeout) | ||
@@ -93,5 +94,5 @@ socket.onPong(() => { | ||
try { | ||
// call will be rejected if no reply will come in keepAlivePeriod / 2, see #sendCall | ||
// call will be rejected if no reply will come in pongWaitTimeout, see #sendCall | ||
await this.callRemote("", "ping", "ping") | ||
this.pingTimer = setTimeout(this.sendPing, this.keepAlivePeriod) | ||
this.pingTimer = setTimeout(this.sendPing, this.pingSendTimeout) | ||
} catch (e) { | ||
@@ -198,3 +199,3 @@ log.debug(`Keep alive check failed ${this.connectionContext.remoteId}`) | ||
const expireCallBefore = | ||
messageId == PING_MESSAGE_ID ? now - this.keepAlivePeriod / 2 : now - callTimeout | ||
messageId == PING_MESSAGE_ID ? now - this.pongWaitTimeout : now - callTimeout | ||
@@ -201,0 +202,0 @@ if (this.runningCalls[messageId].startedAt < expireCallBefore) { |
@@ -16,3 +16,4 @@ import * as UUID from "uuid-js" | ||
messageParser?(data): any[] | ||
keepAlivePeriod?: number | ||
pingSendTimeout?: number | ||
pongWaitTimeout?: number | ||
syncRemoteCalls?: boolean | ||
@@ -37,3 +38,4 @@ | ||
clientLevel: 0, | ||
keepAlivePeriod: 50 * 1000, | ||
pingSendTimeout: 50 * 1000, | ||
pongWaitTimeout: 25 * 1000, | ||
syncRemoteCalls: false, | ||
@@ -112,3 +114,4 @@ messageParser: data => JSON.parse(data, dateReviver), | ||
opts.messageParser, | ||
opts.keepAlivePeriod, | ||
opts.pingSendTimeout, | ||
opts.pongWaitTimeout, | ||
opts.syncRemoteCalls | ||
@@ -115,0 +118,0 @@ ) |
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
116300
3106