注意:对于支持问题,请使用以下渠道之一: stackoverflow或slack
对于Swift 客户端的错误报告和功能请求,请在那里打开一个问题。
对于Java 客户端的错误报告和功能请求,请在那里打开一个问题。
实际发生了什么?
从 2.3.0 升级到 3.0.1 后在 react-native 中出错
- 创建新的 react-native 项目。
-安装socket.io-client。
- 在您的代码中使用它。
注意:获得快速答案的最好方法(我们的意思是唯一方法)是通过 fork 下面的fiddle来提供一个失败的测试用例。
什么是预期?
要正常工作。
操作系统:安卓
浏览器:
我的 react native 项目也有同样的问题,它在 iOS 上运行良好,但我在 android 上遇到了这个错误。
版本:
“反应原生”:“0.63.3”,
"socket.io-client": "^3.0.1",
连接过程中出现错误:
io.connect('http://192.168.1.81:3750');
还在努力去了解。
升级我的库后,我也面临同样的问题,所有应用程序都运行良好,但套接字抛出了同样的错误:
版本:
“反应原生”:“0.63.3”,
"socket.io-client": "^3.0.1",
我是 react-native 的新手,我也遇到了这个问题,是否有已知的解决方法?
我降级到 2.3.1 版,解决了这个问题。
纱线添加插座。 [email protected]
大家好。 我确实可以重现。
有没有办法找到触发此错误的行?
@darrachequesne我阅读了您的提交并添加了{withCredentials: false}
在套接字配置中,它可以工作,所以代码是这样的:
io(SOCKET_URL, {
withCredentials: false,
})
@Mohamed-Rajab-2112 你是对的,明确设置withCredentials
应该有效:+1:
它应该由[email protected]
(包含在[email protected]
)修复。 你能确认一下吗?
我在这里用 Socket.IO v3 更新了 React Native 示例: https :
我遇到了同样的问题,但仅适用于我在 Typescript 中的 RN 项目。 我的另一个用 JS 编写的 RN 项目没有这个问题。 而{ withCredentials: false }
不是SocketClient.Socket
一个选项。
@Rc85
我遇到了同样的问题,但仅适用于我在 Typescript 中的 RN 项目。 我的另一个用 JS 编写的 RN 项目没有这个问题。 而
{ withCredentials: false }
不是SocketClient.Socket
一个选项。
是的,您是对的, withCredentials
不是配置界面的一部分,但是,我认为您应该将此作为打字稿问题来解决,但是为了测试起见,如果此解决方案是否适用于您,请尝试忽略 ts 错误。
对于打字稿,您可以尝试扩展套接字配置并将withCredentials
到它,只是为了让打字稿不抱怨。
添加withCredentials
停止了错误,但我无法连接到我的服务器。 在我的服务器上,它显示连接进入并且控制台日志因重新连接而被垃圾邮件
io.on('connection', (socket) => {
console.log('Connecting');
}
但在客户端,connected 是假的。
{"_callbacks": {"$connecting": [[Function onConnecting]]}, "acks": {}, "connected": false, "disconnected": true, "flags": {}, "ids": 0, "io": {"_autoConnect": true, "_callbacks": {"$close": [Array], "$open": [Array], "$packet": [Array]}, "_randomizationFactor": 0.5, "_readyState": "opening", "_reconnection": true, "_reconnectionAttempts": Infinity, "_reconnectionDelay": 1000, "_reconnectionDelayMax": 5000, "_timeout": 20000, "backoff": {"attempts": 0, "factor": 2, "jitter": 0.5, "max": 5000, "ms": 1000}, "connecting": [[Circular]], "decoder": {}, "encoder": {}, "engine": {"_callbacks": [Object], "hostname": "10.0.0.100", "id": null, "opts": [Object], "pingInterval": null, "pingTimeout": null, "pingTimeoutTimer": null, "port": "80", "prevBufferLen": 0, "readyState": "opening", "secure": false, "transport": [XHR], "transports": [Array], "upgrades": null, "writeBuffer": [Array]}, "nsps": {"/": [Circular]}, "opts": {"hostname": "10.0.0.100", "path": "/socket.io", "port": "80", "secure": false, "withCredentials": false}, "skipReconnect": false, "subs": [[Object], [Object], [Object]], "uri": "http://10.0.0.100"}, "nsp": "/", "receiveBuffer": [], "sendBuffer": [], "subs": [{"destroy": [Function destroy]}, {"destroy": [Function destroy]}, {"destroy": [Function destroy]}]}
我想降级到2.3.1,但无法启动我的RN项目的地铁服务器,因为模块的../util
的node_modules\engine.io-client\lib\transports\polling-xhr.js
不能得到解决。 如果这很重要的话,我用 JS 编写的 RN 项目没有这个问题。
我在 engine.io-client 的 repo 中打开了一个问题。
@darrachequesne所以要测试它,我应该npm uninstall socket.io-client
并运行npm install socket.io-client
以获取最新更新吗?
添加
withCredentials
停止了错误,但我无法连接到我的服务器。 在我的服务器上,它显示连接进入并且控制台日志因重新连接而被垃圾邮件io.on('connection', (socket) => { console.log('Connecting'); }
但在客户端,connected 是假的。
{"_callbacks": {"$connecting": [[Function onConnecting]]}, "acks": {}, "connected": false, "disconnected": true, "flags": {}, "ids": 0, "io": {"_autoConnect": true, "_callbacks": {"$close": [Array], "$open": [Array], "$packet": [Array]}, "_randomizationFactor": 0.5, "_readyState": "opening", "_reconnection": true, "_reconnectionAttempts": Infinity, "_reconnectionDelay": 1000, "_reconnectionDelayMax": 5000, "_timeout": 20000, "backoff": {"attempts": 0, "factor": 2, "jitter": 0.5, "max": 5000, "ms": 1000}, "connecting": [[Circular]], "decoder": {}, "encoder": {}, "engine": {"_callbacks": [Object], "hostname": "10.0.0.100", "id": null, "opts": [Object], "pingInterval": null, "pingTimeout": null, "pingTimeoutTimer": null, "port": "80", "prevBufferLen": 0, "readyState": "opening", "secure": false, "transport": [XHR], "transports": [Array], "upgrades": null, "writeBuffer": [Array]}, "nsps": {"/": [Circular]}, "opts": {"hostname": "10.0.0.100", "path": "/socket.io", "port": "80", "secure": false, "withCredentials": false}, "skipReconnect": false, "subs": [[Object], [Object], [Object]], "uri": "http://10.0.0.100"}, "nsp": "/", "receiveBuffer": [], "sendBuffer": [], "subs": [{"destroy": [Function destroy]}, {"destroy": [Function destroy]}, {"destroy": [Function destroy]}]}
我想降级到2.3.1,但无法启动我的RN项目的地铁服务器,因为模块的
../util
的node_modules\engine.io-client\lib\transports\polling-xhr.js
不能得到解决。 如果这很重要的话,我用 JS 编写的 RN 项目没有这个问题。我在 engine.io-client 的 repo 中打开了一个问题。
好的,我今晚晚些时候会给它一个检查:)
目前的临时修复,至少对我来说是将 socket.io-client 降级到 2.3.1。 但是,engine.io-client 引发了上述错误,因为它在某处寻找../util
模块,而该模块在 engine.io-client 版本 3.4.4 中不存在。 我不得不执行npm install engine.io-client@latest
来解决错误。
现在我可以连接到我的服务器。 现在要坚持使用 2.3.1。
@Rc85几个小时前刚刚更新了软件包,尝试新版本我认为它解决了问题,祝你好运!
这应该由https://github.com/socketio/engine.io-client/commit/ccb99e3718e8ee2c50960430d2bd6c12a3dcb0dc修复
请运行npm install socket.io-client@3
以强制更新依赖项(或npm update --depth 9999 engine.io-client
)。
如果你使用 Expo,你可能需要用expo start --clear
清除它的缓存