Skip to content

Commit

Permalink
fix(socketio-client): Throw an error and show a warning if someone tr…
Browse files Browse the repository at this point in the history
…ies to use socket.io-client v3 (#2135)

* fix(socketio-client): Throw an error and show a warning if someone tries to use socket.io-client v3
  • Loading branch information
daffl authored Nov 22, 2020
1 parent d31c26a commit cc3521c
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 112 deletions.
166 changes: 58 additions & 108 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/authentication-client/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class AuthenticationClient {

socket.on(disconnected, () => {
const authPromise = new Promise(resolve =>
socket.once(connected, () => resolve())
socket.once(connected, (data: any) => resolve(data))
)
// Only reconnect when `reAuthenticate()` or `authenticate()`
// has been called explicitly first
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-oauth/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default (options: OauthSetupSettings) => {
...payload
};

await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
if (!req.session.destroy) {
req.session = null;
resolve();
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-oauth/test/express.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('@feathersjs/authentication-oauth/express', () => {
before(async () => {
server = app.listen(9876);

await new Promise(resolve => server.once('listening', () => resolve()));
await new Promise<void>(resolve => server.once('listening', () => resolve()));
});

after(() => server.close());
Expand Down
9 changes: 9 additions & 0 deletions packages/socketio-client/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ function socketioClient (connection, options) {
throw new Error('Socket.io connection needs to be provided');
}

if (connection && connection.io && connection.io.engine &&
connection.io.engine.transport && connection.io.engine.transport.query &&
connection.io.engine.transport.query.EIO > 3
) {
// tslint:disable-next-line
console.error('You are trying to use the Socket.io client version 3 or later with Feathers v4 which only supports Socket.io version 2. Please use socket.io-client version 2 instead.');
throw new Error('socket.io-client must be version 2.x');
}

const defaultService = function (name) {
const events = Object.keys(this.eventMappings || {})
.map(method => this.eventMappings[method]);
Expand Down
2 changes: 1 addition & 1 deletion packages/transport-commons/test/channels/channel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('app.channel', () => {
it('is an EventEmitter', () => {
const channel = app.channel('emitchannel');

return new Promise((resolve) => {
return new Promise<void>((resolve) => {
channel.once('message', data => {
assert.strictEqual(data, 'hello');
resolve();
Expand Down

0 comments on commit cc3521c

Please sign in to comment.