@pryv/monitor 1.0.4 → 2.3.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/README.md CHANGED
@@ -1,236 +1,212 @@
1
- # Monitor add-on for Pryv lib-js
1
+ # Monitor add-on for `pryv`
2
2
 
3
- Extends Pryv's [lib-js](https://github.com/pryv/lib-js) with event driven notifications for changes on a Pryv.io account.
3
+ Extends the [Pryv JavaScript library](https://github.com/pryv/lib-js) with event-driven notifications of changes on a Pryv.io account.
4
4
 
5
- ## Setup
6
5
 
7
- This library extends `Pryv` with a `Pryv.Monitor` class.
8
-
9
- ### Browser
10
-
11
- Note: `pryv-monitor.js` must be loaded **after** `pryv.js`
12
-
13
- ```html
14
- <script src="https://api.pryv.com/lib-js/pryv.js"></script>
15
- <script src="https://api.pryv.com/lib-js-monitor/pryv-monitor.js"></script>
16
- ```
6
+ ## Usage
17
7
 
18
- #### Others distributions for browsers:
8
+ The add-on extends `pryv` with a `pryv.Monitor` class.
19
9
 
20
- - ES6: `https://api.pryv.com/lib-js-monitor/pryv-monitor-es6.js`
21
- - Socket.io + Monitor + Lib-js: `https://api.pryv.com/lib-js/pryv-socket.io-monitor.js`.
22
10
 
23
- ### Node.js
11
+ ### Importing
24
12
 
25
- ```bash
26
- npm install pryv @pryv/monitor
27
- ```
13
+ #### NPM
28
14
 
29
- In your project files, load it **once only**. The Pryv javascript package will be patched with monitor capabilities.
15
+ `npm install --save pryv @pryv/monitor`, then in your code (the add-on must be loaded **once only**):
30
16
 
31
- ```javascript
32
- const Pryv = require('pryv');
33
- require('@pryv/monitor')(Pryv);
17
+ ```js
18
+ const pryv = require('pryv');
19
+ require('@pryv/monitor')(pryv);
34
20
  ```
35
21
 
36
- ## Usage
37
-
38
- Once Monitor has been set up, `Pryv.Monitor` can be instantiated.
22
+ #### `<script>` tag
39
23
 
40
- ### Constructor
24
+ `pryv-monitor.js` must be loaded **after** `pryv.js`:
41
25
 
42
- ```javascript
43
- new Pryv.Monitor({apiEndpoint | connection}, eventsGetScope)
26
+ ```html
27
+ <script src="https://api.pryv.com/lib-js/pryv.js"></script>
28
+ <script src="https://api.pryv.com/lib-js/pryv-monitor.js"></script>
44
29
  ```
45
30
 
46
- - apiEndpointUrl: [App guidelines - ApiEnpoint](https://api.pryv.com/guides/app-guidelines/#auto-configuration)
47
-
48
- Pryv.Connection: [lib-js Connection](https://github.com/pryv/lib-js#obtaining-a-pryvconnection)
31
+ Other distributions available:
49
32
 
50
- - eventsGetScope: [events.get parameters](https://api.pryv.com/reference/#get-events)
33
+ - ES6 version: `https://api.pryv.com/lib-js-monitor/pryv-monitor-es6.js`
34
+ - `pryv` library bundled with Socket.IO and Monitor add-ons: `https://api.pryv.com/lib-js/pryv-socket.io-monitor.js`.
51
35
 
52
- ### Event listeners
53
36
 
54
- Register event listeners for data changes on the `eventsGetScope`.
37
+ ### Using `pryv.Monitor`
55
38
 
56
- **Monitor** extends [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter).
39
+ Once the add-on is loaded, `pryv.Monitor` can be instantiated.
57
40
 
58
- You can register to them using:
41
+ #### Constructor
59
42
 
60
- ```javascript
61
- monitor.on({event}, {callback})
43
+ ```js
44
+ new pryv.Monitor({apiEndpoint | connection}, eventsGetScope)
62
45
  ```
63
46
 
64
- #### Events:
65
-
66
- - `event`: on every Pryv event **creation** and **update**
67
-
68
- callback argument: the Pryv event
47
+ - `apiEndpoint`: an API endpoint URL (see [app guidelines](https://api.pryv.com/guides/app-guidelines/#auto-configuration))
48
+ - `connection`: a `pryv.Connection` instance (see [library README](https://github.com/pryv/lib-js#obtaining-a-pryvconnection))
49
+ - `eventsGetScope`: `event.get` parameters (see [API reference](https://api.pryv.com/reference/#get-events))
69
50
 
70
- - `eventDeleted`: on Pryv event deletion
51
+ #### Event listeners
71
52
 
72
- callback argument: `{id: "...."}` the id of the deleted Pryv event
53
+ Register event listeners for data changes on the specified scope. `pryv.Monitor` extends [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) so you can register listeners with:
73
54
 
74
- - `streams`: on any change (creation, update, deletion) in the Pryv stream structure
75
-
76
- callback argument: `{streams: ...}` as the [streams.get](https://api.pryv.com/reference/#get-streams) result
77
-
78
- - `error`: on error
79
-
80
- callback argument: The error or an error message
55
+ ```js
56
+ monitor.on(event, callback)
57
+ ```
81
58
 
82
- - `ready`: Emitted when the monitor is ready (For internal and UpdateMethod usage)
59
+ The possible events are:
83
60
 
84
- - `stop`: When the monitor stops
61
+ - `event`: on Pryv event **creation** and **update**; callback argument: the Pryv event
62
+ - `eventDeleted`: on Pryv event deletion; callback argument: an object with the `id` of the deleted Pryv event (e.g. `{id: "...."}`)
63
+ - `streams`: on any change (creation, update, deletion) in the Pryv stream structure; callback argument: a [`streams.get`](https://api.pryv.com/reference/#get-streams) result object (e.g. `{streams: ...}`)
64
+ - `error`: on error; callback argument: the error or error message
65
+ - `ready`: emitted when the monitor is ready (for internal and `UpdateMethod` usage – see below)
66
+ - `stop`: when the monitor stops
85
67
 
86
68
  #### Start monitoring
87
69
 
88
- ```javascript
70
+ ```js
89
71
  await monitor.start()
90
72
  ```
91
73
 
92
- When starting, the monitor will fetch entire dataset covered by the `eventsGetScope` and trigger the changes event accordingly.
74
+ The monitor will fetch the entire dataset in the specified scope then trigger the change events accordingly.
93
75
 
94
76
  #### Trigger Pryv events update
95
77
 
96
- ```javascript
78
+ ```js
97
79
  await monitor.updateEvents()
98
80
  ```
99
81
 
100
- This will push a request to update Pryv events into the task stack. It will be executed as soon as the monitor has finished eventual pending tasks.
82
+ This will push a request to update Pryv events into the task stack. It will be executed as soon as the monitor has finished possible pending tasks.
101
83
 
102
84
  #### Trigger streams update
103
85
 
104
- ```javascript
86
+ ```js
105
87
  await monitor.updateStreams()
106
88
  ```
107
89
 
108
- This will push a request to update Pryv streams into task the stack. It will be executed as soon as the monitor has finished eventual pending tasks.
90
+ This will push a request to update Pryv streams into the task stack. It will be executed as soon as the monitor has finished possible pending tasks.
109
91
 
110
92
  #### Add auto-update method
111
93
 
112
- ```javascript
113
- monitor.addUpdateMethod({UpdateMethod})
94
+ ```js
95
+ monitor.addUpdateMethod(updateMethod)
114
96
  ```
115
97
 
116
98
  Update methods can be triggered automatically with:
117
99
 
118
- - **EventsTimer**
119
-
120
- ```javascript
121
- new Pryv.Monitor.UpdateMethod.EventsTimer({ms})
122
- ```
123
-
124
- This will call `monitor.updateEvents()` regularly at a rate `{ms}` in milliseconds (It has no real world but for demonstrative purposes).
125
-
126
- - **Socket**
127
-
128
- ```javascript
129
- new Pryv.Monitor.UpdateMethod.Socket()
130
- ```
131
-
132
- Based on websockets, it uses [lib-js-socket.io](https://github.com/pryv/lib-js-socket.io) to relay notification from Pryv.io to the monitor.
133
-
134
- - **Custom**
100
+ - `EventsTimer`
101
+ ```js
102
+ new pryv.Monitor.UpdateMethod.EventsTimer(ms)
103
+ ```
104
+ This will call `monitor.updateEvents()` every `ms` milliseconds (intended for demonstrative purposes).
105
+ - `Socket`
106
+ ```js
107
+ new pryv.Monitor.UpdateMethod.Socket()
108
+ ```
109
+ This uses the [Socket.IO add-on](https://github.com/pryv/lib-js/tree/master/components/pryv-socket.io#readme) to relay notifications from Pryv.io to the monitor.
110
+ - **Custom**: You can design your own update method by extending the [`UpdateMethod`](https://github.com/pryv/lib-js/tree/master/components/pryv-monitor/src/UpdateMethod/UpdateMethod.js) class.
135
111
 
136
- You can design your own UpdateMethod by extending the [UpdateMethod](https://github.com/pryv/lib-js-monitor/blob/master/src/UpdateMethod/UpdateMethod.js) class.
137
-
138
112
  #### Stop monitoring
139
113
 
140
- ```javascript
114
+ ```js
141
115
  monitor.stop()
142
116
  ```
143
117
 
144
- The monitor will stop auto updaters and will throw errors if `updateEvents` or `updateStreams` is called.
118
+ The monitor will stop auto updaters and will throw errors if `updateEvents()` or `updateStreams()` are called.
119
+ It can be restarted.
120
+
145
121
 
146
- A monitor can be restarted.
122
+ ### Known limitation
147
123
 
148
- ## Example
124
+ If an event's update moves it out of the monitor's scope – for example the event's `streamIds` property is updated to a stream not covered by the scope – the Pryv.io API does not currently provide the necessary synchronization mechanism to detect such a change.
149
125
 
150
126
 
151
- ```javascript
127
+ ### Examples
128
+
129
+ ```js
152
130
  const apiEndpoint = 'https://ck6bwmcar00041ep87c8ujf90@drtom.pryv.me';
153
131
 
154
- // reduce the eventsGetScope of the monitor to the stream: diary
132
+ // set monitor scope to the stream 'diary'
155
133
  const eventsGetScope = {'streamIds': [diary]};
156
134
 
157
- // refresh the monitor using the 'timer' method with a refreshrate of 5 seconds
158
-
159
- const monitor = new Pryv.Monitor(apiEndpoint || connection, eventsGetScope)
160
- .on('event', (event) => {}) // per event - new or change
161
- .on('streams', (streams) => {}) // all streams structure
162
- .on('eventDelete', (event) => {}) // an event needs to be deleted
163
- .addUpdateMethod(new Pryv.Monitor.UpdateMethod.EventsTimer(1000)); // add refresh timer
135
+ // refresh the monitor using the 'timer' method with a refresh rate of 1 second
136
+ const monitor = new pryv.Monitor(apiEndpoint || connection, eventsGetScope)
137
+ .on('event', (event) => {}) // event created or updated
138
+ .on('streams', (streams) => {}) // streams structure changed
139
+ .on('eventDelete', (event) => {}) // event deleted
140
+ .addUpdateMethod(new pryv.Monitor.UpdateMethod.EventsTimer(1000)); // set refresh timer
164
141
 
142
+ // start the monitor
165
143
  (async () => {
166
- await monitor.start(); // start the monitor
144
+ await monitor.start();
167
145
  }())
168
146
  ```
169
147
 
170
- Chain (async) `.start()`
148
+ You can also chain `start()`:
171
149
 
172
- ```javascript
150
+ ```js
173
151
  (async () => { 
174
- const monitor = await (new Pryv.Monitor(apiEndpoint || connection, eventsGetScope)
175
- .on('event', (event) => {})))
176
- .start();
152
+ const monitor = await (new pryv.Monitor(apiEndpoint || connection, eventsGetScope)
153
+ .on('event', (event) => {}))
154
+ .start();
177
155
  })();
178
156
  ```
179
157
 
180
- ### Auto-update with web sockets
158
+ #### Auto-update with web sockets
181
159
 
182
- #### Node.js
160
+ ##### Node.js
183
161
 
184
- ```javascript
185
- const Pryv = require('pryv');
186
- require('@pryv/socket.io')(Pryv);
187
- require('../src/')(Pryv);
162
+ Install packages: `npm install pryv @pryv/socket.io @pryv/monitor`
163
+
164
+ ```js
165
+ const pryv = require('pryv');
166
+ require('@pryv/socket.io')(pryv);
167
+ require('@pryv/monitor')(pryv);
188
168
 
189
169
  const apiEndpoint = 'https://ck60yn9yv00011hd3vu1ocpi7@jslibtest.pryv.me';
190
170
  (async () => { 
191
- const monitor = await (new Pryv.Monitor(apiEndpoint || connection, eventsGetScope)
192
- .on('event', (event) => {}))
193
- .addUpdateMethod(new Pryv.Monitor.UpdateMethod.Socket())
194
- ).start();
171
+ const monitor = await (new pryv.Monitor(apiEndpoint || connection, eventsGetScope)
172
+ .on('event', (event) => {}))
173
+ .addUpdateMethod(new pryv.Monitor.UpdateMethod.Socket())
174
+ .start();
195
175
  })();
196
176
  ```
197
177
 
198
- #### Browser
178
+ ##### Browser
199
179
 
200
180
  ```html
201
181
  <script src="https://api.pryv.com/lib-js/pryv.js"></script>
202
182
  <script src="https://api.pryv.com/lib-js-socket.io/pryv-socket.io.js"></script>
203
183
  <script src="https://api.pryv.com/lib-js-monitor/pryv-monitor.js"></script>
184
+ <!--
185
+ The previous lines can be replaced by the bundled version of the library:
186
+ <script src="https://api.pryv.com/lib-js/pryv-socket.io-monitor.js"></script>
187
+ -->
204
188
 
205
189
  <script>
206
190
  const apiEndpoint = 'https://ck60yn9yv00011hd3vu1ocpi7@jslibtest.pryv.me';
207
191
  (async () => { 
208
- const monitor = await (new Pryv.Monitor(apiEndpoint || connection, eventsGetScope)
209
- .on('event', (event) => {}))
210
- .addUpdateMethod(new Pryv.Monitor.UpdateMethod.Socket())
211
- ).start();
192
+ const monitor = await (new pryv.Monitor(apiEndpoint || connection, eventsGetScope)
193
+ .on('event', (event) => {}))
194
+ .addUpdateMethod(new pryv.Monitor.UpdateMethod.Socket())
195
+ .start();
212
196
  })();
213
197
  </script>
214
198
  ```
215
199
 
200
+ #### Example web app
216
201
 
202
+ See [here](`../../examples/monitor.html`) for a simple app that allows to sign in to a Pryv.io platform, register to monitor events changes and create notes. You can try it running [there](https://api.pryv.com/lib-js/examples/monitor.html).
217
203
 
218
- ### Example web app
219
-
220
- ![Screenshot](examples/screenshot.png)
221
-
222
- The `./examples/index.html` file is a simple demo app that allows loging in a Pryv.io platform, register to events changes and create notes.
223
-
224
- It can be tested on [http://pryv.github.io/lib-js-monitor](http://pryv.github.io/lib-js-monitor)
225
204
 
226
- ## Contribute
205
+ ## Contributing
227
206
 
228
- *Prerequisites*: Node 12
207
+ See the [Pryv JavaScript library README](https://github.com/pryv/lib-js#contributing)
229
208
 
230
- - Setup: `npm run setup`
231
- - Build pryv-monitor.js library for browsers: `npm run build`, the result is published in `./dist`
232
- - Node Tests: `npm run test`
233
209
 
234
- ## Known limitations
210
+ ## License
235
211
 
236
- - If an event's update makes it "out of eventsGetScope". For example an (in eventsGetScope) event streamIds[] property is "moved" to a streamId not convered by the eventsGetScope, the current Pryv.io API does not provide the necessary synchronization mechanism to detect such changes.
212
+ [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
package/package.json CHANGED
@@ -1,20 +1,7 @@
1
1
  {
2
2
  "name": "@pryv/monitor",
3
- "version": "1.0.4",
4
- "description": "Extends `pryv` lib-js with event driven notifications for changes on a Pryv.io account.",
5
- "main": "src/index.js",
6
- "scripts": {
7
- "test": "mocha --reporter spec test/*.test.js",
8
- "setup": "./scripts/setup-environment-dev.sh",
9
- "build": "webpack"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git://github.com/pryv/lib-js-monitor"
14
- },
15
- "bugs": {
16
- "url": "https://github.com/pryv/lib-js-monitor/issues"
17
- },
3
+ "version": "2.3.0",
4
+ "description": "Extends `pryv` with event-driven notifications for changes on a Pryv.io account",
18
5
  "keywords": [
19
6
  "Pryv",
20
7
  "Pryv.io",
@@ -22,13 +9,15 @@
22
9
  "Scope",
23
10
  "Monitor"
24
11
  ],
25
- "author": "Pryv S.A.",
12
+ "homepage": "https://github.com/pryv/lib-js/tree/master/components/pryv-monitor#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/pryv/lib-js/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git://github.com/pryv/lib-js"
19
+ },
26
20
  "license": "BSD-3-Clause",
27
- "devDependencies": {
28
- "@pryv/lib-js-common": "git+https://github.com/pryv/lib-js-common.git#1.0.3",
29
- "@pryv/socket.io": "^1.0.2",
30
- "chai": "^4.2.0",
31
- "mocha": "^8.2.1",
32
- "pryv": "^2.1.2"
33
- }
21
+ "author": "Pryv S.A. <info@pryv.com> (https://pryv.com)",
22
+ "main": "src/index.js"
34
23
  }
package/src/Monitor.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @license
3
+ * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
+ */
1
5
  const EventEmitter = require('events');
2
6
  const UpdateMethod = require('./UpdateMethod/');
3
7
  const _updateEvents = require('./lib/updateEvents');
@@ -5,37 +9,37 @@ const _updateStreams = require('./lib/updateStreams');
5
9
  const Changes = require('./lib/Changes');
6
10
 
7
11
  /**
8
- * @memberof Pryv
12
+ * @memberof pryv
9
13
  */
10
14
  class Monitor extends EventEmitter {
11
15
  /**
12
- *
13
- * @param {(Pryv.PryvApiEndpoint|Pryv.Connection)} apiEndpointOrConnection ApiEnpoint or connection to use.
14
- * @param {Pryv.Monitor.Scope} [eventsGetScope={}] The Scope to monitor
16
+ *
17
+ * @param {(pryv.APIEndpoint|pryv.Connection)} apiEndpointOrConnection APIEndoint or connection to use
18
+ * @param {pryv.Monitor.Scope} [eventsGetScope={}] The Scope to monitor
15
19
  */
16
- constructor(apiEndpointOrConnection, eventsGetScope = {}) {
20
+ constructor (apiEndpointOrConnection, eventsGetScope = {}) {
17
21
  super();
18
- if (!Monitor.Pryv) {
22
+ if (!Monitor.pryv) {
19
23
  throw new Error('package \'@pryv/monitor\' must loaded after package \'pryv\'');
20
24
  }
21
25
 
22
26
  this.eventsGetScope = { // default eventsGetScope values
23
- fromTime: - Number.MAX_VALUE,
27
+ fromTime: -Number.MAX_VALUE,
24
28
  toTime: Number.MAX_VALUE,
25
- modifiedSince: - Number.MAX_VALUE
26
- }
29
+ modifiedSince: -Number.MAX_VALUE
30
+ };
27
31
  Object.assign(this.eventsGetScope, eventsGetScope);
28
32
 
29
- if (apiEndpointOrConnection instanceof Monitor.Pryv.Connection) {
33
+ if (apiEndpointOrConnection instanceof Monitor.pryv.Connection) {
30
34
  this.connection = apiEndpointOrConnection;
31
35
  } else {
32
- this.connection = new Monitor.Pryv.Connection(apiEndpointOrConnection);
36
+ this.connection = new Monitor.pryv.Connection(apiEndpointOrConnection);
33
37
  }
34
38
  this.states = {
35
39
  started: false,
36
40
  starting: false, // in phase of initializing
37
41
  updatingEvents: false, // semaphore to prevent updating events in parallel
38
- updatingStreams: false, // semaphore to prevent updating streams in parallel
42
+ updatingStreams: false // semaphore to prevent updating streams in parallel
39
43
  };
40
44
  }
41
45
 
@@ -43,7 +47,7 @@ class Monitor extends EventEmitter {
43
47
  * Start the monitor
44
48
  * @returns {Monitor} this
45
49
  */
46
- async start() {
50
+ async start () {
47
51
  if (this.states.started || this.states.starting) return this;
48
52
  this.states.starting = true;
49
53
  await _updateStreams(this);
@@ -62,7 +66,7 @@ class Monitor extends EventEmitter {
62
66
  * request and update of events
63
67
  * @returns {Monitor} this
64
68
  */
65
- async updateEvents() {
69
+ async updateEvents () {
66
70
  if (!this.states.started) {
67
71
  throw new Error('Start Monitor before calling update Events');
68
72
  }
@@ -94,7 +98,7 @@ class Monitor extends EventEmitter {
94
98
  * request and update of streams
95
99
  * @returns {Monitor} this
96
100
  */
97
- async updateStreams() {
101
+ async updateStreams () {
98
102
  if (!this.states.started) {
99
103
  throw new Error('Start Monitor before calling update Streams');
100
104
  }
@@ -125,20 +129,19 @@ class Monitor extends EventEmitter {
125
129
  /**
126
130
  * @private
127
131
  * Called after init phase and each updateEvents
128
- * Advertise the update method or any listener that the Monitor is ready
132
+ * Advertise the update method or any listener that the Monitor is ready
129
133
  * for a next event update
130
134
  */
131
- ready() {
132
- if (!this.states.started) return; // it might be stoped
135
+ ready () {
136
+ if (!this.states.started) return; // it might be stoped
133
137
  this.emit(Changes.READY);
134
138
  }
135
139
 
136
-
137
140
  /**
138
141
  * Stop monitoring (no event will be fired anymore)
139
142
  * @returns {Monitor} this
140
143
  */
141
- stop() {
144
+ stop () {
142
145
  if (!this.states.started) return this;
143
146
  if (this.states.starting) throw new Error('Process is starting, wait for the end of initialization to stop it');
144
147
  this.emit(Changes.STOP);
@@ -150,14 +153,14 @@ class Monitor extends EventEmitter {
150
153
  * Used by updateMethods to be sure they can call updateXXX methods
151
154
  * @property {Boolean} started - true is monitor is started
152
155
  */
153
- get started() {
156
+ get started () {
154
157
  return this.states.started;
155
158
  }
156
159
 
157
160
  /**
158
161
  * Initialize the updateMethods with this Monitor
159
162
  * @callback Monitor~UpdateMethod
160
- * @param {Monitor} setMonitor
163
+ * @param {Monitor} setMonitor
161
164
  */
162
165
 
163
166
  /**
@@ -167,14 +170,11 @@ class Monitor extends EventEmitter {
167
170
  * @param {Monitor~UpdateMethod} updateMethod - the auto-update method
168
171
  * @returns {Monitor} this
169
172
  */
170
- addUpdateMethod(updateMethod) {
171
- if (false) {
172
- throw new Error('Argument is not a valid UpdateMethod instance');
173
- }
173
+ addUpdateMethod (updateMethod) {
174
174
  updateMethod.setMonitor(this);
175
- return this
175
+ return this;
176
176
  }
177
177
  }
178
178
 
179
179
  Monitor.UpdateMethod = UpdateMethod;
180
- module.exports = Monitor;
180
+ module.exports = Monitor;
@@ -1,10 +1,14 @@
1
+ /**
2
+ * @license
3
+ * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
+ */
1
5
  const UpdateMethod = require('./UpdateMethod');
2
6
 
3
7
  class EventsTimer extends UpdateMethod {
4
8
  /**
5
9
  * @param {Number} updateRateMS - the refresh rate in milliseconds
6
10
  */
7
- constructor(updateRateMS) {
11
+ constructor (updateRateMS) {
8
12
  super();
9
13
  this.timer = null;
10
14
  if (!updateRateMS || isNaN(updateRateMS) || updateRateMS < 1) {
@@ -15,10 +19,10 @@ class EventsTimer extends UpdateMethod {
15
19
 
16
20
  async ready () {
17
21
  if (this.timer != null) clearTimeout(this.timer);
18
- this.timer = setTimeout(() => {
19
- if (this.monitor.started) this.monitor.updateEvents()
22
+ this.timer = setTimeout(() => {
23
+ if (this.monitor.started) this.monitor.updateEvents();
20
24
  }, this.updateRateMS);
21
25
  }
22
26
  }
23
27
 
24
- module.exports = EventsTimer;
28
+ module.exports = EventsTimer;
@@ -1,22 +1,23 @@
1
+ /**
2
+ * @license
3
+ * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
+ */
1
5
 
2
6
  const UpdateMethod = require('./UpdateMethod');
3
7
  const Changes = require('../lib/Changes');
4
8
 
5
9
  class Socket extends UpdateMethod {
6
- constructor() {
7
- super();
8
- }
9
-
10
- async ready() {
10
+ async ready () {
11
11
  if (this.socket) return;
12
12
  if (!this.monitor.connection.socket) {
13
13
  throw new Error('You should load package @pryv/socket.io to use monitor with websockets');
14
14
  }
15
15
  this.socket = await this.monitor.connection.socket.open();
16
- this.socket.on('eventsChanged', () => { this.monitor.updateEvents(); });
16
+ this.socket.on('eventsChanged', () => { this.monitor.updateEvents(); });
17
17
  this.socket.on('streamsChanged', () => { this.monitor.updateStreams(); });
18
- this.socket.on('error', (error) => { this.monitor.emit(Changes.ERROR.error); });
19
- };
18
+ /* eslint-disable-next-line node/handle-callback-err */
19
+ this.socket.on('error', (error) => { this.monitor.emit(Changes.ERROR.error); });
20
+ }
20
21
 
21
22
  async stop () {
22
23
  if (!this.socket) return;
@@ -24,4 +25,4 @@ class Socket extends UpdateMethod {
24
25
  this.socket = null;
25
26
  }
26
27
  }
27
- module.exports = Socket;
28
+ module.exports = Socket;
@@ -1,16 +1,20 @@
1
+ /**
2
+ * @license
3
+ * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
+ */
1
5
  const Changes = require('../lib/Changes');
2
6
  /**
3
7
  * Interface for UpdateMonitor
4
- * @memberof Pryv.Monitor
8
+ * @memberof pryv.Monitor
5
9
  * @constructor {Monitor~UpdateMethod} updateMethod.setMonitor - set only once
6
10
  */
7
11
  class UpdateMethod {
8
12
  /**
9
- * Assign a Monitor to this updater.
13
+ * Assign a Monitor to this updater.
10
14
  * Usually called by the monitor itself on monitor.addUpdateMethod()
11
- * @param {Monitor} monitor
15
+ * @param {Monitor} monitor
12
16
  */
13
- setMonitor(monitor) {
17
+ setMonitor (monitor) {
14
18
  if (this.monitor) {
15
19
  throw new Error('An update Method can be assigned to one monitor only');
16
20
  }
@@ -27,13 +31,13 @@ class UpdateMethod {
27
31
  * Called with no params, when all update tasks are done.
28
32
  * Also used at "start" call
29
33
  */
30
- async ready() { }
34
+ async ready () { }
31
35
 
32
36
  /**
33
37
  * Should be overwritten by subclases
34
38
  * Called with no params, when monitor is stoped: updater should be stoped too.
35
39
  */
36
- async stop() { }
40
+ async stop () { }
37
41
  }
38
42
 
39
- module.exports = UpdateMethod;
43
+ module.exports = UpdateMethod;
@@ -1,7 +1,10 @@
1
-
1
+ /**
2
+ * @license
3
+ * [BSD-3-Clause](https://github.com/pryv/lib-js/blob/master/LICENSE)
4
+ */
2
5
 
3
6
  module.exports = {
4
7
  Null: require('./UpdateMethod'),
5
8
  Socket: require('./Socket'),
6
9
  EventsTimer: require('./EventsTimer')
7
- }
10
+ };