From 256ab53998503b49036b965fe99a664863777181 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Wed, 4 Sep 2024 13:37:58 -0600 Subject: [PATCH] Update readme and the other thing --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++++- WebSocket.lua | 5 ++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cbab6c5..f6ed1fc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,45 @@ # Websocket Client for Roblox -TODO: Detailed instructions on how to use this module will be added soon. \ No newline at end of file + +## Setup +1. Place the WebSocket and Base64 files in ServerScriptService. +2. Create a new script in Workspace, or wherever you want. +3. If you are hosting your own WebSocket server, replace the URL `https://sock.kcadev.org` with your own. + +## Usage +```lua +local ws = require(game.ServerScriptService:WaitForChild("WebSocket")) +local server = ws({ + url = "wss://echo.websocket.org/", + onMessage = function(message) + print("Message received: " .. message) + end, + onError = function(error) + print("Error: " .. error) + end +}) +server.sendMessage("Hello World") +``` + +## Functions +### ws +```lua +local server = ws({ + url = "wss://echo.websocket.org/", + onMessage = function(message) + print("Message received: " .. message) + end, + onError = function(error) + print("Error: " .. error) + end +}) +``` + +### server.sendMessage +```lua +server.sendMessage("Hello World") +``` + +### server.close +```lua +server.close() +``` \ No newline at end of file diff --git a/WebSocket.lua b/WebSocket.lua index cef0301..5846e2c 100644 --- a/WebSocket.lua +++ b/WebSocket.lua @@ -1,7 +1,6 @@ -local Base64 = require(script.Base64) +local Base64 = require(script.Parent:WaitForChild("Base64")) local JobId = game:GetService('HttpService'):GenerateGUID(false) -local config = require(script.Parent.Parent:WaitForChild("Configuration")) -local BaseUrl = config["websocket-proxy"] +local BaseUrl = "https://sock.kcadev.org" local atob = Base64.atob local btoa = Base64.btoa local messages = {}