Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Event handler of 'offline' event must be added on the initial evaluation of worker script on Service Worker #5125

Closed
wanfahmi11 opened this issue Feb 8, 2024 · 5 comments
Labels
needs investigation package:engine.io-client This concerns the "engine.io-client" package

Comments

@wanfahmi11
Copy link

Describe the bug
Getting a warning when including socket.io client to service worker:

image

Event handler of 'offline' event must be added on the initial evaluation of worker script on Service Worker

To Reproduce

Socket.IO server version: 4.7.4

Server

import { Server } from "socket.io";

const io = new Server(3000, {});

io.on("connection", (socket) => {
  console.log(`connect ${socket.id}`);

  socket.on("disconnect", () => {
    console.log(`disconnect ${socket.id}`);
  });
});

Socket.IO client version: 4.7.4

Client

import { io } from "socket.io-client";

const socket = io("ws://localhost:3000/", {});

socket.on("connect", () => {
  console.log(`connect ${socket.id}`);
});

socket.on("disconnect", () => {
  console.log("disconnect");
});

Expected behavior
Probably can skip adding "offline" event listener for service worker, since it's already skipped it for offline, I don't see any harm skipping it for service worker.

Platform:

  • Device: [e.g. Samsung S8]
  • OS: [e.g. Android 9.2]

Additional context
I would like to contribute myself but I can't find the exact line to modify. I can find the codes in dist/socket.io.js but I'm not sure if that's the right file.

@wanfahmi11 wanfahmi11 added the to triage Waiting to be triaged by a member of the team label Feb 8, 2024
@darrachequesne
Copy link
Member

@darrachequesne darrachequesne transferred this issue from socketio/socket.io-client Jul 9, 2024
@darrachequesne darrachequesne added the package:socket.io-client This concerns the "socket.io-client" package label Jul 9, 2024
@FMaz008
Copy link

FMaz008 commented Sep 14, 2024

Is there a milestone for this fix? I just installed socket.io (current version being 4.7.5) and I'm encountering this very same warning.

@darrachequesne darrachequesne added bug Something isn't working package:engine.io-client This concerns the "engine.io-client" package and removed to triage Waiting to be triaged by a member of the team package:socket.io-client This concerns the "socket.io-client" package labels Sep 17, 2024
@darrachequesne
Copy link
Member

@FMaz008 out of curiosity, could you please explain your use case? Why use a ServiceWorker and not a SharedWorker?

@darrachequesne darrachequesne added needs investigation and removed bug Something isn't working labels Sep 19, 2024
@FMaz008
Copy link

FMaz008 commented Sep 19, 2024

@FMaz008 out of curiosity, could you please explain your use case? Why use a ServiceWorker and not a SharedWorker?

Honestly everything works fine with the Service Worker coupled with an Alarm. That and I had never heard of a Shared Worker before today. So it seems I'm just outdated a bit on my knowledge here.

(Not to side track the conversation, but I tried implementing a SharedWorker, but I keep getting a security error. But even assuming I could sort out this problem, it would be a major refactor of the existing code if it worked.)

@darrachequesne
Copy link
Member

For future readers:

This should be fixed by 8a2f5a3, included in engine.io-client@6.6.1 and socket.io-client@4.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation package:engine.io-client This concerns the "engine.io-client" package
Projects
None yet
Development

No branches or pull requests

3 participants