mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-26 07:08:11 +00:00
fix(jitsi): keep bytestream endpoints alive
This commit is contained in:
@@ -316,6 +316,13 @@ func (s *Session) joinAndOpenBridge(ctx context.Context) (*j.Session, error) {
|
||||
}
|
||||
|
||||
func (s *Session) shouldNegotiatePC() bool {
|
||||
if s.onData != nil {
|
||||
return true
|
||||
}
|
||||
return s.shouldRequestVideo()
|
||||
}
|
||||
|
||||
func (s *Session) shouldRequestVideo() bool {
|
||||
s.videoTrackMu.RLock()
|
||||
defer s.videoTrackMu.RUnlock()
|
||||
return len(s.videoTracks) > 0 || s.onVideoTrack != nil
|
||||
@@ -472,9 +479,11 @@ func (s *Session) negotiatePC(ctx context.Context, jSess *j.Session) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Tell JVB to forward video streams to this endpoint.
|
||||
if err := jSess.RequestVideo(ctx, 720); err != nil {
|
||||
logger.Debugf("jitsi: request video: %v", err)
|
||||
if s.shouldRequestVideo() {
|
||||
// Tell JVB to forward video streams to this endpoint.
|
||||
if err := jSess.RequestVideo(ctx, 720); err != nil {
|
||||
logger.Debugf("jitsi: request video: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
s.pcMu.Lock()
|
||||
|
||||
@@ -93,6 +93,57 @@ func TestNewSucceeds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteStreamNegotiatesPeerConnectionWithoutRequestingVideo(t *testing.T) {
|
||||
sess, err := New(context.Background(), engine.Config{
|
||||
URL: testHost,
|
||||
Extra: map[string]string{credentialKeyRoom: testRoom},
|
||||
OnData: func([]byte) {},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New: %v", err)
|
||||
}
|
||||
defer func() { _ = sess.Close() }()
|
||||
|
||||
js, ok := sess.(*Session)
|
||||
if !ok {
|
||||
t.Fatal("sess is not *Session")
|
||||
}
|
||||
if !js.shouldNegotiatePC() {
|
||||
t.Fatal("shouldNegotiatePC() = false for bytestream session")
|
||||
}
|
||||
if js.shouldRequestVideo() {
|
||||
t.Fatal("shouldRequestVideo() = true for bytestream-only session")
|
||||
}
|
||||
}
|
||||
|
||||
func TestVideoSessionNegotiatesPeerConnectionAndRequestsVideo(t *testing.T) {
|
||||
sess, err := New(context.Background(), engine.Config{
|
||||
URL: testHost,
|
||||
Extra: map[string]string{credentialKeyRoom: testRoom},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("New: %v", err)
|
||||
}
|
||||
defer func() { _ = sess.Close() }()
|
||||
|
||||
js, ok := sess.(*Session)
|
||||
if !ok {
|
||||
t.Fatal("sess is not *Session")
|
||||
}
|
||||
if js.shouldNegotiatePC() {
|
||||
t.Fatal("shouldNegotiatePC() = true before bytestream/video is configured")
|
||||
}
|
||||
if err := js.AddVideoTrack(nil); err != nil {
|
||||
t.Fatalf("AddVideoTrack(nil): %v", err)
|
||||
}
|
||||
if !js.shouldNegotiatePC() {
|
||||
t.Fatal("shouldNegotiatePC() = false for video session")
|
||||
}
|
||||
if !js.shouldRequestVideo() {
|
||||
t.Fatal("shouldRequestVideo() = false for video session")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendBeforeConnect(t *testing.T) {
|
||||
sess, err := New(context.Background(), engine.Config{
|
||||
URL: testHost,
|
||||
|
||||
Reference in New Issue
Block a user