All checks were successful
Quality Check / Linting (push) Successful in 7s
Build Application / build (tower_defence_web, build/*, build, build/index.html, Web) (push) Successful in 14s
Build Application / build (tower_defence.elf, tower_defence.elf, tower_defence.elf, Linux) (push) Successful in 17s
Build Application / build (tower_defence.exe, tower_defence.exe, tower_defence.exe, Windows) (push) Successful in 19s
Build Application / release (push) Successful in 8s
Build Application / build-docker (push) Successful in 10s
28 lines
788 B
GDScript
28 lines
788 B
GDScript
extends RichTextLabel
|
|
|
|
# docs.redotengine.org/en/stable/tutorials/networking/websocket.html
|
|
@export var fallpack_websocket_url = "ws://localhost:8080/ws/server"
|
|
var websocket_url = OS.get_environment("TD_SERVER_WS")
|
|
var socket = WebSocketPeer.new()
|
|
|
|
|
|
func _ready() -> void:
|
|
if websocket_url.is_empty():
|
|
websocket_url = fallpack_websocket_url
|
|
var err = socket.connect_to_url(websocket_url)
|
|
if err != OK:
|
|
error_string(err)
|
|
set_process(false)
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
socket.poll()
|
|
var state = socket.get_ready_state()
|
|
|
|
if state == WebSocketPeer.STATE_CLOSED:
|
|
self.text = "Disconnected"
|
|
return
|
|
|
|
if state == WebSocketPeer.STATE_OPEN:
|
|
while socket.get_available_packet_count():
|
|
self.text = "Current Unixtime: " + socket.get_packet().get_string_from_utf8()
|