-
Notifications
You must be signed in to change notification settings - Fork 14
/
client.ts
156 lines (142 loc) · 3.96 KB
/
client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import {
MosConnection,
ConnectionConfig,
IMOSROAck,
IMOSROAction,
IMOSROReadyToAir,
IMOSROStory,
IMOSRunningOrder,
IMOSStoryAction,
MosDevice,
IMOSString128,
} from '@mos-connection/connector'
const mos = new MosConnection(
new ConnectionConfig({
mosID: 'sofie.client.tv.automation',
acceptsConnections: true,
profiles: {
'0': true,
'1': true,
},
openRelay: true,
debug: false,
})
)
// mos.on('rawMessage', (_source, _type, _message) => {
// console.log('rawMessage', _source, _type, _message)
// })
mos.on('error', (err) => {
console.log('MosConnection emitted error', err, err.stack)
})
mos.onConnection((mosDevice: MosDevice) => {
console.log('new mosDevice: ', mosDevice.idPrimary, mosDevice.idSecondary)
// console.log(dev)
const mosTypes = mosDevice.mosTypes // Could also be retrieved with getMosTypes(strict)
let hasSentInit = false
mosDevice.onConnectionChange((status) => {
console.log('connection status: ', status)
if (!hasSentInit) {
sendInit().catch(console.error)
hasSentInit = true
}
})
const sendInit = async () => {
const machineInfo = await mosDevice.requestMachineInfo()
console.log('Machineinfo', machineInfo)
const ros = await mosDevice.sendRequestAllRunningOrders()
console.log('allRunningOrders', ros)
// trigger a re-send of those running orders:
// return dev.getRunningOrder(mosTypes.mosString128.create('696297DF-1568-4B36-B43B3B79514B40D4'))
const roLists = await Promise.all(
ros.map(async (ro) => {
return mosDevice.sendRequestRunningOrder(ro.ID)
})
)
console.log('roLists', roLists)
}
mosDevice.onRequestMachineInfo(async () => {
return {
manufacturer: mosTypes.mosString128.create('mommy'),
model: mosTypes.mosString128.create('model!'),
hwRev: mosTypes.mosString128.create('0.1'),
swRev: mosTypes.mosString128.create('1.0'),
DOM: mosTypes.mosString128.create('1989-07-01'),
SN: mosTypes.mosString128.create('1234'),
ID: mosTypes.mosString128.create('MY ID'),
time: mosTypes.mosTime.create(Date.now()),
// opTime?: mosTypes.mosTime.create(),
mosRev: mosTypes.mosString128.create('A'),
supportedProfiles: {
deviceType: 'MOS',
profile0: true,
},
}
})
mosDevice.onReadyToAir(async (Action: IMOSROReadyToAir): Promise<IMOSROAck> => {
console.log('ready to air', Action)
return {
ID: Action.ID,
Status: mosTypes.mosString128.create('OK'),
Stories: [],
}
})
mosDevice.onCreateRunningOrder(async (ro: IMOSRunningOrder) => {
console.log('create running order', ro)
return {
ID: ro.ID,
Status: mosTypes.mosString128.create('OK'),
Stories: [],
}
})
mosDevice.onDeleteRunningOrder(async (RunningOrderID: IMOSString128) => {
console.log('delete running order', RunningOrderID)
return {
ID: RunningOrderID,
Status: mosTypes.mosString128.create('OK'),
Stories: [],
}
})
mosDevice.onROInsertStories(async (Action: IMOSStoryAction, Stories: Array<IMOSROStory>): Promise<IMOSROAck> => {
console.log('insert stories', Action, Stories)
return {
ID: Action.StoryID,
Status: mosTypes.mosString128.create('OK'),
Stories: [],
}
})
mosDevice.onROMoveStories(async (Action: IMOSStoryAction, Stories: Array<IMOSString128>): Promise<IMOSROAck> => {
console.log('move stories', Action, Stories)
return {
ID: Action.StoryID,
Status: mosTypes.mosString128.create('OK'),
Stories: [],
}
})
mosDevice.onRODeleteStories(async (Action: IMOSROAction, Stories: Array<IMOSString128>): Promise<IMOSROAck> => {
console.log('delete stories', Action, Stories)
return {
ID: Action.RunningOrderID,
Status: mosTypes.mosString128.create('OK'),
Stories: [],
}
})
})
mos.init()
.then(async (_listening) => {
return mos.connect({
primary: {
id: 'sofie.server.tv.automation',
host: '127.0.0.1',
timeout: 100000,
// To connect to a server on custom ports:
// ports: {
// lower: 11540,
// upper: 11541,
// query: 11542,
// },
},
})
})
.catch((e) => {
console.log(e)
})