- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当在 Javascript 中使用 stomp.js 和 sockjs 时,我可以与 Spring Boot 后端很好地连接。
当在 Angular5 中使用 stompjs 和 sockjs 时,我不断收到这些错误:
InvalidStateError:连接尚未建立
有解决办法吗?只需添加 sockjs.min.js,as mentioned in this post ,没有帮助。
详细日志为:
Setting up connection/1 main.3388a5e3a20e64e3bdb8.bundle.js:1 Setting up connection/2 main.3388a5e3a20e64e3bdb8.bundle.js:1 Going to subscribe ... main.3388a5e3a20e64e3bdb8.bundle.js:1 Opening Web Socket... main.3388a5e3a20e64e3bdb8.bundle.js:1 >>> SEND destination:/app/chat.addUser content-length:29
{"sender":"me","type":"JOIN"} main.3388a5e3a20e64e3bdb8.bundle.js:1 ERROR Error: Uncaught (in promise): Error: InvalidStateError: The connection has not been established yet Error: InvalidStateError: The connection has not been established yet at r.send (scripts.d6f701ecf84f24372966.bundle.js:1)
我的 Angular 代码(从 Javascript 翻译而来)是:
let ws = new SockJS(this.serverUrl);
this.stompClient = Stomp.over(ws);
let that = this;
console.log('Setting up connection/2');
console.log('Going to subscribe ... ');
this.stompClient.connect({}, function (frame) {
console.log('Going to subscribe ... ');
that.stompClient.subscribe('/topic/public', (payload) => {
console.log('Subscribe: Incoming message: ' + payload.body);
if (payload.body) {
let message = JSON.parse(payload.body);
if (message.sender === 'MyBot') {
this.createAndAddChat('you', message.content);
} else {
this.createAndAddChat('me', message.content);
}
console.log('New message arrived: ' + payload.body);
}
},
error => {
console.log( 'Subscribe: error: ' + error)
},
() => {
console.log( 'Subscribe, On complete')
});
});
this.stompClient.send("/app/chat.addUser", {},
JSON.stringify({sender: 'me', type: 'JOIN'})
)
最佳答案
现在,在启动(!)异步获取连接调用后直接调用发送方法。那是错误的。
有两种解决方案:
关于javascript - Websocket-sockjs-InvalidStateError : The connection has not been established yet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52898952/
我刚开始学习 websockets,我得到了一个奇怪的错误: window.onload = function(){ var service = new WebSocket(
我正在编写一个 JavaScript/HTML5 Windows 8 应用程序。写入 IndexedDB 时偶尔会出现 InvalidStateError。我的功能在下面,它发生在第一行。有没有办法保
我正在建立一个网站,当您将鼠标指针移到视频上时,视频就会开始播放。当用户离开视频区域时,它会暂停并跳回第一帧。这在除 IE 之外的所有浏览器中都能完美运行。当我打开开发控制台时,它会在处理停止功能的代
我正在集成一个使用 IndexedDB 的 javascript 库,但是当 Firefox 处于隐私浏览/窗口模式时它会“粗鲁地”失败。该库返回一个 500 内部错误,同时 Firefox 向控制台
我已经阅读了另一个线程,它并不好:Put data into JSON with Jquery 每当我尝试对对象数组进行 JSON.stringify 时,我都会收到一条错误消息: Uncaught
我已经使用 vue-cli 工具配置了一个简单的 Vue 项目: vue init webpack my-project 现在我想在页面呈现之前通过网络套接字发送一些信息。由于我不想将此逻辑绑定(bi
什么会导致 Promise 在此处被 'InvalidStateError' 拒绝? const SERVICE_WORKER_VERSION = "3.0.0"; // is updated in
当我在 iOS 上调用 Audio.stopAudio() 时,会导致 InvalidStateError。它引用了 Three.js:38399。有人在使用 Three.js/A-Frame 时遇到
使用此处提供的基本示例:https://developer.here.com/javascript-apis/documentation/v3/maps/topics/quick-start.html
我正在为桌面共享编写一个简单的 WebRTC Google Chrome 扩展程序。我尝试使用 getusermedia,但每次调用错误回调函数时返回的错误是: NavigatorUserMediaE
我无法将 Angular2 前端与 Spring 的 websocket 后端连接起来。 Spring配置xml文件:
我收到此错误消息: Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInp
情况 我有一个类似网格的无序列表,其中包含 144 (90px x 90px) 个图像 (12x12),可以旋转。我的最终目标是获取 144 个图像网格并将其保存为 1 个图像。 当前解决方案 我当前
当在 Javascript 中使用 stomp.js 和 sockjs 时,我可以与 Spring Boot 后端很好地连接。 当在 Angular5 中使用 stompjs 和 sockjs 时,我
以下适用于 Chrome 但不适用于 Firefox: var myVideo = document.getElementById('myVideo') myVideo.currentTime = 5
我正在编写一个 Web 应用程序,我想在其中使用 SSL 通过 Tornado WebSockets 从客户端向服务器端发送 JSON 代码。当我想建立连接时,谷歌浏览器在控制台日志中显示错误: Un
我在 IE11 中遇到这个错误,我临时更改了一个数字上的所有变量,但我无法摆脱这个错误。 audio.currentTime = 10; 错误看起来像: SCRIPT5022: InvalidStat
在 Firefox 17.0.1 中,当我尝试打开 IndexedDB 数据库时,Firebug 控制台向我显示了一个InvalidStateError 异常。还引发了 request.onerror
我正在创建一个 webRTC 视频聊天,当从 firefox 发起调用并且接收者正在使用 chrome 时,它会向调用者显示所有事件成员,此错误显示为“未捕获( promise 中)DOMExce
我在实现绕过 Internet Explorer 中“下载”属性缺失行为的解决方案时遇到了一些问题。 用户可以下载三种类型的文件: CSV geoJSON 知识分子语言 所以在 Chrome 和 FF
我是一名优秀的程序员,十分优秀!