(track *webrtc.TrackLocalStaticSample, path string, opts ...AddTrackOption)
| 886 | } |
| 887 | |
| 888 | func (c *RTCClient) AddTrack(track *webrtc.TrackLocalStaticSample, path string, opts ...AddTrackOption) (writer TrackWriter, err error) { |
| 889 | select { |
| 890 | case <-c.transportReady: |
| 891 | case <-c.ctx.Done(): |
| 892 | return nil, c.ctx.Err() |
| 893 | } |
| 894 | var params AddTrackParams |
| 895 | for _, opt := range opts { |
| 896 | opt(¶ms) |
| 897 | } |
| 898 | trackType := livekit.TrackType_AUDIO |
| 899 | if track.Kind() == webrtc.RTPCodecTypeVideo { |
| 900 | trackType = livekit.TrackType_VIDEO |
| 901 | } |
| 902 | |
| 903 | sender, _, err := c.publisher.AddTrack(track, types.AddTrackParams{}, nil, rtc.RTCPFeedbackConfig{}) |
| 904 | if err != nil { |
| 905 | logger.Errorw( |
| 906 | "add track failed", err, |
| 907 | "participant", c.localParticipant.Identity, |
| 908 | "participantID", c.localParticipant.Sid, |
| 909 | "trackID", track.ID(), |
| 910 | ) |
| 911 | return |
| 912 | } |
| 913 | |
| 914 | if err = c.SendAddTrack(track.ID(), track.Codec().MimeType, track.StreamID(), trackType); err != nil { |
| 915 | return |
| 916 | } |
| 917 | |
| 918 | // wait till track published message is received |
| 919 | timeout := time.After(5 * time.Second) |
| 920 | var ti *livekit.TrackInfo |
| 921 | for { |
| 922 | select { |
| 923 | case <-timeout: |
| 924 | return nil, errors.New("could not publish track after timeout") |
| 925 | default: |
| 926 | c.lock.Lock() |
| 927 | ti = c.pendingPublishedTracks[track.ID()] |
| 928 | if ti != nil { |
| 929 | delete(c.pendingPublishedTracks, track.ID()) |
| 930 | c.lock.Unlock() |
| 931 | break |
| 932 | } |
| 933 | c.lock.Unlock() |
| 934 | time.Sleep(50 * time.Millisecond) |
| 935 | } |
| 936 | if ti != nil { |
| 937 | break |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | c.lock.Lock() |
| 942 | defer c.lock.Unlock() |
| 943 | |
| 944 | c.localTracks[ti.Sid] = track |
| 945 | c.trackSenders[ti.Sid] = sender |
no test coverage detected