feat: Add streaming support (#125)

This adds:
- [x] Keyboard and mouse handling on the frontend
- [x] Video and audio streaming from the backend to the frontend
- [x] Input server that works with Websockets

Update - 17/11
- [ ] Master docker container to run this
- [ ] Steam runtime
- [ ] Entrypoint.sh

---------

Co-authored-by: Kristian Ollikainen <14197772+DatCaptainHorse@users.noreply.github.com>
Co-authored-by: Kristian Ollikainen <DatCaptainHorse@users.noreply.github.com>
This commit is contained in:
Wanjohi
2024-12-08 14:54:56 +03:00
committed by GitHub
parent 5eb21eeadb
commit 379db1c87b
137 changed files with 12737 additions and 5234 deletions

View File

@@ -0,0 +1,69 @@
package relay
import (
"fmt"
"github.com/google/uuid"
"github.com/pion/webrtc/v4"
"math/rand"
)
type Participant struct {
ID uuid.UUID //< Internal IDs are useful to keeping unique internal track and not have conflicts later
Name string
WebSocket *SafeWebSocket
PeerConnection *webrtc.PeerConnection
DataChannel *NestriDataChannel
}
func NewParticipant(ws *SafeWebSocket) *Participant {
return &Participant{
ID: uuid.New(),
Name: createRandomName(),
WebSocket: ws,
}
}
func (vw *Participant) addTrack(trackLocal *webrtc.TrackLocal) error {
rtpSender, err := vw.PeerConnection.AddTrack(*trackLocal)
if err != nil {
return err
}
go func() {
rtcpBuffer := make([]byte, 1400)
for {
if _, _, rtcpErr := rtpSender.Read(rtcpBuffer); rtcpErr != nil {
return
}
}
}()
return nil
}
func (vw *Participant) signalOffer() error {
if vw.PeerConnection == nil {
return fmt.Errorf("peer connection is nil for participant: '%s' - cannot signal offer", vw.ID)
}
offer, err := vw.PeerConnection.CreateOffer(nil)
if err != nil {
return err
}
err = vw.PeerConnection.SetLocalDescription(offer)
if err != nil {
return err
}
return vw.WebSocket.SendSDPMessageWS(offer)
}
var namesFirst = []string{"Happy", "Sad", "Angry", "Calm", "Excited", "Bored", "Confused", "Confident", "Curious", "Depressed", "Disappointed", "Embarrassed", "Energetic", "Fearful", "Frustrated", "Glad", "Guilty", "Hopeful", "Impatient", "Jealous", "Lonely", "Motivated", "Nervous", "Optimistic", "Pessimistic", "Proud", "Relaxed", "Shy", "Stressed", "Surprised", "Tired", "Worried"}
var namesSecond = []string{"Dragon", "Unicorn", "Troll", "Goblin", "Elf", "Dwarf", "Ogre", "Gnome", "Mermaid", "Siren", "Vampire", "Ghoul", "Werewolf", "Minotaur", "Centaur", "Griffin", "Phoenix", "Wyvern", "Hydra", "Kraken"}
func createRandomName() string {
randomFirst := namesFirst[rand.Intn(len(namesFirst))]
randomSecond := namesSecond[rand.Intn(len(namesSecond))]
return randomFirst + " " + randomSecond
}