@makefully/engagefully 0.2.0 → 0.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/src/Controller.js CHANGED
@@ -1,74 +1,74 @@
1
- import EventEmitter from 'events';
2
- import controlMap from "./actions/index";
3
-
4
- class Controller extends EventEmitter {
5
- constructor (devices = [], controlClasses = {}) {
6
- super();
7
-
8
- this.devices = [];
9
- this.controls = {};
10
-
11
- // Set up control map with type to class conversions
12
- this.controlMap = {
13
- ...controlMap,
14
- ...controlClasses
15
- };
16
-
17
- devices.forEach((device) => this.addDevice(device));
18
- }
19
-
20
- addControl (id, type) {
21
- const
22
- Control = this.controlMap[type];
23
-
24
- if (Control) {
25
- const
26
- control = this.controls[id] = new Control(id);
27
-
28
- return control;
29
- } else {
30
- const
31
- control = this.controls[id] = new this.controlMap.Data(id);
32
-
33
- console.warn(`${id}: "${type}" has no associated control class. Using 'Data'.`);
34
-
35
- return control;
36
- }
37
- }
38
-
39
- addDevice (device) {
40
- this.devices.push(device);
41
-
42
- device.on('updated', (event) => {
43
- const
44
- key = event.control;
45
- let control = this.controls[key];
46
-
47
- if (!control) {
48
- control = this.addControl(key, event.type);
49
-
50
- if (!control) {
51
- return;
52
- }
53
- }
54
-
55
- control.update(event, this);
56
- });
57
- }
58
-
59
- getControl (id, type) {
60
- let control = this.controls[id];
61
-
62
- if (!control && type) {
63
- control = this.addControl(id, type);
64
- }
65
-
66
- return control;
67
- }
68
-
69
- poll (id) {
70
- return this.controls[id]?.poll?.();
71
- }
72
- };
73
-
1
+ import EventEmitter from 'events';
2
+ import controlMap from "./actions/index";
3
+
4
+ class Controller extends EventEmitter {
5
+ constructor (devices = [], controlClasses = {}) {
6
+ super();
7
+
8
+ this.devices = [];
9
+ this.controls = {};
10
+
11
+ // Set up control map with type to class conversions
12
+ this.controlMap = {
13
+ ...controlMap,
14
+ ...controlClasses
15
+ };
16
+
17
+ devices.forEach((device) => this.addDevice(device));
18
+ }
19
+
20
+ addControl (id, type) {
21
+ const
22
+ Control = this.controlMap[type];
23
+
24
+ if (Control) {
25
+ const
26
+ control = this.controls[id] = new Control(id);
27
+
28
+ return control;
29
+ } else {
30
+ const
31
+ control = this.controls[id] = new this.controlMap.Data(id);
32
+
33
+ console.warn(`${id}: "${type}" has no associated control class. Using 'Data'.`);
34
+
35
+ return control;
36
+ }
37
+ }
38
+
39
+ addDevice (device) {
40
+ this.devices.push(device);
41
+
42
+ device.on('updated', (event) => {
43
+ const
44
+ key = event.control;
45
+ let control = this.controls[key];
46
+
47
+ if (!control) {
48
+ control = this.addControl(key, event.type);
49
+
50
+ if (!control) {
51
+ return;
52
+ }
53
+ }
54
+
55
+ control.update(event, this);
56
+ });
57
+ }
58
+
59
+ getControl (id, type) {
60
+ let control = this.controls[id];
61
+
62
+ if (!control && type) {
63
+ control = this.addControl(id, type);
64
+ }
65
+
66
+ return control;
67
+ }
68
+
69
+ poll (id) {
70
+ return this.controls[id]?.poll?.();
71
+ }
72
+ };
73
+
74
74
  export default Controller;
@@ -1,21 +1,21 @@
1
- class Amount {
2
- constructor (control) {
3
- this.control = control;
4
- this.value = 0;
5
- }
6
-
7
- update (event, controller) {
8
- let updated = false;
9
-
10
- if (event.value !== this.value) {
11
- updated = true;
12
- this.value = event.value;
13
- }
14
-
15
- if (updated) {
16
- controller.emit(this.control, event, this);
17
- }
18
- }
19
- }
20
-
1
+ class Amount {
2
+ constructor (control) {
3
+ this.control = control;
4
+ this.value = 0;
5
+ }
6
+
7
+ update (event, controller) {
8
+ let updated = false;
9
+
10
+ if (event.value !== this.value) {
11
+ updated = true;
12
+ this.value = event.value;
13
+ }
14
+
15
+ if (updated) {
16
+ controller.emit(this.control, event, this);
17
+ }
18
+ }
19
+ }
20
+
21
21
  export default Amount;
