phigros.tools

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)
ParameterType
methodstring
urlstring
body?string
donefun(status: integer, body: string)
timeout?number

Returns UnityWebRequest: the request, :Abort() cancels it

SocketHandlers

FieldType
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,
})
ParameterType
urlstring
handlersSocketHandlers

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" })
ParameterType
pathstring"/api/room"
domainstring
heardtable<string, fun(message: table)>
closedfunction

Returns { send: fun(message: table), close: fun() }