stomp-js / stompjs

Javascript and Typescript Stomp client for Web browsers and node.js apps
Apache License 2.0
770 stars 81 forks source link

How to use StompJS in a SharedWorker #337

Open silentiumNoxe opened 3 years ago

silentiumNoxe commented 3 years ago

The standard UMD header does not work within Shared Workers. Shared Workers run in a browser, however, these do not have access to window.

if (typeof exports !== "undefined" && exports !== null) {
  exports.Stomp = Stomp;
}

if (typeof window !== "undefined" && window !== null) {
  window.Stomp = Stomp;
} else if (!exports) {
  self.Stomp = Stomp;
}

The above block would give undefined exports.

To fix this problem, please define the following before including stompjs.

 self.exports = {};
kum-deepak commented 3 years ago

Edited the issue to make it like documentation.

synscen commented 1 year ago

Yes, it works. can use it as below: var stompClient = exports.Stomp.over(socket);

Thank you, @silentiumNoxe