parent
e510b9c895
commit
35abb87114
|
|
@ -545,5 +545,38 @@ export function UpdateActions(instance: MPinstance): void {
|
|||
instance.moduloplayer?.sendShowSendShowToRemote()
|
||||
},
|
||||
},
|
||||
|
||||
// ----- SPYDOG -----
|
||||
spydog_start_mp: {
|
||||
name: 'Start Modulo Player',
|
||||
options: [],
|
||||
callback: async () => {
|
||||
instance.spydog?.sendStartModuloPlayer()
|
||||
},
|
||||
},
|
||||
|
||||
spydog_stop_mp: {
|
||||
name: 'Stop Modulo Player',
|
||||
options: [],
|
||||
callback: async () => {
|
||||
instance.spydog?.sendStopModuloPlayer()
|
||||
},
|
||||
},
|
||||
|
||||
spydog_reboot_mp: {
|
||||
name: 'Reboot Modulo Player',
|
||||
options: [],
|
||||
callback: async () => {
|
||||
instance.spydog?.sendRebootComputer()
|
||||
},
|
||||
},
|
||||
|
||||
spydog_power_off_mp: {
|
||||
name: 'Power Off Modulo Player',
|
||||
options: [],
|
||||
callback: async () => {
|
||||
instance.spydog?.sendPowerOffComputer()
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
29
src/main.ts
29
src/main.ts
|
|
@ -78,7 +78,7 @@ export class MPinstance extends InstanceBase<ModuloPlayConfig> {
|
|||
this.config = config
|
||||
this.mpConnection.disconnect()
|
||||
this.sdConnection.disconnect()
|
||||
this.updateStatus(InstanceStatus.Connecting, `Init Connection`)
|
||||
this.updateStatus(InstanceStatus.Connecting, `Init Connection, Start Modulo Player`)
|
||||
await this.mpConnection.connect(this.config.host, this.config.mpPort)
|
||||
if (this.config.sdEnable) {
|
||||
await this.sdConnection.connect(this.config.host, this.config.sdPort)
|
||||
|
|
@ -86,22 +86,33 @@ export class MPinstance extends InstanceBase<ModuloPlayConfig> {
|
|||
}
|
||||
|
||||
async isConnected() {
|
||||
this.log('warn', `IS CONNECTED ? >>> ${this.mpConnected} ${this.sdConnected}`)
|
||||
if (this.config.sdEnable) {
|
||||
if (this.mpConnected && this.sdConnected) {
|
||||
this.updateStatus(InstanceStatus.Ok, `Connected`)
|
||||
if (this.mpConnected) this.moduloplayer?.sendTaskListModuloPlayer()
|
||||
if (this.mpConnected) this.moduloplayer?.sendPlaylistModuloPlayer()
|
||||
if (this.sdConnected) this.spydog?.getStaticInfo()
|
||||
if (this.sdConnected) this.spydog?.getDynamicInfo()
|
||||
if (this.sdConnected) this.spydog?.sendStaticInfo()
|
||||
if (this.sdConnected) this.spydog?.sendDynamicInfo()
|
||||
} else if (!this.mpConnected && this.sdConnected) {
|
||||
this.updateStatus(InstanceStatus.Ok, `Spydog Online | Modulo Player Offline`)
|
||||
if (this.sdConnected) this.spydog?.getStaticInfo()
|
||||
if (this.sdConnected) this.spydog?.getDynamicInfo()
|
||||
this.updateStatus(InstanceStatus.Connecting, `Modulo Player Offline | Spydog Online `)
|
||||
if (this.sdConnected) this.spydog?.sendStaticInfo()
|
||||
if (this.sdConnected) this.spydog?.sendDynamicInfo()
|
||||
} else if (this.mpConnected && !this.sdConnected) {
|
||||
this.updateStatus(InstanceStatus.Ok, `Modulo Player Online | Spydog Offline`)
|
||||
this.updateStatus(InstanceStatus.Connecting, `Modulo Player Online | Spydog Offline`)
|
||||
if (this.mpConnected) this.moduloplayer?.sendTaskListModuloPlayer()
|
||||
if (this.mpConnected) this.moduloplayer?.sendPlaylistModuloPlayer()
|
||||
} else {
|
||||
this.updateStatus(InstanceStatus.Connecting, `Init Connection`)
|
||||
this.updateStatus(InstanceStatus.ConnectionFailure, `Start Modulo Player or Check IP Address`)
|
||||
}
|
||||
} else {
|
||||
if (this.mpConnected) {
|
||||
this.updateStatus(InstanceStatus.Ok, `Connected`)
|
||||
if (this.mpConnected) this.moduloplayer?.sendTaskListModuloPlayer()
|
||||
if (this.mpConnected) this.moduloplayer?.sendPlaylistModuloPlayer()
|
||||
} else {
|
||||
this.updateStatus(InstanceStatus.ConnectionFailure, `Start Modulo Player or Check IP Address`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +127,7 @@ export class MPinstance extends InstanceBase<ModuloPlayConfig> {
|
|||
if (this.mpConnected) this.moduloplayer?.sendCurrentCues()
|
||||
if (this.mpConnected) this.moduloplayer?.sendTaskListModuloPlayer()
|
||||
if (this.mpConnected) this.moduloplayer?.sendPlaylistModuloPlayer()
|
||||
if (this.sdConnected) this.spydog?.getDynamicInfo()
|
||||
if (this.sdConnected) this.spydog?.sendDynamicInfo()
|
||||
}
|
||||
|
||||
// Return config fields for web config
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import WebSocket from 'ws'
|
|||
|
||||
export class MPconnection {
|
||||
instance: MPinstance
|
||||
private websocket: WebSocket | undefined | null
|
||||
public websocket: WebSocket | undefined | null
|
||||
private wsTimeout: NodeJS.Timeout | undefined
|
||||
private mpAddr: string | undefined
|
||||
private mpPort: any | undefined | null
|
||||
|
|
@ -38,12 +38,14 @@ export class MPconnection {
|
|||
this.websocket.on('open', async () => {
|
||||
this.reconnectinterval = this.reconnectmin
|
||||
this.instance!.log('info', 'WEBSOCKET MP OPENED ' + this.websocket?.readyState)
|
||||
this.instance.mpConnected = true
|
||||
this.instance.mpConnected = this.websocket?.readyState === 1
|
||||
this.instance.isConnected()
|
||||
this.instance.initPolling()
|
||||
})
|
||||
|
||||
this.websocket.on('close', (ev: { toString: () => any }) => {
|
||||
this.instance.mpConnected = this.websocket?.readyState === 1
|
||||
this.instance.isConnected()
|
||||
console.log(
|
||||
'ws closed',
|
||||
ev.toString(),
|
||||
|
|
@ -64,7 +66,8 @@ export class MPconnection {
|
|||
this.websocket.on('error', (error: string) => {
|
||||
this.instance.log('error', 'Socket ' + error)
|
||||
this.instance.log('warn', 'Check if Modulo Player is started ?')
|
||||
//this.instance.updateStatus(InstanceStatus.ConnectionFailure)
|
||||
this.instance.mpConnected = this.websocket?.readyState === 1
|
||||
this.instance.isConnected()
|
||||
})
|
||||
|
||||
this.websocket.on('message', (data: { toString: () => string }) => {
|
||||
|
|
@ -85,25 +88,6 @@ export class MPconnection {
|
|||
}
|
||||
}
|
||||
|
||||
// sendMessage(method: string, id: any): void {
|
||||
// if (this.websocket?.readyState === 1) {
|
||||
// var m = `{"jsonrpc":"2.0","method":"${method}","id": ${id}}`
|
||||
// this.websocket?.send(m)
|
||||
// //this.instance.log('debug', 'SENDING WS MESSAGE ' + this.websocket.url + ' ' + m)
|
||||
// }
|
||||
// }
|
||||
|
||||
// sendMessageLunchTask(uuid: any, id: any): void {
|
||||
// if (this.websocket?.readyState === 1) {
|
||||
// var m = `{"jsonrpc":"2.0","method":"doaction.task", "params": {
|
||||
// "uuid": "${uuid}",
|
||||
// "action": "launch"
|
||||
// },"id": ${id}}`
|
||||
// this.websocket?.send(m)
|
||||
// //this.instance.log('debug', 'SENDING WS MESSAGE LAUNCH TASK ' + this.websocket.url + ' ' + m)
|
||||
// }
|
||||
// }
|
||||
|
||||
sendJsonMessage(message: String) {
|
||||
if (this.websocket?.readyState === 1 && message !== '') {
|
||||
this.websocket?.send(message)
|
||||
|
|
@ -111,27 +95,6 @@ export class MPconnection {
|
|||
}
|
||||
}
|
||||
|
||||
// sendMessagePlaylistsCues(): void {
|
||||
// if (this.websocket?.readyState === 1) {
|
||||
// var m = `{"jsonrpc":"2.0","method":"get.list.playlists",
|
||||
// "params": {
|
||||
// "level": "cue"},
|
||||
// "id": 3}`
|
||||
// this.websocket?.send(m)
|
||||
// //this.instance.log('debug', 'SENDING WS MESSAGE GET PLAYLISTS CUES ' + this.websocket.url + ' ' + m)
|
||||
// }
|
||||
// }
|
||||
|
||||
// async sendMessageCurrentCues(): Promise<void> {
|
||||
// if (this.websocket?.readyState === 1) {
|
||||
// var m = `{"jsonrpc":"2.0","method":"get.list.playlists",
|
||||
// "params": {
|
||||
// "level": "playlist"},
|
||||
// "id": 110}`
|
||||
// this.websocket?.send(m)
|
||||
// }
|
||||
// }
|
||||
|
||||
disconnect(): void {
|
||||
clearTimeout(this.wsTimeout)
|
||||
// if (this.pollAPI !== undefined) {
|
||||
|
|
|
|||
111
src/presets.ts
111
src/presets.ts
|
|
@ -734,6 +734,107 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions {
|
|||
return showPresets
|
||||
}
|
||||
|
||||
const getSpydogPresets = (): mpPresetArray => {
|
||||
const spydogPresets: mpPresetArray = []
|
||||
|
||||
// REBOOT
|
||||
spydogPresets.push({
|
||||
category: `Spydog`,
|
||||
name: `Reboot Server`,
|
||||
type: 'button',
|
||||
style: {
|
||||
text: `Reboot Server`,
|
||||
size: textSize,
|
||||
color: combineRgb(255, 255, 255),
|
||||
bgcolor: instance.redModuloPlayer,
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
down: [
|
||||
{
|
||||
actionId: 'spydog_reboot_mp',
|
||||
},
|
||||
],
|
||||
up: [],
|
||||
},
|
||||
],
|
||||
feedbacks: [],
|
||||
})
|
||||
|
||||
// POWER OFF
|
||||
spydogPresets.push({
|
||||
category: `Spydog`,
|
||||
name: `Power Off Server`,
|
||||
type: 'button',
|
||||
style: {
|
||||
text: `Power Off Server`,
|
||||
size: textSize,
|
||||
color: combineRgb(255, 255, 255),
|
||||
bgcolor: instance.redModuloPlayer,
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
down: [
|
||||
{
|
||||
actionId: 'spydog_power_off_mp',
|
||||
},
|
||||
],
|
||||
up: [],
|
||||
},
|
||||
],
|
||||
feedbacks: [],
|
||||
})
|
||||
|
||||
// RESTART MODULO PLAYER
|
||||
spydogPresets.push({
|
||||
category: `Spydog`,
|
||||
name: `Start Modulo Player`,
|
||||
type: 'button',
|
||||
style: {
|
||||
text: `Start Modulo Player`,
|
||||
size: textSize,
|
||||
color: combineRgb(255, 255, 255),
|
||||
bgcolor: instance.greenModuloPlayer,
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
down: [
|
||||
{
|
||||
actionId: 'spydog_start_mp',
|
||||
},
|
||||
],
|
||||
up: [],
|
||||
},
|
||||
],
|
||||
feedbacks: [],
|
||||
})
|
||||
// STOP MODULO PLAYER
|
||||
spydogPresets.push({
|
||||
category: `Spydog`,
|
||||
name: `Stop Modulo Player`,
|
||||
type: 'button',
|
||||
style: {
|
||||
text: `Stop Modulo Player`,
|
||||
size: textSize,
|
||||
color: combineRgb(255, 255, 255),
|
||||
bgcolor: instance.orangeModuloPlayer,
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
down: [
|
||||
{
|
||||
actionId: 'spydog_stop_mp',
|
||||
},
|
||||
],
|
||||
up: [],
|
||||
},
|
||||
],
|
||||
feedbacks: [],
|
||||
})
|
||||
|
||||
return spydogPresets
|
||||
}
|
||||
|
||||
// VARIABLES CUES
|
||||
const getVariablesPresets = (): mpPresetArray => {
|
||||
const variablesPresets: mpPresetArray = []
|
||||
|
|
@ -1015,9 +1116,15 @@ export function getPresets(instance: MPinstance): CompanionPresetDefinitions {
|
|||
|
||||
let presets: mpPresetArray = []
|
||||
if (instance.sdConnected) {
|
||||
presets = [...getTasksPresets(), ...getPlayListsCuesPresets(), ...getShowPresets(), ...getVariablesPresets()]
|
||||
presets = [
|
||||
...getTasksPresets(),
|
||||
...getPlayListsCuesPresets(),
|
||||
...getShowPresets(),
|
||||
...getSpydogPresets(),
|
||||
...getVariablesPresets(),
|
||||
]
|
||||
} else {
|
||||
presets = [...getTasksPresets(), ...getPlayListsCuesPresets(), ...getShowPresets()]
|
||||
presets = [...getTasksPresets(), ...getPlayListsCuesPresets(), ...getShowPresets(), ...getVariablesPresets()]
|
||||
}
|
||||
|
||||
return presets as unknown as CompanionPresetDefinitions
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { MPinstance } from './main.js'
|
||||
import { InstanceStatus } from '@companion-module/base'
|
||||
//import { InstanceStatus } from '@companion-module/base'
|
||||
|
||||
import WebSocket from 'ws'
|
||||
|
||||
export class SDconnection {
|
||||
instance: MPinstance
|
||||
private websocket: WebSocket | undefined | null
|
||||
public websocket: WebSocket | undefined | null
|
||||
private wsTimeout: NodeJS.Timeout | undefined
|
||||
private mpAddr: string | undefined
|
||||
private sdPort: any | null
|
||||
|
|
@ -31,7 +31,7 @@ export class SDconnection {
|
|||
const urlObj = `ws://${this.mpAddr}:${this.sdPort}`
|
||||
if (urlObj === null) return
|
||||
|
||||
this.instance.updateStatus(InstanceStatus.Connecting, `Init Connection`)
|
||||
//this.instance.updateStatus(InstanceStatus.Connecting, `Init Connection`)
|
||||
|
||||
try {
|
||||
const setupMP = async () => {
|
||||
|
|
@ -40,19 +40,21 @@ export class SDconnection {
|
|||
this.websocket.on('open', async () => {
|
||||
this.reconnectinterval = this.reconnectmin
|
||||
this.instance!.log('info', 'WEBSOCKET SPYDOG OPENED ' + this.websocket?.readyState)
|
||||
this.instance.sdConnected = true
|
||||
this.instance.sdConnected = this.websocket?.readyState === 1
|
||||
this.instance.isConnected()
|
||||
this.instance.initPolling()
|
||||
})
|
||||
|
||||
this.websocket.on('close', (ev: { toString: () => any }) => {
|
||||
this.instance.sdConnected = this.websocket?.readyState === 1
|
||||
this.instance.isConnected()
|
||||
console.log(
|
||||
'ws closed',
|
||||
ev.toString(),
|
||||
this.shouldBeConnected ? 'should be connected' : 'should not be connected',
|
||||
)
|
||||
if (this.shouldBeConnected) {
|
||||
this.instance.updateStatus(InstanceStatus.Disconnected)
|
||||
//this.instance.updateStatus(InstanceStatus.Disconnected)
|
||||
if (this.wsTimeout) clearTimeout(this.wsTimeout)
|
||||
this.wsTimeout = setTimeout(() => {
|
||||
this.connect(this.mpAddr, this.sdPort)
|
||||
|
|
@ -64,8 +66,9 @@ export class SDconnection {
|
|||
|
||||
this.websocket.on('error', (error: string) => {
|
||||
this.instance.log('error', 'Socket ' + error)
|
||||
this.instance.log('error', 'Check if Modulo Player is started ?')
|
||||
this.instance.updateStatus(InstanceStatus.ConnectionFailure)
|
||||
this.instance.log('error', 'Check if Modulo Spydog is started ?')
|
||||
this.instance.sdConnected = this.websocket?.readyState === 1
|
||||
this.instance.isConnected()
|
||||
})
|
||||
|
||||
this.websocket.on('message', (data: { toString: () => string }) => {
|
||||
|
|
|
|||
|
|
@ -21,18 +21,6 @@ export class SpyDog {
|
|||
}
|
||||
}
|
||||
|
||||
async getStaticInfo() {
|
||||
//this.instance.log('info', 'SPYDOG | GET STATIC INFO')
|
||||
var m = `{"jsonrpc":"2.0", "method":"get.computer.static.info", "id": ${201}}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
|
||||
async getDynamicInfo() {
|
||||
//this.instance.log('info', 'SPYDOG | GET DYNAMIC INFO')
|
||||
var m = `{"jsonrpc":"2.0", "method":"get.computer.dynamic.info", "id": ${200}}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
|
||||
async setStaticInfo(objs: any) {
|
||||
this.instance.staticInfo = objs[0]
|
||||
for (var key in objs[0]) {
|
||||
|
|
@ -76,4 +64,43 @@ export class SpyDog {
|
|||
this.instance.checkFeedbacks(`${key}`)
|
||||
}
|
||||
}
|
||||
|
||||
// SEND INFOS
|
||||
async sendStaticInfo() {
|
||||
//this.instance.log('info', 'SPYDOG | GET STATIC INFO')
|
||||
var m = `{"jsonrpc":"2.0", "method":"get.computer.static.info", "id": ${201}}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
|
||||
async sendDynamicInfo() {
|
||||
//this.instance.log('info', 'SPYDOG | GET DYNAMIC INFO')
|
||||
var m = `{"jsonrpc":"2.0", "method":"get.computer.dynamic.info", "id": ${200}}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
|
||||
//SEND DOACTIONS
|
||||
|
||||
async sendStartModuloPlayer() {
|
||||
//this.instance.log('info', 'SPYDOG | START MODULO PLAYER')
|
||||
var m = `{"jsonrpc":"2.0", "method":"doaction.computer", "params": {"action": "startModuloPlayer"}, "id": 0}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
|
||||
async sendStopModuloPlayer() {
|
||||
//this.instance.log('info', 'SPYDOG | STOP MODULO PLAYER')
|
||||
var m = `{"jsonrpc":"2.0", "method":"doaction.computer", "params": {"action": "stopModuloPlayer"}, "id": 0}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
|
||||
async sendRebootComputer() {
|
||||
//this.instance.log('info', 'SPYDOG | REBOOT COMPUTER')
|
||||
var m = `{"jsonrpc":"2.0", "method":"doaction.computer", "params": {"action": "rebootComputer"}, "id": 0}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
|
||||
async sendPowerOffComputer() {
|
||||
//this.instance.log('info', 'SPYDOG | POWER OFF COMPUTER')
|
||||
var m = `{"jsonrpc":"2.0", "method":"doaction.computer", "params": {"action": "powerOffComputer"}, "id": 0}`
|
||||
this.instance.sdConnection.sendJsonMessage(m)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue