It works over the internet across clients
This commit is contained in:
parent
1417401ccd
commit
7d76876f99
4 changed files with 22 additions and 15 deletions
|
@ -4,7 +4,7 @@ extends Node
|
|||
This module sets up WebRTC peer connections.
|
||||
"""
|
||||
|
||||
var multiplayer_url = "ws://webrtc-signaller.deno.dev"
|
||||
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 = [
|
||||
|
|
|
@ -20,7 +20,11 @@ Global="*res://global.gd"
|
|||
|
||||
[gdnative]
|
||||
|
||||
singletons=[ ]
|
||||
singletons=[ "res://webrtc/webrtc.tres" ]
|
||||
|
||||
[network]
|
||||
|
||||
ssl/certificates="res://ca-certificates.crt"
|
||||
|
||||
[physics]
|
||||
|
||||
|
|
15
server.ts
15
server.ts
|
@ -15,7 +15,7 @@ interface DataMessage {
|
|||
}
|
||||
|
||||
type ServerDataObject = Record<string, string | number | symbol | null>;
|
||||
type ServerData = ServerDataObject | string;
|
||||
type ServerData = ServerDataObject[] | ServerDataObject | string;
|
||||
type Message = string | DataMessage;
|
||||
|
||||
const broadcast = (message: Message) =>
|
||||
|
@ -185,12 +185,13 @@ class Lobby {
|
|||
peerId: client.peerId,
|
||||
}),
|
||||
);
|
||||
this.clients.forEach((c) =>
|
||||
client.send(buildMessage("peer_joined", {
|
||||
id: c.id,
|
||||
name: c.name,
|
||||
peerId: c.peerId,
|
||||
}))
|
||||
client.send(
|
||||
buildMessage(
|
||||
"peer_joined",
|
||||
Array.from(this.clients.values()).map(
|
||||
({ id, name, peerId }) => ({ id, name, peerId }),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.clients.set(client.id, client);
|
||||
}
|
||||
|
|
|
@ -30,9 +30,14 @@ func _ready():
|
|||
var _result = ws.connect("data_received", self, "_parse_msg")
|
||||
_result = ws.connect("connection_established", self, "_connected")
|
||||
_result = ws.connect("connection_closed", self, "_closed")
|
||||
_result = ws.connect("connection_error", self, "_closed")
|
||||
_result = ws.connect("connection_error", self, "_closed", [false])
|
||||
_result = ws.connect("connection_failed", self, "_closed", [false])
|
||||
_result = ws.connect("connection_succeeded", self, "_succ")
|
||||
_result = ws.connect("server_close_request", self, "_close_request")
|
||||
|
||||
func _succ():
|
||||
print("WebSocket Connection Succeeded")
|
||||
|
||||
func close():
|
||||
ws.disconnect_from_host()
|
||||
|
||||
|
@ -60,11 +65,8 @@ func _connected(protocol = ""):
|
|||
|
||||
func _process(_delta: float):
|
||||
var status: int = ws.get_connection_status()
|
||||
ws.poll()
|
||||
if status == WebSocketClient.CONNECTION_CONNECTED || status == WebSocketClient.CONNECTION_CONNECTING:
|
||||
print("I'm polling! %s" % status)
|
||||
else:
|
||||
print("Not polling! %s" % status)
|
||||
if status in [WebSocketClient.CONNECTION_CONNECTED, WebSocketClient.CONNECTION_CONNECTING]:
|
||||
ws.poll()
|
||||
|
||||
func join_lobby(id: String):
|
||||
return _send("lobby_join:%s" % id)
|
||||
|
|
Loading…
Reference in a new issue