Skip to content

feat(esx_lib): add a pub/sub multicast module#1796

Open
ASTROWwwW wants to merge 1 commit into
esx-framework:esx_libfrom
ASTROWwwW:feat/esx-lib-pubsub
Open

feat(esx_lib): add a pub/sub multicast module#1796
ASTROWwwW wants to merge 1 commit into
esx-framework:esx_libfrom
ASTROWwwW:feat/esx-lib-pubsub

Conversation

@ASTROWwwW

Copy link
Copy Markdown

Adds xLib.pubsub, a server-driven topic multicast: a producer subscribes
players to a topic server-side and publishes data pushed only to them. Clients
only listen. For things like a shop pushing live stock updates to the players
who have it open, without broadcasting to everyone.

Server: subscribe, unsubscribe, publish, subscribers, isSubscribed, clear
Client: on, off

-- server
xLib.pubsub.subscribe(source, 'myshop:247:stock')
xLib.pubsub.publish('myshop:247:stock', stock)
-- client
xLib.pubsub.on('myshop:247:stock', function(stock) updateUI(stock) end)

subscribe/publish are server-only (never a net event); subscriptions are
cleaned up on playerDropped and on resource stop.

Comment thread [core]/esx_lib/resource/pubsub/server.lua
Adds xLib.pubsub for server-driven topic multicast: a producer resource
subscribes players to a topic server-side and publishes data that is pushed
only to the subscribed players. Clients listen with xLib.pubsub.on and never
subscribe or publish themselves.

The subscription registry is a single shared instance in the esx_lib server VM,
reached cross-resource through exports; the client side is a per-VM listener
over one net event. Subscriptions are cleaned up on playerDropped, so a reused
serverId never inherits them, and on the owning resource stopping.

Also adds xLib.triggerClientEvent, which packs the payload once when sending to
many players; publish uses it so a broadcast to N subscribers serialises once.
@ASTROWwwW ASTROWwwW force-pushed the feat/esx-lib-pubsub branch from 16ea1cd to 2d1facf Compare June 25, 2026 00:17
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.

2 participants