Working prototype
This commit is contained in:
parent
3de181134d
commit
1ed0ec226d
24 changed files with 682 additions and 31 deletions
|
|
@ -16,7 +16,6 @@ func _init():
|
|||
peer_connected.connect(self._peer_connected)
|
||||
peer_disconnected.connect(self._peer_disconnected)
|
||||
|
||||
|
||||
func start(url, _lobby = "", _mesh:=true):
|
||||
stop()
|
||||
sealed = false
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ enum Message {JOIN, ID, PEER_CONNECT, PEER_DISCONNECT, OFFER, ANSWER, CANDIDATE,
|
|||
var ws: WebSocketPeer = WebSocketPeer.new()
|
||||
var code = 1000
|
||||
var reason = "Unknown"
|
||||
var old_state = WebSocketPeer.STATE_CLOSED
|
||||
|
||||
signal lobby_joined(lobby)
|
||||
signal connected(id, use_mesh)
|
||||
|
|
@ -33,9 +34,6 @@ func close():
|
|||
|
||||
|
||||
func _process(delta):
|
||||
var old_state: int = ws.get_ready_state()
|
||||
if old_state == WebSocketPeer.STATE_CLOSED:
|
||||
return
|
||||
ws.poll()
|
||||
var state = ws.get_ready_state()
|
||||
if state != old_state and state == WebSocketPeer.STATE_OPEN and autojoin:
|
||||
|
|
@ -43,10 +41,11 @@ func _process(delta):
|
|||
while state == WebSocketPeer.STATE_OPEN and ws.get_available_packet_count():
|
||||
if not _parse_msg():
|
||||
print("Error parsing message from server.")
|
||||
if state == WebSocketPeer.STATE_CLOSED:
|
||||
if state != old_state and state == WebSocketPeer.STATE_CLOSED:
|
||||
code = ws.get_close_code()
|
||||
reason = ws.get_close_reason()
|
||||
disconnected.emit()
|
||||
old_state = state
|
||||
|
||||
|
||||
func _parse_msg():
|
||||
|
|
@ -93,7 +92,7 @@ func _parse_msg():
|
|||
return true # Parsed
|
||||
|
||||
|
||||
func join_lobby(_lobby: String):
|
||||
func join_lobby(lobby: String):
|
||||
return _send_msg(Message.JOIN, 0 if mesh else 1, lobby)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue