Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BrandonMakin/3ee48b4da19521307f5f5703a183a03d to your computer and use it in GitHub Desktop.
Save BrandonMakin/3ee48b4da19521307f5f5703a183a03d to your computer and use it in GitHub Desktop.
GSoC 2018 Final Submission - Brandon Makin - WebRTC in Godot
My project was to allow users of the Godot game engine to create multiplayer games by connecting players via WebRTC using Godot's existing multiplayer APIs.
Godot's core can be extended by adding modules - essentially plugins that are compiled with the engine. I created a WebRTC module that can be found here:
https://github.com/BrandonMakin/godot/tree/webrtc_static_final/modules/webrtc
That folder - modules/webrtc/ - represents my work for Google Summer of Code. SConstruct, config.py, are to help the build system compile and were created by my mentor Fabio Alessandrelli. register_types.h and register_types.cpp are there to expose the WebRTCPeer and NetworkedMultiplayerWebRTC classes to Godot's internal scripting and were created by Fabio Alessandrelli and modified by me, Brandon Makin. The rest of the code uses WebRTC's PeerConnectionInterface to implement Godot's multiplayer API. webrtc_peer.h and webrtc_peer.cpp create the WebRTCPeer class, a class that uses Godot's lower-level PacketPeer API. The four files with "observer" in their names hold the implementations for WebRTCPeer's four subclasses that implement WebRTC's observer patterns to provide callbacks after WebRTC events.
The files, networked_multiplayer_webrtc.h and networked_multiplayer_webrtc.cpp, hold the NetworkedMultiplayerWebRTC class, a class that implements Godot's high level multiplayer API, NetworkedMultiplayerPeer, to allow for multiple simultaneous connections from clients to a server.
This code will not be committed to the master branch of Godot. Godot prides itself on being small in both source and binary size as well as being easily customizable. Hence, it has modules, and we chose to build WebRTC as an independent module.
-- HOW TO USE --
Anybody can use the WebRTC godot implementation by adding themselves by including modules/webrtc and thirdparty/webrtc into their copy of the Godot source. The webrtc module can be found here:
They put inside thirdparty/webrtc a compiled WebRTC dynamic library. This is not included so that the repository remains platform-independent. Users may also compile my branch of Godot, seen above. [My branch also contains a websockets lib whith incompatible headers, so if you compile my branch of Godot you must use "scons platform=[platform] module_websockets_enabled=no"]
-- FUTURE WORK --
As the process of using a module is a little too involved for many users, we plan on porting it to a GDNative Extension. Godots GDNative allows us to create our C++ extension, compile it as a dynamic library, and allow users to drop it into their Godot projects and use it with ease. I was unable to complete this within the scope of Google Summer of Code. My current progress can be seen in my repository here:
https://github.com/BrandonMakin/webrtc-native
Once the WebRTC GDNative extension is complete, it will be available in an official Godot repository here:
https://github.com/godotengine/webrtc-native
We will then make a pull request to Godot adding support for GDNative extensions' access to network APIs, designed by my mentor Fabio Alessandrelli and available here:
https://github.com/Faless/godot/tree/webrtc_module/modules/webrtc
In the above link, my mentor provides a cleaned up version of the WebRTC interfaces I created in WebRTCPeer and NetworkedMultiplayerWebRTC in such a way that GDNative extensions can access it. This also provides his support for WebRTC in the HTML5 export (which had to be done separately to take advantage of WebRTC already existing in web browsers).
@mdswamp
Copy link

mdswamp commented Nov 8, 2018

hi, when i want to compile, i get error on webrtc

scons platform=windows module_websockets_enabled=no

c:\godot-webrtc_static_final\modules\webrtc\webrtc_peer.h(12): fatal error C1083
: Cannot open include file: 'api/peerconnectioninterface.h': No such file or dir
ectory
scons: *** [modules\webrtc\gd_create_session_description_observer.windows.tools.
obj] Error 2
scons: building terminated because of errors.

@mdswamp
Copy link

mdswamp commented Nov 12, 2018

which godot package should i download that contain peerconnectioninterface.h and mediaengine.h ???????????

@derofim
Copy link

derofim commented Jan 16, 2019

which godot package should i download that contain peerconnectioninterface.h and mediaengine.h ???????????

Its from https://chromium.googlesource.com/external/webrtc/+/branch-heads/69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment