I'm using Angular2 webapp project for FRONT-END and Vertex3 for BACK-END.
Using Sockjs-client i'm creating websocket (at client side) to create a communication channel between Frontend and Backend.
I have installed sockjs-client using npm :
npm install sockjs-client
When I import sockjs-client in LoginService.ts file :
import * as SockJS from 'sockjs-client';
export class LoginService { URL: string = 'http://localhost:8082/eventbus'; sock: SockJS; handlers = {}; private _opened: boolean = false; public open(): void { if (!this._opened) { this.sock = new SockJS(this.URL); this.sock.onopen = (e) => { this.callHandlers('open', e); } this.sock.onmessage = (e) => { this.messageReceived(e); } this.sock.onclose = (e) => { this.callHandlers('close', e); } this._opened = true; } public isOpen(): boolean { return this._opened; } public close(): void { if (this._opened) { this.sock.close(); delete this.sock; this._opened = false; } } private messageReceived (e) { var msg = JSON.parse(e.data); this.callHandlers('message', msg.type, msg.originator, msg.data); } private callHandlers (type: string, ...params: any[]) { if (this.handlers[type]) { this.handlers[type].forEach(function(cb) { cb.apply(cb, params); }); } } public send (type: string, data: any) { if (this._opened) { var msg = JSON.stringify({ type: type, data: data }); this.sock.send(msg); } } }
no errors while running angular2 webapp project using
npm run server
But no websocket connection is created at client side. As I have already created server using vertex vertex.createHttpServer
( which is hosted on : http://localhost:8082).
So I have two issues :
1.Unable to import sockjs-client in angular2 webapp , so can't create websocket connection.
2.Error while building an angular2 webapp project as 'sockjs-client' is not found in node_modules (weird is that its present in node_modules )
Is there anything I'm missing ?
Thanks in Advance !!!