Code Monkey home page Code Monkey logo

Comments (6)

bryanmylee avatar bryanmylee commented on August 11, 2024 1

For anyone interested in doing something similar with WebRTC in the future, I resolved this by making the following edits:

# network-time-synchronizer.gd
-L121: var sync_result = await sync_time(1)
+L121: var sync_result = await sync_time(Program.game_authority_id)
# network-time.gd
-L299: if not multiplayer.is_server():
+L299: if not Program.is_game_authority:
...
-L335: if not multiplayer.is_server():
+L335: if not Program.is_game_authority:

Program.game_authority_id and Program.is_game_authority are simply variables set across the network when setting up my WebRTC mesh.

On my own WebRTC signalling and setup code, I added the following calls:

# webrtc_client.gd
func _handle_webrtc_peer_connected(new_peer_id: int) -> void:
+ if new_peer_id == Program.game_authority_id:
+   NetworkTime.start()
# webrtc_signalling.gd
func _handle_authority_webrtc_client_ready(peer_id: int) -> void:
~   Program.game_authority_id = peer_id
+   NetworkTime.start()
~   await set_game_authority_on_existing_peers(peer_id)

from netfox.

bryanmylee avatar bryanmylee commented on August 11, 2024

I've realized that all of the network configuration starts from NetworkEvents, which doesn't get fired for me because I've rolled my own server-client connection with WebRTC.

I'm going to add the same hooks to my own GameClient and GameServer code and report back.

I'll also have to replace multiplayer.is_server() with my own Program.is_game_authority since every peer in WebRTC technically listens for and initiates connections.

from netfox.

elementbound avatar elementbound commented on August 11, 2024

Thanks for the detailed post @bryanmylee!

I've realized that all of the network configuration starts from NetworkEvents

I see you've also figured this out, so this note is mostly for anyone else reading 🙂 You can also manually start things by calling NetworkTime.start. NetworkEvents is a convenience wrapper over Godot's multiplayer events, but you can skip that layer.

I think I can support your use case by making NetworkTime's authority configurable, but default to 1 as it currently does. So that way you would set the NetworkTime's sync authority to Program.game_authority_id and be done with it.

By the way, do I understand it right that your WebRTC setup does not emit the usual events ( connected_to_server, peer_connected, etc. ), and that's the reason why the original NetworkEvents implementation did nothing?

from netfox.

bryanmylee avatar bryanmylee commented on August 11, 2024

@elementbound As far as I know, that's correct. connected_to_server isn't emitted in a WebRTC environment since all connection nodes are peers.

peer_connected is emitted, but unlike a traditional client-server model, it's not isolated to the server only and is emitted on all peers when a new peer joins the mesh.

I've essentially replaced:

  1. connected_to_server with peer_connected(id) where id == Program.game_authority_id, and
  2. peer_connected with peer_connected where Program.is_game_authority.

from netfox.

elementbound avatar elementbound commented on August 11, 2024

Thanks! I'll try to cater a bit to this use case, both in implementation and in docs 🙂

from netfox.

bryanmylee avatar bryanmylee commented on August 11, 2024

@elementbound Actually, I think you can ignore this. I've realized that it's practically impossible to get a WebRTC client to work when it's deployed on a server, especially if it's behind a container network like Docker.

I'm basically abandoning this approach :/

from netfox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.