{"id":"jarnster/rbxconnectionmanager","name":"rbxconnectionmanager","scope":"jarnster","platform":"roblox","description":"Mirrored from the Wally registry.","version":"0.1.4","latest":"0.1.4","versions":["0.1.2","0.1.3","0.1.4"],"license":"AGPL-3.0","licenseRating":"unsafe","licenseCaveats":["Strongest copyleft: even network use counts as distribution, so running this in a live game plausibly requires releasing your game's entire source under AGPL-3.0. Not recommended for closed-source projects.","License identified from the packaged LICENSE file; the manifest declared none."],"licenseVerified":true,"dependencies":{},"integrity":"23b0efc7267201b44e0ebc7b396347f9d8bbdcd88d4c3c3a7e63e2f79b9dc2dd","likes":0,"downloads":0,"install":"forest install jarnster/rbxconnectionmanager","url":"https://forest.dev/p/roblox/jarnster/rbxconnectionmanager","files":"https://api.forest.dev/ai/package/roblox/jarnster/rbxconnectionmanager/files","readme":"# RBXConnectionManager\r\n\r\nThis is our first open-source release. Please add a ⭐ if you like the idea of this project or if you like to use it.\r\n\r\nRoblox Developer Forum Thread: https://devforum.roblox.com/t/3503750\r\n\r\nConsider joining our community aswell! https://discord.gg/8ed3W53kHv/ to see progress on our very advanced projects and enjoy early-access benefits while you still can!\r\n\r\n## Overview\r\nRBXConnectionManager is a lightweight and efficient module for managing `RBXScriptConnection` objects in Roblox. It allows for easy connection handling, automatic cleanup, and optional event monitoring.\r\n\r\n## Features\r\n- **Efficient Connection Management**: Easily create, store, and disconnect connections by name.\r\n- **Automatic Cleanup**: Removes player-specific connections when a player leaves (server-side feature) -> the player's UserId must be in the connection name.\r\n- **Batch Disconnection**: Disconnect all connections or those within a specific group.\r\n- **Monitoring**: Logs and displays event calls along with timestamps.\r\n- **Self-Destruction**: Provides a method to completely clean up the manager.\r\n\r\n---\r\n\r\n## Installation\r\n1. Add `RBXConnectionManager.luau` to your Roblox project.\r\n2. Require the module where needed:\r\n   ```lua\r\n   local RBXConnectionManager = require(path.to.rbxconnectionmanager)\r\n   ```\r\n---\r\n\r\n## Usage\r\n\r\n### Creating an Instance\r\n```lua\r\nlocal connectionManager = RBXConnectionManager.new()\r\n```\r\n\r\n### Adding Connections\r\n```lua\r\nlocal myEvent = game.ReplicatedStorage.SomeRemoteEvent\r\n\r\nconnectionManager:Connect(\"ExampleConnection\", myEvent.OnServerEvent, function(player, data)\r\n    print(\"Event triggered by:\", player.Name, \"with data:\", data)\r\nend, true) -- Enable monitoring\r\n```\r\n\r\n### Disconnecting a Specific Connection\r\n```lua\r\nconnectionManager:Disconnect(\"ExampleConnection\")\r\n```\r\n\r\n### Disconnecting All Connections in a Group\r\nThis will disconnect all events that contain the provided string in their name.\r\n```lua\r\nconnectionManager:DisconnectAllInGroup(\"OnCarShowClicked\")\r\n```\r\n\r\n### Disconnecting All Connections\r\n```lua\r\nconnectionManager:DisconnectAll()\r\n```\r\n\r\n### Retrieving Monitoring Logs\r\n```lua\r\nconnectionManager:GetAllMonitoringData()\r\n```\r\n\r\n### Destroying the Manager\r\nThis will also disconnect all existing connections (like connectionManager:DisconnectAll() does)\r\n```lua\r\nconnectionManager:Destroy()\r\n```\r\n\r\n### Using AutoDisconnect\r\nThis will disconnect all connections in group (group_name, like connectionManager:DisconnectAllInGroup) when an RBXScriptConnection (event) is fired\r\n```lua\r\nconnectionManager:AddAutoDisconnect(group_name, event)\r\n```\r\n\r\n---\r\n\r\n### Basic Example (Server-side Car Show Handler)\r\n\r\n```lua\r\nlocal Players = game:GetService(\"Players\")\r\nlocal RBXConnectionManager = require(game.ServerScriptService.rbxconnectionmanager)\r\n\r\n-- Create a new connection manager\r\nlocal connectionManager = RBXConnectionManager.new()\r\n\r\n-- Example RemoteEvent\r\nlocal remoteEvent = game.ReplicatedStorage.SomeRemoteEvent\r\n\r\n-- Connect an event with automatic tracking\r\nPlayers.PlayerAdded:Connect(function(playerObj)\r\n    local userid = playerObj.UserId\r\n\tconnectionManager:Connect(\"OnCarShowClicked_\" .. tostring(userid), remoteEvent.OnServerEvent, function(triggeringPlayer, data)\r\n\t\tprint(triggeringPlayer.Name .. \" triggered the event with data:\", data)\r\n        warn(\"Send \" .. triggeringPlayer.Name .. \" congratulations about \" .. triggeringPlayer.Name .. \" clicking on his car show\")\r\n\tend, true) -- Enable monitoring\r\nend)\r\n```\r\n\r\n---\r\n\r\n## Notes\r\n- On the **server-side**, connections linked to a player will be automatically removed when they leave.\r\n- Monitoring can be useful for debugging event calls, but it may have performance implications if used excessively.\r\n- The module is designed to work efficiently in both **server-side** and **client-side** scripts.\r\n\r\n---\r\n\r\n## Open-source\r\nThis module is open-source and free to use in any Roblox project. Contributions and improvements are welcome!\r\n","readmeTruncated":false}