Skip to content

add webrtc support #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft

Conversation

dank074
Copy link
Contributor

@dank074 dank074 commented Apr 16, 2025

This is still in draft mode since I still gotta finish and polish some stuff. It's a combination of work from previous iterations done by other people (puyo, Maddy, Chris, etc)

In order for the webrtc server to be completely compatible with a Discord client, the webrtc server:

  • Must support using a single peer connections for sending and receiving media. This meant that Janus Video Room plugin was incompatible since they use different connections for sending and receiving
  • Must support server-side ice-lite since the way discord works is that the client is the controlling agent in the ice connection. This meant that libraries such as werift were incompatible
  • Must support the sdp offer deciding the codec payload ids. Mediasoup SFU does not currently support this so if using that library we would only be able to support chromium or firefox, one or the other (they send different payload ids). There's a fork with support for it but it's not anything official

This really limits us to which webrtc libraries we can use. The only Node ones that I found compatible were the abandoned Medooze Media Server library and an outdated fork of MediaSoup. Since these are not good long-term options, I decided to write an abstraction layer between spacebar and the webrtc server implementation that allows us to easily change the implementation without modifying spacebar source. The user can decide to use any implementation by setting an .env variable with the implementation package name and spacebar will attempt to load it. Even if none is configured, spacebar will just disable the webrtc endpoint but continue to start up normally.

This is a sample implementation that works currently: https://github.com/dank074/medooze-spacebar-wrtc
I am also planning on writing one for the Mediasoup fork. The great thing about this setup is that anyone can easily write an implementation using their favorite webrtc library and use it without any modifications to spacebar source.

This PR supports guild voice connections, DM voice connections, as well as Go Live streams

Copy link
Member

@MaddyUnderStars MaddyUnderStars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the few times I've reviewed your work, your code quality has been very high. very easy to read. I haven't had to chance to actually test this, but my quick glance here only gave me a few nitpick issues. thanks for all your work.

@@ -67,6 +67,7 @@
"husky": "^9.1.7",
"prettier": "^3.5.3",
"pretty-quick": "^4.1.1",
"spacebar-webrtc-types": "github:dank074/spacebar-webrtc-types",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once this is merged, it'd be best for the org to take over this repo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, can we somehow get this on npm? some deployment methods dont support using github uris in nodejs packages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that it should be an org repo. Once merged repo will be transferred and it can be published under a spacebar npm account

@MathMan05
Copy link
Contributor

hey, I see a lot of the config is done in .env instead of the config table, is there a reason for it being this way?

@MathMan05
Copy link
Contributor

"VOICE_SERVER_UPDATE" is not sent on join which is needed to know how to connect to the server

@MathMan05
Copy link
Contributor

the server does not notify newly joining people of the people already in voice chats, instead they only know of people they see join while they're online. And I also can't get any connection to work, it gets mostly connected, but not the rest of the way

@dank074
Copy link
Contributor Author

dank074 commented Apr 18, 2025

hey, I see a lot of the config is done in .env instead of the config table, is there a reason for it being this way?

Config values added in this PR are related to either configuring network port or the public ip for the werbtc media server. Since the other previous port-related configs were in .env I figured it was best to keep these there as well

"VOICE_SERVER_UPDATE" is not sent on join which is needed to know how to connect to the server

VOICE_SERVER_UPDATE should only be sent to the client after they request to join a voice channel since it contains their token for connecting to that voice channel

the server does not notify newly joining people of the people already in voice chats, instead they only know of people they see > join while they're online. And I also can't get any connection to work, it gets mostly connected, but not the rest of the way

You mean on page load? yeah currently the previous sent state updates aren't synced with new connections. Need to add this somewhere, not sure where. The connections problems were related to the public ip config and we resolved over DM

@MathMan05
Copy link
Contributor

the issue with VOICE_SERVER_UPDATE is that it's not sent on join, it's only sent after the user joins a voice channel the the second time around.

@CE1CECL
Copy link

CE1CECL commented Apr 19, 2025

Hey! Nice work!
Just 2 quick questions:

  • Does this webrtc package work with the discord desktop app when you change the endpoint from discord.com to your instance? Discord's desktop app doesn't send SDP info, so I was wondering if your package handles that or not?
  • Does this work on Windows natively? I see it can disable webrtc when unconfigured but since medooze doesn't work on Windows, I'd think no? (Wonder if Medooze can be compiled on win32 using mingw64 or not?)

@dank074
Copy link
Contributor Author

dank074 commented Apr 19, 2025

  • Does this webrtc package work with the discord desktop app when you change the endpoint from discord.com to your instance? Discord's desktop app doesn't send SDP info, so I was wondering if your package handles that or not?

It does not currently. According to the medooze readme the library supports plain RTP transports though, so we could add support for the native udp protocol (which uses encrypted plain rtp packets).

  • Does this work on Windows natively? I see it can disable webrtc when unconfigured but since medooze doesn't work on Windows, I'd think no? (Wonder if Medooze can be compiled on win32 using mingw64 or not?)

Medooze only works on Linux/macos. However, since the media server package is loaded dynamically Windows users can still either start up spacebar without any webrtc support or opt to use an alternative. I'm planning to create an alternative using a mediasoup fork, just haven't gotten to it yet

@MathMan05
Copy link
Contributor

this is looking very promising, I hope the few bugs in this can be ironed out so that spacebar can get working WebRTC :3
Thanks for all of the work on this pull

@dank074 dank074 force-pushed the dev/webrtc-shit branch from 47e91f1 to 8d1fa40 Compare May 7, 2025 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants