mirror of
https://github.com/lune-org/lune.git
synced 2025-01-05 19:09:10 +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 net = require("@lune/net")
|
||||||
local stdio = require("@lune/stdio")
|
local serde = require("@lune/serde")
|
||||||
local task = require("@lune/task")
|
local task = require("@lune/task")
|
||||||
|
|
||||||
-- net.socket() will inherently spit out an error if init connection fails, but for
|
-- We're going to use Discord's WebSocket gateway server
|
||||||
-- the sake of this test, prot. call checks are unnecessary. Also, we're going to use
|
-- for testing wss - it does not require auth, and this test
|
||||||
-- Discord's WebSocket gateway server for soley testing wss, as we don't need to auth
|
-- only exists to ensure wss (WebSockets with TLS) works correctly
|
||||||
-- or anything for that; we just want to make sure it functions..
|
|
||||||
print("Connecting to Discord wss gateway..")
|
|
||||||
local socket = net.socket("wss://gateway.discord.gg/?v=10&encoding=json")
|
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
|
while not socket.closeCode do
|
||||||
local nextMessage = socket.next()
|
local response = socket.next()
|
||||||
|
|
||||||
if nextMessage then
|
if response then
|
||||||
print(`{stdio.style("bold")}Discord:{stdio.style("reset")}`, nextMessage)
|
local decodeSuccess, decodeMessage = pcall(serde.decode, "json" :: "json", response)
|
||||||
|
if not decodeSuccess then
|
||||||
print("Will (deliberately) close the socket in 2 seconds..")
|
error(
|
||||||
task.wait(2)
|
string.format(
|
||||||
socket.close(1000)
|
"Discord API did not respond with valid JSON!\n%s",
|
||||||
end
|
tostring(decodeMessage)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Close the connection after a second with the success close code
|
||||||
|
task.wait(1)
|
||||||
|
socket.close(1000)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print(`Connection to socket closed with closeCode {socket.closeCode}`)
|
|
||||||
|
|
Loading…
Reference in a new issue