StompJs v5+, RxStomp: Polyfills

1 minute read

This guide covers critical dependencies and polyfills for version 5+ of @stomp/stompjs; which is internally used by @stomp/rx-stomp as well.

In NodeJS

WebSocket

There are two alternate libraries websocket and ws which have been reported to work.

websocket

  • Add websocket npm module:

    $ npm install websocket
    
  • Using import syntax

    import websocket from 'websocket';
    
    Object.assign(global, { WebSocket: websocket.w3cwebsocket });
    

ws

  • Instead of websocket lib ws has also been reported to work. See: stompjs/issues/28.
  • Add ws npm module:

    $ npm install ws
    
  • Require the module and expose it through global

    import { WebSocket } from 'ws';
    
    Object.assign(global, { WebSocket });
    

In React Native

TextEncoder/TextDecoder

  • React Native makes it deceptive. When an application is executed in debug mode, it works, as it is executed on an actual browser where TextEncoder/TextDecoder is available. However, when executed in production mode, it fails as TextEncoder/TextDecoder is not available.
  • Please install text-encoding
    $ npm install text-encoding
    
  • Add the following to your index.js or App.js:

    import * as encoding from 'text-encoding';
    
  • There are additional issues with React Native in some device/version combinations. Please see: React Native - Additional Notes

Updated: