@c8y/client 1017.0.346 → 1017.0.355
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/NOTICES +1 -1
- package/lib/bundles/client.umd.js +35 -4
- package/lib/bundles/client.umd.js.map +1 -1
- package/lib/bundles/client.umd.min.js +1 -1
- package/lib/bundles/client.umd.min.js.map +1 -1
- package/lib/cjs/src/realtime/Realtime.js +35 -4
- package/lib/cjs/src/realtime/Realtime.js.map +1 -1
- package/lib/esm2015/src/realtime/Realtime.js +36 -5
- package/lib/esm2015/src/realtime/Realtime.js.map +1 -1
- package/lib/src/realtime/Realtime.d.ts +25 -4
- package/package.json +2 -1
|
@@ -13,12 +13,13 @@ class Realtime {
|
|
|
13
13
|
constructor(client, url = '/notification/realtime', handshakeCallback) {
|
|
14
14
|
this.client = client;
|
|
15
15
|
this.url = url;
|
|
16
|
-
this.cometd = new isomorphic_cometd_1.CometD();
|
|
17
16
|
this.metaHandshake = msg => {
|
|
18
17
|
if (!msg.successful) {
|
|
19
18
|
throw new Error('Handshake failed');
|
|
20
19
|
}
|
|
21
20
|
};
|
|
21
|
+
this.cometd = new isomorphic_cometd_1.CometD({});
|
|
22
|
+
// does not actually seem to be needed/supported? Just keeping to satisfy unit test snapshots
|
|
22
23
|
this.cometd.websocketEnabled = true;
|
|
23
24
|
this.cometd.addListener(MetaChannel_1.MetaChannel.HANDSHAKE, handshakeCallback || this.metaHandshake);
|
|
24
25
|
}
|
|
@@ -38,11 +39,41 @@ class Realtime {
|
|
|
38
39
|
unsubscribe(subscription) {
|
|
39
40
|
return this.cometd.unsubscribe(subscription);
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Allows to listen to Cometd handshake to find out if e.g. the connection was reestablished.
|
|
44
|
+
*/
|
|
45
|
+
addHandshakeListener(callback) {
|
|
46
|
+
return this.cometd.addListener(MetaChannel_1.MetaChannel.HANDSHAKE, callback);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Allows to listen to Cometd connection to e.g. detect when connection was lost.
|
|
50
|
+
*/
|
|
51
|
+
addConnectListener(callback) {
|
|
52
|
+
return this.cometd.addListener(MetaChannel_1.MetaChannel.CONNECT, callback);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Removes the subscription obtained with a call to `addHandshakeListener` or `addConnectListener`.
|
|
56
|
+
*/
|
|
57
|
+
removeListener(subscriptionHandle) {
|
|
58
|
+
return this.cometd.removeListener(subscriptionHandle);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resubscribes as necessary in case of a re-handshake.
|
|
62
|
+
*/
|
|
63
|
+
resubscribe(subscriptionHandle) {
|
|
64
|
+
return this.cometd.resubscribe(subscriptionHandle);
|
|
65
|
+
}
|
|
41
66
|
/**
|
|
42
67
|
* Disconnects the current connection.
|
|
43
68
|
*/
|
|
44
|
-
disconnect() {
|
|
45
|
-
this.cometd.disconnect();
|
|
69
|
+
disconnect(disconnectCallback = undefined) {
|
|
70
|
+
this.cometd.disconnect(disconnectCallback);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns true if the CometD instance is disconnected or disconnecting.
|
|
74
|
+
*/
|
|
75
|
+
isDisconnected() {
|
|
76
|
+
return this.cometd.isDisconnected();
|
|
46
77
|
}
|
|
47
78
|
checkConnection() {
|
|
48
79
|
const { cometd, client, url } = this;
|
|
@@ -57,7 +88,7 @@ class Realtime {
|
|
|
57
88
|
}
|
|
58
89
|
}
|
|
59
90
|
handshake(config) {
|
|
60
|
-
this.cometd.handshake(config);
|
|
91
|
+
this.cometd.handshake(config, undefined);
|
|
61
92
|
}
|
|
62
93
|
}
|
|
63
94
|
exports.Realtime = Realtime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Realtime.js","sourceRoot":"","sources":["../../../../src/realtime/Realtime.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Realtime.js","sourceRoot":"","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C;IAED;;OAEG;IACH,cAAc,CAAC,kBAAsC;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,kBAAsC;QAChD,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,qBAAqC,SAAS;QACvD,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;IAEO,eAAe;QACrB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACrC,IAAI,MAAM,CAAC,cAAc,EAAE,EAAE;YAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;YAC7C,MAAM,MAAM,GAAG;gBACb,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;gBACvB,cAAc,EAAE,OAAO;aACxB,CAAC;YACF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC;SAC7C;IACH,CAAC;IAEO,SAAS,CAAC,MAAc;QAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;CAOF;AAtGD,4BAsGC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CometD } from 'isomorphic-cometd';
|
|
1
|
+
import { CometD as IsoCometD } from 'isomorphic-cometd';
|
|
2
2
|
import { MetaChannel } from './MetaChannel';
|
|
3
3
|
export class Realtime {
|
|
4
4
|
/**
|
|
@@ -10,12 +10,13 @@ export class Realtime {
|
|
|
10
10
|
constructor(client, url = '/notification/realtime', handshakeCallback) {
|
|
11
11
|
this.client = client;
|
|
12
12
|
this.url = url;
|
|
13
|
-
this.cometd = new CometD();
|
|
14
13
|
this.metaHandshake = msg => {
|
|
15
14
|
if (!msg.successful) {
|
|
16
15
|
throw new Error('Handshake failed');
|
|
17
16
|
}
|
|
18
17
|
};
|
|
18
|
+
this.cometd = new IsoCometD({});
|
|
19
|
+
// does not actually seem to be needed/supported? Just keeping to satisfy unit test snapshots
|
|
19
20
|
this.cometd.websocketEnabled = true;
|
|
20
21
|
this.cometd.addListener(MetaChannel.HANDSHAKE, handshakeCallback || this.metaHandshake);
|
|
21
22
|
}
|
|
@@ -35,11 +36,41 @@ export class Realtime {
|
|
|
35
36
|
unsubscribe(subscription) {
|
|
36
37
|
return this.cometd.unsubscribe(subscription);
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Allows to listen to Cometd handshake to find out if e.g. the connection was reestablished.
|
|
41
|
+
*/
|
|
42
|
+
addHandshakeListener(callback) {
|
|
43
|
+
return this.cometd.addListener(MetaChannel.HANDSHAKE, callback);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Allows to listen to Cometd connection to e.g. detect when connection was lost.
|
|
47
|
+
*/
|
|
48
|
+
addConnectListener(callback) {
|
|
49
|
+
return this.cometd.addListener(MetaChannel.CONNECT, callback);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Removes the subscription obtained with a call to `addHandshakeListener` or `addConnectListener`.
|
|
53
|
+
*/
|
|
54
|
+
removeListener(subscriptionHandle) {
|
|
55
|
+
return this.cometd.removeListener(subscriptionHandle);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resubscribes as necessary in case of a re-handshake.
|
|
59
|
+
*/
|
|
60
|
+
resubscribe(subscriptionHandle) {
|
|
61
|
+
return this.cometd.resubscribe(subscriptionHandle);
|
|
62
|
+
}
|
|
38
63
|
/**
|
|
39
64
|
* Disconnects the current connection.
|
|
40
65
|
*/
|
|
41
|
-
disconnect() {
|
|
42
|
-
this.cometd.disconnect();
|
|
66
|
+
disconnect(disconnectCallback = undefined) {
|
|
67
|
+
this.cometd.disconnect(disconnectCallback);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns true if the CometD instance is disconnected or disconnecting.
|
|
71
|
+
*/
|
|
72
|
+
isDisconnected() {
|
|
73
|
+
return this.cometd.isDisconnected();
|
|
43
74
|
}
|
|
44
75
|
checkConnection() {
|
|
45
76
|
const { cometd, client, url } = this;
|
|
@@ -54,7 +85,7 @@ export class Realtime {
|
|
|
54
85
|
}
|
|
55
86
|
}
|
|
56
87
|
handshake(config) {
|
|
57
|
-
this.cometd.handshake(config);
|
|
88
|
+
this.cometd.handshake(config, undefined);
|
|
58
89
|
}
|
|
59
90
|
}
|
|
60
91
|
//# sourceMappingURL=Realtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Realtime.js","sourceRoot":"","sources":["../../../../src/realtime/Realtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"Realtime.js","sourceRoot":"","sources":["../../../../src/realtime/Realtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,OAAO,QAAQ;IAGnB;;;;;OAKG;IACH,YACU,MAAoB,EACpB,MAAc,wBAAwB,EAC9C,iBAAkB;QAFV,WAAM,GAAN,MAAM,CAAc;QACpB,QAAG,GAAH,GAAG,CAAmC;QAsFxC,kBAAa,GAAG,GAAG,CAAC,EAAE;YAC5B,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE;gBACnB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;aACrC;QACH,CAAC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ACZ,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IACtC,CAAC;IAEO,eAAe;QACrB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QACrC,IAAI,MAAM,CAAC,cAAc,EAAE,EAAE;YAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;YAC7C,MAAM,MAAM,GAAG;gBACb,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;gBACvB,cAAc,EAAE,OAAO;aACxB,CAAC;YACF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC,CAAC;SAC7C;IACH,CAAC;IAEO,SAAS,CAAC,MAAc;QAC9B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;CAOF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CometD, SubscriptionHandle, Listener as CometDListener, Callback as CometDCallback, HandshakeMessage as CometDHandshakeMessage, Message as CometDMessage } from 'cometd';
|
|
1
2
|
import { IFetchClient } from '../core';
|
|
2
3
|
export interface ICometdConfig {
|
|
3
4
|
url: string;
|
|
@@ -9,7 +10,7 @@ export interface ICometdConfig {
|
|
|
9
10
|
export declare class Realtime {
|
|
10
11
|
private client;
|
|
11
12
|
private url;
|
|
12
|
-
|
|
13
|
+
protected cometd: CometD;
|
|
13
14
|
/**
|
|
14
15
|
* Allows to set up a realtime (websocket or long-polling) connection to the platform.
|
|
15
16
|
* @param client The fetch client instance to use
|
|
@@ -22,16 +23,36 @@ export declare class Realtime {
|
|
|
22
23
|
* @param channel The channel to connect to
|
|
23
24
|
* @param callback A function to call when data is received
|
|
24
25
|
*/
|
|
25
|
-
subscribe(channel: string, callback:
|
|
26
|
+
subscribe(channel: string, callback: CometDCallback): SubscriptionHandle;
|
|
26
27
|
/**
|
|
27
28
|
* Cancels the listening to a channel.
|
|
28
29
|
* @param subscription The subscription object returned by subscribe()
|
|
29
30
|
*/
|
|
30
|
-
unsubscribe(subscription:
|
|
31
|
+
unsubscribe(subscription: SubscriptionHandle): void;
|
|
32
|
+
/**
|
|
33
|
+
* Allows to listen to Cometd handshake to find out if e.g. the connection was reestablished.
|
|
34
|
+
*/
|
|
35
|
+
addHandshakeListener(callback: (msg: CometDHandshakeMessage) => void): SubscriptionHandle;
|
|
36
|
+
/**
|
|
37
|
+
* Allows to listen to Cometd connection to e.g. detect when connection was lost.
|
|
38
|
+
*/
|
|
39
|
+
addConnectListener(callback: (msg: CometDMessage) => void): SubscriptionHandle;
|
|
40
|
+
/**
|
|
41
|
+
* Removes the subscription obtained with a call to `addHandshakeListener` or `addConnectListener`.
|
|
42
|
+
*/
|
|
43
|
+
removeListener(subscriptionHandle: SubscriptionHandle): void;
|
|
44
|
+
/**
|
|
45
|
+
* Resubscribes as necessary in case of a re-handshake.
|
|
46
|
+
*/
|
|
47
|
+
resubscribe(subscriptionHandle: SubscriptionHandle): SubscriptionHandle;
|
|
31
48
|
/**
|
|
32
49
|
* Disconnects the current connection.
|
|
33
50
|
*/
|
|
34
|
-
disconnect(): void;
|
|
51
|
+
disconnect(disconnectCallback?: CometDListener): void;
|
|
52
|
+
/**
|
|
53
|
+
* Returns true if the CometD instance is disconnected or disconnecting.
|
|
54
|
+
*/
|
|
55
|
+
isDisconnected(): boolean;
|
|
35
56
|
private checkConnection;
|
|
36
57
|
private handshake;
|
|
37
58
|
private metaHandshake;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c8y/client",
|
|
3
|
-
"version": "1017.0.
|
|
3
|
+
"version": "1017.0.355",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Cumulocity",
|
|
6
6
|
"description": "Client application programming interface to access the Cumulocity IoT-Platform REST services.",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"isomorphic-cometd": "1.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@types/cometd": "4.0.8",
|
|
49
50
|
"@types/fs-extra": "5.0.1",
|
|
50
51
|
"@types/jest": "^26.0.22",
|
|
51
52
|
"fs-extra": "5.0.0",
|