@@ -1,33 +1,33 @@
1
- class Button {
2
- constructor (control) {
3
- this.control = control;
4
- this.value = 0;
5
- }
6
-
7
- update (event, controller) {
8
- if (event.value !== this.value) {
9
- this.value = event.value;
10
- if (this.value === 1) {
11
- controller.emit(`${this.control}:pressed`, event, this);
12
- }
13
- if (this.value === 0) {
14
- controller.emit(`${this.control}:released`, event, this);
15
- }
16
- controller.emit(this.control, event, this);
17
- }
18
- }
19
-
20
- poll () {
21
- return this.value;
22
- }
23
-
24
- toJSON () {
25
- return {
26
- control: this.control,
27
- type: 'Button',
28
- value: this.value
29
- };
30
- }
31
- }
32
-
1
+ class Button {
2
+ constructor (control) {
3
+ this.control = control;
4
+ this.value = 0;
5
+ }
6
+
7
+ update (event, controller) {
8
+ if (event.value !== this.value) {
9
+ this.value = event.value;
10
+ if (this.value === 1) {
11
+ controller.emit(`${this.control}:pressed`, event, this);
12
+ }
13
+ if (this.value === 0) {
14
+ controller.emit(`${this.control}:released`, event, this);
15
+ }
16
+ controller.emit(this.control, event, this);
17
+ }
18
+ }
19
+
20
+ poll () {
21
+ return this.value;
22
+ }
23
+
24
+ toJSON () {
25
+ return {
26
+ control: this.control,
27
+ type: 'Button',
28
+ value: this.value
29
+ };
30
+ }
31
+ }
32
+
33
33
  export default Button;
@@ -1,13 +1,13 @@
1
- class Data {
2
- constructor (control) {
3
- this.control = control;
4
- this.value = null;
5
- }
6
-
7
- update (event, controller) {
8
- this.value = event.value;
9
- controller.emit(this.control, event, this);
10
- }
11
- }
12
-
1
+ class Data {
2
+ constructor (control) {
3
+ this.control = control;
4
+ this.value = null;
5
+ }
6
+
7
+ update (event, controller) {
8
+ this.value = event.value;
9
+ controller.emit(this.control, event, this);
10
+ }
11
+ }
12
+
13
13
  export default Data;
@@ -1,15 +1,15 @@
1
- class Dial {
2
- constructor (control) {
3
- this.control = control;
4
- this.value = 0;
5
- }
6
-
7
- update (event, controller) {
8
- if (event.value !== this.value) {
9
- this.value = event.value;
10
- controller.emit(this.control, event, this);
11
- }
12
- }
13
- }
14
-
1
+ class Dial {
2
+ constructor (control) {
3
+ this.control = control;
4
+ this.value = 0;
5
+ }
6
+
7
+ update (event, controller) {
8
+ if (event.value !== this.value) {
9
+ this.value = event.value;
10
+ controller.emit(this.control, event, this);
11
+ }
12
+ }
13
+ }
14
+
15
15
  export default Dial;
@@ -1,19 +1,19 @@
1
- class Drop {
2
- constructor (control) {
3
- this.control = control;
4
- this.value = '';
5
- this.x = 0;
6
- this.y = 0;
7
- }
8
-
9
- update (event, controller) {
10
- if ((event.value !== this.value) || (event.x !== this.x) || (event.y !== this.y)) {
11
- this.value = event.value;
12
- this.x = event.x;
13
- this.y = event.y;
14
- controller.emit(this.control, event, this);
15
- }
16
- }
17
- }
18
-
1
+ class Drop {
2
+ constructor (control) {
3
+ this.control = control;
4
+ this.value = '';
5
+ this.x = 0;
6
+ this.y = 0;
7
+ }
8
+
9
+ update (event, controller) {
10
+ if ((event.value !== this.value) || (event.x !== this.x) || (event.y !== this.y)) {
11
+ this.value = event.value;
12
+ this.x = event.x;
13
+ this.y = event.y;
14
+ controller.emit(this.control, event, this);
15
+ }
16
+ }
17
+ }
18
+
19
19
  export default Drop;
@@ -1,17 +1,17 @@
1
- class Joystick {
2
- constructor (control) {
3
- this.control = control;
4
- this.x = 0;
5
- this.y = 0;
6
- }
7
-
8
- update (event, controller) {
9
- if ((event.x !== this.x) || (event.y !== this.y)) {
10
- this.x = event.x;
11
- this.y = event.y;
12
- controller.emit(this.control, event, this);
13
- }
14
- }
15
- }
16
-
1
+ class Joystick {
2
+ constructor (control) {
3
+ this.control = control;
4
+ this.x = 0;
5
+ this.y = 0;
6
+ }
7
+
8
+ update (event, controller) {
9
+ if ((event.x !== this.x) || (event.y !== this.y)) {
10
+ this.x = event.x;
11
+ this.y = event.y;
12
+ controller.emit(this.control, event, this);
13
+ }
14
+ }
15
+ }
16
+
17
17
  export default Joystick;
