Skip to content

[Enhancement]Align peerconnection preparation timeout with the clients#1085

Merged
ipavlidakis merged 3 commits intodevelopfrom
iliaspavlidakis/align-peerconnection-preparation-timeout-with-the-clients
Mar 17, 2026
Merged

[Enhancement]Align peerconnection preparation timeout with the clients#1085
ipavlidakis merged 3 commits intodevelopfrom
iliaspavlidakis/align-peerconnection-preparation-timeout-with-the-clients

Conversation

@ipavlidakis
Copy link
Contributor

@ipavlidakis ipavlidakis commented Mar 17, 2026

🎯 Goal

Align with the other clients on the timeout that we wait the peerconnections to connect.

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change follows zero ⚠️ policy (required)
  • This change should receive manual QA
  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (tutorial, CMS)

Summary by CodeRabbit

  • New Features

    • Added telemetry reporting for various connection flow types (regular, fast, reconnection, and migration) to improve connection monitoring and observability.
  • Improvements

    • Simplified the peer connection readiness join policy by removing the explicit timeout parameter; timeouts are now managed internally with a configurable default.

@ipavlidakis ipavlidakis self-assigned this Mar 17, 2026
@ipavlidakis ipavlidakis requested a review from a team as a code owner March 17, 2026 09:36
@ipavlidakis ipavlidakis added the enhancement New feature or request label Mar 17, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

This PR refactors WebRTC join flow telemetry handling by removing the timeout parameter from WebRTCJoinPolicy.peerConnectionReadinessAware, introducing a new JoinedStateTelemetryReporter for centralized telemetry emission, updating WebRTCCoordinator stage transitions to async with telemetry integration, and moving peer connection readiness timeout to WebRTCConfiguration.

Changes

Cohort / File(s) Summary
Policy API Update
Sources/StreamVideo/WebRTC/v2/Policies/JoinPolicy/WebRTCJoinPolicy.swift
Removed associated timeout value from peerConnectionReadinessAware enum case, converting from parameterized to parameterless variant.
New Telemetry Reporter
Sources/StreamVideo/WebRTC/v2/StateMachine/Components/JoinedStateTelemetryReporter.swift
Introduced new struct for building and reporting telemetry with configurable flow types (regular, fast, rejoin, migrate), duration tracking, and async telemetry emission via SFU adapter.
State Machine Refactoring
Sources/StreamVideo/WebRTC/v2/StateMachine/Stages/WebRTCCoordinator+Joining.swift, Sources/StreamVideo/WebRTC/v2/StateMachine/Stages/WebRTCCoordinator+PeerConnectionPreparing.swift
Replaced inline telemetry reporting and timeout tracking with telemetryReporter integration; made transitionToNextStage async and updated all call sites; removed internal FlowType enum and reportTelemetry method; centralized telemetry logic.
Configuration Update
Sources/StreamVideo/WebRTC/v2/WebRTCConfiguration.swift
Added peerConnectionReadiness: TimeInterval field to Timeout struct with value of 5 seconds in both production and testing initializers.
Call Flow Updates
Sources/StreamVideoSwiftUI/CallViewModel.swift
Updated acceptCall to pass parameterless peerConnectionReadinessAware policy instead of peerConnectionReadinessAware(timeout: 2).
Test API Alignment
StreamVideoSwiftUITests/CallViewModel_Tests.swift, StreamVideoTests/Call/Call_Tests.swift, StreamVideoTests/CallStateMachine/CallStateMachine/Stages/CallStateMachine_JoiningStageTests.swift, StreamVideoTests/Controllers/CallController_Tests.swift, StreamVideoTests/WebRTC/v2/StateMachine/Stages/WebRTCCoordinatorStateMachine_JoiningStageTests.swift, StreamVideoTests/WebRTC/v2/StateMachine/Stages/WebRTCCoordinatorStateMachine_PeerConnectionPreparingStageTests.swift
Updated test cases to use parameterless peerConnectionReadinessAware policy; modified assertions to remove timeout validation; updated stage initialization to use telemetryReporter instead of timeout parameter; added telemetry verification assertions where applicable.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Hops rejoice! Telemetry consolidated,
Async flows, timeouts relocated,
State machines dance with newfound grace,
A cleaner joining flow takes place! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: removing the timeout parameter from peerConnectionReadinessAware and centralizing timeout configuration. The enhancement aligns peer connection preparation timeouts with a configurable, client-wide setting.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch iliaspavlidakis/align-peerconnection-preparation-timeout-with-the-clients
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@Sources/StreamVideo/WebRTC/v2/StateMachine/Components/JoinedStateTelemetryReporter.swift`:
- Around line 42-45: In JoinedStateTelemetryReporter.swift the switch's .fast
branch shadows the outer reconnection variable and builds a new
Stream_Video_Sfu_Signal_Reconnection without setting timeSeconds, causing zero
durations to be reported; change the .fast case to reuse the existing
reconnection variable (do not redeclare it), set reconnection.strategy = .fast
(keeping reconnection.timeSeconds already assigned) and return
.reconnection(reconnection) so the real duration is preserved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8fe9e89f-f8e5-432d-b9a6-e19ef6cecc10

📥 Commits

Reviewing files that changed from the base of the PR and between 3fef2ff and 38c9246.

📒 Files selected for processing (12)
  • Sources/StreamVideo/WebRTC/v2/Policies/JoinPolicy/WebRTCJoinPolicy.swift
  • Sources/StreamVideo/WebRTC/v2/StateMachine/Components/JoinedStateTelemetryReporter.swift
  • Sources/StreamVideo/WebRTC/v2/StateMachine/Stages/WebRTCCoordinator+Joining.swift
  • Sources/StreamVideo/WebRTC/v2/StateMachine/Stages/WebRTCCoordinator+PeerConnectionPreparing.swift
  • Sources/StreamVideo/WebRTC/v2/WebRTCConfiguration.swift
  • Sources/StreamVideoSwiftUI/CallViewModel.swift
  • StreamVideoSwiftUITests/CallViewModel_Tests.swift
  • StreamVideoTests/Call/Call_Tests.swift
  • StreamVideoTests/CallStateMachine/CallStateMachine/Stages/CallStateMachine_JoiningStageTests.swift
  • StreamVideoTests/Controllers/CallController_Tests.swift
  • StreamVideoTests/WebRTC/v2/StateMachine/Stages/WebRTCCoordinatorStateMachine_JoiningStageTests.swift
  • StreamVideoTests/WebRTC/v2/StateMachine/Stages/WebRTCCoordinatorStateMachine_PeerConnectionPreparingStageTests.swift

Comment on lines +42 to +45
case .fast:
var reconnection = Stream_Video_Sfu_Signal_Reconnection()
reconnection.strategy = .fast
return .reconnection(reconnection)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Bug: .fast case creates a new reconnection without timeSeconds.

The .fast case shadows the outer reconnection variable and creates a new one without setting timeSeconds. This means fast reconnection telemetry will report timeSeconds = 0 instead of the actual duration, unlike .rejoin and .migrate which correctly reuse the outer variable.

🐛 Proposed fix
             case .fast:
-                var reconnection = Stream_Video_Sfu_Signal_Reconnection()
+                reconnection.strategy = .fast
-                reconnection.strategy = .fast
                 return .reconnection(reconnection)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@Sources/StreamVideo/WebRTC/v2/StateMachine/Components/JoinedStateTelemetryReporter.swift`
