webSocket_sharedWorker.js 614 B

123456789101112131415161718192021
  1. onconnect = function(evt) {
  2. var ws = new WebSocket("ws://mochi.test:8888/tests/dom/base/test/file_websocket_hello");
  3. ws.onopen = function(e) {
  4. evt.ports[0].postMessage({type: 'status', status: true, msg: 'OnOpen called' });
  5. ws.send("data");
  6. }
  7. ws.onclose = function(e) {}
  8. ws.onerror = function(e) {
  9. evt.ports[0].postMessage({type: 'status', status: false, msg: 'onerror called!'});
  10. }
  11. ws.onmessage = function(e) {
  12. evt.ports[0].postMessage({type: 'status', status: e.data == 'Hello world!', msg: 'Wrong data'});
  13. ws.close();
  14. evt.ports[0].postMessage({type: 'finish' });
  15. }
  16. }