Skip to content

Fix Socket.io outdated private chat example for Vue #4699

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

Closed
wants to merge 36 commits into from

Conversation

haneenmahd
Copy link

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

The current private chat example for vue does have two problems, it's outdated and uses legacy ssl provider. This means it can't run on Node version above 16. Other issues are with installing dependencies and people getting confused of why a redis connection error has occured.

New behavior

I have fixed the issue by adding NODE_OPTIONS=--openssl-legacy-provider while serving the website and also adding documentation that improves the understanding of getting started with the example.

Other information (e.g. related issues)

#4681

haneenmahd and others added 30 commits January 18, 2023 08:25
I have implemented the server for private messaging example in react.
The frontend of this example is still unimplemented.
Adds improved styling for the forms and the home page
Implements feature to switch between users and also implement the message box
This commit adds a new option, "cleanupEmptyChildNamespaces". With this
option enabled (disabled by default), when a socket disconnects from a
dynamic namespace and if there are no other sockets connected to it
then the namespace will be cleaned up and its adapter will be closed.

Note: the namespace can be connected to later (it will be recreated)

Related: socketio/socket.io-redis-adapter#480
This commit adds some syntactic sugar around acknowledgements:

- `emitWithAck()`

```js
try {
  const responses = await io.timeout(1000).emitWithAck("some-event");
  console.log(responses); // one response per client
} catch (e) {
  // some clients did not acknowledge the event in the given delay
}

io.on("connection", async (socket) => {
    // without timeout
  const response = await socket.emitWithAck("hello", "world");

  // with a specific timeout
  try {
    const response = await socket.timeout(1000).emitWithAck("hello", "world");
  } catch (err) {
    // the client did not acknowledge the event in the given delay
  }
});
```

- `serverSideEmitWithAck()`

```js
try {
  const responses = await io.timeout(1000).serverSideEmitWithAck("some-event");
  console.log(responses); // one response per server (except itself)
} catch (e) {
  // some servers did not acknowledge the event in the given delay
}
```

Related:

- socketio#4175
- socketio#4577
- socketio#4583
The RemoteSocket interface, which is returned when the client is
connected on another Socket.IO server of the cluster, was lacking the
`timeout()` method.

Syntax:

```js
const sockets = await io.fetchSockets();

for (const socket of sockets) {
  if (someCondition) {
    socket.timeout(1000).emit("some-event", (err) => {
      if (err) {
        // the client did not acknowledge the event in the given delay
      }
    });
  }
}
```

Related: socketio#4595
So that the client knows whether the connection state recovery feature
is enabled.

See also: socketio@54d5ee0
This reverts commit 4e64123.

Using the id of the socket is not possible, since it is lost upon
reconnection (unless connection recovery is successful), so we revert
the previous change.
…bled

This is a follow-up commit of [1]. Without it, adapter.persistSession()
would be called even if the connection state recovery feature was
disabled.

[1]: socketio@54d5ee0
The import added in [1] was invalid, because it used an non-exported
class.

Related: socketio#4621

[1]: socketio@d4a9b2c
Namespaces that match the regex of a parent namespace will now be added
as a child of this namespace:

```js
const parentNamespace = io.of(/^\/dynamic-\d+$/);
const childNamespace = io.of("/dynamic-101");
```

Related:

- socketio#4615
- socketio#4164
- socketio#4015
- socketio#3960
@darrachequesne
Copy link
Member

@haneenmahd it seems there is a problem with the PR, there are a lot of unrelated changes. Did you rebase against the main branch?

@haneenmahd
Copy link
Author

Sorry, It is rebased from the main branch. I will fix that and open a new PR.

@darrachequesne
Copy link
Member

Superseded by cbf0362. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants