我正在实现socketjs.然而,我遇到了下面的错误.
x1c 0d1x下面是我正在使用的socket和stomp包。
import * as SockJS from 'sockjs-client';
import * as Stomp from 'stompjs/lib/stomp.js';
字符串
提前致谢。
下面是我的Angular代码-
import * as Socket from 'socket.io-client';
import * as Stomp from 'stompjs/lib/stomp.js';
initializeWebSocketConnection2(){
let ws = new Socket(this.serverUrl);
this.stompClient = Stomp.over(ws);
let that = this;
this.stompClient.connect({}, function(frame) {
that.stompClient.subscribe("/test", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();
}
});
that.stompClient.subscribe("/operation", function(message){
if(message.body) {
console.log(message.body);
window.location.reload();
}
});
型
});
}
4条答案
按热度按时间avwztpqn1#
将此添加到polyfills.ts中
字符串
首先,你需要安装socket-client,
型
然后,您可以像这样在组件或服务中导入socket.io-client
型
像这样更改代码
型
ujv3wf0j2#
在index.html的 head 中添加以下片段解决了我的问题-
字符串
参考https://github.com/stomp-js/ng2-stompjs/issues/70
v7pvogib3#
添加以下代码对我来说很有用
字符串
i1icjdpr4#
我解决这个问题使用内置版本
字符串