script.js 768 B

123456789101112131415161718192021222324252627282930313233
  1. function connect(stream_url, control_url) {
  2. var socket = new WebSocket(control_url);
  3. var keys = [];
  4. socket.onopen = function() {
  5. var sendInput = function () {
  6. socket.send(JSON.stringify(keys));
  7. };
  8. setInterval(sendInput, 69);
  9. }
  10. $(document).keydown(function(e) {
  11. if (keys.indexOf(e.keyCode) === -1) {
  12. keys.push(e.keyCode);
  13. }
  14. });
  15. $(document).keyup(function(e) {
  16. if (keys.indexOf(e.keyCode) !== -1) {
  17. keys.splice(keys.indexOf(e.keyCode), 1);
  18. }
  19. });
  20. $("#stream").append('<img src="' + stream_url + '" width="1280" height="720" />');
  21. }
  22. $(document).ready(function () {
  23. $("#connect").click(function () {
  24. connect($("#stream_url").val(), $("#control_url").val());
  25. $("#settings").remove();
  26. });
  27. });