@pryv/monitor 3.0.3 → 3.2.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/package.json +1 -1
- package/src/Monitor.js +24 -0
- package/src/UpdateMethod/Socket.js +9 -0
- package/src/index.d.ts +8 -0
package/package.json
CHANGED
package/src/Monitor.js
CHANGED
|
@@ -163,6 +163,30 @@ class Monitor extends EventEmitter {
|
|
|
163
163
|
return this.states.started;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Plan 66: register a handler for the server's fine-grained
|
|
168
|
+
* `accessUpdated` event. Fires whenever a Pryv.io ≥ 2.0.0-pre.X server
|
|
169
|
+
* emits the event after a successful `accesses.update` — payload is
|
|
170
|
+
* `{ type: 'access-updated', accessId: '<base>:<serial>', serial }`.
|
|
171
|
+
*
|
|
172
|
+
* Requires `Monitor.UpdateMethod.Socket` to be active (the event
|
|
173
|
+
* is server-pushed via `@pryv/socket.io`). With other update methods
|
|
174
|
+
* (e.g. `EventsTimer` polling), the handler will never fire —
|
|
175
|
+
* polling-based consumers should call `connection.accessInfo(true)`
|
|
176
|
+
* themselves when they need to refresh the cache.
|
|
177
|
+
*
|
|
178
|
+
* The underlying `connection.socket` already busts the
|
|
179
|
+
* `connection.accessInfo` cache when this event fires, so the next
|
|
180
|
+
* `connection.accessInfo()` call returns the freshly-fetched copy.
|
|
181
|
+
*
|
|
182
|
+
* @param {Function} handler - called with `(payload)` on each event
|
|
183
|
+
* @returns {Monitor} this (chainable)
|
|
184
|
+
*/
|
|
185
|
+
onAccessUpdated (handler) {
|
|
186
|
+
this.on('accessUpdated', handler);
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
|
|
166
190
|
/**
|
|
167
191
|
* @private
|
|
168
192
|
* Called by UpdateMethod to share cross references
|
|
@@ -23,6 +23,15 @@ class Socket extends UpdateMethod {
|
|
|
23
23
|
this.socket = await this.monitor.connection.socket.open();
|
|
24
24
|
this.socket.on('eventsChanged', () => { this.monitor.updateEvents(); });
|
|
25
25
|
this.socket.on('streamsChanged', () => { this.monitor.updateStreams(); });
|
|
26
|
+
// Plan 66: re-emit the server's fine-grained `accessUpdated` event
|
|
27
|
+
// on the Monitor itself so consumers can subscribe via
|
|
28
|
+
// `monitor.onAccessUpdated(handler)`. The underlying SocketIO has
|
|
29
|
+
// already busted the connection's accessInfo cache; the payload
|
|
30
|
+
// carries the new composite accessId + serial for fine-grained
|
|
31
|
+
// reactions.
|
|
32
|
+
this.socket.on('accessUpdated', (payload) => {
|
|
33
|
+
this.monitor.emit('accessUpdated', payload);
|
|
34
|
+
});
|
|
26
35
|
this.socket.on('error', (error) => {
|
|
27
36
|
this.monitor.emit(Changes.ERROR, error);
|
|
28
37
|
// If the underlying socket.io-client transport has been torn down
|
package/src/index.d.ts
CHANGED
|
@@ -96,6 +96,14 @@ declare module 'pryv' {
|
|
|
96
96
|
*/
|
|
97
97
|
stop(): Monitor;
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Plan 66: register a handler for the server's fine-grained
|
|
101
|
+
* `accessUpdated` event. Requires `Monitor.UpdateMethod.Socket`.
|
|
102
|
+
* The underlying `connection.socket` busts the
|
|
103
|
+
* `connection.accessInfo` cache before this fires.
|
|
104
|
+
*/
|
|
105
|
+
onAccessUpdated(handler: (payload: { type: 'access-updated', accessId: string, serial: number }) => void): Monitor;
|
|
106
|
+
|
|
99
107
|
/**
|
|
100
108
|
* True when the monitor has been started and not yet stopped.
|
|
101
109
|
*/
|