@service-broker/webclient 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -2
- package/package.json +4 -1
- package/src/index.ts +9 -0
- package/tsconfig.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare class ServiceBroker {
|
|
|
39
39
|
publish(topic: string, text: string): void;
|
|
40
40
|
subscribe(topic: string, handler: (text: string) => void): void;
|
|
41
41
|
unsubscribe(topic: string): void;
|
|
42
|
+
status(): Promise<any>;
|
|
42
43
|
isConnected(): boolean;
|
|
43
44
|
addConnectListener(listener: Function): void;
|
|
44
45
|
}
|
package/dist/index.js
CHANGED
|
@@ -84,7 +84,12 @@ export class ServiceBroker {
|
|
|
84
84
|
Promise.resolve(provider.handler(msg))
|
|
85
85
|
.then(res => {
|
|
86
86
|
if (msg.header.id) {
|
|
87
|
-
this.send(
|
|
87
|
+
this.send({
|
|
88
|
+
...res?.header,
|
|
89
|
+
to: msg.header.from,
|
|
90
|
+
id: msg.header.id,
|
|
91
|
+
type: "ServiceResponse"
|
|
92
|
+
}, res?.payload);
|
|
88
93
|
}
|
|
89
94
|
})
|
|
90
95
|
.catch(err => {
|
|
@@ -133,7 +138,7 @@ export class ServiceBroker {
|
|
|
133
138
|
};
|
|
134
139
|
if (endpointId)
|
|
135
140
|
header.to = endpointId;
|
|
136
|
-
this.send(
|
|
141
|
+
this.send({ ...req.header, ...header }, req.payload);
|
|
137
142
|
return promise;
|
|
138
143
|
}
|
|
139
144
|
advertise(service, handler) {
|
|
@@ -174,6 +179,12 @@ export class ServiceBroker {
|
|
|
174
179
|
unsubscribe(topic) {
|
|
175
180
|
return this.unadvertise("#" + topic);
|
|
176
181
|
}
|
|
182
|
+
async status() {
|
|
183
|
+
const id = ++this.pendingIdGen;
|
|
184
|
+
this.send({ id, type: "SbStatusRequest" });
|
|
185
|
+
const res = await new Promise((fulfill, reject) => this.pendingResponses.set(id, { fulfill, reject }));
|
|
186
|
+
return JSON.parse(res.payload);
|
|
187
|
+
}
|
|
177
188
|
isConnected() {
|
|
178
189
|
return this.ws != null;
|
|
179
190
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@service-broker/webclient",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Browser ESM client library for communicating with the service broker",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc"
|
|
9
|
+
},
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "git+https://github.com/service-broker/webclient.git"
|
package/src/index.ts
CHANGED
|
@@ -217,6 +217,15 @@ export class ServiceBroker {
|
|
|
217
217
|
return this.unadvertise("#" + topic)
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
async status() {
|
|
221
|
+
const id = ++this.pendingIdGen
|
|
222
|
+
this.send({ id, type: "SbStatusRequest" })
|
|
223
|
+
const res = await new Promise<Message>((fulfill, reject) =>
|
|
224
|
+
this.pendingResponses.set(id, { fulfill, reject })
|
|
225
|
+
)
|
|
226
|
+
return JSON.parse(res.payload!)
|
|
227
|
+
}
|
|
228
|
+
|
|
220
229
|
isConnected() {
|
|
221
230
|
return this.ws != null
|
|
222
231
|
}
|