around lines 42 - 45, In JoinedStateTelemetryReporter.swift the switch's .fast
branch shadows the outer reconnection variable and builds a new
Stream_Video_Sfu_Signal_Reconnection without setting timeSeconds, causing zero
durations to be reported; change the .fast case to reuse the existing
reconnection variable (do not redeclare it), set reconnection.strategy = .fast
(keeping reconnection.timeSeconds already assigned) and return
.reconnection(reconnection) so the real duration is preserved.

@Stream-SDK-Bot
Copy link
Collaborator

SDK Size

title develop branch diff status
StreamVideo 10.12 MB 10.12 MB 0 KB 🟢
StreamVideoSwiftUI 2.45 MB 2.45 MB 0 KB 🟢
StreamVideoUIKit 2.58 MB 2.58 MB 0 KB 🟢
StreamWebRTC 11.09 MB 11.09 MB 0 KB 🟢

@Stream-SDK-Bot
Copy link
Collaborator

StreamVideo XCSize

Object Diff (bytes)
JoinedStateTelemetryReporter.o +5445
WebRTCCoordinator+Joining.o -4960
WebRTCCoordinator+PeerConnectionPreparing.o +1324
WebRTCJoinPolicy.o +507
Call+Stage.o -272
WebRTCCoordinator+Stage.o -80

@Stream-SDK-Bot
Copy link
Collaborator

StreamVideoSwiftUI XCSize

Object Diff (bytes)
CallViewModel.o -208
ViewFactory.o -68

@github-actions
Copy link

Public Interface

 public enum WebRTCJoinPolicy: Sendable  
-   case peerConnectionReadinessAware(timeout: TimeInterval)
+   case peerConnectionReadinessAware

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
7.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@ipavlidakis ipavlidakis merged commit 1a9686b into develop Mar 17, 2026
12 of 13 checks passed
@ipavlidakis ipavlidakis deleted the iliaspavlidakis/align-peerconnection-preparation-timeout-with-the-clients branch March 17, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants