Skip to content

fix: integers not properly casted in WASM builds#1216

Open
OutdatedGuy wants to merge 3 commits into
GetStream:mainfrom
OutdatedGuy:fix/wasm-casting
Open

fix: integers not properly casted in WASM builds#1216
OutdatedGuy wants to merge 3 commits into
GetStream:mainfrom
OutdatedGuy:fix/wasm-casting

Conversation

@OutdatedGuy
Copy link
Copy Markdown
Contributor

@OutdatedGuy OutdatedGuy commented Apr 17, 2026

🎯 Goal

Cast dynamic values to num first before casting them to int to avoid below error:

Type 'int' is not a subtype of type 'double' in type cast

See flutter/flutter#159400

🛠 Implementation details

Update all dynamic values implicitly casted to int? as:

(value as num?)?.toInt()

🎨 UI Changes

Add relevant screenshots

Before After
img img

Add relevant videos

Before After

🧪 Testing

Run the example app and watch sea of type casting errors in browser's console. Use the updated code and see no errors are printed (aside from type casting errors in dart_webrtc)

Provide a patch below if it is necessary for testing

Provide the patch summary here
Provide the patch code here

☑️Contributor Checklist

General

  • Assigned a person / code owner group (required)
  • Thread with the PR link started in a respective Slack channel (#flutter-team) (required)
  • PR is linked to the GitHub issue it resolves

☑️Reviewer Checklist

  • Sample runs & works
  • UI Changes correct (before & after images)
  • Bugs validated (bugfixes)
  • New feature tested and works
  • All code we touched has new or updated Documentation

Summary by CodeRabbit

  • Bug Fixes
    • Improved robustness of WebRTC data parsing across the platform: numeric fields in audio/video metrics, codec info, ICE candidate and candidate-pair stats, inbound/outbound RTP streams, media track metrics, video source dimensions, and track settings are now parsed more defensively to reduce type- and null-related parsing errors and improve stability of real-time statistics and media reporting.

@OutdatedGuy OutdatedGuy requested a review from a team as a code owner April 17, 2026 15:18
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c369f50f-5d00-45dc-bc70-5b62c6e1f1bc

📥 Commits

Reviewing files that changed from the base of the PR and between d75dd9d and a760f9c.

📒 Files selected for processing (1)
  • packages/stream_video/lib/src/webrtc/rtc_manager.dart

📝 Walkthrough

Walkthrough

Multiple fromJson implementations and one RTC utility were updated to coerce numeric JSON values via (value[...] as num?)?.toInt() (or equivalent), replacing direct dynamic assignments to enforce null-safe int conversion during deserialization.

Changes

Cohort / File(s) Summary
Health Check & Manager Utilities
packages/stream_video/lib/src/coordinator/open_api/event/health_check.dart, packages/stream_video/lib/src/webrtc/rtc_manager.dart
Me.fromJson and RtcLocalTrack<VideoConstraints>.getVideoDimension() now cast numeric inputs through num and call toInt() before assigning.
RTC Stats - Codec & Video Source
packages/stream_video/lib/src/webrtc/model/stats/rtc_codec.dart, packages/stream_video/lib/src/webrtc/model/stats/rtc_video_source.dart
fromJson now converts numeric fields (payloadType, clockRate, width, height, frames) via nullable numtoInt().
RTC Stats - ICE Candidates & Pairs
packages/stream_video/lib/src/webrtc/model/stats/rtc_ice_candidate.dart, packages/stream_video/lib/src/webrtc/model/stats/rtc_ice_candidate_pair.dart
Candidate and pair numeric fields (e.g., port, priority, requestsSent, bytesReceived, etc.) now use (value[...] as num?)?.toInt() for safer parsing.
RTC Stats - Inbound Streams
packages/stream_video/lib/src/webrtc/model/stats/rtc_inbound_rtp_audio_stream.dart, packages/stream_video/lib/src/webrtc/model/stats/rtc_inbound_rtp_video_stream.dart
Multiple integer-like fields (e.g., packetsLost, ssrc, qpSum, keyFramesDecoded, etc.) are now parsed via nullable numtoInt().
RTC Stats - Outbound Streams
packages/stream_video/lib/src/webrtc/model/stats/rtc_outbound_rtp_audio_stream.dart, packages/stream_video/lib/src/webrtc/model/stats/rtc_outbound_rtp_video_stream.dart
Outbound stream fromJson methods now coerce many numeric fields (bytesSent, packetsSent, framesEncoded, qpSum, etc.) through num to int.
RTC Stats - Media Tracks
packages/stream_video/lib/src/webrtc/model/stats/rtc_media_stream_track_local_video.dart, packages/stream_video/lib/src/webrtc/model/stats/rtc_media_stream_track_receiver_audio.dart, packages/stream_video/lib/src/webrtc/model/stats/rtc_media_stream_track_remote_video.dart
Media track parsing updated to convert numeric fields (frameHeight, frameWidth, framesSent, concealedSamples, etc.) using nullable numtoInt().
RTC Stats - Remote Inbound Streams
packages/stream_video/lib/src/webrtc/model/stats/rtc_remote_inbound_rtp_audio_stream.dart, packages/stream_video/lib/src/webrtc/model/stats/rtc_remote_inbound_rtp_video_stream.dart
Remote inbound stream deserialization now coerces ssrc, packetsLost, roundTripTimeMeasurements via (value[...] as num?)?.toInt().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibble bytes and hop through streams,
Numbers wobble, dance in parsing dreams,
From dynamic to num, then toInt() I peep,
Safe integers tucked in burrows deep,
Hooray—no surprises in the heap! 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: fixing integer casting issues specific to WASM builds by improving type safety in numeric conversions.
Description check ✅ Passed The description covers the Goal and Implementation details well, clearly explaining the casting pattern change. However, UI changes section is incomplete (no images/videos provided), Testing section lacks the promised patch, and Contributor/Reviewer checklists remain empty without assignments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@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 `@packages/stream_video/lib/src/webrtc/rtc_manager.dart`:
- Around line 1642-1651: The type guards for settings['width'] and
settings['height'] currently use `is int`, which skips values like 1280.0 on
WASM; change those checks to `is num` so both int and double values are
accepted, ensuring the code enters the dimension.copyWith(...) branches and the
(settings['...'] as num).toInt() conversion is executed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e40e7241-9ffc-47ab-abd5-f70f1f6436b5

📥 Commits

Reviewing files that changed from the base of the PR and between 5201b9b and d75dd9d.

📒 Files selected for processing (15)
  • packages/stream_video/lib/src/coordinator/open_api/event/health_check.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_codec.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_ice_candidate.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_ice_candidate_pair.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_inbound_rtp_audio_stream.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_inbound_rtp_video_stream.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_media_stream_track_local_video.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_media_stream_track_receiver_audio.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_media_stream_track_remote_video.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_outbound_rtp_audio_stream.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_outbound_rtp_video_stream.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_remote_inbound_rtp_audio_stream.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_remote_inbound_rtp_video_stream.dart
  • packages/stream_video/lib/src/webrtc/model/stats/rtc_video_source.dart
  • packages/stream_video/lib/src/webrtc/rtc_manager.dart

Comment thread packages/stream_video/lib/src/webrtc/rtc_manager.dart Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 0% with 123 lines in your changes missing coverage. Please review.
✅ Project coverage is 5.78%. Comparing base (5201b9b) to head (a760f9c).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...rtc/model/stats/rtc_outbound_rtp_video_stream.dart 0.00% 21 Missing ⚠️
...brtc/model/stats/rtc_inbound_rtp_audio_stream.dart 0.00% 17 Missing ⚠️
...brtc/model/stats/rtc_inbound_rtp_video_stream.dart 0.00% 17 Missing ⚠️
...src/webrtc/model/stats/rtc_ice_candidate_pair.dart 0.00% 13 Missing ⚠️
...l/stats/rtc_media_stream_track_receiver_audio.dart 0.00% 12 Missing ⚠️
...del/stats/rtc_media_stream_track_remote_video.dart 0.00% 9 Missing ⚠️
...rtc/model/stats/rtc_outbound_rtp_audio_stream.dart 0.00% 9 Missing ⚠️
...kages/stream_video/lib/src/webrtc/rtc_manager.dart 0.00% 6 Missing ⚠️
...odel/stats/rtc_media_stream_track_local_video.dart 0.00% 4 Missing ⚠️
...del/stats/rtc_remote_inbound_rtp_audio_stream.dart 0.00% 4 Missing ⚠️
... and 4 more
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #1216      +/-   ##
========================================
- Coverage   5.78%   5.78%   -0.01%     
========================================
  Files        676     676              
  Lines      49235   49251      +16     
========================================
  Hits        2847    2847              
- Misses     46388   46404      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@OutdatedGuy
Copy link
Copy Markdown
Contributor Author

@Brazol let me know if any changes are required :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant