-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
105 lines (88 loc) · 2.16 KB
/
app.js
File metadata and controls
105 lines (88 loc) · 2.16 KB
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
const applescript = require('applescript');
const express = require('express');
require('dotenv').config();
const PORT = process.env.PORT;
const WIRECAST_DOCUMENT = process.env.WIRECAST_DOCUMENT;
const app = express();
app.use(express.json());
app.listen(PORT, () => {
console.log(`Server Listening on PORT: http://localhost:${PORT}`);
});
class WirecastController {
document;
baseCommand;
constructor(document) {
this.document = document;
this.baseCommand = `tell application "Wirecast"\n set myDoc to last document\n `;
}
execute(command) {
applescript.execString(this.baseCommand + command);
}
startRecording() {
this.execute("start recording myDoc\nend tell");
}
stopRecording() {
this.execute("stop recording myDoc\nend tell");
}
startBroadcasting() {
this.execute("start broadcasting myDoc\nend tell");
}
stopBroadcasting() {
this.execute("stop broadcasting myDoc\nend tell");
}
}
let doc = new WirecastController(process.env.WIRECAST_DOCUMENT);
app.get("/", (request, response) => {
const status = {
"Status": "Running"
};
response.send(status);
})
// Start recording
app.get("/start-recording", (request, response) => {
try {
doc.startRecording();
} catch {
console.log("Error")
}
const status = {
"Status": "Started"
};
response.send(status);
})
// Stop recording
app.get("/stop-recording", (request, response) => {
try {
doc.stopRecording();
} catch {
console.log("Error")
}
const status = {
"Status": "Stopped"
};
response.send(status);
})
// Start broadcasting
app.get("/start-broadcasting", (request, response) => {
try {
doc.startBroadcasting();
} catch {
console.log("Error")
}
const status = {
"Status": "Started"
};
response.send(status);
})
// Stop broadcasting
app.get("/stop-broadcasting", (request, response) => {
try {
doc.stopBroadcasting();
} catch {
console.log("Error")
}
const status = {
"Status": "Stopped"
};
response.send(status);
})