godot-webrtc-mplayer-testing/lobby.gd

41 lines
1.1 KiB
GDScript3
Raw Normal View History

2021-11-15 16:25:13 -06:00
extends Node2D
2021-11-17 13:57:45 -06:00
onready var peers = $MarginContainer/peers
2021-11-15 16:25:13 -06:00
func _ready():
2021-11-17 13:57:45 -06:00
Global.client.signaller.connect("peer_joined", self, "_peer_joined")
Global.client.signaller.connect("peer_left", self, "_peer_left")
Global.client.signaller.connect("lobby_left", self, "_lobby_left")
$MarginContainer/Label.text = Global.client.signaller.lobby_id
2021-11-17 16:24:00 -06:00
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
2021-11-17 13:57:45 -06:00
Global.client.signaller.request_peer_list()
2021-11-15 16:25:13 -06:00
2021-11-17 16:24:00 -06:00
func _signaller_disconnected():
Global.main_menu()
2021-11-15 16:25:13 -06:00
func _draw():
pass
func _process(_delta):
pass
2021-11-17 13:57:45 -06:00
func _peer_joined(joined_peers):
for i in range(len(joined_peers)):
var id = joined_peers[i]["id"]
var name = joined_peers[i]["name"]
2021-11-17 16:24:00 -06:00
print("New Lobby Peer ", id, name)
2021-11-17 13:57:45 -06:00
peers.add_item("%s" % name)
peers.set_item_metadata(peers.get_item_count() - 1, { "id": id })
func _peer_left(id):
for i in range(peers.get_item_count()):
if id == peers.get_item_metadata(i)["id"]:
peers.remove_item(i)
return
2021-11-15 16:25:13 -06:00
func _on_Button_pressed():
2021-11-17 13:57:45 -06:00
Global.lobby_browser()
func _lobby_left(_id):
Global.lobby_browser()