update main script
This commit is contained in:
parent
77d779dd4d
commit
2f947401da
|
@ -23,28 +23,48 @@ local ws = function (dict)
|
||||||
print(msg)
|
print(msg)
|
||||||
end
|
end
|
||||||
local server = game:GetService('HttpService')
|
local server = game:GetService('HttpService')
|
||||||
local id = server:RequestAsync({
|
local response, status = server:RequestAsync({
|
||||||
["Url"] = BaseUrl .. "api/connect/" .. JobId,
|
["Url"] = BaseUrl .. "/api/connect/" .. JobId,
|
||||||
["Method"] = "PUT",
|
["Method"] = "PUT",
|
||||||
["Body"] = dict.url
|
["Body"] = server:JSONEncode({["url"] = dict.url}),
|
||||||
}).Body
|
["Headers"] = {["Content-Type"] = "application/json"}
|
||||||
print(id)
|
})
|
||||||
print(typeof(id))
|
if response.Success then
|
||||||
|
local id = response.Body
|
||||||
local function sendMessage(msg)
|
local function sendMessage(msg)
|
||||||
wait()
|
wait()
|
||||||
server:PostAsync(BaseUrl .. "api/send/" .. JobId .."/"..id, msg)
|
local resp = server:RequestAsync({
|
||||||
|
["Url"] = BaseUrl .. "/api/send/" .. JobId .."/"..id,
|
||||||
|
["Method"] = "POST",
|
||||||
|
["Body"] = server:JSONEncode({["data"] = msg}),
|
||||||
|
["Headers"] = {["Content-Type"] = "application/json"}
|
||||||
|
})
|
||||||
|
if not resp.Success then
|
||||||
|
error("Error Sending Message: " .. resp.StatusCode .. " " .. resp.StatusMessage)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function close()
|
local function close()
|
||||||
server:RequestAsync({
|
server:RequestAsync({
|
||||||
["Url"] = BaseUrl .. "api/close/" .. JobId .. "/" .. id,
|
["Url"] = BaseUrl .. "/api/close/" .. JobId .. "/" .. id,
|
||||||
["Method"] = "DELETE"
|
["Method"] = "DELETE"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local loop = coroutine.create(function()
|
local loop = coroutine.create(function()
|
||||||
while wait(50 / 1000) do
|
while wait(0.1) do
|
||||||
local msg = server:GetAsync(BaseUrl .. "api/poll/"..JobId.."/"..id)
|
print("poll")
|
||||||
|
local response = server:RequestAsync({
|
||||||
|
["Url"] = BaseUrl .. "/api/poll/"..JobId.."/".. id,
|
||||||
|
["Method"] = "GET"
|
||||||
|
})
|
||||||
|
|
||||||
|
if response.Success then
|
||||||
|
local msg = response.Body
|
||||||
|
-- Rest of the code
|
||||||
|
else
|
||||||
|
error("Error Polling Messages: " .. response.StatusCode .. " " .. response.StatusMessage)
|
||||||
|
end
|
||||||
if notExists(messages, msg) then
|
if notExists(messages, msg) then
|
||||||
table.insert(messages, msg)
|
table.insert(messages, msg)
|
||||||
if notEmpty(msg) then
|
if notEmpty(msg) then
|
||||||
|
@ -60,6 +80,9 @@ local ws = function (dict)
|
||||||
onMessage = onMessage,
|
onMessage = onMessage,
|
||||||
close = close
|
close = close
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
error("Error Connecting to Websocket Server: " .. response.StatusCode .. " " .. response.StatusMessage)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return ws
|
return ws
|
||||||
|
|
Loading…
Reference in a new issue