gpt4 book ai didi

ios - 获取错误代码 : 1006 when running nativescript-actioncable with ios

转载 作者:行者123 更新时间:2023-11-29 11:46:52 27 4
gpt4 key购买 nike

我正在测试 actioncable 和 nativescript 并收到上述错误。我已经在我的 github 上设置了测试应用程序。

一个代表 ActionCableNativescript

nativescript 应用来自 nativescript-actioncable包裹。这只发生在 iOS 上,Android 连接正常。

我找不到关于这个问题的任何信息,这让我抓狂。任何帮助都会很棒。

控制台输出如下:

Rails 控制台:

Started GET "/cable" for 127.0.0.1 at 2017-04-06 16:24:50 -0700
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2017-04-06 16:24:50 -0700
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for 127.0.0.1 at 2017-04-06 16:24:50 -0700

Nativescript 控制台:

CONSOLE LOG file:///app/tns_modules/nativescript-actioncable/lib/action_cable.js:46:33: [ActionCable] ConnectionMonitor reopening 1491521019978
CONSOLE LOG file:///app/tns_modules/nativescript-actioncable/lib/action_cable.js:46:33: [ActionCable] Reopening WebSocket, current state is closed 1491521019978
CONSOLE LOG file:///app/tns_modules/nativescript-actioncable/lib/action_cable.js:46:33: [ActionCable] Opening WebSocket, current state is closed, subprotocols: actioncable-v1-json,actioncable-unsupported 1491521019978

最佳答案

我有同样的错误并通过替换 actioncable 修复了插件 nativescript-websockets并自己编写与 actioncable 服务器通信的代码。

这是我用过的示例代码

this.socket = new WebSocket('ws://192.168.8.104:3000/cable', []);
this.socket.on('open', function(evt) {
console.log("Hey I'm open");
var identifier = JSON.stringify({"channel": "ConversationsChannel"});
var data = {"command": "subscribe", "identifier": identifier};
var payload = JSON.stringify(data);
evt.target.send(payload);
});
this.socket.on('message', function(socket, message) {console.log("Got a message", message);});
this.socket.on('close', function(socket, code, reason) { console.log("Socket was closed because: ", reason, " code: ", code); });
this.socket.on('error', function(socket, error) { console.log("Socket had an error", error);});

发送消息

public sendMessage() {
// "{"command":"message","identifier":"{\"channel\":\"ConversationsChannel\",\"conversation_id\":\"12\"}","data":"{\"message\":\"ssss\",\"conversation_id\":\"12\",\"user_id\":39,\"action\":\"send_message\"}"}"
var data = JSON.stringify({"message": "ssss","conversation_id":"12","user_id":39,"action":"send_message"});
var identifier = JSON.stringify({"channel": "ConversationsChannel"});
var payload = JSON.stringify({"command": "message", "identifier": identifier, "data": data});
this.socket.send(payload);
}

同样你可以写退订发送payload

"{"command":"unsubscribe","identifier":"{\"channel\":\"ConversationsChannel\",\"conversation_id\":\"12\"}"}"

或者您可以转到 node_modules/nativescript-actioncable/lib/action_cable.js 并从此更改第 240 行

this.webSocket = new WS(this.consumer.url, {protocols: protocols, headers: headers});

对此

this.webSocket = new WS(this.consumer.url, {protocols: ["actioncable-v1-json"], headers: headers});

我希望这能给你一个想法,如果你需要更多帮助,请告诉我。

关于ios - 获取错误代码 : 1006 when running nativescript-actioncable with ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43267381/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com