@push-rpc/core
Advanced tools
Comparing version 1.5.8 to 1.6.0
@@ -111,2 +111,3 @@ "use strict"; | ||
return; | ||
// session.send and not session.callRemote because unsubscribe doesn't yield any response from the server side | ||
this.session.send(rpc_1.MessageType.Unsubscribe, utils_1.createMessageId(), this.topicName, params); | ||
@@ -136,2 +137,3 @@ var subscriptions = this.consumers[paramsKey]; | ||
var params = JSON.parse(paramsKey); | ||
// session.send and not session.callRemote b/c we don't want resubscribes to be pass thru middleware | ||
_this.session.send(rpc_1.MessageType.Subscribe, utils_1.createMessageId(), _this.topicName, params); | ||
@@ -138,0 +140,0 @@ }); |
@@ -130,2 +130,3 @@ "use strict"; | ||
this.callTimeoutTimer = setInterval(function () { return _this.timeoutCalls(); }, 1000); // every 1s | ||
this.flushPendingCalls(); | ||
}; | ||
@@ -139,2 +140,6 @@ RpcSession.prototype.trackMessageReceived = function (msg) { | ||
return new Promise(function (resolve) { | ||
if (!_this.socket) { | ||
resolve(); | ||
return; | ||
} | ||
var timer = setTimeout(function () { | ||
@@ -170,3 +175,3 @@ // if not disconnected in 5s, just ignore it | ||
__spreadArrays(this.queue, Object.values(this.runningCalls)).forEach(function (call) { | ||
call.reject(new Error("Timeout" + call.type + "-" + call.name)); | ||
call.reject(new Error("Timeout " + call.type + ", " + call.name)); | ||
}); | ||
@@ -177,2 +182,3 @@ this.queue = []; | ||
this.resolveDisconnect = function () { }; | ||
this.socket = null; | ||
return [2 /*return*/]; | ||
@@ -195,4 +201,9 @@ } | ||
if (data == exports.PING_MESSAGE) { | ||
this.listeners.messageOut(exports.PONG_MESSAGE); | ||
this.socket.send(exports.PONG_MESSAGE); | ||
if (this.socket) { | ||
this.listeners.messageOut(exports.PONG_MESSAGE); | ||
this.socket.send(exports.PONG_MESSAGE); | ||
} | ||
else { | ||
logger_1.log.debug("Received PING but socket is not open " + this.connectionContext.remoteId); | ||
} | ||
return; | ||
@@ -270,6 +281,11 @@ } | ||
} | ||
this.lastSendAt = Date.now(); | ||
var data = utils_1.message.apply(void 0, __spreadArrays([type, id], params)); | ||
this.listeners.messageOut(data); | ||
this.socket.send(data); | ||
if (this.socket) { | ||
this.lastSendAt = Date.now(); | ||
var data = utils_1.message.apply(void 0, __spreadArrays([type, id], params)); | ||
this.listeners.messageOut(data); | ||
this.socket.send(data); | ||
} | ||
else { | ||
logger_1.log.debug("Can't send message, socket is not connected"); | ||
} | ||
}; | ||
@@ -317,2 +333,4 @@ RpcSession.prototype.timeoutCalls = function () { | ||
} | ||
if (!this.socket) | ||
return; | ||
while (this.queue.length > 0) { | ||
@@ -319,0 +337,0 @@ var call = this.queue.shift(); |
{ | ||
"name": "@push-rpc/core", | ||
"version": "1.5.8", | ||
"version": "1.6.0", | ||
"main": "dist/index.js", | ||
@@ -21,3 +21,3 @@ "types": "dist/index.d.ts", | ||
}, | ||
"gitHead": "a7e7b8e17d529a119b69adef461d06e8f9a1b190" | ||
"gitHead": "193290f9397e577b92f9087b5a359126ddf7d02c" | ||
} |
@@ -60,2 +60,3 @@ import { | ||
// session.send and not session.callRemote because unsubscribe doesn't yield any response from the server side | ||
this.session.send(MessageType.Unsubscribe, createMessageId(), this.topicName, params) | ||
@@ -87,2 +88,4 @@ | ||
const params = JSON.parse(paramsKey) | ||
// session.send and not session.callRemote b/c we don't want resubscribes to be pass thru middleware | ||
this.session.send(MessageType.Subscribe, createMessageId(), this.topicName, params) | ||
@@ -89,0 +92,0 @@ }) |
@@ -91,2 +91,4 @@ import {LocalTopicImpl} from "./local" | ||
this.callTimeoutTimer = setInterval(() => this.timeoutCalls(), 1000) // every 1s | ||
this.flushPendingCalls() | ||
} | ||
@@ -103,2 +105,7 @@ | ||
return new Promise(resolve => { | ||
if (!this.socket) { | ||
resolve() | ||
return | ||
} | ||
const timer = setTimeout(() => { | ||
@@ -133,3 +140,3 @@ // if not disconnected in 5s, just ignore it | ||
;[...this.queue, ...Object.values(this.runningCalls)].forEach(call => { | ||
call.reject(new Error("Timeout" + call.type + "-" + call.name)) | ||
call.reject(new Error("Timeout " + call.type + ", " + call.name)) | ||
}) | ||
@@ -142,2 +149,4 @@ | ||
this.resolveDisconnect = () => {} | ||
this.socket = null | ||
} | ||
@@ -169,4 +178,9 @@ | ||
if (data == PING_MESSAGE) { | ||
this.listeners.messageOut(PONG_MESSAGE) | ||
this.socket.send(PONG_MESSAGE) | ||
if (this.socket) { | ||
this.listeners.messageOut(PONG_MESSAGE) | ||
this.socket.send(PONG_MESSAGE) | ||
} else { | ||
log.debug(`Received PING but socket is not open ${this.connectionContext.remoteId}`) | ||
} | ||
return | ||
@@ -262,7 +276,11 @@ } | ||
send(type: MessageType, id: string, ...params) { | ||
this.lastSendAt = Date.now() | ||
if (this.socket) { | ||
this.lastSendAt = Date.now() | ||
const data = message(type, id, ...params) | ||
this.listeners.messageOut(data) | ||
this.socket.send(data) | ||
const data = message(type, id, ...params) | ||
this.listeners.messageOut(data) | ||
this.socket.send(data) | ||
} else { | ||
log.debug(`Can't send message, socket is not connected`) | ||
} | ||
} | ||
@@ -289,3 +307,3 @@ | ||
type, | ||
name: name, | ||
name, | ||
params: cloneParams(p), | ||
@@ -318,2 +336,4 @@ resolve, | ||
if (!this.socket) return | ||
while (this.queue.length > 0) { | ||
@@ -320,0 +340,0 @@ const call = this.queue.shift() |
import {assert} from "chai" | ||
import {createNodeWebsocket} from "../../websocket/src" | ||
import {createRpcClient} from "../src" | ||
import {createRpcClient, RpcClient} from "../src" | ||
import {createTestClient, startTestServer, TEST_PORT} from "./testUtils" | ||
@@ -211,2 +211,43 @@ | ||
}).timeout(5000) | ||
it("wait for call when disconnected", async () => { | ||
let client: RpcClient<any> | ||
try { | ||
const server = await startTestServer({ | ||
test: { | ||
async getSomething() { | ||
return "ok" | ||
}, | ||
}, | ||
}) | ||
let response | ||
client = await createRpcClient( | ||
1, | ||
async () => createNodeWebsocket(`ws://localhost:${TEST_PORT}`), | ||
{ | ||
reconnect: true, | ||
} | ||
) | ||
// disconnect | ||
await server.disconnectClient(server.getConnectedIds()[0]) | ||
// give some time for client to catch disconnect | ||
await new Promise(r => setTimeout(r, 10)) | ||
client.remote.test.getSomething().then(r => { | ||
response = r | ||
}) | ||
// wait for reconnect & call | ||
await new Promise(r => setTimeout(r, 50)) | ||
assert.equal(response, "ok") | ||
} finally { | ||
await client.disconnect() | ||
} | ||
}) | ||
}) |
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
180291
4743