mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
🔥 🔥 Yes lots of commits because rebasing and all.. thankfully I know Git just enough to have backups 😅 --------- Co-authored-by: Wanjohi <elviswanjohi47@gmail.com> Co-authored-by: Kristian Ollikainen <DatCaptainHorse@users.noreply.github.com> Co-authored-by: Wanjohi <71614375+wanjohiryan@users.noreply.github.com> Co-authored-by: AquaWolf <3daquawolf@gmail.com>
70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
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 {
|
|
break
|
|
}
|
|
}
|
|
}()
|
|
|
|
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
|
|
}
|