websocket.js 838 B

1234567891011121314151617181920212223242526272829303132333435
  1. self.importScripts("helper.js");
  2. // self.importScripts("pcm-player.js");
  3. // self.importScripts("pcm-player.min.js");
  4. var socketURL = "ws://192.168.198.11:9101";
  5. // var socketURL = "ws://14.215.128.98:14102"
  6. // socketURL = "ws://127.0.0.1:8081"
  7. var ws = new WebSocket(socketURL);
  8. ws.binaryType = 'arraybuffer';
  9. ws.addEventListener('open', function(event) {
  10. console.log("发送配置帧");
  11. // ws.send(ConfigChannel("RK3923C1201900139"));
  12. });
  13. self.addEventListener('message', function(e) {
  14. console.log("收到数据", e.data);
  15. ws.send(e.data);
  16. console.log('ws', ws)
  17. }, false);
  18. ws.addEventListener('message', function(event) {
  19. //var objData = {type:0, data:input};
  20. var input = new Uint8Array(event.data);
  21. if (input[0] == 0xff) {
  22. // console.log("1111111")
  23. // decodeAAC(input);
  24. } else {
  25. self.postMessage(input);
  26. }
  27. });