Giter VIP home page Giter VIP logo

Comments (13)

kum-deepak avatar kum-deepak commented on September 24, 2024 3

Please check https://stomp-js.github.io/guide/stompjs/rx-stomp/ng2-stompjs/2018/06/28/pollyfils-for-stompjs-v5.html. All the test cases successfully pass with this setup. The suggested setup is similar to what you have used.

If you are bundling with Webpack to run at browsers, please include "lib": ["es5", "es2015", "dom"] in your tsconfig. You will be able to skip the polyfills - depending on your target browsers.

This library does need TextEncoder/Decoder as it needs to convert internally between String and Bytes. This is built in as default in most of the Web Browsers. It seems it is planned to be distributed by default in future Node versions (https://nodejs.org/api/util.html#util_class_util_textencoder).

from stompjs.

kum-deepak avatar kum-deepak commented on September 24, 2024 3

I assume you are using Node JS.

require is not necessarily equivalent to import in Node JS. Please try the following:

  Object.assign(global, { WebSocket: require('ws') });

from stompjs.

kum-deepak avatar kum-deepak commented on September 24, 2024 1

Leaving this open - so that others can use it as documentation.

from stompjs.

Code2Life avatar Code2Life commented on September 24, 2024

It would be awesome if there is an out of box pure ts/js solution for node.js + TS project, without any preconditions.

from stompjs.

kum-deepak avatar kum-deepak commented on September 24, 2024

I just now checked - if I use Node v11.2.0, I did not need text-encoding, please check if it works for you.

from stompjs.

Code2Life avatar Code2Life commented on September 24, 2024

Thanks a lot ! In my case, the project is supposed to run in node.js env with dynamic js file downloaded, so I use 'ws' instead of 'websocket' to eliminate c++ add on. It works pretty fine.

from stompjs.

kum-deepak avatar kum-deepak commented on September 24, 2024

Thanks, will add this into documentation 😄

from stompjs.

fintecheand0 avatar fintecheand0 commented on September 24, 2024

Good Solution, works in Google firebase

from stompjs.

shakura avatar shakura commented on September 24, 2024

Nice solution, would be good to have it in the documentation for TS+nodejs. There is nothing in docs and it was a great pain to find this page to understand which solution would work for text encoder.

from stompjs.

soulmachine avatar soulmachine commented on September 24, 2024

I added this to the top of my .ts files but it doesn't work:

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

from stompjs.

kum-deepak avatar kum-deepak commented on September 24, 2024

Please enable debug and attach console output if it does not work.

from stompjs.

soulmachine avatar soulmachine commented on September 24, 2024

@kum-deepak Now it works, thanks! My code runs at server side instead of browser.

from stompjs.

UmamaheshMaxwell avatar UmamaheshMaxwell commented on September 24, 2024

#28 (comment) This worked for me in NodeJS, thank you @kum-deepak . below is my code.

const WebSocket = require('ws');
Object.assign(global, { WebSocket: require('ws') });

 new WebSocket.Server({
    port: 8080
})

from stompjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.