Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Guys, I really have trouble creating tests.

    describe('Websocket', function () {

    //load module

    var $websocketBackend, createController;
    beforeEach(angular.mock.module('ngWebSocket', 'ngWebSocketMock'));

    beforeEach(inject(function ($websocketBackend) {
    $websocketBackend = $websocketBackend;
    $websocketBackend.expectSend({data: JSON.stringify({test: true})});


    beforeEach(inject(function ($injector) {
    // The $controller service is used to create instances of controllers
    var $service = $injector.get('$service');
    createController = function () {
    return $service('mzksWebsocket');

    it(’test1', function () {
    var mzksWebsocket = createController();
    //some test

    ->failed to instantiate module ngWebSocketMock due to:
    Error: [$injector:nomod] Module 'ngWebSocketMock' is not available! You either misspelled the module name or forgot to load it. If registering a module ensu
    I fixed it.
    Benoit LeBlanc
    Hi there, Is there a quick way to find out if your socket is connected?
    nevermind, looked in source for readyStates :smile:
    Benoit LeBlanc
    Is this library still bein maintained though?
    Diego Benjamín Aguilar Aguilar
    @beleblanc I guess AngularClass/angular-websocket@88b6e88
    Benoit LeBlanc
    Will there be a new npm package soon with the latest merge as it resolves an issue I was having with webpack
    Hi there, does anybody know about an angular2 version of websocket?
    It should be compatible, shouldn’t it?
    Antonio Troina
    Hi guys, a quick question: I'm missing what the autoApply function should do. After around 60 seconds I see in my console.log this message: "angular.js:26309 Uncaught ReferenceError: autoApply is not defined" and my front-end stops receiving messages from the websocket server... any idea?
    Hey all, I'm looking to bring this module into my project. My project is using requirejs. Anytime I require the module, it tries to require "ws" and fails which fails the whole page. I looked at the src and seems its trying to require in module, exports, angular and ws. Has anyone got around this issue?
    Harish Gadiya
    how we can use angular websocket with typesscript anguarljs2 with unit testing
    Hamed Nourhani
    hi must i use socket.io alongside angular to connect server socket or there is a builltin functionality with ng?
    Pulkit Agarwal
    This message was deleted
    This message was deleted
    Bart Peperkamp
    Hi there, I managed to reconnect the socket session (in case of a server restart/error). The connection is 'open', however, i cannot get messages. Does anybody know what to do?
    Muhammad Aref
    I spent around 4 hours to figure out how to write a unit test, and I couldn't
    This is my service:
        function eventsStream (storage, $websocket) {
            const _collection = [];
            return {
                 * @param  {function} callback
                 * @return {object}
                connect (callback) {
                    // FIXME: we have to redirect to the config state
                    if (storage.get('streamConfig')) {
                        const wsUri = 'ws://localhost:8888/api';
                        const dataStream = $websocket(wsUri);
                        dataStream.onMessage(message => {
                            if (angular.isFunction(callback)) {
                    } else {
                        return 'You have to set the stream configuration.';
                    return {
                        collection: _collection
    The unit test:
        describe('Unit testing eventsStream service', () => {
            let $websocketBackend,
            beforeEach(angular.mock.module('ngWebSocket', 'ngWebSocketMock'));
            beforeEach(inject((_$websocketBackend_, _eventsStream_, _storage_) => {
                $websocketBackend = _$websocketBackend_;
                eventsStream = _eventsStream_;
                storage = _storage_;
                $websocketBackend.expectSend({data: JSON.stringify({test: true})});
            it('Should passes the collection to the connect callback is the configuration exists', () => {
                storage.set('streamConfig', {});
                eventsStream.connect(collection => {
    Muhammad Aref
    any help??
    Muhammad Aref
    I tried to use AMD (requireJS) to load angular-websocket file, but I get an error stating - Uncaught Error: Script error for "ws"
    I checked the source code of angular-websockets.js file, and seems the code tries to require['ws'] module
    I don't see any existence of 'ws' module. Any help would be appreciated here
    i just tried it and i didnt have any problems
    maybe use cdn?
    how can you open a connection with a different url?
    inside the controller
    also having trouble with unit testing with $websocketBackend. I can test the connect successfully, but I want to trigger the onOpen event handler so that I can test that functionality. how can I achieve a mocked successful websocket handshake using the mock library?
    Is Ok?

    Hi all!
    I am trying to make a small webapp, and was wondering what the best practice method was for getting initialization data when the socket makes the first connection? I currently have setup a .factoryto return a collection with a .send method. i,e

    .factory('WebSktData', function ($websocket) {
      <snip snip>
    var methods = {
                    collection: collection,
                     send: function (message) {
    return methods;

    What would be considered the correct way to pass a function to the onOpen and onError from the controller, and not directly in the factory?

    Jeremy Carlsten
    Anyone using this with typescript yet?

    I ask because I'm having issues with getting the typings setup. I've found a typings file for angular-websockets but when I try to compile my ts files I get the following error
    tsconfig.json generated: tsconfig.json

    typings/modules/angular-websocket/index.d.ts(23,22): error TS1110: Type expected.
    typings/modules/angular-websocket/index.d.ts(24,35): error TS1109: Expression expected.
    typings/modules/angular-websocket/index.d.ts(163,1): error TS1128: Declaration or statement expected.

    Hi there
    I'm looking to use angular-websocket but once I've install it and injecting it to my all app my unit test beforeEarch call are not... called, is someone have seen a similar issue?
    my bad, I just forget to add angular-websocket to karma imports
    sorry for the noise :D
    Ask, angular2-websocket support IPv6 access?
    Ask, angular2-websocket support IPv6 access?
    Saurabh Mishra
    Hi, can somebody give me pointers for using websocket with angular 4
    A general websocket question
    Is there any option to send data to client, without any request from client?
    yes use emit
    websockets is about events
    there are 4 events
    or you can use intervals