在研究 OBS (Open Broadcaster Software) 時意外發現了一個好用的 Plugin OBS Remote
其用意主要就是當OBS安裝了Plugin後~可以透過手機APP、Web等環境經由WebSocket的方式進行控制
預設走的Port是TCP 4444,如果需要改Port的話就必須要改一下語法了
//原本的 js / websocket.js 檔案
function connectWebSocket(host)
{
connectingHost = host;
var url = "ws://" + connectingHost + ":4444";
console.log("trying to connect to: " + url);
if (typeof MozWebSocket != "undefined")
{
socket_obsapi = new MozWebSocket(url, "obsapi");
}
else
{
socket_obsapi = new WebSocket(url, "obsapi");
}
try {
socket_obsapi.onopen = _onWebSocketConnected;
socket_obsapi.onmessage = _onWebSocketReceiveMessage;
socket_obsapi.onerror = _onWebSocketError;
socket_obsapi.onclose = _onWebSocketClose;
} catch(exception) {
alert('Error' + exception);
}
}
//修改後的 js / websocket.js 檔案
function connectWebSocket(host)
{
var n = host.indexOf(":");
//console.log(n.toString());
if (n == -1)
{
console.log("沒有帶port資訊");
connectingHost = host;
var url = "ws://" + connectingHost + ":4444";
}
else
{
console.log("有帶port資訊");
var hosts = host.split(":");
connectingHost = hosts[0];
var url = "ws://" + connectingHost + ":" + hosts[1];
}
console.log("trying to connect to: " + url);
if (typeof MozWebSocket != "undefined")
{
socket_obsapi = new MozWebSocket(url, "obsapi");
}
else
{
socket_obsapi = new WebSocket(url, "obsapi");
}
try {
socket_obsapi.onopen = _onWebSocketConnected;
socket_obsapi.onmessage = _onWebSocketReceiveMessage;
socket_obsapi.onerror = _onWebSocketError;
socket_obsapi.onclose = _onWebSocketClose;
} catch(exception) {
alert('Error' + exception);
}
}