freehuntx / godot-matcha

Easy webrtc matchmaking using WebTorrent tracker
MIT License
89 stars 4 forks source link

godot-matcha

Easy webrtc matchmaking using WebTorrent tracker.
This project uses webtorrent to do signaling. This allows you to connect players peer2peer without a server!
I plan on improving this library and add more features. Stay tuned!

Try the demo here

Installation

  1. Copy addons/matcha to your godot project.
  2. For non browser builds: Install webrtc-native
  3. Done!

Usage

Example (Mesh):

extends Node

var mp1 := MatchaRoom.create_mesh_room({ "identifier": "my-unique-game-identifier" })
var mp2 := MatchaRoom.create_mesh_room({ "identifier": "my-unique-game-identifier" })

func _init():
    mp1.peer_joined.connect(func(_id, peer):
        print("(1) Peer connected: ", peer.peer_id)
    )

    mp1.peer_left.connect(func(_id, peer):
        print("(1) Peer disconnected: ", peer.peer_id)
    )

    mp2.peer_joined.connect(func(_id, peer):
        print("(2) Peer connected: ", peer.peer_id)
    )

    mp2.peer_left.connect(func(_id, peer):
        print("(2) Peer disconnected: ", peer.peer_id)
    )

Example (Server/Client):

extends Node

var server := MatchaRoom.create_server_room()
var client := MatchaRoom.create_client_room(server.room_id) # Client must know the room id

func _init():
    server.peer_joined.connect(func(_id, peer):
        print("(server) Peer connected: ", peer.peer_id)
    )

    server.peer_left.connect(func(_id, peer):
        print("(server) Peer disconnected: ", peer.peer_id)
    )

    client.peer_joined.connect(func(_id, peer):
        print("(client) Peer connected: ", peer.peer_id)
    )

    client.peer_left.connect(func(_id, peer):
        print("(client) Peer disconnected: ", peer.peer_id)
    )

Changelog

29. Dec. 2023

26. Dec. 2023

23. Dec. 2023

Thanks to

dmotz - https://github.com/dmotz/trystero

I got the idea for using webtorrent for signaling from that project.
Big thanks :)