client.js 802 B

1234567891011121314151617181920212223242526272829303132
  1. var WebSocket = require('..').Client,
  2. deflate = require('permessage-deflate'),
  3. fs = require('fs');
  4. var url = process.argv[2],
  5. proxy = process.argv[3],
  6. ca = fs.readFileSync(__dirname + '/../spec/server.crt'),
  7. tls = {ca: ca};
  8. var ws = new WebSocket(url, [], {
  9. proxy: {origin: proxy, headers: {'User-Agent': 'Echo'}, tls: tls},
  10. tls: tls,
  11. headers: {Origin: 'http://faye.jcoglan.com'},
  12. extensions: [deflate]
  13. });
  14. ws.onopen = function() {
  15. console.log('[open]', ws.headers);
  16. ws.send('mic check');
  17. };
  18. ws.onclose = function(close) {
  19. console.log('[close]', close.code, close.reason);
  20. };
  21. ws.onerror = function(error) {
  22. console.log('[error]', error.message);
  23. };
  24. ws.onmessage = function(message) {
  25. console.log('[message]', message.data);
  26. };