Progress
This commit is contained in:
parent
7d76876f99
commit
dbe320ab34
5 changed files with 36 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,3 +6,5 @@ export_presets.cfg
|
|||
data_*/
|
||||
/webrtc/
|
||||
/exports/
|
||||
*.crt
|
||||
*.keystore
|
||||
|
|
11
lobby.gd
11
lobby.gd
|
@ -9,6 +9,7 @@ func _ready():
|
|||
Global.client.signaller.connect("lobby_left", self, "_lobby_left")
|
||||
$MarginContainer/Label.text = "%s (%s)" % [Global.client.signaller.lobby_id, get_tree().get_network_unique_id()]
|
||||
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
|
||||
$shifter.connect("mouse_entered", self, "do_ping")
|
||||
|
||||
_peer_joined([{
|
||||
"id": Global.client.signaller.client_id,
|
||||
|
@ -16,6 +17,8 @@ func _ready():
|
|||
"name": "You!",
|
||||
}])
|
||||
|
||||
Global.client.signaller.request_peer_list()
|
||||
|
||||
func _signaller_disconnected():
|
||||
Global.main_menu()
|
||||
|
||||
|
@ -23,6 +26,7 @@ func _draw():
|
|||
$text.text = JSON.print(Global.client.signaller)
|
||||
|
||||
func _peer_joined(joined_peers):
|
||||
print("Joined Peers: %s" % joined_peers)
|
||||
for i in range(len(joined_peers)):
|
||||
var id = joined_peers[i]["id"]
|
||||
var exists = false
|
||||
|
@ -51,6 +55,13 @@ remotesync func shift_cursor():
|
|||
print("Shifting cursor...")
|
||||
$shifter.rect_position.x += 10
|
||||
|
||||
func do_ping():
|
||||
print(rpc("ping"))
|
||||
|
||||
remotesync func ping():
|
||||
print("pinged")
|
||||
return 0
|
||||
|
||||
func _lobby_left(_id):
|
||||
Global.lobby_browser()
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ extends Node
|
|||
This module sets up WebRTC peer connections.
|
||||
"""
|
||||
|
||||
var multiplayer_url = "wss://webrtc-signaller.deno.dev:443"
|
||||
# var multiplayer_url = "ws://localhost:8888"
|
||||
# var multiplayer_url = "wss://webrtc-signaller.deno.dev:443"
|
||||
var multiplayer_url = "ws://localhost:8888"
|
||||
# var multiplayer_url = "ws://echo.websocket.org"
|
||||
var webrtc_ice_servers = [
|
||||
{ "urls": ["stun:stun.l.google.com:19302"] },
|
||||
|
|
14
server.ts
14
server.ts
|
@ -185,6 +185,7 @@ class Lobby {
|
|||
peerId: client.peerId,
|
||||
}),
|
||||
);
|
||||
console.log("Sending peer_joined...");
|
||||
client.send(
|
||||
buildMessage(
|
||||
"peer_joined",
|
||||
|
@ -196,6 +197,12 @@ class Lobby {
|
|||
this.clients.set(client.id, client);
|
||||
}
|
||||
|
||||
clientList() {
|
||||
return Array.from(this.clients.values()).map(
|
||||
({ id, name, peerId }) => ({ id, name, peerId }),
|
||||
);
|
||||
}
|
||||
|
||||
removeClient({ id }: Client) {
|
||||
this.clients.delete(id);
|
||||
this.broadcast(buildMessage("peer_left", { id }));
|
||||
|
@ -220,6 +227,13 @@ function onMessage(client: Client, ev: MessageEvent) {
|
|||
if (msg === "lobby_create") client.lobbyCreate();
|
||||
if (msg === "lobby_leave") client.lobbyLeave();
|
||||
if (msg === "request_lobby_list") client.lobbyList();
|
||||
if (msg === "request_peer_list") {
|
||||
if (client.lobby == null) {
|
||||
client.send(`[info] not in a lobby`);
|
||||
} else {
|
||||
client.send(buildMessage("peer_joined", client.lobby.clientList()));
|
||||
}
|
||||
}
|
||||
if (msg.startsWith("lobby_join:")) {
|
||||
const id = msg.substr(11);
|
||||
const lobby = allLobbies.get(id);
|
||||
|
|
|
@ -10,7 +10,7 @@ signal lobby_new(lobbiesList)
|
|||
signal lobby_delete(id)
|
||||
signal lobby_joined(id, peer_id)
|
||||
signal lobby_left(id)
|
||||
signal peer_joined(id)
|
||||
signal peer_joined(peers)
|
||||
signal peer_left(id)
|
||||
signal candidate_received(data)
|
||||
signal offer_received(data)
|
||||
|
@ -114,7 +114,12 @@ func handle_message(data: Dictionary):
|
|||
lobby_id = null
|
||||
emit_signal("lobby_left", data["id"])
|
||||
|
||||
"peer_joined": emit_signal("peer_joined", [{"id": data["id"], "name": data["name"], "peerId": data["peerId"]}])
|
||||
"peer_joined":
|
||||
print(typeof(data), data)
|
||||
if data.get("id") != null:
|
||||
emit_signal("peer_joined", [{"id": data["id"], "name": data["name"], "peerId": data["peerId"]}])
|
||||
else:
|
||||
emit_signal("peer_joined", data["data"])
|
||||
"peer_left": emit_signal("peer_left", data["id"])
|
||||
|
||||
"candidate":
|
||||
|
|
Loading…
Reference in a new issue