7

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?

2
  • Hi MAV, welcome to SFSE! No need to add thanks or your name in your posts. They just add noise and will be removed.
    – Adrian Larson
    Commented Mar 1, 2017 at 22:52
  • 1
    I've mentioned you on a post in the Partner Community regarding a conversation about this. Commented Mar 1, 2017 at 22:58

1 Answer 1

9

WebSocket will be exposed in Summer '17 and you can instantiate a WebSocket instance like in your example.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .