fix(jitsi): keep bytestream endpoints alive

This commit is contained in:
zarazaex69
2026-05-16 20:25:54 +03:00
parent 5d4592f055
commit f51889ac52
2 changed files with 63 additions and 3 deletions

View File

@@ -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()

View File

@@ -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,