@ariva-mds/mds 2.14.0 → 2.15.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/lib/cjs/index.js +58 -25
- package/lib/cjs/types/index.d.ts +25 -3
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/esm/index.mjs +58 -25
- package/lib/esm/types/index.d.ts +25 -3
- package/lib/esm/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/cjs/index.js
CHANGED
|
@@ -24,10 +24,12 @@ class MdsConnectionState {
|
|
|
24
24
|
constructor() {
|
|
25
25
|
this.isConnected = false;
|
|
26
26
|
this.isAuthenticated = false;
|
|
27
|
+
this.lastUpdate = new Date();
|
|
27
28
|
}
|
|
28
29
|
connectionOpened() {
|
|
29
30
|
this.isConnected = true;
|
|
30
31
|
this.isAuthenticated = false;
|
|
32
|
+
this.lastUpdate = new Date();
|
|
31
33
|
}
|
|
32
34
|
connectionClosed() {
|
|
33
35
|
this.isConnected = false;
|
|
@@ -39,6 +41,12 @@ class MdsConnectionState {
|
|
|
39
41
|
authenticationEnded() {
|
|
40
42
|
this.isAuthenticated = false;
|
|
41
43
|
}
|
|
44
|
+
messageReceived() {
|
|
45
|
+
this.lastUpdate = new Date();
|
|
46
|
+
}
|
|
47
|
+
isTimedOut() {
|
|
48
|
+
return Date.now() - this.lastUpdate.getTime() < 20000; // 20 seconds timeout
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
51
|
exports.MdsConnectionState = MdsConnectionState;
|
|
44
52
|
class RunningRequest {
|
|
@@ -57,6 +65,9 @@ class RunningRequest {
|
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
67
|
class MdsConnection {
|
|
68
|
+
/**
|
|
69
|
+
* construct an MdsCoonnection
|
|
70
|
+
*/
|
|
60
71
|
constructor(websocketUrl, authdataCallback, options = { debug: false }) {
|
|
61
72
|
this.state = new MdsConnectionState();
|
|
62
73
|
this.waitingForAuthentification = [];
|
|
@@ -67,71 +78,92 @@ class MdsConnection {
|
|
|
67
78
|
this.authdataCallback = authdataCallback;
|
|
68
79
|
this.isDebug = options.debug ? true : false;
|
|
69
80
|
this.websocket = new reconnecting_websocket_1.default(websocketUrl, [], options.wsOptions);
|
|
70
|
-
this.stayAuthenticated();
|
|
71
81
|
const outer = this;
|
|
82
|
+
// open-handler -> resend open requests from previous connection
|
|
72
83
|
this.websocket.onopen = function () {
|
|
84
|
+
outer.debug("websocket open, resending " + JSON.stringify(outer.waitingForReconnect));
|
|
73
85
|
outer.state.connectionOpened();
|
|
74
86
|
// @ts-ignore
|
|
75
87
|
for (const request of outer.waitingForReconnect) {
|
|
76
|
-
|
|
77
|
-
outer.sendWhenAuthenticated(request.request);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
outer.websocket.send(JSON.stringify(request.request));
|
|
81
|
-
}
|
|
88
|
+
outer.sendAsSoonAsAuthenticationPermits(request.request);
|
|
82
89
|
}
|
|
83
90
|
};
|
|
91
|
+
// close handler -> store open requests for resending on reconnect
|
|
84
92
|
this.websocket.onclose = function () {
|
|
93
|
+
outer.debug("websocket closed, queuing " + JSON.stringify(outer.waitingForReconnect));
|
|
85
94
|
outer.state.connectionClosed();
|
|
86
95
|
outer.waitingForReconnect = Array.from(outer.runningRequests.values());
|
|
87
|
-
outer.debug("close");
|
|
88
96
|
};
|
|
89
97
|
this.websocket.onmessage = function (e) {
|
|
90
98
|
outer.processWebsocketMessageEvent(e);
|
|
91
99
|
};
|
|
100
|
+
this.stayAuthenticated();
|
|
101
|
+
setInterval(() => {
|
|
102
|
+
if (!outer.state.isTimedOut()) {
|
|
103
|
+
outer.debug("websocket timed out, calling reconnect");
|
|
104
|
+
outer.websocket.reconnect();
|
|
105
|
+
}
|
|
106
|
+
}, 1000);
|
|
92
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* create a hearbeat observable that can be subscribed to
|
|
110
|
+
*/
|
|
93
111
|
heartbeat() {
|
|
94
112
|
return this.observable({ 'heartbeat': {} }, true)
|
|
95
113
|
.pipe((0, rxjs_1.map)((x) => x.dataHeartbeat));
|
|
96
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* create a MarketstateUpdate observable that can be subscribed to, contains both full state and delta for every marketstate
|
|
117
|
+
*/
|
|
97
118
|
marketstates(marketstateQueries) {
|
|
98
119
|
const full = new Map();
|
|
99
120
|
return this.marketstateUpdates(marketstateQueries)
|
|
100
121
|
.pipe((0, rxjs_1.map)((update) => {
|
|
101
122
|
let existingEntry = update.marketstateId ? full.get(update.marketstateId) : null;
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
for (let key in updateJson) {
|
|
106
|
-
if (!(updateJson[key] == undefined)) {
|
|
107
|
-
existingJson[key] = updateJson[key];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
existingEntry = (0, MarketstateWithId_1.MarketstateWithIdFromJSON)(existingJson);
|
|
111
|
-
if (update.marketstateId) {
|
|
123
|
+
if (update.marketstateId) {
|
|
124
|
+
if (existingEntry) {
|
|
125
|
+
existingEntry = this.updateExistingMarketstateWithDeltaUpdate(existingEntry, update);
|
|
112
126
|
full.set(update.marketstateId, existingEntry);
|
|
113
127
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
existingEntry = update;
|
|
117
|
-
if (update.marketstateId) {
|
|
128
|
+
else {
|
|
129
|
+
existingEntry = update;
|
|
118
130
|
full.set(update.marketstateId, existingEntry);
|
|
119
131
|
}
|
|
120
132
|
}
|
|
121
133
|
return new MarketstateUpdate(existingEntry, update);
|
|
122
134
|
}));
|
|
123
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* create a Marketstate observable that can be subscribed to, contains only delta for every marketstate
|
|
138
|
+
*/
|
|
124
139
|
marketstateUpdates(marketstateQueries) {
|
|
125
140
|
return this.observable({ 'subscribeMarketstates': { 'marketstateQueries': marketstateQueries } }, true)
|
|
126
141
|
.pipe((0, rxjs_1.map)((x) => (0, MarketstateWithId_1.MarketstateWithIdFromJSON)(x.dataMarketstate)));
|
|
127
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* create a Marketstate observable that can be subscribed to, contains only full state for every marketstate
|
|
145
|
+
*/
|
|
128
146
|
marketstatesStates(marketstateQueries) {
|
|
129
147
|
return this.marketstates(marketstateQueries).pipe((0, rxjs_1.map)((x) => x.state));
|
|
130
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* sets the priority for sources
|
|
151
|
+
*/
|
|
131
152
|
priority(sources) {
|
|
132
153
|
return this.promise({ 'priority': { 'sources': sources } });
|
|
133
154
|
}
|
|
134
|
-
|
|
155
|
+
updateExistingMarketstateWithDeltaUpdate(existingEntry, update) {
|
|
156
|
+
const existingJson = (0, MarketstateWithId_1.MarketstateWithIdToJSON)(existingEntry);
|
|
157
|
+
const updateJson = (0, MarketstateWithId_1.MarketstateWithIdToJSON)(update);
|
|
158
|
+
for (let key in updateJson) {
|
|
159
|
+
if (!(updateJson[key] == undefined)) {
|
|
160
|
+
existingJson[key] = updateJson[key];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
existingEntry = (0, MarketstateWithId_1.MarketstateWithIdFromJSON)(existingJson);
|
|
164
|
+
return existingEntry;
|
|
165
|
+
}
|
|
166
|
+
sendAsSoonAsAuthenticationPermits(json) {
|
|
135
167
|
if (this.state.isAuthenticated || json.subscribeAuthentication) {
|
|
136
168
|
this.websocket.send(JSON.stringify(json));
|
|
137
169
|
}
|
|
@@ -175,7 +207,7 @@ class MdsConnection {
|
|
|
175
207
|
const outer = this;
|
|
176
208
|
const observable = new rxjs_1.Observable((subscriber) => {
|
|
177
209
|
outer.runningRequests.set(requestId, RunningRequest.withObservable(req, subscriber));
|
|
178
|
-
outer.
|
|
210
|
+
outer.sendAsSoonAsAuthenticationPermits(req);
|
|
179
211
|
// Provide a way of canceling and disposing the resources
|
|
180
212
|
return function unsubscribe() {
|
|
181
213
|
let runningRequest = outer.runningRequests.get(requestId);
|
|
@@ -195,7 +227,7 @@ class MdsConnection {
|
|
|
195
227
|
const outer = this;
|
|
196
228
|
const promise = new Promise((resolve, reject) => {
|
|
197
229
|
outer.runningRequests.set(requestId, RunningRequest.withPromise(req, resolve, reject));
|
|
198
|
-
outer.
|
|
230
|
+
outer.sendAsSoonAsAuthenticationPermits(req);
|
|
199
231
|
});
|
|
200
232
|
return promise;
|
|
201
233
|
}
|
|
@@ -203,6 +235,7 @@ class MdsConnection {
|
|
|
203
235
|
const msg = JSON.parse(e.data);
|
|
204
236
|
this.debug("we received " + JSON.stringify(msg));
|
|
205
237
|
const request = this.runningRequests.get(msg.requestId);
|
|
238
|
+
this.state.messageReceived();
|
|
206
239
|
if (request && request.promiseResolve) {
|
|
207
240
|
if (msg.isError) {
|
|
208
241
|
request.promiseReject(msg.errorMessage);
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -13,12 +13,15 @@ export declare class MarketstateUpdate {
|
|
|
13
13
|
export declare class MdsConnectionState {
|
|
14
14
|
isConnected: boolean;
|
|
15
15
|
isAuthenticated: boolean;
|
|
16
|
+
lastUpdate: Date;
|
|
16
17
|
connectionOpened(): void;
|
|
17
18
|
connectionClosed(): void;
|
|
18
19
|
authenticationAccepted(): void;
|
|
19
20
|
authenticationEnded(): void;
|
|
21
|
+
messageReceived(): void;
|
|
22
|
+
isTimedOut(): boolean;
|
|
20
23
|
}
|
|
21
|
-
export type
|
|
24
|
+
export type MdsOptions = {
|
|
22
25
|
debug?: boolean;
|
|
23
26
|
wsOptions?: ReconnectingWebSocketOptions;
|
|
24
27
|
};
|
|
@@ -31,13 +34,32 @@ export declare class MdsConnection {
|
|
|
31
34
|
private nextGeneratedRequestId;
|
|
32
35
|
private readonly runningRequests;
|
|
33
36
|
private isDebug;
|
|
34
|
-
|
|
37
|
+
/**
|
|
38
|
+
* construct an MdsCoonnection
|
|
39
|
+
*/
|
|
40
|
+
constructor(websocketUrl: string, authdataCallback: () => Promise<MdsAuthdata>, options?: MdsOptions);
|
|
41
|
+
/**
|
|
42
|
+
* create a hearbeat observable that can be subscribed to
|
|
43
|
+
*/
|
|
35
44
|
heartbeat(): Observable<String>;
|
|
45
|
+
/**
|
|
46
|
+
* create a MarketstateUpdate observable that can be subscribed to, contains both full state and delta for every marketstate
|
|
47
|
+
*/
|
|
36
48
|
marketstates(marketstateQueries: String[]): Observable<MarketstateUpdate>;
|
|
49
|
+
/**
|
|
50
|
+
* create a Marketstate observable that can be subscribed to, contains only delta for every marketstate
|
|
51
|
+
*/
|
|
37
52
|
marketstateUpdates(marketstateQueries: String[]): Observable<MarketstateWithId>;
|
|
53
|
+
/**
|
|
54
|
+
* create a Marketstate observable that can be subscribed to, contains only full state for every marketstate
|
|
55
|
+
*/
|
|
38
56
|
marketstatesStates(marketstateQueries: String[]): Observable<MarketstateWithId>;
|
|
57
|
+
/**
|
|
58
|
+
* sets the priority for sources
|
|
59
|
+
*/
|
|
39
60
|
priority(sources: string[]): Promise<void>;
|
|
40
|
-
private
|
|
61
|
+
private updateExistingMarketstateWithDeltaUpdate;
|
|
62
|
+
private sendAsSoonAsAuthenticationPermits;
|
|
41
63
|
private stayAuthenticated;
|
|
42
64
|
private generateNextRequestId;
|
|
43
65
|
private observable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAA8B,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,wBAAwB,CAAC;AACtG,OAAO,EAAM,UAAU,EAAqB,MAAM,MAAM,CAAC;AACzD,OAAO,EAAC,iBAAiB,EAAqD,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAA8B,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,wBAAwB,CAAC;AACtG,OAAO,EAAM,UAAU,EAAqB,MAAM,MAAM,CAAC;AACzD,OAAO,EAAC,iBAAiB,EAAq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AiB,CAAC;IAKtF;;OAEG;IAEI,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC;IAMtF;;OAEG;IAEI,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjD,OAAO,CAAC,wCAAwC;IAehD,OAAO,CAAC,iCAAiC;IASzC,OAAO,CAAC,iBAAiB;IAuCzB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,UAAU;IA2BlB,OAAO,CAAC,OAAO;IAgBf,OAAO,CAAC,4BAA4B;IA6BpC,OAAO,CAAC,KAAK;CAKhB"}
|
package/lib/esm/index.mjs
CHANGED
|
@@ -18,9 +18,11 @@ export class MarketstateUpdate {
|
|
|
18
18
|
export class MdsConnectionState {
|
|
19
19
|
isConnected = false;
|
|
20
20
|
isAuthenticated = false;
|
|
21
|
+
lastUpdate = new Date();
|
|
21
22
|
connectionOpened() {
|
|
22
23
|
this.isConnected = true;
|
|
23
24
|
this.isAuthenticated = false;
|
|
25
|
+
this.lastUpdate = new Date();
|
|
24
26
|
}
|
|
25
27
|
connectionClosed() {
|
|
26
28
|
this.isConnected = false;
|
|
@@ -32,6 +34,12 @@ export class MdsConnectionState {
|
|
|
32
34
|
authenticationEnded() {
|
|
33
35
|
this.isAuthenticated = false;
|
|
34
36
|
}
|
|
37
|
+
messageReceived() {
|
|
38
|
+
this.lastUpdate = new Date();
|
|
39
|
+
}
|
|
40
|
+
isTimedOut() {
|
|
41
|
+
return Date.now() - this.lastUpdate.getTime() < 20000; // 20 seconds timeout
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
44
|
class RunningRequest {
|
|
37
45
|
observableSubscriber;
|
|
@@ -61,75 +69,99 @@ export class MdsConnection {
|
|
|
61
69
|
nextGeneratedRequestId = 0;
|
|
62
70
|
runningRequests = new Map();
|
|
63
71
|
isDebug = false;
|
|
72
|
+
/**
|
|
73
|
+
* construct an MdsCoonnection
|
|
74
|
+
*/
|
|
64
75
|
constructor(websocketUrl, authdataCallback, options = { debug: false }) {
|
|
65
76
|
this.authdataCallback = authdataCallback;
|
|
66
77
|
this.isDebug = options.debug ? true : false;
|
|
67
78
|
this.websocket = new ReconnectingWebSocket(websocketUrl, [], options.wsOptions);
|
|
68
|
-
this.stayAuthenticated();
|
|
69
79
|
const outer = this;
|
|
80
|
+
// open-handler -> resend open requests from previous connection
|
|
70
81
|
this.websocket.onopen = function () {
|
|
82
|
+
outer.debug("websocket open, resending " + JSON.stringify(outer.waitingForReconnect));
|
|
71
83
|
outer.state.connectionOpened();
|
|
72
84
|
// @ts-ignore
|
|
73
85
|
for (const request of outer.waitingForReconnect) {
|
|
74
|
-
|
|
75
|
-
outer.sendWhenAuthenticated(request.request);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
outer.websocket.send(JSON.stringify(request.request));
|
|
79
|
-
}
|
|
86
|
+
outer.sendAsSoonAsAuthenticationPermits(request.request);
|
|
80
87
|
}
|
|
81
88
|
};
|
|
89
|
+
// close handler -> store open requests for resending on reconnect
|
|
82
90
|
this.websocket.onclose = function () {
|
|
91
|
+
outer.debug("websocket closed, queuing " + JSON.stringify(outer.waitingForReconnect));
|
|
83
92
|
outer.state.connectionClosed();
|
|
84
93
|
outer.waitingForReconnect = Array.from(outer.runningRequests.values());
|
|
85
|
-
outer.debug("close");
|
|
86
94
|
};
|
|
87
95
|
this.websocket.onmessage = function (e) {
|
|
88
96
|
outer.processWebsocketMessageEvent(e);
|
|
89
97
|
};
|
|
98
|
+
this.stayAuthenticated();
|
|
99
|
+
setInterval(() => {
|
|
100
|
+
if (!outer.state.isTimedOut()) {
|
|
101
|
+
outer.debug("websocket timed out, calling reconnect");
|
|
102
|
+
outer.websocket.reconnect();
|
|
103
|
+
}
|
|
104
|
+
}, 1000);
|
|
90
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* create a hearbeat observable that can be subscribed to
|
|
108
|
+
*/
|
|
91
109
|
heartbeat() {
|
|
92
110
|
return this.observable({ 'heartbeat': {} }, true)
|
|
93
111
|
.pipe(map((x) => x.dataHeartbeat));
|
|
94
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* create a MarketstateUpdate observable that can be subscribed to, contains both full state and delta for every marketstate
|
|
115
|
+
*/
|
|
95
116
|
marketstates(marketstateQueries) {
|
|
96
117
|
const full = new Map();
|
|
97
118
|
return this.marketstateUpdates(marketstateQueries)
|
|
98
119
|
.pipe(map((update) => {
|
|
99
120
|
let existingEntry = update.marketstateId ? full.get(update.marketstateId) : null;
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
for (let key in updateJson) {
|
|
104
|
-
if (!(updateJson[key] == undefined)) {
|
|
105
|
-
existingJson[key] = updateJson[key];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
existingEntry = MarketstateWithIdFromJSON(existingJson);
|
|
109
|
-
if (update.marketstateId) {
|
|
121
|
+
if (update.marketstateId) {
|
|
122
|
+
if (existingEntry) {
|
|
123
|
+
existingEntry = this.updateExistingMarketstateWithDeltaUpdate(existingEntry, update);
|
|
110
124
|
full.set(update.marketstateId, existingEntry);
|
|
111
125
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
existingEntry = update;
|
|
115
|
-
if (update.marketstateId) {
|
|
126
|
+
else {
|
|
127
|
+
existingEntry = update;
|
|
116
128
|
full.set(update.marketstateId, existingEntry);
|
|
117
129
|
}
|
|
118
130
|
}
|
|
119
131
|
return new MarketstateUpdate(existingEntry, update);
|
|
120
132
|
}));
|
|
121
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* create a Marketstate observable that can be subscribed to, contains only delta for every marketstate
|
|
136
|
+
*/
|
|
122
137
|
marketstateUpdates(marketstateQueries) {
|
|
123
138
|
return this.observable({ 'subscribeMarketstates': { 'marketstateQueries': marketstateQueries } }, true)
|
|
124
139
|
.pipe(map((x) => MarketstateWithIdFromJSON(x.dataMarketstate)));
|
|
125
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* create a Marketstate observable that can be subscribed to, contains only full state for every marketstate
|
|
143
|
+
*/
|
|
126
144
|
marketstatesStates(marketstateQueries) {
|
|
127
145
|
return this.marketstates(marketstateQueries).pipe(map((x) => x.state));
|
|
128
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* sets the priority for sources
|
|
149
|
+
*/
|
|
129
150
|
priority(sources) {
|
|
130
151
|
return this.promise({ 'priority': { 'sources': sources } });
|
|
131
152
|
}
|
|
132
|
-
|
|
153
|
+
updateExistingMarketstateWithDeltaUpdate(existingEntry, update) {
|
|
154
|
+
const existingJson = MarketstateWithIdToJSON(existingEntry);
|
|
155
|
+
const updateJson = MarketstateWithIdToJSON(update);
|
|
156
|
+
for (let key in updateJson) {
|
|
157
|
+
if (!(updateJson[key] == undefined)) {
|
|
158
|
+
existingJson[key] = updateJson[key];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
existingEntry = MarketstateWithIdFromJSON(existingJson);
|
|
162
|
+
return existingEntry;
|
|
163
|
+
}
|
|
164
|
+
sendAsSoonAsAuthenticationPermits(json) {
|
|
133
165
|
if (this.state.isAuthenticated || json.subscribeAuthentication) {
|
|
134
166
|
this.websocket.send(JSON.stringify(json));
|
|
135
167
|
}
|
|
@@ -173,7 +205,7 @@ export class MdsConnection {
|
|
|
173
205
|
const outer = this;
|
|
174
206
|
const observable = new Observable((subscriber) => {
|
|
175
207
|
outer.runningRequests.set(requestId, RunningRequest.withObservable(req, subscriber));
|
|
176
|
-
outer.
|
|
208
|
+
outer.sendAsSoonAsAuthenticationPermits(req);
|
|
177
209
|
// Provide a way of canceling and disposing the resources
|
|
178
210
|
return function unsubscribe() {
|
|
179
211
|
let runningRequest = outer.runningRequests.get(requestId);
|
|
@@ -193,7 +225,7 @@ export class MdsConnection {
|
|
|
193
225
|
const outer = this;
|
|
194
226
|
const promise = new Promise((resolve, reject) => {
|
|
195
227
|
outer.runningRequests.set(requestId, RunningRequest.withPromise(req, resolve, reject));
|
|
196
|
-
outer.
|
|
228
|
+
outer.sendAsSoonAsAuthenticationPermits(req);
|
|
197
229
|
});
|
|
198
230
|
return promise;
|
|
199
231
|
}
|
|
@@ -201,6 +233,7 @@ export class MdsConnection {
|
|
|
201
233
|
const msg = JSON.parse(e.data);
|
|
202
234
|
this.debug("we received " + JSON.stringify(msg));
|
|
203
235
|
const request = this.runningRequests.get(msg.requestId);
|
|
236
|
+
this.state.messageReceived();
|
|
204
237
|
if (request && request.promiseResolve) {
|
|
205
238
|
if (msg.isError) {
|
|
206
239
|
request.promiseReject(msg.errorMessage);
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -13,12 +13,15 @@ export declare class MarketstateUpdate {
|
|
|
13
13
|
export declare class MdsConnectionState {
|
|
14
14
|
isConnected: boolean;
|
|
15
15
|
isAuthenticated: boolean;
|
|
16
|
+
lastUpdate: Date;
|
|
16
17
|
connectionOpened(): void;
|
|
17
18
|
connectionClosed(): void;
|
|
18
19
|
authenticationAccepted(): void;
|
|
19
20
|
authenticationEnded(): void;
|
|
21
|
+
messageReceived(): void;
|
|
22
|
+
isTimedOut(): boolean;
|
|
20
23
|
}
|
|
21
|
-
export type
|
|
24
|
+
export type MdsOptions = {
|
|
22
25
|
debug?: boolean;
|
|
23
26
|
wsOptions?: ReconnectingWebSocketOptions;
|
|
24
27
|
};
|
|
@@ -31,13 +34,32 @@ export declare class MdsConnection {
|
|
|
31
34
|
private nextGeneratedRequestId;
|
|
32
35
|
private readonly runningRequests;
|
|
33
36
|
private isDebug;
|
|
34
|
-
|
|
37
|
+
/**
|
|
38
|
+
* construct an MdsCoonnection
|
|
39
|
+
*/
|
|
40
|
+
constructor(websocketUrl: string, authdataCallback: () => Promise<MdsAuthdata>, options?: MdsOptions);
|
|
41
|
+
/**
|
|
42
|
+
* create a hearbeat observable that can be subscribed to
|
|
43
|
+
*/
|
|
35
44
|
heartbeat(): Observable<String>;
|
|
45
|
+
/**
|
|
46
|
+
* create a MarketstateUpdate observable that can be subscribed to, contains both full state and delta for every marketstate
|
|
47
|
+
*/
|
|
36
48
|
marketstates(marketstateQueries: String[]): Observable<MarketstateUpdate>;
|
|
49
|
+
/**
|
|
50
|
+
* create a Marketstate observable that can be subscribed to, contains only delta for every marketstate
|
|
51
|
+
*/
|
|
37
52
|
marketstateUpdates(marketstateQueries: String[]): Observable<MarketstateWithId>;
|
|
53
|
+
/**
|
|
54
|
+
* create a Marketstate observable that can be subscribed to, contains only full state for every marketstate
|
|
55
|
+
*/
|
|
38
56
|
marketstatesStates(marketstateQueries: String[]): Observable<MarketstateWithId>;
|
|
57
|
+
/**
|
|
58
|
+
* sets the priority for sources
|
|
59
|
+
*/
|
|
39
60
|
priority(sources: string[]): Promise<void>;
|
|
40
|
-
private
|
|
61
|
+
private updateExistingMarketstateWithDeltaUpdate;
|
|
62
|
+
private sendAsSoonAsAuthenticationPermits;
|
|
41
63
|
private stayAuthenticated;
|
|
42
64
|
private generateNextRequestId;
|
|
43
65
|
private observable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAA8B,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,wBAAwB,CAAC;AACtG,OAAO,EAAM,UAAU,EAAqB,MAAM,MAAM,CAAC;AACzD,OAAO,EAAC,iBAAiB,EAAqD,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAA8B,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,wBAAwB,CAAC;AACtG,OAAO,EAAM,UAAU,EAAqB,MAAM,MAAM,CAAC;AACzD,OAAO,EAAC,iBAAiB,EAAqD,MAAM,4BAA4B,CAAA;AAGhH,qBAAa,WAAW;IAEb,KAAK,EAAE,MAAM,CAAC;gBAET,KAAK,EAAE,MAAM;CAI5B;AAGD,qBA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