WIP
This commit is contained in:
parent
bf3de3775b
commit
1417401ccd
|
@ -28,7 +28,6 @@ process/fix_alpha_border=true
|
|||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
process/normal_map_invert_y=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
|
|
|
@ -11,7 +11,7 @@ func _ready():
|
|||
Global.client.signaller.connect("lobby_left", self, "_lobby_left")
|
||||
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
|
||||
Global.client.signaller.request_lobby_list()
|
||||
|
||||
|
||||
func _draw():
|
||||
$join.disabled = len($lobbies.get_selected_items()) <= 1
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@ extends Node
|
|||
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 = [
|
||||
{ "urls": ["stun:stun.l.google.com:19302"] },
|
||||
# { "urls": ["stun:localhost:3478"] }
|
||||
|
|
|
@ -20,7 +20,7 @@ Global="*res://global.gd"
|
|||
|
||||
[gdnative]
|
||||
|
||||
singletons=[ "res://webrtc/webrtc.tres" ]
|
||||
singletons=[ ]
|
||||
|
||||
[physics]
|
||||
|
||||
|
|
19
server.ts
19
server.ts
|
@ -213,21 +213,22 @@ interface ClientMessage {
|
|||
// events
|
||||
function onMessage(client: Client, ev: MessageEvent) {
|
||||
// TODO: log who from?
|
||||
console.log("Client Message Received", ev.data);
|
||||
if (ev.data === "init") client.send(buildMessage("your_id", client.id));
|
||||
if (ev.data === "lobby_create") client.lobbyCreate();
|
||||
if (ev.data === "lobby_leave") client.lobbyLeave();
|
||||
if (ev.data === "request_lobby_list") client.lobbyList();
|
||||
if (ev.data.startsWith("lobby_join:")) {
|
||||
const id = ev.data.substr(11);
|
||||
const msg = ev.data.trim();
|
||||
console.log("Client Message Received", msg);
|
||||
if (msg === "init") client.send(buildMessage("your_id", client.id));
|
||||
if (msg === "lobby_create") client.lobbyCreate();
|
||||
if (msg === "lobby_leave") client.lobbyLeave();
|
||||
if (msg === "request_lobby_list") client.lobbyList();
|
||||
if (msg.startsWith("lobby_join:")) {
|
||||
const id = msg.substr(11);
|
||||
const lobby = allLobbies.get(id);
|
||||
if (lobby) {
|
||||
client.lobbyJoin(lobby);
|
||||
client.clientList();
|
||||
} else client.send(`[info] could not find lobby ${id}`);
|
||||
}
|
||||
if (ev.data.startsWith("json:")) {
|
||||
const data: ClientMessage = JSON.parse(ev.data.substr(5));
|
||||
if (msg.startsWith("json:")) {
|
||||
const data: ClientMessage = JSON.parse(msg.substr(5));
|
||||
if (["candidate", "answer", "offer"].includes(data.type)) {
|
||||
console.log("Received WebRTC Negotiation Message...");
|
||||
if (typeof data.data === "object") {
|
||||
|
|
|
@ -40,10 +40,13 @@ func connect_to_websocket_signaller(url: String):
|
|||
print("WebSocket: %s" % ws)
|
||||
close()
|
||||
print("Attempting to connect to WebSocket signalling server at %s" % url)
|
||||
var _result = ws.connect_to_url(url)
|
||||
print("%s" % _result)
|
||||
var result = ws.connect_to_url(url)
|
||||
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")
|
||||
|
||||
func _close_request(code: int, reason: String):
|
||||
|
@ -57,8 +60,11 @@ func _connected(protocol = ""):
|
|||
|
||||
func _process(_delta: float):
|
||||
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):
|
||||
return _send("lobby_join:%s" % id)
|
||||
|
@ -81,6 +87,7 @@ func _parse_msg():
|
|||
var data = JSON.parse(msg.substr(5))
|
||||
if data.error == OK:
|
||||
handle_message(data.result)
|
||||
ws.get_peer(1).put_packet("".to_utf8())
|
||||
else:
|
||||
print("Unhandled message: %s" % msg)
|
||||
|
||||
|
|
Loading…
Reference in a new issue