Skip to content

Commit 8002e09

Browse files
authored
Merge pull request #45 from GetStream/feat/screenshare-events
feat: added events on rtc side to handle screen share
2 parents 4055b1a + 71c625f commit 8002e09

File tree

10 files changed

+51
-17
lines changed

10 files changed

+51
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
# Changelog
33

4+
[1.0.13] - 2025-10-28
5+
* Exposed `eventStream` in `MediaDevices`.
6+
* [Android] Sends event when screen capture ends.
7+
48
[1.0.12] - 2025-09-30
59
* [Android] Changed the configuration used when creating EGL rendering context to one that supports alpha channel to fix an issue with Impeller blending background with video texture on some devices.
610
* [Android] Migrate from onSurfaceDestroyed to onSurfaceCleanup for SurfaceProducer.Callback.

android/src/main/java/io/getstream/webrtc/flutter/GetUserMediaImpl.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class GetUserMediaImpl {
9696
private static final int DEFAULT_HEIGHT = 720;
9797
private static final int DEFAULT_FPS = 30;
9898

99+
private static final String EVENT_DISPLAY_MEDIA_STOPPED = "screenSharingStopped";
99100
private static final String PERMISSION_AUDIO = Manifest.permission.RECORD_AUDIO;
100101
private static final String PERMISSION_VIDEO = Manifest.permission.CAMERA;
101102
private static final String PERMISSION_SCREEN = "android.permission.MediaProjection";
@@ -519,19 +520,24 @@ private void getDisplayMedia(final Result result, final MediaStream mediaStream,
519520
/* Create ScreenCapture */
520521
VideoTrack displayTrack = null;
521522
VideoCapturer videoCapturer = null;
522-
videoCapturer =
523-
new OrientationAwareScreenCapturer(
524-
applicationContext,
525-
mediaProjectionData,
526-
new MediaProjection.Callback() {
527-
@Override
528-
public void onStop() {
529-
super.onStop();
530-
// After Huawei P30 and Android 10 version test, the onstop method is called, which will not affect the next process,
531-
// and there is no need to call the resulterror method
532-
//resultError("MediaProjection.Callback()", "User revoked permission to capture the screen.", result);
533-
}
534-
});
523+
String trackId = stateProvider.getNextTrackUUID();
524+
525+
videoCapturer = new OrientationAwareScreenCapturer(
526+
applicationContext,
527+
mediaProjectionData,
528+
new MediaProjection.Callback() {
529+
@Override
530+
public void onStop() {
531+
super.onStop();
532+
533+
ConstraintsMap params = new ConstraintsMap();
534+
params.putString("event", EVENT_DISPLAY_MEDIA_STOPPED);
535+
params.putString("trackId", trackId);
536+
FlutterWebRTCPlugin.sharedSingleton.sendEvent(params.toMap());
537+
}
538+
}
539+
);
540+
535541
if (videoCapturer == null) {
536542
resultError("screenRequestPermissions", "GetDisplayMediaFailed, User revoked permission to capture the screen.", result);
537543
return;
@@ -563,7 +569,6 @@ public void onStop() {
563569
videoCapturer.startCapture(info.width, info.height, info.fps);
564570
Log.d(TAG, "OrientationAwareScreenCapturer.startCapture: " + info.width + "x" + info.height + "@" + info.fps);
565571

566-
String trackId = stateProvider.getNextTrackUUID();
567572
mVideoCapturers.put(trackId, info);
568573
mVideoSources.put(trackId, videoSource);
569574

common/darwin/Classes/FlutterWebRTCPlugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ typedef void (^CapturerStopHandler)(CompletionHandler _Nonnull handler);
9797
- (RTCRtpSender* _Nullable)getRtpSenderById:(RTCPeerConnection* _Nonnull)peerConnection
9898
Id:(NSString* _Nonnull)Id;
9999

100+
- (void)postEventWithName:(NSString* _Nonnull)eventName data:(NSDictionary* _Nullable)data;
101+
100102
+ (FlutterWebRTCPlugin* _Nullable)sharedSingleton;
101103

102104
@end

common/darwin/Classes/FlutterWebRTCPlugin.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,4 +2503,19 @@ - (FlutterRTCVideoRenderer *)findRendererByTrackId:(NSString *)trackId {
25032503
}
25042504
return nil;
25052505
}
2506+
2507+
#pragma mark - Event Posting Helper
2508+
2509+
- (void)postEventWithName:(NSString*)eventName data:(NSDictionary*)data {
2510+
if (!self.eventSink) {
2511+
return;
2512+
}
2513+
2514+
NSMutableDictionary* eventData = [NSMutableDictionary dictionaryWithObject:eventName forKey:@"event"];
2515+
if (data) {
2516+
[eventData addEntriesFromDictionary:data];
2517+
}
2518+
2519+
postEvent(self.eventSink, eventData);
2520+
}
25062521
@end

ios/stream_webrtc_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'stream_webrtc_flutter'
6-
s.version = '1.0.12'
6+
s.version = '1.0.13'
77
s.summary = 'Flutter WebRTC plugin for iOS.'
88
s.description = <<-DESC
99
A new flutter plugin project.

lib/src/native/factory_impl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,6 @@ DesktopCapturer get desktopCapturer => DesktopCapturerNative.instance;
187187
MediaDevices get mediaDevices => MediaDeviceNative.instance;
188188

189189
FrameCryptorFactory get frameCryptorFactory => FrameCryptorFactoryImpl.instance;
190+
191+
Stream<Map<String, dynamic>> get eventStream =>
192+
MediaDeviceNative.instance.eventStream;

lib/src/native/mediadevices_impl.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class MediaDeviceNative extends MediaDevices {
1919

2020
static final MediaDeviceNative instance = MediaDeviceNative._internal();
2121

22+
Stream<Map<String, dynamic>> get eventStream =>
23+
FlutterWebRTCEventChannel.instance.handleEvents.stream;
24+
2225
void handleEvent(String event, final Map<dynamic, dynamic> map) async {
2326
switch (map['event']) {
2427
case 'onDeviceChange':

lib/src/web/factory_impl.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ Future<void> handleCallInterruptionCallbacks(
2222
throw UnimplementedError(
2323
'handleCallInterruptionCallbacks() is not supported on web');
2424
}
25+
26+
Stream<Map<String, dynamic>> get eventStream => Stream.empty();

macos/stream_webrtc_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
Pod::Spec.new do |s|
55
s.name = 'stream_webrtc_flutter'
6-
s.version = '1.0.12'
6+
s.version = '1.0.13'
77
s.summary = 'Flutter WebRTC plugin for macOS.'
88
s.description = <<-DESC
99
A new flutter plugin project.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: stream_webrtc_flutter
22
description: Flutter WebRTC plugin for iOS/Android/Destkop/Web, based on GoogleWebRTC.
3-
version: 1.0.12
3+
version: 1.0.13
44
homepage: https://github.com/GetStream/webrtc-flutter
55
environment:
66
sdk: ">=3.6.0 <4.0.0"

0 commit comments

Comments
 (0)