question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Looking to capture all messages

See original GitHub issue

Situation I’d like to hook into all websocket data events to develop middleware using your Centrifuge::_transport private websocket object. This would open the door for redux and other integrations.

Background In prior versions, I was doing something like below. The problem is that socket._transport is overwritten, removing my onmessage hook when the socket has a network issue. To overcome this, I’ve been reloading the page to re-apply my hook.

if (!socket._transportIsSet) {
  socket._transportIsSet = true
  const onCentrifugeMsg = socket._transport.onmessage
  socket._transport.onmessage = function (msg) {
    onCentrifugeMsg(msg)
    try {
      const data = JSON.parse(msg.data)

      // Action responder:
      const isAction = data.result?.data?.data
      if (isAction) {
        store.dispatch(isAction[1])
      }
    } catch (e) {
      return
    }
  }
}

Assessment Without a way to hook into data streams reliably, there isn’t a good way to handle global side effects from the servers. For example, sending all channels of a specific “type” a popup message.

Ex: I want to send the data: [‘action’, { type: ‘ALERT’, ‘Free donuts in the lunch room!’ }] to all rooms starting with “staff:”.

This would require specific middleware that the library shouldn’t be concerned with.

Recommendation Expose a function in the library to allow a custom callback to be run during socket onmessage hook.

🤞

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
FZambiacommented, Dec 3, 2020

If you already have channels then having an event type inside payload should be enough I suppose. You can always put your middleware logic on top of available API anyway - since you have message handlers and can do whatever you want with incoming messages.

0reactions
shycecommented, Dec 3, 2020

If I’m in the following rooms; “lobby” “session:302894” “location:support” “bin:385”

and I want to respond with the same API to “session:”, “location:”, and “bin:” but not “lobby” : you are saying that I have to create 7 rooms now and use: “lobby” “session:302894” “session-events:302894” “location:support” “location-events:support” “bin:385” “bin-events:385”

Even though my users and spin up and leave rooms instantly and dynamically? This will lead to a very complex class needed to maintain, hook, watch, close, and clean them up as they are opening and closing bin rooms. One bin room might have an error that only that bin should see; now I have to hope they are in the “bin-events” channel fast enough as the error came from “bin” events.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I capture all application/window messages from start ...
I am trying to figure out exactly how I can capture all window messages of a process/window, from the time it was launched...
Read more >
Capturing all messages in a log - Logstash - Elastic Discuss
I'm trying to capture all the messages in a log. For example, we get this log that contains 6 messages. "message":["18.59.43 STC47873 ...
Read more >
Documenting Text Messages for Trial or Legal Matters
Need to save or print text messages for court? ... to export text messages for evidence with divorce, custody cases, or any other...
Read more >
How to capture the system messages ? | SAP Community
Hi ! Can any body help me to capture the system messages , The requirement is that here i need to map those...
Read more >
Finding Text Strings in Wireshark Captures - YouTube
Scroll for details. New! Watch ads now so you can enjoy fewer interruptions. Got it. Packet Capture and Analysis ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found