在研究 OBS (Open Broadcaster Software) 時意外發現了一個好用的 Plugin OBS Remote
其用意主要就是當OBS安裝了Plugin後~可以透過手機APP、Web等環境經由WebSocket的方式進行控制
預設走的Port是TCP 4444,如果需要改Port的話就必須要改一下語法了
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 |
//原本的 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('<p>Error' + exception); } } |
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 |
//修改後的 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('<p>Error' + exception); } } |