Browse Source

Make URLs configurable in client

Tankernn 7 năm trước cách đây
mục cha
commit
7c105d770f
2 tập tin đã thay đổi với 19 bổ sung3 xóa
  1. 8 1
      client/index.html
  2. 11 2
      client/js/script.js

+ 8 - 1
client/index.html

@@ -12,7 +12,14 @@
 </head>
 
 <body>
-  <img src="http://raspberrypi:8080/?action=stream" />
+  <form id="settings">
+    <input type="text" id="control_url" placeholder="ws://..." />
+    <input type="text" id="stream_url" placeholder="http://..." />
+    <button id="connect">Connect</button>
+  </form>
+  <div id="stream">
+
+  </div>
   <script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
   <script src="js/script.js"></script>
 </body>

+ 11 - 2
client/js/script.js

@@ -1,5 +1,5 @@
-$(document).ready(function () {
-  var socket = new WebSocket("ws://raspberrypi:54321");
+function connect(stream_url, control_url) {
+  var socket = new WebSocket(control_url);
   var keys = [];
 
   socket.onopen = function() {
@@ -21,4 +21,13 @@ $(document).ready(function () {
       keys.splice(keys.indexOf(e.keyCode), 1);
     }
   });
+
+  $("#stream").append('<img src="' + stream_url + '" width="1280" height="720" />');
+}
+
+$(document).ready(function () {
+  $("#connect").click(function () {
+    connect($("#stream_url").val(), $("#control_url").val());
+    $("#settings").remove();
+  });
 });