socket.io-client: Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?
You want to:
- report a bug
- request a feature
Current behaviour
When I install socket.io-client on a blank React Native Expo project I have a yellow message with:
Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?
Steps to reproduce (if the current behaviour is a bug)
yarn add socket.io-client
In App.js in the React Native project:
import React from 'react';
import { YellowBox } from 'react-native';
import io from 'socket.io-client';
YellowBox.ignoreWarnings(['Remote debugger']);
import AppContainer from './config/routing';
export default class App extends React.Component {
constructor(props) {
super(props);
}
componentWillMount() {
const socket = io('http://10.0.60.26:3000', {
forceNew: true
});
socket.on('connect', () => console.log('Connection'));
}
render() {
return <AppContainer />;
}
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 53
- Comments: 50 (1 by maintainers)
Commits related to this issue
- Issue: https://github.com/socketio/socket.io-client/issues/1290 — committed to SoSa-Community/app-oldnew by JamesMahy 4 years ago
For me it worked when I downgraded to 2.1.1 I did:
yarn add socket.io-client@2.1.1At first it didn’t work because I was adding the
^symbol before the versionsocket.io-client@^2.1.1which I believe accepts other minor versions of the package.const _io = ioClient.connect(socketurl, { forceNode: true });It’s workI am still getting this warning when using socket.io (2.2.0) on React-Native. I can silence the yellow box on the device screen with:
but I still get this annoying warning on the console…
Still an issue @^2.3.0
Hey guys! We have fixed this issue by downgrading to v2.1.1
Make sure you completely remove the older version and clear the cache.
Done! This should work with react-native & react-native-web!
This warning is raised here by
ReactNative/WebSocket.js:117because EngineIO (used by SocketIO under the hood) will reference the exposed ReactNative WebSocket implementation viaEngineIO/websocket.js:121which is passedoptswhich contains the properties that the warning message mentions. Curiously enough, these added properties described by the EngineIO maintainers via comment are “SSL options for Node.js client”.By inserting something like the code below at
EngineIO/websocket.js:114to manipulate theoptsgiven to the WebSocket constructor we remove all the extraneous keys inoptsto successfully stop the warning from appearing in the first place (omitis imported from Lodash, can be reworked out).If you’re looking for a solution that doesn’t involve simply muting the warning via
YellowBox.ignoreWarningsthen you could completely override thedoOpenas definedEngineIO/websocket.js:87by adding something like this below, to the entry point of your ReactNative project, typicallyindex.js.Overall, if we create a pull request for EngineIO to exclude these extra
optsthat aren’t needed when used in ReactNative viathis.isReactNativethen we could suppress this warning for all using the SocketIO Client in their ReactNative projects.Still an issue @2.2.0
It works with me, Thanks!
"socket.io-client": "^2.3.0"I am very worried about if the socket.io library is still maintained or not because of no official reply about a fix or an upcoming update.
Your code wouldn’t allow me to connect to the server and changed the intended behaviour of EngineIO so I’ve just wrapped those options in an if statement but used the same patch mechanism you suggested
You can simply add some headers and it works!
socket = io.connect('SOCKET_URL_HERE', { jsonp: false, agent: '-', pfx: '-', cert: '-', ca: '-', ciphers: '-', rejectUnauthorized: '-', perMessageDeflate: '-' });It worked for me too! Big thanks
Proxying WebSockets is working for me. I am using node HTTP-proxy to allow ‘ws’ on the local machine, on a remote server configured Nginx proxy.
Server Side: const io = require(“socket.io”)(server.listener, { log: true, pingInterval: 60000, pingTimeout: 600000, cors: { origin: “http://localhost:3000”, methods: [“GET”, “POST”] } }); const proxy = HttpProxy.createProxyServer({ ws: true }); io.on(“upgrade”, function(req, socket, head) { proxy.ws(req, socket, head); });
Front Side: import {Manager} from “socket.io-client”; socketInstance = new Manager(‘ws://localhost:1342/’, { transports: [“websocket”] , protocols:[“http”], port:1342, auth:{ token: xxxxxx} });
This issue should be fixed on
engine.io-clientv3.4.3 so all you need to do is to delete theyarn.lockfile and thenode_modulesdirectory then runyarn installref https://github.com/socketio/engine.io-client/commit/2f5c948abe8fd1c0fdb010e88f96bd933a3792ea
This resolves the warning but makes my socket connection really really slow(timeout actually), so its unusable for me.
Thank you. this work for me.
@isthaison It doesn’t work for me
downgrade to “socket.io-client”: “2.1.0” and all OK