mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 05:20:37 +00:00
Dont output anything from wss test unless its an error
This commit is contained in:
parent
518e263c69
commit
594e773236
1 changed files with 20 additions and 17 deletions
|
@ -1,25 +1,28 @@
|
|||
local net = require("@lune/net")
|
||||
local stdio = require("@lune/stdio")
|
||||
local serde = require("@lune/serde")
|
||||
local task = require("@lune/task")
|
||||
|
||||
-- net.socket() will inherently spit out an error if init connection fails, but for
|
||||
-- the sake of this test, prot. call checks are unnecessary. Also, we're going to use
|
||||
-- Discord's WebSocket gateway server for soley testing wss, as we don't need to auth
|
||||
-- or anything for that; we just want to make sure it functions..
|
||||
print("Connecting to Discord wss gateway..")
|
||||
-- We're going to use Discord's WebSocket gateway server
|
||||
-- for testing wss - it does not require auth, and this test
|
||||
-- only exists to ensure wss (WebSockets with TLS) works correctly
|
||||
local socket = net.socket("wss://gateway.discord.gg/?v=10&encoding=json")
|
||||
print("Connected!") -- Would've errored at net.socket() call before this if init connection err
|
||||
|
||||
while not socket.closeCode do
|
||||
local nextMessage = socket.next()
|
||||
local response = socket.next()
|
||||
|
||||
if nextMessage then
|
||||
print(`{stdio.style("bold")}Discord:{stdio.style("reset")}`, nextMessage)
|
||||
|
||||
print("Will (deliberately) close the socket in 2 seconds..")
|
||||
task.wait(2)
|
||||
socket.close(1000)
|
||||
end
|
||||
if response then
|
||||
local decodeSuccess, decodeMessage = pcall(serde.decode, "json" :: "json", response)
|
||||
if not decodeSuccess then
|
||||
error(
|
||||
string.format(
|
||||
"Discord API did not respond with valid JSON!\n%s",
|
||||
tostring(decodeMessage)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
-- Close the connection after a second with the success close code
|
||||
task.wait(1)
|
||||
socket.close(1000)
|
||||
end
|
||||
end
|
||||
|
||||
print(`Connection to socket closed with closeCode {socket.closeCode}`)
|
||||
|
|
Loading…
Reference in a new issue