The missing AngularJS 1.x WebSocket module for connecting client applications to servers.
describe('Unit testing eventsStream service', () => {
let $websocketBackend,
eventsStream,
storage;
beforeEach(module('mcp.gogo.services'));
beforeEach(angular.mock.module('ngWebSocket', 'ngWebSocketMock'));
beforeEach(inject((_$websocketBackend_, _eventsStream_, _storage_) => {
$websocketBackend = _$websocketBackend_;
eventsStream = _eventsStream_;
storage = _storage_;
$websocketBackend.mock();
$websocketBackend.expectConnect('ws://localhost:8888/api');
$websocketBackend.expectSend({data: JSON.stringify({test: true})});
$websocketBackend.mockSend();
}));
it('Should passes the collection to the connect callback is the configuration exists', () => {
storage.set('streamConfig', {});
eventsStream.connect(collection => {
console.log(collection);
});
$websocketBackend.flush();
});
});
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 .factory
to return a collection with a .send
method. i,e
.factory('WebSktData', function ($websocket) {
<snip snip>
var methods = {
collection: collection,
send: function (message) {
dataStream.send(JSON.stringify(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?
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.
var wsTransactions = $websocket('wss://frontend.smartloxs.io:8090/access/transactions', {
reconnectIfNotNormalClose: false
});