index.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  6. <title>OBS Twitch Points Alerts</title>
  7. <meta name='viewport' content='width=device-width, initial-scale=1'>
  8. <style>
  9. body {
  10. width: 100%;
  11. height: 100%;
  12. }
  13. * {
  14. color: white;
  15. }
  16. video {
  17. background-color: rgba(0, 0, 0, 0);
  18. height: 100vh;
  19. margin: 0 auto;
  20. display: block;
  21. z-index: -100;
  22. }
  23. h2 {
  24. display: none;
  25. position: absolute;
  26. top: 5em;
  27. left: 5em;
  28. z-index: 100;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <video></video>
  34. <script>
  35. let video = document.querySelector("video");
  36. video.volume = 0.2;
  37. </script>
  38. <h2 id="ran">
  39. Random text
  40. </h2>
  41. <script>
  42. let el = document.querySelector("h2#ran");
  43. let randomnumber = Math.random() * 1000000;
  44. randomnumber = randomnumber.toString();
  45. el.textContent = "Random Number: " + randomnumber;
  46. </script>
  47. <script>
  48. function parseCommand(cmdObject){
  49. console.log(cmdObject.cmd);
  50. switch(cmdObject.cmd){
  51. case "reload":
  52. location.reload();
  53. break;
  54. case "stop":
  55. video.pause();
  56. break;
  57. case "start":
  58. video.play();
  59. break;
  60. case "vol":
  61. if(cmdObject.volume)
  62. video.volume = Number.parseFloat(cmdObject.volume)
  63. break;
  64. case "src":
  65. if(cmdObject.src){
  66. video.src=cmdObject.src
  67. }
  68. break;
  69. case "videoInQueue":
  70. if(video.src == ""){
  71. ws.send(JSON.stringify({
  72. action: "waitingForVideo"
  73. }))
  74. }
  75. break;
  76. case "abort":
  77. video.pause();
  78. video.src = "";
  79. video.removeAttribute("src");
  80. ws.send(JSON.stringify({
  81. action: "waitingForVideo"
  82. }))
  83. break;
  84. }
  85. }
  86. let ws = new WebSocket("ws://localhost:8045");
  87. ws.onmessage = (msg)=>{
  88. let data = msg.data;
  89. let commandArray = JSON.parse(msg.data)
  90. if(commandArray instanceof Array){
  91. for(let it of commandArray){
  92. parseCommand(it);
  93. }
  94. }
  95. };
  96. video.addEventListener("ended", ()=>{
  97. video.src = "";
  98. video.removeAttribute("src");
  99. ws.send(JSON.stringify({
  100. action: "ended"
  101. }));
  102. })
  103. </script>
  104. <script>
  105. setInterval(()=>{
  106. if(!ws || ws.readyState != 1){
  107. location.reload();
  108. }
  109. }, 5000);
  110. </script>
  111. </body>
  112. </html>