angular stomp Sock.js
import { Injectable } from '@angular/core';
import * as Stomp from 'stompjs/lib/stomp.js';
import * as SockJS from 'sockjs-client';
import {GLOBAL_URL} from '../../shared/constant/url.constant';
import {StartRefresh} from '../../shared/models/start-refresh.model';
import {Subject} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class WebSocketAPI {
webSocketEndPoint: string = GLOBAL_URL + '/socket';
topic: string = "/message";
stompClient: any;
private map = new Subject<StartRefresh>();
map$ = this.map.asObservable();
_connect() {
console.log("Initialize WebSocket Connection");
let ws = new SockJS(this.webSocketEndPoint);
this.stompClient = Stomp.over(ws);
const _this = this;
_this.stompClient.connect({}, function (frame) {
_this.stompClient.subscribe(_this.topic, message => {
_this.onMessageReceived(message.body);
});
//_this.stompClient.reconnect_delay = 2000;
}, this.errorCallBack);
};
_disconnect() {
if (this.stompClient !== null) {
this.stompClient.disconnect();
}
console.log("Disconnected");
}
// on error, schedule a reconnection attempt
errorCallBack(error) {
console.log("errorCallBack -> " + error)
setTimeout(() => {
this._connect();
}, 5000);
}
/**
* Send message to sever via web socket
* @param {*} message
*/
_send(message) {
console.log("calling logout api via web socket");
this.stompClient.send("/app/hello", {}, JSON.stringify(message));
}
onMessageReceived(startRefresh: StartRefresh) {
console.log("Message Recieved from Server :: " + startRefresh);
this.map.next(startRefresh);
}
}
в консоле браузера пишет это:
[WDS] Warnings while compiling.
warnings @ client:126
client:135 /home/lis/IdeaProjects/application_template/application_template_frontend/src/app/core/websocket/web-socket-api.service.ts depends on 'sockjs-client'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
depends on 'sockjs-client'. CommonJS or AMD dependencies can cause optimization bailouts.
и с бека соответствено сообщения не приходят