* Prevent missing entry in pending tracks Problem: -------- A track received via signalling request `AddTrack` is stored in `pendingTracks` of participant. A MediaTrack is created when `onTrack` fires after `SetRemoteDescription`. At that time, pending tracks are searched to find a matching track and look up an already published MediaTrack. This is because `onTrack` fires once for every layer of Simulcast and MediaTrack abstraction is for a media track and not one for every layer of Simulcast track. To accomplish that, pending tracks are cleaned up 5 seconds after the MediaTrack is created. The theory there is that `onTrack` will fire on all layers within 5 seconds. But, have observed several instances on my slow machine of that firing after 5 seconds which results in the search failing and we end up creating a new MediaTrack. The above is probably the reason (I am guessing though) for subscriber PC having an extra m-line some times. Considered fix: --------------- One possible option is to increase that 5 seconds timeout to a very large value. But, it has another issue. `getPendingTrack` is given the track id which comes in the SDP. Entries are added to the pending tracks using track id received via the `AddTrack` signalling message. And those two need not be the same. Especially Firefox has different ids every time. Not sure if that is something we do on client side which causes that, but it does look like a real possibility. To handle that case, `getPendingTrack` looks up tracks by media kind (audio/video) if the look up by SDP client id fails. Here, it is possible that there are two pending tracks of type video (think camera and screen sharing as an example) and looking up by kind might end up picking the wrong one. Fix: ---- Store the signalled client id and SDP client id in the MediaTrack and look up the published tracks by SDP client id for a track match. If there is no match, create a new MediaTrack and add it to publishedTracks and delete the corresponding pending track all within the lock (yeah not great to have a lot of code within the lock, but this is probably worth it to have the correctness). This does solve the issue of deferred pending track removal causing issues. However, note that kind based look up may do some switching. In a scenario where there are two pending tracks of kind video and the look up has to rely on kind, it is possible that signalCid and sdpCid get cross matched (i. e. client might have sent a signalCid for a Simulcast track, but during kind based look up it gets assigned to a non-simulcast track). I think that is okay as there is no strong correlation between the two. Testing: -------- - Connect from Chrome, Firefox (both orders, Chrome joining first, Firefox joining first) and ensure that media subscriptions and publishing are correct - Ensure that DTX munging works properly too. * Fix tests Add back adding track to publishedTracks for testing purposes. * Add a test to check case of `AddTrack` rejecting already published track * Remove debug. * Address PR comments - do not need to return SDP cid from `getPendingTracks`.
LiveKit - Open source, distributed video/audio rooms over WebRTC
LiveKit is an open source project that provides scalable, multi-user conferencing over WebRTC. It's designed to give you everything you need to build real time video/audio capabilities in your applications.
Features
- Horizontally scalable WebRTC Selective Forwarding Unit (SFU)
- Modern, full-featured client SDKs for JS, iOS, Android, and Flutter
- Built for production - JWT authentication and server APIs
- Robust networking & connectivity, over UDP & TCP
- Easy to deploy - pure Go & single binary
- Advanced features - speaker detection, simulcast, selective subscription, moderation APIs, and webhooks.
Documentation & Guides
Docs & Guides at: https://docs.livekit.io
Try it live
Head to our playground and give it a spin. Build a Zoom-like conferencing app in under 100 lines of code!
SDKs & Tools
Client SDKs:
Server SDKs:
- Javascript (docs)
- Go (docs)
Tools:
Installing
From source
Pre-requisites:
- Go 1.15+ is installed
- GOPATH/bin is in your PATH
Then run
git clone https://github.com/livekit/livekit-server
cd livekit-server
./bootstrap.sh
mage
Docker
LiveKit is published to Docker Hub under livekit/livekit-server
Running
Creating API keys
LiveKit utilizes JWT based access tokens for authentication to all of its APIs. Because of this, the server needs a list of valid API keys and secrets to validate the provided tokens. For more, see Access Tokens guide.
Generate API key/secret pairs with:
./bin/livekit-server generate-keys
or
docker run --rm livekit/livekit-server generate-keys
Store the generate keys in a YAML file like:
APIwLeah7g4fuLYDYAJeaKsSE: 8nTlwISkb-63DPP7OH4e.nw.J44JjicvZDiz8J59EoQ+
Starting the server
In development mode, LiveKit has no external dependencies. You can start LiveKit by passing it the keys it should use in LIVEKIT_KEYS.
LiveKit could also use a config file or config environment variable LIVEKIT_CONFIG
LIVEKIT_KEYS="<key>: <secret>" ./bin/livekit-server --dev
or
docker run --rm \
-p 7880:7880 \
-p 7881:7881 \
-p 7882:7882/udp \
-e LIVEKIT_KEYS="<key>: <secret>" \
livekit/livekit-server \
--dev \
--node-ip=<machine-ip>
When running with docker, --node-ip needs to be set to your machine's local IP address.
The --dev flag turns on log verbosity to make it easier for local debugging/development
Creating a JWT token
To create a join token for clients, livekit-server provides a convenient subcommand to create a development token. This token has an expiration of a month, which is useful for development & testing, but not appropriate for production use.
./bin/livekit-server --key-file <path/to/keyfile> create-join-token --room "myroom" --identity "myidentity"
Sample client
To test your server, you can use our example web client (built with our React component)
Enter generated access token and you are connected to a room!
Deploying for production
LiveKit is deployable to any environment that supports docker, including Kubernetes and Amazon ECS.
See deployment docs at https://docs.livekit.io/guides/deploy
Contributing
We welcome your contributions to make LiveKit better! Please join us on Slack to discuss your ideas and/or submit PRs.
License
LiveKit server is licensed under Apache License v2.0.