-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
153 lines (98 loc) · 3.01 KB
/
index.js
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
const OBSWebSocket = require('obs-websocket-js').default;
const sheetLoader = require('./sheet-loader');
const config = require('./config.json');
const update = async (sceneList) => {
const data = await sheetLoader.loadData();
const batch = []
const range = config.range;
const startcell = range.split(":")[0].trim();
const startcol = startcell.match("[a-zA-Z]+");
//console.log("starting column is " + startcol);
const startrow = startcell.match("[0-9]+");
//console.log("starting row is " + startrow);
const rowoffset = startrow[0];
//console.log("row offset to array is " + rowoffset);
const coloffset = columnToNumber(startcol[0]);
//console.log("colum offset to array is " + coloffset);
await sceneList.sceneItems.forEach(async scene => {
// console.log(scene);
if (scene.sourceName.includes('|sheet')) {
const reference = scene.sourceName.split('|sheet')[1].trim();
let col = reference.match("[a-zA-Z]+");
let colnumber = columnToNumber(col[0]) - coloffset;
let row = reference.match("[0-9]+");
let rownumber = row[0] - rowoffset;
let cellvalue = data[colnumber][rownumber];
console.log("Value for cell in source is " + cellvalue)
if (cellvalue.length > 0) {
batch.push({
requestType: "SetInputSettings",
requestData: {
inputName: scene.sourceName,
inputSettings: {
text: cellvalue,
}
}
}
)
} else {
console.log(`Field is empty`)
batch.push({
requestType: "SetInputSettings",
requestData: {
inputName: scene.sourceName,
inputSettings: {
text: "Empty Field",
}
}
}
)
}
}
});
return batch
}
const getSceneList = async (obs) => {
const { sceneName } = config
console.log(sceneName)
const sceneList = await obs.call('GetSceneItemList', {
sceneName
});
console.log(sceneList)
return sceneList
}
const main = async () => {
const obs = new OBSWebSocket();
console.log("ran")
try {
const {
obsWebSocketVersion,
negotiatedRpcVersion
} = await obs.connect(config.obsaddress, config.obsauth, {
rpcVersion: 1,
eventSubscriptions: config.eventSubs,
});
console.log(`Connected to server ${obsWebSocketVersion} (using RPC ${negotiatedRpcVersion})`)
} catch (error) {
console.error('Failed to connect', error.code, error.message);
}
const sceneList = await getSceneList(obs)
const updateWrapped = async () => {
const batch = await update(sceneList)
console.log(batch)
await obs.callBatch(batch)
};
setInterval(updateWrapped, config.polling);
updateWrapped();
}
main().catch(e => {
console.log("EXECUTION ERROR:");
console.log(e);
});
function columnToNumber(str) {
var out = 0, len = str.length;
for (pos = 0; pos < len; pos++) {
out += (str.charCodeAt(pos) - 64) * Math.pow(26, len - pos - 1);
}
return out - 1;
}