Listen to Multiple Events on a Pusher Channel - pusher

I'm trying to listen on a single channel to multiple events using Pusher.js.
I thought you had to separate the event names by a space, but that doesn't seem to be working. I've tried comma limited and also passing an array of strings.
channel.bind(
"open_auction close_auction"
"open_auction, close_auction"
"['open_auction', 'close_auction']"

You can only bind to a single event so you'd either need to manually define each listener or store an array of events and loop through them (creating a new listener each time). Check out the answer here for more information: Pusher: How to bind to 100s of events?

This is probably outdated, but pusher has a channel.bind_global that would allow you to listen to all events sent to that channel. Docs: https://pusher.com/docs/channels/using_channels/events/#example-3

Related

Where can I see a list of reserved events in Socket.io

For example, in socket.io there is a reserved event 'disconnect'. Where can I find a list of full events?
You can find the full list in the source code.
https://github.com/socketio/socket.io/blob/master/lib/socket.ts#L46

Threaded messaging on pubnub

We want to create threads for messages within a chat channel on Pubnub. For example, someone could respond to a specific message in a channel by 'creating a thread' and starting to chat. Is there a prescribed way to model this behavior? If so, can you please reference documentation?
This is the behavior you see in slack, for reference.
There's no ready-made solution documented for threaded messaging. However, building a hierarchical relationship between messages could be achieved by tagging them with metadata (using PN Objects and/or MessageActions) and then some coding on your end to maintain and handle their relationship.
You could use the time token of the thread's first message as the key, group messages based on it, and use the messages' own time tokens to generate the order for the UI.
https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe#methods
Here's the high-level design for doing this:
A message is published to a channel with the name chat_11223344 (channel name uses chat_ as a prefix for all chat channels and a generated id - keeping it short here but you can use a uuid generator for this). That publish returns a publish timetoken, something like this: 16183330926487763.
Using PN Objects, your display name for the channel can be set along with a description.
In your chat UI, you allow a person to create a thread on that message. The message gets published to a channel named chat_11223344.16183330926487763 , using the publish timetoken of the top-level message as the "sub-channel" name.
So that you can easily identify top-level messages that are threaded, you would add a MessageAction to that message when the first "threaded" message is published. You may also want to add custom Channel Metadata (PN Objects, again) to add a "isThreaded":true key/value.
So with PubNub you can append meta data to either the message itself or PubNub has a section called meta (https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe#methods).
An example payload could be:
{
"type":"message",
"payload":"What do people want for lunch? Pizza?",
"sender":"me",
"sent":1618336638,
"messageActive":true,
"channel":"main",
"messageID":"main.abc123"
}
where abc123 is a uuid that references that message.
When someone wants to thread a message you can append "threaded":true variable to the object.
{
...
"messageID":"main.abc123",
"threaded":true,
...
}
Now your UI knows that there is a breakout thread, using main.abc123.thread as the channelID for that specific thread.
Your app then subscribes to the new channel main.abc123.thread and you can use fetchMessages(); to get history messages as well as new real time messages.

Can't get voiceStateUpdate when user disconnect from server

I have a function of automatized channels,
All changes are triggered with voiceStateUpdate event.
All work very good but when a user disconnect from server, voiceStateUpdate is not called...
So how can i know if user leave with disconnection from server ?
UPDATE :
I finally got it in voiceStateUpdate, I just dont check if newMember or oldMember, I make my channels update directly by Client and not by the user.
There is currently no voiceStateUpdate event emitted when a Member disconnects from a voicechannel by leaving the Guild. This is a limitation with Discord itself, not the library.
I'd suggest using the guildMemberRemove event, which emits a GuildMember object. You can use that Object to loop through all the voicechannels in the Guild and check which one the Member disconnected from when leaving.
You can save users who are in the voice channel and then checking if the user who left the guild is in the list.
Upon testing, voiceStatusUpdate does not fire when a user has exit. This seems to be an issue with Discord itself. The guildMemberRemove event does fire, though. So to work around this, you must create an array that holds the user's ID, and if a member leaves, check if they were in a voice channel. If you want to monitor multiple channels, you can put all of the channels in an object with the channel ID as a key, and the array of participants (using their IDs, to preserve memory) as the value.
Depending on what method you choose, the resulting object might look like this.
{
"channel1ID": ["member1ID", "member2ID"],
"channel2ID": ["member3ID", "member4ID"]
}
Now when a member disconnects, simply remove their name from the array of the voice channel they were in. When a member leaves, check every array for their ID. Using this, you'll also be able to get the ID of the channel the member was originally part of.

logstash - store content of fields in dynamic lists

Purpose: Track privileged user activity in Windows logs.
Logic:
If logon event contains token_elev %1937 or %1938 save the logon_id (hex value) to a dynamic priv_logons list.
For subsequent events, if the logon_id in the event matches one of the entries in priv_logons list, add a 'privileged' tag to the event.
When receiving a logoff event with one of the logon_ids saved in priv_logons list, remove it from the list.
Is this doable in LogStash? If yes, how?
Not with Logstash alone.
Logstash does not maintain internal states or data objects in between events, it is simply a parsing engine.
Logstash may help you create this kind of solution by doing the parsing work and then passing clean and sensible data to a program which performs the logic you are looking for.

Pusher.com : Is there a way to use channel.bind_all() where I only get my pushed events?

I have a channel that publishes thermostat events. The events are grouped by temperature changes and thermostat control changes. I have 3 listeners (web pages): summary, temperature changes and thermostat changes.
I'm thinking I set up a channel 't1' (thermostat 1) and have events such as tc (temp change), tm (thermostat mode change), tsh (temperature set heat), etc.
The temperature change page is easy to set up: subscribe to 't1', bind to 'tc'.
But the thermostat control page is harder. Can I do something like: subscribe to 't1', bind to NOT 'tc'? This page wants to receive events on everything except 'tc'.
What I've done is a loop in the webpage javascript to generate multiple 't1'.bind() calls for each event (tm, tsh, tsc, etc.). t1.bind(tm), t1.bind(tsh), t1.bind(tsc), etc.
And the summary page needs to see all events. So I wondered about using bind_all().
But if I use bind_all I get a lot of pusher events also. I guess I can figure out how to filter those out but wondered if you guys have any better ideas.
Thanks for any suggestions!
I figured this out by using multiple channels (which is a feature), with specific events.

Resources