@@ -1,30 +1,30 @@
1
- import {BroadcastChannel} from 'broadcast-channel';
2
-
3
- class PageAction {
4
- constructor (controllerOrDeviceList, id = 'PageDevice') {
5
- const
6
- devices = controllerOrDeviceList.devices || controllerOrDeviceList;
7
-
8
- this.channel = new BroadcastChannel(id);
9
-
10
- devices.forEach((device) => {
11
- device.on('updated', (event) => {
12
- const
13
- newEvent = {
14
- ...event
15
- };
16
-
17
- newEvent.device = `${id}-${event.device}`;
18
- newEvent.control = `Page${event.control}`;
19
-
20
- // These aren't necessarily serializable.
21
- delete newEvent.target;
22
- delete newEvent.event;
23
-
24
- this.channel.postMessage(newEvent);
25
- });
26
- });
27
- }
28
- }
29
-
1
+ import {BroadcastChannel} from 'broadcast-channel';
2
+
3
+ class PageAction {
4
+ constructor (controllerOrDeviceList, id = 'PageDevice') {
5
+ const
6
+ devices = controllerOrDeviceList.devices || controllerOrDeviceList;
7
+
8
+ this.channel = new BroadcastChannel(id);
9
+
10
+ devices.forEach((device) => {
11
+ device.on('updated', (event) => {
12
+ const
13
+ newEvent = {
14
+ ...event
15
+ };
16
+
17
+ newEvent.device = `${id}-${event.device}`;
18
+ newEvent.control = `Page${event.control}`;
19
+
20
+ // These aren't necessarily serializable.
21
+ delete newEvent.target;
22
+ delete newEvent.event;
23
+
24
+ this.channel.postMessage(newEvent);
25
+ });
26
+ });
27
+ }
28
+ }
29
+
30
30
  export default PageAction;
@@ -1,19 +1,19 @@
1
- class Pointer {
2
- constructor (control) {
3
- this.control = control;
4
- this.value = 0;
5
- this.x = 0;
6
- this.y = 0;
7
- }
8
-
9
- update (event, controller) {
10
- if ((event.value !== this.value) || (event.x !== this.x) || (event.y !== this.y)) {
11
- this.value = event.value;
12
- this.x = event.x;
13
- this.y = event.y;
14
- controller.emit(this.control, event, this);
15
- }
16
- }
17
- }
18
-
1
+ class Pointer {
2
+ constructor (control) {
3
+ this.control = control;
4
+ this.value = 0;
5
+ this.x = 0;
6
+ this.y = 0;
7
+ }
8
+
9
+ update (event, controller) {
10
+ if ((event.value !== this.value) || (event.x !== this.x) || (event.y !== this.y)) {
11
+ this.value = event.value;
12
+ this.x = event.x;
13
+ this.y = event.y;
14
+ controller.emit(this.control, event, this);
15
+ }
16
+ }
17
+ }
18
+
19
19
  export default Pointer;
@@ -1,6 +1,6 @@
1
- class Throttle {
2
- constructor () {
3
- }
4
- }
5
-
1
+ class Throttle {
2
+ constructor () {
3
+ }
4
+ }
5
+
6
6
  export default Throttle;
@@ -1,6 +1,6 @@
1
- class Wheel {
2
- constructor () {
3
- }
4
- }
5
-
1
+ class Wheel {
2
+ constructor () {
3
+ }
4
+ }
5
+
6
6
  export default Wheel;
@@ -1,24 +1,24 @@
1
- /**
2
- * @namespace actions
3
- * @memberof engagefully
4
- */
5
- import Amount from './Amount';
6
- import Button from './Button';
7
- import Data from './Data';
8
- import Dial from './Dial';
9
- import Drop from './Drop';
10
- import PageAction from './PageAction';
11
- import Pointer from './Pointer';
12
- import Joystick from './Joystick';
13
-
14
- export default {
15
- Amount,
16
- Button,
17
- Data,
18
- Dial,
19
- Drop,
20
- PageAction,
21
- Pointer,
22
- Joystick
23
- };
1
+ /**
2
+ * @namespace actions
3
+ * @memberof engagefully
4
+ */
5
+ import Amount from './Amount';
6
+ import Button from './Button';
7
+ import Data from './Data';
8
+ import Dial from './Dial';
9
+ import Drop from './Drop';
10
+ import PageAction from './PageAction';
11
+ import Pointer from './Pointer';
12
+ import Joystick from './Joystick';
13
+
14
+ export default {
15
+ Amount,
16
+ Button,
17
+ Data,
18
+ Dial,
19
+ Drop,
20
+ PageAction,
21
+ Pointer,
22
+ Joystick
23
+ };
24
24