|
1 |
| -import debug from 'debug' |
2 |
| -import { Atem } from 'atem-connection' |
3 |
| -import { EventEmitter } from 'inf-ee' |
| 1 | +import debug from 'debug'; |
| 2 | +import {Atem} from 'atem-connection'; |
| 3 | +import {EventEmitter} from 'inf-ee'; |
4 | 4 |
|
5 |
| -const log = debug(`sio:atem`) |
| 5 | +const log = debug('sio:atem'); |
6 | 6 |
|
7 |
| -const ATEM_DEFAULT_ADDRESS = '192.168.10.240' |
| 7 | +const ATEM_DEFAULT_ADDRESS = '192.168.10.240'; |
8 | 8 |
|
9 | 9 | export class ControllerAtem extends EventEmitter {
|
10 |
| - constructor(options = {}) { |
11 |
| - super() |
12 |
| - console.log(`Constructing ATEM Controller`) |
| 10 | + constructor(options = {}) { |
| 11 | + super(); |
| 12 | + console.log('Constructing ATEM Controller'); |
13 | 13 |
|
14 |
| - this.componentName = 'ATEM Controller' |
| 14 | + this.componentName = 'ATEM Controller'; |
15 | 15 |
|
16 |
| - this.sessionId = -1 |
| 16 | + this.sessionId = -1; |
17 | 17 |
|
18 |
| - this._address = options.address || ATEM_DEFAULT_ADDRESS |
19 |
| - this._atem = undefined |
| 18 | + this._address = options.address || ATEM_DEFAULT_ADDRESS; |
| 19 | + this._atem = undefined; |
| 20 | + } |
20 | 21 |
|
21 |
| - return this |
22 |
| - } |
| 22 | + connect(options = {}) { |
| 23 | + this._address = options.address || ATEM_DEFAULT_ADDRESS; |
23 | 24 |
|
24 |
| - connect(options = {}) { |
25 |
| - this._address = options.address || ATEM_DEFAULT_ADDRESS |
| 25 | + this._atem = new Atem(); |
26 | 26 |
|
27 |
| - this._atem = new Atem() |
| 27 | + // This._atem.on('debug', (msg) => this.log('debug', msg)) |
| 28 | + this._atem.on('info', message => this.log('info', message)); |
| 29 | + this._atem.on('error', message => this.log('error', message)); |
28 | 30 |
|
29 |
| - // this._atem.on('debug', (msg) => this.log('debug', msg)) |
30 |
| - this._atem.on('info', (msg) => this.log('info', msg)) |
31 |
| - this._atem.on('error', (msg) => this.log('error', msg)) |
| 31 | + this._atem.on('disconnected', () => { |
| 32 | + this.log('info', 'Disconnected'); |
| 33 | + this.emit('disconnect', {sessionId: this.sessionId}); |
| 34 | + }); |
32 | 35 |
|
33 |
| - this._atem.on('disconnected', () => { |
34 |
| - this.log('info', 'Disconnected') |
35 |
| - this.emit('disconnect', { sessionId: this.sessionId }) |
36 |
| - }) |
| 36 | + this._atem.on('connected', () => { |
| 37 | + this.log('info', 'Connected'); |
| 38 | + this.sessionId += 1; |
| 39 | + this.emit('connected', {isReconnect: (this.sessionId > 0), sessionId: this.sessionId}); |
| 40 | + }); |
37 | 41 |
|
38 |
| - this._atem.on('connected', () => { |
39 |
| - this.log('info', `Connected`) |
40 |
| - this.sessionId = this.sessionId + 1 |
41 |
| - this.emit('connected', { isReconnect: (this.sessionId > 0), sessionId: this.sessionId }) |
42 |
| - }) |
| 42 | + this._atem.on('stateChanged', (state, pathToChange) => this.emit('stateChanged', {state, pathToChange})); |
| 43 | + this._atem.on('receivedCommand', command => this.emit('receivedCommand', {command})); |
43 | 44 |
|
44 |
| - this._atem.on('stateChanged', (state, pathToChange) => this.emit('stateChanged', { state, pathToChange })) |
45 |
| - this._atem.on('receivedCommand', (command) => this.emit('receivedCommand', { command })) |
| 45 | + this._atem.connect(this._address).catch(error => { |
| 46 | + this.log('error', error); |
| 47 | + }); |
| 48 | + } |
46 | 49 |
|
47 |
| - this._atem.connect(this._address).catch((e) => { |
48 |
| - this.log('error', e) |
49 |
| - }) |
50 |
| - } |
| 50 | + disconnect() { |
| 51 | + if (this._atem) { |
| 52 | + this._atem.disconnect(); |
| 53 | + } |
| 54 | + } |
51 | 55 |
|
52 |
| - disconnect() { |
53 |
| - if (this._atem) this._atem.disconnect() |
54 |
| - } |
| 56 | + getState() { |
| 57 | + return this._atem.state; |
| 58 | + } |
55 | 59 |
|
56 |
| - getState() { |
57 |
| - return this._atem.state |
58 |
| - } |
| 60 | + getProgramInput(me = 0) { |
| 61 | + return this._atem.state.video.mixEffects[me].programInput; |
| 62 | + } |
59 | 63 |
|
60 |
| - getProgramInput(me = 0) { |
61 |
| - return this._atem.state.video.mixEffects[me].programInput |
62 |
| - } |
| 64 | + getPreviewInput(me = 0) { |
| 65 | + return this._atem.state.video.mixEffects[me].previewInput; |
| 66 | + } |
63 | 67 |
|
64 |
| - getPreviewInput(me = 0) { |
65 |
| - return this._atem.state.video.mixEffects[me].previewInput |
66 |
| - } |
| 68 | + isUpstreamKeyerActive(me = 0, usk = 0) { |
| 69 | + return this._atem.state.video.mixEffects[me].upstreamKeyers[usk].onAir; |
| 70 | + } |
67 | 71 |
|
68 |
| - isUpstreamKeyerActive(me = 0, usk = 0) { |
69 |
| - return this._atem.state.video.mixEffects[me].upstreamKeyers[usk].onAir |
70 |
| - } |
| 72 | + getUpstreamKeyerFillSource(me = 0, usk = 0) { |
| 73 | + return this._atem.state.video.mixEffects[me].upstreamKeyers[usk].fillSource; |
| 74 | + } |
71 | 75 |
|
72 |
| - getUpstreamKeyerFillSource(me = 0, usk = 0) { |
73 |
| - return this._atem.state.video.mixEffects[me].upstreamKeyers[usk].fillSource |
74 |
| - } |
| 76 | + getUpstreamKeyerType(me = 0, usk = 0) { |
| 77 | + return this._atem.state.video.mixEffects[me].upstreamKeyers[usk].mixEffectKeyType; |
| 78 | + } |
75 | 79 |
|
76 |
| - getUpstreamKeyerType(me = 0, usk = 0) { |
77 |
| - return this._atem.state.video.mixEffects[me].upstreamKeyers[usk].mixEffectKeyType |
78 |
| - } |
| 80 | + getTransitionDuration(me = 0) { |
| 81 | + return this._atem.state.video.mixEffects[me].transitionSettings.mix.rate; |
| 82 | + } |
79 | 83 |
|
80 |
| - getTransitionDuration(me = 0) { |
81 |
| - return this._atem.state.video.mixEffects[me].transitionSettings.mix.rate |
82 |
| - } |
| 84 | + setUpstreamKeyerType(...args) { |
| 85 | + return this._atem.setUpstreamKeyerType(...args); |
| 86 | + } |
83 | 87 |
|
84 |
| - setUpstreamKeyerType(...args) { |
85 |
| - return this._atem.setUpstreamKeyerType.apply(this._atem, args) |
86 |
| - } |
| 88 | + setUpstreamKeyerDVESettings(...args) { |
| 89 | + return this._atem.setUpstreamKeyerDVESettings(...args); |
| 90 | + } |
87 | 91 |
|
88 |
| - setUpstreamKeyerDVESettings(...args) { |
89 |
| - return this._atem.setUpstreamKeyerDVESettings.apply(this._atem, args) |
90 |
| - } |
| 92 | + changePreviewInput(...args) { |
| 93 | + return this._atem.changePreviewInput(...args); |
| 94 | + } |
91 | 95 |
|
92 |
| - changePreviewInput(...args) { |
93 |
| - return this._atem.changePreviewInput.apply(this._atem, args) |
94 |
| - } |
| 96 | + setTransitionStyle(...args) { |
| 97 | + return this._atem.setTransitionStyle(...args); |
| 98 | + } |
95 | 99 |
|
96 |
| - setTransitionStyle(...args) { |
97 |
| - return this._atem.setTransitionStyle.apply(this._atem, args) |
98 |
| - } |
| 100 | + setUpstreamKeyerFillSource(...args) { |
| 101 | + return this._atem.setUpstreamKeyerFillSource(...args); |
| 102 | + } |
99 | 103 |
|
100 |
| - setUpstreamKeyerFillSource(...args) { |
101 |
| - return this._atem.setUpstreamKeyerFillSource.apply(this._atem, args) |
102 |
| - } |
| 104 | + autoTransition(...args) { |
| 105 | + return this._atem.autoTransition(...args); |
| 106 | + } |
103 | 107 |
|
104 |
| - autoTransition(...args) { |
105 |
| - return this._atem.autoTransition.apply(this._atem, args) |
106 |
| - } |
| 108 | + cut(...args) { |
| 109 | + return this._atem.cut(...args); |
| 110 | + } |
107 | 111 |
|
108 |
| - cut(...args) { |
109 |
| - return this._atem.cut.apply(this._atem, args) |
110 |
| - } |
| 112 | + setFairlightAudioMixerSourceProps(...args) { |
| 113 | + return this._atem.setFairlightAudioMixerSourceProps(...args); |
| 114 | + } |
111 | 115 |
|
112 |
| - setFairlightAudioMixerSourceProps(...args) { |
113 |
| - return this._atem.setFairlightAudioMixerSourceProps.apply(this._atem, args) |
114 |
| - } |
115 |
| - |
116 |
| - fadeToBlack(...args) { |
117 |
| - return this._atem.fadeToBlack.apply(this._atem, args) |
118 |
| - } |
119 |
| - |
120 |
| - setUpstreamKeyerFlyKeyKeyframe(...args) { |
121 |
| - return this._atem.setUpstreamKeyerFlyKeyKeyframe.apply(this._atem, args) |
122 |
| - } |
123 |
| - |
124 |
| - runUpstreamKeyerFlyKeyTo(...args) { |
125 |
| - return this._atem.runUpstreamKeyerFlyKeyTo.apply(this._atem, args) |
126 |
| - } |
127 |
| - |
128 |
| - log(level, ...args) { |
129 |
| - this.emit('log', { component: this.componentName, level: level.toLowerCase(), message: args }) |
130 |
| - log(`${level.toLowerCase()}: ${args}`) |
131 |
| - } |
| 116 | + fadeToBlack(...args) { |
| 117 | + return this._atem.fadeToBlack(...args); |
| 118 | + } |
| 119 | + |
| 120 | + setUpstreamKeyerFlyKeyKeyframe(...args) { |
| 121 | + return this._atem.setUpstreamKeyerFlyKeyKeyframe(...args); |
| 122 | + } |
| 123 | + |
| 124 | + runUpstreamKeyerFlyKeyTo(...args) { |
| 125 | + return this._atem.runUpstreamKeyerFlyKeyTo(...args); |
| 126 | + } |
| 127 | + |
| 128 | + log(level, ...args) { |
| 129 | + this.emit('log', {component: this.componentName, level: level.toLowerCase(), message: args}); |
| 130 | + log(`${level.toLowerCase()}: ${args}`); |
| 131 | + } |
132 | 132 | }
|
133 | 133 |
|
134 |
| -export default ControllerAtem |
| 134 | +export default ControllerAtem; |
0 commit comments