You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
942 B
GDScript
42 lines
942 B
GDScript
2 years ago
|
extends Node
|
||
|
|
||
|
export var websocket_url = "ws://127.0.0.1:8080"
|
||
|
var _client = WebSocketClient.new()
|
||
|
onready var UI = $UI
|
||
|
var chat_name
|
||
|
|
||
|
func join_chat(username):
|
||
|
pass
|
||
|
|
||
|
func send_message(message):
|
||
|
pass
|
||
|
|
||
|
sync func receive_message(packet):
|
||
|
pass
|
||
|
|
||
|
func _ready():
|
||
|
_client.connect("connection_closed", self, "_closed")
|
||
|
_client.connect("connection_error", self, "_error")
|
||
|
_client.connect("connection_established", self, "_connected")
|
||
|
_client.connect("data_received", self, "_on_data_received")
|
||
|
|
||
|
var err = _client.connect_to_url(websocket_url)
|
||
|
if err != OK:
|
||
|
print_debug("Unable to connect")
|
||
|
set_process(false)
|
||
|
|
||
|
func _error(was_clean = false):
|
||
|
print_debug("Error. Clean break? ", was_clean)
|
||
|
|
||
|
func _closed(was_clean = false):
|
||
|
print_debug("Closed. Clean break? ", was_clean)
|
||
|
|
||
|
func _connected(protocol = ""):
|
||
|
print_debug("Connected with protocol ", protocol)
|
||
|
|
||
|
func _on_data_received():
|
||
|
pass
|
||
|
|
||
|
func _process(_delta):
|
||
|
_client.poll()
|