{"id":"karlobii/relay","name":"relay","scope":"karlobii","platform":"roblox","description":"A lightweight module for client-server communication","version":"0.1.0-test","latest":"0.1.0-test","versions":["0.1.0-test"],"license":"MIT","licenseRating":"safe","licenseCaveats":["The package archive does not include its license text; the license is declared in its manifest metadata."],"licenseVerified":false,"dependencies":{"sleitnick/signal":{"version":"^2.0.3","alias":"Signal"}},"integrity":"16bfbaa8d070bb48976bb082e2fbf79e95366831b83629711bb1907964535d8b","likes":0,"downloads":0,"install":"forest install karlobii/relay","url":"https://forest.dev/p/roblox/karlobii/relay","files":"https://api.forest.dev/ai/package/roblox/karlobii/relay/files","readme":"# Relay\r\n\r\nRelay is a lightweight Roblox networking utility for routing client requests to\r\nserver methods and sending server events or state updates to clients. It\r\nprovides reliable events, unreliable events, request/response calls, and\r\ninstance-scoped remotes.\r\n\r\n## Installation\r\n\r\nInstall `karlobii/relay` with [Wally](https://wally.run/). Relay depends on\r\n`sleitnick/signal` for changed-state signals.\r\n\r\n## Quick start\r\n\r\nRequire Relay from its package root on both the server and client:\r\n\r\n```luau\r\nlocal Relay = require(path.to.Relay)\r\n```\r\n\r\nOn the server, register only the methods clients are allowed to call:\r\n\r\n```luau\r\nlocal service = {}\r\n\r\nfunction service:requestGreeting(player: Player, name: string): string\r\n\treturn \"Hello, \" .. name\r\nend\r\n\r\nlocal server = Relay.server.new(\"GreetingService\", service, {\r\n\tservice.requestGreeting,\r\n})\r\n\r\nserver:fireAll(\"showGreeting\", \"Welcome!\")\r\n```\r\n\r\nOn the client, provide handlers for server messages and call the registered\r\nserver method:\r\n\r\n```luau\r\nlocal handlers = {}\r\n\r\nfunction handlers:showGreeting(message: string)\r\n\tprint(message)\r\nend\r\n\r\nlocal client = Relay.client.new(\"GreetingService\", handlers)\r\nlocal greeting = client:fetch(\"requestGreeting\", \"Ada\")\r\n```\r\n\r\nClient-accessible methods receive the calling `Player` as their first argument.\r\nMethods invoked on the client receive the handler table as `self`.\r\n\r\n## API overview\r\n\r\n- `Relay.server.new(tag, module?, clientAccess?)` creates a server endpoint.\r\n  `tag` can be a shared string or an `Instance`; instance tags are assigned and\r\n  replicated by Relay.\r\n- `Relay.client.new(tag, module)` creates the corresponding client endpoint.\r\n- `server:fire(playerOrPlayers, method, ...)` and `server:fireAll(method, ...)`\r\n  send reliable events. `fireUnreliable` and `fireAllUnreliable` use an\r\n  `UnreliableRemoteEvent`.\r\n- `client:fire(method, ...)` sends a reliable request without a return value.\r\n  `client:fetch(method, ...)` uses a `RemoteFunction` and yields for its result.\r\n- `server:set(...)`, `setAll(...)`, `setAllExcept(...)`, and `setRecipients(...)`\r\n  update client-side values. `client:getServerChangedSignal(key)` returns a\r\n  signal that fires when that value changes.\r\n- `server:addRecipient(player)`, `removeRecipient(player)`, and\r\n  `clearRecipients()` manage the recipient list used by `fireRecipients`,\r\n  `fireRecipientsUnreliable`, and `setRecipients`.\r\n- Call `destroy()` on either endpoint when it is no longer needed. Relay\r\n  disconnects its listeners and releases owned resources; destroying a client\r\n  endpoint does not destroy the server-owned remotes. Server endpoints\r\n  automatically remove departing players from their recipient lists. Methods\r\n  other than `destroy()` raise an error if called after their endpoint has been\r\n  destroyed; calling `destroy()` more than once is safe.\r\n\r\nAlways validate client-provided arguments and authorize requests in your server\r\nmethods. Registering a method grants every connected client permission to call\r\nit.\r\n","readmeTruncated":false}