PatrickJS / angular-websocket

:arrow_upper_left: The missing Angular WebSocket module for connecting client applications to servers by @AngularClass
https://angularclass.github.io/angular-websocket
MIT License
1.22k stars 194 forks source link

Electron support - condition for require('ws') #111

Open manikantag opened 7 years ago

manikantag commented 7 years ago

Hi,

Now that developing Electron based apps is common, to support those apps, I think we better remove the check if (typeof window === 'undefined') as anyway it is in try/catch.

if (typeof window === 'undefined') { // removing this check would work in Browser, Node.js, Electron apps :)
  try {
    var ws = require('ws');

    Socket = (ws.Client || ws.client || ws);
  } catch(e) {}
}

(at github.com/AngularClass/angular-websocket/blob/master/src/angular-websocket.js#L5)

Due to this check, as Electron has 'window' in render process, it is not picking 'ws' module, and lacking many features 'ws' supports (like, auth).

I knew we can achieve basic auth with wss://user:pass@serverurl. But it does has more options.

Any thoughts?