您是否曾经使用WebSocket(来自'socket.io-client'的SocketIOClient)在React Native应用程序中遇到此消息?...
Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?
答案 0 :(得分:21)
是的,这是在Socket.io中的WebSocket类构造函数中发生的。我认为在构造函数中将传输层指定为“ websocket”时会发生这种情况(这对于使用React Native socket io是必需的)。它没有做任何坏事,但是很烦人。
您可以使用本机YellowBox.ignoreWarnings
摆脱它:
启动应用程序时:
console.ignoredYellowBox = ['Remote debugger'];
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings([
'Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?'
]);
答案 1 :(得分:1)
消除错误的一种方法:
let socket = io.connect(SOCKET_URL, {
timeout: 10000,
jsonp: false,
transports: [‘websocket’],
autoConnect: false,
agent: ‘-’,
path: ‘/’, // Whatever your path is
pfx: ‘-’,
key: token, // Using token-based auth.
passphrase: cookie, // Using cookie auth.
cert: ‘-’,
ca: ‘-’,
ciphers: ‘-’,
rejectUnauthorized: ‘-’,
perMessageDeflate: ‘-’
});