This commit is contained in:
Daniel Flanagan 2021-12-03 17:05:31 -06:00
parent bf3de3775b
commit 1417401ccd
6 changed files with 27 additions and 18 deletions

View file

@ -28,7 +28,6 @@ process/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/HDR_as_SRGB=false process/HDR_as_SRGB=false
process/invert_color=false process/invert_color=false
process/normal_map_invert_y=false
stream=false stream=false
size_limit=0 size_limit=0
detect_3d=true detect_3d=true

View file

@ -4,7 +4,9 @@ extends Node
This module sets up WebRTC peer connections. This module sets up WebRTC peer connections.
""" """
var multiplayer_url = "wss://webrtc-signaller.deno.dev" # "ws://localhost:8888" var multiplayer_url = "ws://webrtc-signaller.deno.dev"
# var multiplayer_url = "ws://localhost:8888"
# var multiplayer_url = "ws://echo.websocket.org"
var webrtc_ice_servers = [ var webrtc_ice_servers = [
{ "urls": ["stun:stun.l.google.com:19302"] }, { "urls": ["stun:stun.l.google.com:19302"] },
# { "urls": ["stun:localhost:3478"] } # { "urls": ["stun:localhost:3478"] }

View file

@ -20,7 +20,7 @@ Global="*res://global.gd"
[gdnative] [gdnative]
singletons=[ "res://webrtc/webrtc.tres" ] singletons=[ ]
[physics] [physics]

View file

@ -213,21 +213,22 @@ interface ClientMessage {
// events // events
function onMessage(client: Client, ev: MessageEvent) { function onMessage(client: Client, ev: MessageEvent) {
// TODO: log who from? // TODO: log who from?
console.log("Client Message Received", ev.data); const msg = ev.data.trim();
if (ev.data === "init") client.send(buildMessage("your_id", client.id)); console.log("Client Message Received", msg);
if (ev.data === "lobby_create") client.lobbyCreate(); if (msg === "init") client.send(buildMessage("your_id", client.id));
if (ev.data === "lobby_leave") client.lobbyLeave(); if (msg === "lobby_create") client.lobbyCreate();
if (ev.data === "request_lobby_list") client.lobbyList(); if (msg === "lobby_leave") client.lobbyLeave();
if (ev.data.startsWith("lobby_join:")) { if (msg === "request_lobby_list") client.lobbyList();
const id = ev.data.substr(11); if (msg.startsWith("lobby_join:")) {
const id = msg.substr(11);
const lobby = allLobbies.get(id); const lobby = allLobbies.get(id);
if (lobby) { if (lobby) {
client.lobbyJoin(lobby); client.lobbyJoin(lobby);
client.clientList(); client.clientList();
} else client.send(`[info] could not find lobby ${id}`); } else client.send(`[info] could not find lobby ${id}`);
} }
if (ev.data.startsWith("json:")) { if (msg.startsWith("json:")) {
const data: ClientMessage = JSON.parse(ev.data.substr(5)); const data: ClientMessage = JSON.parse(msg.substr(5));
if (["candidate", "answer", "offer"].includes(data.type)) { if (["candidate", "answer", "offer"].includes(data.type)) {
console.log("Received WebRTC Negotiation Message..."); console.log("Received WebRTC Negotiation Message...");
if (typeof data.data === "object") { if (typeof data.data === "object") {

View file

@ -40,10 +40,13 @@ func connect_to_websocket_signaller(url: String):
print("WebSocket: %s" % ws) print("WebSocket: %s" % ws)
close() close()
print("Attempting to connect to WebSocket signalling server at %s" % url) print("Attempting to connect to WebSocket signalling server at %s" % url)
var _result = ws.connect_to_url(url) var result = ws.connect_to_url(url)
print("%s" % _result) if result != OK:
print("FAILED TO CONNECT TO %s" % url)
print("WebSocket Connect Result: %s" % result)
func _closed(_unknown): func _closed(unknown):
print("WebSocket closed: %s: " % unknown)
emit_signal("websocket_disconnected") emit_signal("websocket_disconnected")
func _close_request(code: int, reason: String): func _close_request(code: int, reason: String):
@ -57,8 +60,11 @@ func _connected(protocol = ""):
func _process(_delta: float): func _process(_delta: float):
var status: int = ws.get_connection_status() var status: int = ws.get_connection_status()
if status == WebSocketClient.CONNECTION_CONNECTED:
ws.poll() ws.poll()
if status == WebSocketClient.CONNECTION_CONNECTED || status == WebSocketClient.CONNECTION_CONNECTING:
print("I'm polling! %s" % status)
else:
print("Not polling! %s" % status)
func join_lobby(id: String): func join_lobby(id: String):
return _send("lobby_join:%s" % id) return _send("lobby_join:%s" % id)
@ -81,6 +87,7 @@ func _parse_msg():
var data = JSON.parse(msg.substr(5)) var data = JSON.parse(msg.substr(5))
if data.error == OK: if data.error == OK:
handle_message(data.result) handle_message(data.result)
ws.get_peer(1).put_packet("".to_utf8())
else: else:
print("Unhandled message: %s" % msg) print("Unhandled message: %s" % msg)