Network
phigrospp.fetch(method, url, body?, done, timeout?)
An HTTP request, timeout in seconds (30, 0 for none).
phigrospp.fetch("GET", "https://phigros.tools/api/releases", nil, function(status, body) if status ~= 200 then return toast("Offline") end print(phigrospp.json.decode(body).version) --> 0.3.0-beta.17 end)
| Parameter | Type | |
|---|---|---|
method | string | |
url | string | |
body? | string | |
done | fun(status: integer, body: string) | |
timeout? | number |
Returns UnityWebRequest: the request, :Abort() cancels it
SocketHandlers
| Field | Type | |
|---|---|---|
open? | fun() | |
message? | fun(text: string) | |
close? | fun() | it ended or never opened |
phigrospp.socket(url, handlers)
A WebSocket carrying texts.
local socket socket = phigrospp.socket("wss://example.com/live", { open = function() socket.send("hello") end, message = function(text) print(text) end, close = function() print("closed") end, })
| Parameter | Type | |
|---|---|---|
url | string | |
handlers | SocketHandlers |
Returns { send: fun(text: string), close: fun() }
phigrospp.channel(path, domain, heard, closed)
A socket of phigros.tools signed in with the player's key (domain goes before what's signed): heard[t](message) runs for each json object by its t, "welcome" first, closed() once it ended.
local channel = phigrospp.channel("/api/room", "phigros.tools rooms v1\0", { welcome = function(message) print(message.t) end, --> welcome }, function() print("gone") end) channel.send({ t = "join", room = "ABCD" })
| Parameter | Type | |
|---|---|---|
path | string | "/api/room" |
domain | string | |
heard | table<string, fun(message: table)> | |
closed | function |
Returns { send: fun(message: table), close: fun() }