In a lightning community with LockerService enabled, I am trying to instantiate a websocket using new WebSocker('wss://xyz.com')
, but I am unable to because of the way WebSocket
is implemented in SecureWindowHelper
. It uses the SecureObject.$createFilteredMethod$
which returns a function instead of an "newable" object.
Here's the error:
Uncaught TypeError: Failed to construct 'WebSocket': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
at WrappedWebSocket (:30:55)
at new value (https://livepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/yFpIOtval-qIdUy0rMdm1A/aura_proddebug.js:17508:45)
at eval (eval at evaluate (:85:21), :1:12)
at WrappedWebSocket (:30:55)
at new value (https://livepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/yFpIOtval-qIdUy0rMdm1A/aura_proddebug.js:17508:45)
Also, on the Locker Service API explorer, web sockets are supported.
Any workaround?