MCPcopy
hub / github.com/livekit/livekit / Create

Method Create

pkg/service/roommanager_service.go:45–165  ·  view source on GitHub ↗
(ctx context.Context, req *rpc.WHIPCreateRequest)

Source from the content-addressed store, hash-verified

43}
44
45func (s whipService) Create(ctx context.Context, req *rpc.WHIPCreateRequest) (*rpc.WHIPCreateResponse, error) {
46 pi, err := routing.ParticipantInitFromStartSession(req.StartSession, s.RoomManager.currentNode.Region())
47 if err != nil {
48 logger.Errorw("whip service: could not create participant init", err)
49 return nil, err
50 }
51
52 prometheus.IncrementParticipantRtcInit(1)
53
54 if err = s.RoomManager.StartSession(
55 ctx,
56 *pi,
57 routing.NewNullMessageSource(livekit.ConnectionID(req.StartSession.ConnectionId)), // no requestSource
58 routing.NewNullMessageSink(livekit.ConnectionID(req.StartSession.ConnectionId)), // no responseSink
59 true, // useOneShotSignallingMode
60 ); err != nil {
61 logger.Errorw("whip service: could not start session", err)
62 return nil, err
63 }
64
65 room := s.RoomManager.GetRoom(ctx, livekit.RoomName(req.StartSession.RoomName))
66 if room == nil {
67 logger.Errorw("whip service: could not find room", nil, "room", req.StartSession.RoomName)
68 return nil, ErrRoomNotFound
69 }
70
71 lp := room.GetParticipant(pi.Identity)
72 if lp == nil {
73 room.Logger().Errorw("whip service: could not find local participant", nil, "participant", pi.Identity)
74 return nil, ErrParticipantNotFound
75 }
76
77 if err := lp.HandleOffer(&livekit.SessionDescription{
78 Type: webrtc.SDPTypeOffer.String(),
79 Sdp: req.OfferSdp,
80 Id: 0,
81 }); err != nil {
82 lp.GetLogger().Errorw("whip service: could not handle offer", err)
83 return nil, err
84 }
85
86 // wait for subscriptions to resolve
87 // NOTE: this is outside the WHIP spec, but added as a convenience for clients doing
88 // one-shot signalling (i. e. send an offer and get an answer once) to publish and subscribe to
89 // well-known tracks (i. e. remote participant identity and track names are well known)
90 eg, _ := errgroup.WithContext(ctx)
91 for publisherIdentity, trackList := range req.SubscribedParticipantTracks {
92 for _, trackName := range trackList.TrackNames {
93 eg.Go(func() error {
94 for {
95 if lp.IsTrackNameSubscribed(livekit.ParticipantIdentity(publisherIdentity), trackName) {
96 return nil
97 }
98 time.Sleep(50 * time.Millisecond)
99 }
100 })
101 }
102 }

Callers 2

handleCreateMethod · 0.80
startServerFunction · 0.80

Calls 15

notifySessionMethod · 0.95
NewNullMessageSourceFunction · 0.92
NewNullMessageSinkFunction · 0.92
StartSessionMethod · 0.80
getFirstKeyPairMethod · 0.80
RegionMethod · 0.65
ConnectionIDMethod · 0.65
GetRoomMethod · 0.65

Tested by

no test coverage detected