@push-rpc/next
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -21,2 +21,3 @@ import { RpcContext, Services } from "../rpc.js"; | ||
getHeaders: () => Promise<Record<string, string>>; | ||
getSubscriptionsUrl(url: string): string; | ||
}; | ||
@@ -23,0 +24,0 @@ export declare function consumeServices<S extends Services<S>>(url: string, overrideOptions?: Partial<ConsumeServicesOptions>): Promise<{ |
@@ -34,3 +34,6 @@ "use strict"; | ||
getHeaders: async () => ({}), | ||
getSubscriptionsUrl(url) { | ||
return url.replace(/^https(.*)/, "wss$1").replace(/^http(.*)/, "ws$1"); | ||
}, | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -23,4 +23,5 @@ "use strict"; | ||
} | ||
// Probably needs to be awaited, b/c server needs the connection to be established before making a subscription | ||
void this.connection.connect(); | ||
// Needs to be awaited b/c resubscribe will make a 2nd request then. | ||
// Also, server needs the connection to be established before making a subscription | ||
await this.connection.connect(); | ||
try { | ||
@@ -58,3 +59,3 @@ this.remoteSubscriptions.addSubscription(itemName, parameters, consumer); | ||
this.remoteSubscriptions = new RemoteSubscriptions_js_1.RemoteSubscriptions(); | ||
this.connection = new WebSocketConnection_js_1.WebSocketConnection(url, this.clientId, { | ||
this.connection = new WebSocketConnection_js_1.WebSocketConnection(options.getSubscriptionsUrl(url), this.clientId, { | ||
subscriptions: options.subscriptions, | ||
@@ -61,0 +62,0 @@ errorDelayMaxDuration: options.errorDelayMaxDuration, |
@@ -14,2 +14,3 @@ export declare class WebSocketConnection { | ||
}, consume: (itemName: string, parameters: unknown[], data: unknown) => void, onConnected: () => void, onDisconnected: () => void); | ||
private resolveClose; | ||
close(): Promise<void>; | ||
@@ -16,0 +17,0 @@ /** |
@@ -15,6 +15,6 @@ "use strict"; | ||
this.onDisconnected = onDisconnected; | ||
this.resolveClose = () => { }; | ||
this.socket = null; | ||
this.disconnectedMark = true; | ||
this.pingTimeout = null; | ||
this.url = url.replace(/^https(.*)/, "wss$1").replace(/^http(.*)/, "ws$1"); | ||
this.clientId = clientId; | ||
@@ -26,7 +26,6 @@ } | ||
this.socket.close(); | ||
this.socket = null; | ||
return new Promise((resolve, reject) => { | ||
this.resolveClose = resolve; | ||
}); | ||
} | ||
if (this.pingTimeout) { | ||
clearTimeout(this.pingTimeout); | ||
} | ||
} | ||
@@ -113,2 +112,3 @@ /** | ||
} | ||
this.resolveClose(); | ||
}); | ||
@@ -115,0 +115,0 @@ socket.addEventListener("error", (e) => { |
@@ -149,3 +149,3 @@ "use strict"; | ||
await new Promise((resolve, reject) => { | ||
this.httpServer.closeIdleConnections(); | ||
this.httpServer.closeAllConnections(); | ||
this.httpServer.close((err) => { | ||
@@ -152,0 +152,0 @@ if (err) |
{ | ||
"name": "@push-rpc/next", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -26,2 +26,3 @@ import {RpcContext, Services} from "../rpc.js" | ||
getHeaders: () => Promise<Record<string, string>> | ||
getSubscriptionsUrl(url: string): string | ||
} | ||
@@ -68,2 +69,6 @@ | ||
getHeaders: async () => ({}), | ||
getSubscriptionsUrl(url: string): string { | ||
return url.replace(/^https(.*)/, "wss$1").replace(/^http(.*)/, "ws$1") | ||
}, | ||
} |
@@ -19,3 +19,3 @@ import {CallOptions, InvocationType, RpcContext, Services} from "../rpc.js" | ||
this.connection = new WebSocketConnection( | ||
url, | ||
options.getSubscriptionsUrl(url), | ||
this.clientId, | ||
@@ -117,4 +117,5 @@ { | ||
// Probably needs to be awaited, b/c server needs the connection to be established before making a subscription | ||
void this.connection.connect() | ||
// Needs to be awaited b/c resubscribe will make a 2nd request then. | ||
// Also, server needs the connection to be established before making a subscription | ||
await this.connection.connect() | ||
@@ -121,0 +122,0 @@ try { |
@@ -19,6 +19,7 @@ import {log} from "../logger.js" | ||
) { | ||
this.url = url.replace(/^https(.*)/, "wss$1").replace(/^http(.*)/, "ws$1") | ||
this.clientId = clientId | ||
} | ||
private resolveClose = () => {} | ||
async close() { | ||
@@ -29,7 +30,6 @@ this.disconnectedMark = true | ||
this.socket!.close() | ||
this.socket = null | ||
} | ||
if (this.pingTimeout) { | ||
clearTimeout(this.pingTimeout) | ||
return new Promise<void>((resolve, reject) => { | ||
this.resolveClose = resolve | ||
}) | ||
} | ||
@@ -141,2 +141,4 @@ } | ||
} | ||
this.resolveClose() | ||
}) | ||
@@ -143,0 +145,0 @@ |
@@ -96,3 +96,3 @@ import {PublishServicesOptions, RpcServer} from "./index.js" | ||
await new Promise<void>((resolve, reject) => { | ||
this.httpServer.closeIdleConnections() | ||
this.httpServer.closeAllConnections() | ||
this.httpServer.close((err) => { | ||
@@ -99,0 +99,0 @@ if (err) reject(err) |
@@ -147,3 +147,3 @@ import {assert} from "chai" | ||
item: async () => { | ||
await adelay(1) | ||
await adelay(20) | ||
supplied++ | ||
@@ -150,0 +150,0 @@ return item |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
197476
4389