react-native-webrtc 106.0.3 → 106.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.github/workflows/android_ci.yml +29 -0
  2. package/.github/workflows/ci.yml +1 -1
  3. package/.github/workflows/ios_ci.yml +50 -0
  4. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +11 -0
  5. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +8 -19
  6. package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +1 -1
  7. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +8 -4
  8. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +5 -0
  9. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +0 -2
  10. package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +35 -0
  11. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +62 -42
  12. package/ios/RCTWebRTC/CaptureController.h +3 -0
  13. package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -0
  14. package/ios/RCTWebRTC/RTCVideoViewManager.m +9 -32
  15. package/ios/RCTWebRTC/ScreenCaptureController.h +1 -0
  16. package/ios/RCTWebRTC/ScreenCaptureController.m +11 -0
  17. package/ios/RCTWebRTC/ScreenCapturer.h +3 -0
  18. package/ios/RCTWebRTC/ScreenCapturer.m +1 -0
  19. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +14 -0
  20. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +38 -0
  21. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +7 -0
  22. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +75 -0
  23. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +19 -11
  24. package/ios/RCTWebRTC/WebRTCModule.h +1 -0
  25. package/ios/RCTWebRTC/WebRTCModule.m +1 -0
  26. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +10 -1
  27. package/lib/commonjs/EventEmitter.js +1 -1
  28. package/lib/commonjs/EventEmitter.js.map +1 -1
  29. package/lib/commonjs/MediaStreamTrack.js +25 -0
  30. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  31. package/lib/commonjs/RTCPeerConnection.js +91 -107
  32. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  33. package/lib/module/EventEmitter.js +1 -1
  34. package/lib/module/EventEmitter.js.map +1 -1
  35. package/lib/module/MediaStreamTrack.js +21 -0
  36. package/lib/module/MediaStreamTrack.js.map +1 -1
  37. package/lib/module/RTCPeerConnection.js +91 -107
  38. package/lib/module/RTCPeerConnection.js.map +1 -1
  39. package/lib/typescript/MediaStreamTrack.d.ts +1 -0
  40. package/lib/typescript/RTCPeerConnection.d.ts +1 -0
  41. package/package.json +1 -1
  42. package/src/EventEmitter.ts +1 -0
  43. package/src/MediaStreamTrack.ts +23 -0
  44. package/src/RTCPeerConnection.ts +99 -112
@@ -0,0 +1,29 @@
1
+ name: Android CI
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ android-compile:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+
14
+ - uses: actions/setup-node@v3
15
+ with:
16
+ node-version: '16.x'
17
+ cache: 'npm'
18
+ cache-dependency-path: '**/package-lock.json'
19
+
20
+ - name: Install node modules
21
+ run: npm install
22
+
23
+ - name: Install example node modules
24
+ run: npm install
25
+ working-directory: ./examples/GumTestApp/
26
+
27
+ - name: Compile Android Example
28
+ run: ./gradlew assembleDebug
29
+ working-directory: ./examples/GumTestApp/android
@@ -7,7 +7,7 @@ jobs:
7
7
  name: Lint
8
8
  runs-on: ubuntu-latest
9
9
  steps:
10
- - uses: actions/checkout@v2
10
+ - uses: actions/checkout@v3
11
11
  - uses: actions/setup-node@v3
12
12
  with:
13
13
  node-version: 16
@@ -0,0 +1,50 @@
1
+ name: iOS CI
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ ios-compile:
10
+ runs-on: macos-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+
14
+ - uses: actions/setup-node@v3
15
+ with:
16
+ node-version: '16.x'
17
+ cache: 'npm'
18
+ cache-dependency-path: '**/package-lock.json'
19
+
20
+ - name: Cache cocoapods
21
+ uses: actions/cache@v3
22
+ with:
23
+ path: ./examples/GumTestApp/ios/Pods
24
+ key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
25
+ restore-keys: |
26
+ ${{ runner.os }}-pods-
27
+
28
+ - name: Install node modules
29
+ run: npm install
30
+
31
+ - name: Install example node modules
32
+ working-directory: ./examples/GumTestApp/
33
+ run: npm install
34
+
35
+ - name: Pod install
36
+ working-directory: ./examples/GumTestApp/ios
37
+ run: pod install
38
+
39
+ - name: Compile iOS Example
40
+ working-directory: ./examples/GumTestApp/ios
41
+ run: |
42
+ set -o pipefail && \
43
+ xcodebuild -workspace GumTestApp.xcworkspace/ \
44
+ -scheme GumTestApp \
45
+ -destination generic/platform=iOS \
46
+ CODE_SIGN_IDENTITY="" \
47
+ CODE_SIGNING_REQUIRED=NO \
48
+ CODE_SIGN_ENTITLEMENTS="" \
49
+ CODE_SIGNING_ALLOWED="NO" clean build \
50
+ | xcpretty
@@ -13,6 +13,8 @@ public abstract class AbstractVideoCaptureController {
13
13
  */
14
14
  protected VideoCapturer videoCapturer;
15
15
 
16
+ protected CapturerEventsListener capturerEventsListener;
17
+
16
18
  public AbstractVideoCaptureController(int width, int height, int fps) {
17
19
  this.width = width;
18
20
  this.height = height;
@@ -65,5 +67,14 @@ public abstract class AbstractVideoCaptureController {
65
67
  }
66
68
  }
67
69
 
70
+ public void setCapturerEventsListener(CapturerEventsListener listener) {
71
+ this.capturerEventsListener = listener;
72
+ }
73
+
68
74
  protected abstract VideoCapturer createVideoCapturer();
75
+
76
+ public interface CapturerEventsListener {
77
+ /** Called when the capturer is ended and in an irrecoverable state. */
78
+ public void onCapturerEnded();
79
+ }
69
80
  }
@@ -128,27 +128,27 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
128
128
  String[] deviceNames = cameraEnumerator.getDeviceNames();
129
129
  List<String> failedDevices = new ArrayList<>();
130
130
 
131
- String name;
131
+ String cameraName = null;
132
132
  try {
133
133
  int index = Integer.parseInt(deviceId);
134
- name = deviceNames[index];
134
+ cameraName = deviceNames[index];
135
135
  } catch (Exception e) {
136
136
  Log.d(TAG, "failed to find device with id: " + deviceId);
137
137
  }
138
138
 
139
139
  // If deviceId is specified, then it takes precedence over facingMode.
140
- if (name != null) {
140
+ if (cameraName != null) {
141
141
  VideoCapturer videoCapturer
142
- = cameraEnumerator.createCapturer(name, cameraEventsHandler);
143
- String message = "Create user-specified camera " + name;
142
+ = cameraEnumerator.createCapturer(cameraName, cameraEventsHandler);
143
+ String message = "Create user-specified camera " + cameraName;
144
144
  if (videoCapturer != null) {
145
145
  Log.d(TAG, message + " succeeded");
146
- this.isFrontFacing = cameraEnumerator.isFrontFacing(name);
146
+ this.isFrontFacing = cameraEnumerator.isFrontFacing(cameraName);
147
147
  return videoCapturer;
148
148
  } else {
149
149
  // fallback to facingMode
150
150
  Log.d(TAG, message + " failed");
151
- failedDevices.add(name);
151
+ failedDevices.add(cameraName);
152
152
  }
153
153
  }
154
154
 
@@ -159,17 +159,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
159
159
  if (failedDevices.contains(name)) {
160
160
  continue;
161
161
  }
162
- try {
163
- // This can throw an exception when using the Camera 1 API.
164
- if (cameraEnumerator.isFrontFacing(name) != isFrontFacing) {
165
- continue;
166
- }
167
- } catch (Exception e) {
168
- Log.e(
169
- TAG,
170
- "Failed to check the facing mode of camera " + name,
171
- e);
172
- failedDevices.add(name);
162
+ if (cameraEnumerator.isFrontFacing(name) != isFrontFacing) {
173
163
  continue;
174
164
  }
175
165
  VideoCapturer videoCapturer
@@ -198,7 +188,6 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
198
188
  } else {
199
189
  Log.d(TAG, message + " failed");
200
190
  failedDevices.add(name);
201
- // fallback to the next device.
202
191
  }
203
192
  }
204
193
  }
@@ -13,7 +13,7 @@ class CameraEventsHandler implements CameraVideoCapturer.CameraEventsHandler {
13
13
  // Callback invoked when camera closed.
14
14
  @Override
15
15
  public void onCameraClosed() {
16
- Log.d(TAG, "CameraEventsHandler.onFirstFrameAvailable");
16
+ Log.d(TAG, "CameraEventsHandler.onCameraClosed");
17
17
  }
18
18
 
19
19
  // Called when camera is disconnected.
@@ -307,7 +307,7 @@ class GetUserMediaImpl {
307
307
  displayMediaPromise = null;
308
308
  }
309
309
 
310
- private void createStream(MediaStreamTrack[] tracks, BiConsumer<String, ArrayList<WritableMap>> successCallback) {
310
+ void createStream(MediaStreamTrack[] tracks, BiConsumer<String, ArrayList<WritableMap>> successCallback) {
311
311
  String streamId = UUID.randomUUID().toString();
312
312
  MediaStream mediaStream = webRTCModule.mFactory.createLocalMediaStream(streamId);
313
313
 
@@ -362,7 +362,7 @@ class GetUserMediaImpl {
362
362
  return createVideoTrack(screenCaptureController);
363
363
  }
364
364
 
365
- private VideoTrack createVideoTrack(AbstractVideoCaptureController videoCaptureController) {
365
+ VideoTrack createVideoTrack(AbstractVideoCaptureController videoCaptureController) {
366
366
  videoCaptureController.initializeVideoCapturer();
367
367
 
368
368
  VideoCapturer videoCapturer = videoCaptureController.videoCapturer;
@@ -380,10 +380,14 @@ class GetUserMediaImpl {
380
380
  return null;
381
381
  }
382
382
 
383
+ String id = UUID.randomUUID().toString();
384
+
385
+ TrackCapturerEventsEmitter eventsEmitter = new TrackCapturerEventsEmitter(webRTCModule, id);
386
+ videoCaptureController.setCapturerEventsListener(eventsEmitter);
387
+
383
388
  VideoSource videoSource = pcFactory.createVideoSource(videoCapturer.isScreencast());
384
389
  videoCapturer.initialize(surfaceTextureHelper, reactContext, videoSource.getCapturerObserver());
385
390
 
386
- String id = UUID.randomUUID().toString();
387
391
  VideoTrack track = pcFactory.createVideoTrack(id, videoSource);
388
392
 
389
393
  track.setEnabled(true);
@@ -499,7 +503,7 @@ class GetUserMediaImpl {
499
503
  }
500
504
  }
501
505
 
502
- private interface BiConsumer<T, U> {
506
+ public interface BiConsumer<T, U> {
503
507
  void accept(T t, U u);
504
508
  }
505
509
  }
@@ -57,6 +57,11 @@ public class ScreenCaptureController extends AbstractVideoCaptureController {
57
57
  public void onStop() {
58
58
  Log.w(TAG, "Media projection stopped.");
59
59
  orientatationListener.disable();
60
+ stopCapture();
61
+
62
+ if(capturerEventsListener != null) {
63
+ capturerEventsListener.onCapturerEnded();
64
+ }
60
65
  }
61
66
  });
62
67
 
@@ -122,8 +122,6 @@ public class SerializeUtils {
122
122
  }
123
123
 
124
124
  public static ReadableMap serializeRtpParameters(RtpParameters params) {
125
- if (params == null) return null;
126
-
127
125
  WritableMap result = Arguments.createMap();
128
126
  WritableArray encodings = Arguments.createArray();
129
127
  WritableArray codecs = Arguments.createArray();
@@ -0,0 +1,35 @@
1
+ package com.oney.WebRTCModule;
2
+
3
+ import android.util.*;
4
+
5
+ import org.webrtc.CapturerObserver;
6
+ import org.webrtc.VideoFrame;
7
+
8
+ import com.facebook.react.bridge.Arguments;
9
+ import com.facebook.react.bridge.WritableMap;
10
+
11
+ /**
12
+ * A capturer observer that emits track ended events when the capturer is stopped.
13
+ */
14
+ public class TrackCapturerEventsEmitter implements AbstractVideoCaptureController.CapturerEventsListener {
15
+
16
+ private static final String TAG = TrackCapturerEventsEmitter.class.getCanonicalName();
17
+
18
+ private final WebRTCModule webRTCModule;
19
+ private final String trackId;
20
+
21
+ public TrackCapturerEventsEmitter(WebRTCModule webRTCModule, String trackId) {
22
+ this.webRTCModule = webRTCModule;
23
+ this.trackId = trackId;
24
+ }
25
+
26
+ /** Notify that the capturer has been stopped. */
27
+ public void onCapturerEnded() {
28
+ WritableMap params = Arguments.createMap();
29
+ params.putString("trackId", trackId);
30
+
31
+ Log.d(TAG, "ended event trackId: " + trackId);
32
+
33
+ webRTCModule.sendEvent("mediaStreamTrackEnded", params);
34
+ }
35
+ }
@@ -470,6 +470,14 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
470
470
  return getUserMediaImpl.getTrack(trackId);
471
471
  }
472
472
 
473
+ public VideoTrack createVideoTrack(AbstractVideoCaptureController videoCaptureController) {
474
+ return getUserMediaImpl.createVideoTrack(videoCaptureController);
475
+ }
476
+
477
+ public void createStream(MediaStreamTrack[] tracks, GetUserMediaImpl.BiConsumer<String, ArrayList<WritableMap>> successCallback) {
478
+ getUserMediaImpl.createStream(tracks, successCallback);
479
+ }
480
+
473
481
  /**
474
482
  * Turns an "options" <tt>ReadableMap</tt> into a <tt>MediaConstraints</tt> object.
475
483
  *
@@ -990,19 +998,22 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
990
998
 
991
999
  @Override
992
1000
  public void onSetSuccess() {
993
- WritableMap newSdpMap = Arguments.createMap();
994
- WritableMap params = Arguments.createMap();
1001
+ ThreadUtils.runOnExecutor(() -> {
1002
+ WritableMap newSdpMap = Arguments.createMap();
1003
+ WritableMap params = Arguments.createMap();
1004
+
1005
+ SessionDescription newSdp = peerConnection.getLocalDescription();
1006
+ // Can happen when doing a rollback.
1007
+ if (newSdp != null) {
1008
+ newSdpMap.putString("type", newSdp.type.canonicalForm());
1009
+ newSdpMap.putString("sdp", newSdp.description);
1010
+ }
995
1011
 
996
- SessionDescription newSdp = peerConnection.getLocalDescription();
997
- // Can happen when doing a rollback.
998
- if (newSdp != null) {
999
- newSdpMap.putString("type", newSdp.type.canonicalForm());
1000
- newSdpMap.putString("sdp", newSdp.description);
1001
- }
1012
+ params.putMap("sdpInfo", newSdpMap);
1013
+ params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1002
1014
 
1003
- params.putMap("sdpInfo", newSdpMap);
1004
- params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1005
- promise.resolve(params);
1015
+ promise.resolve(params);
1016
+ });
1006
1017
  }
1007
1018
 
1008
1019
  @Override
@@ -1011,7 +1022,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1011
1022
 
1012
1023
  @Override
1013
1024
  public void onSetFailure(String s) {
1014
- promise.reject("E_OPERATION_ERROR", s);
1025
+ ThreadUtils.runOnExecutor(() -> {
1026
+ promise.reject("E_OPERATION_ERROR", s);
1027
+ });
1015
1028
  }
1016
1029
  };
1017
1030
 
@@ -1029,61 +1042,64 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1029
1042
  }
1030
1043
 
1031
1044
  @ReactMethod
1032
- public void peerConnectionSetRemoteDescription(ReadableMap sdpMap,
1033
- int id,
1034
- Callback callback) {
1045
+ public void peerConnectionSetRemoteDescription(int id,
1046
+ ReadableMap desc,
1047
+ Promise promise) {
1035
1048
  ThreadUtils.runOnExecutor(() -> {
1036
1049
  PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
1037
1050
  PeerConnection peerConnection = pco.getPeerConnection();
1038
1051
 
1039
1052
  if (peerConnection == null) {
1040
1053
  Log.d(TAG, "peerConnectionSetRemoteDescription() peerConnection is null");
1041
- callback.invoke(false, "peerConnection is null");
1054
+ promise.reject(new Exception("PeerConnection not found"));
1042
1055
  return;
1043
1056
  }
1044
1057
 
1045
1058
  SessionDescription sdp = new SessionDescription(
1046
- SessionDescription.Type.fromCanonicalForm(sdpMap.getString("type")),
1047
- sdpMap.getString("sdp")
1059
+ SessionDescription.Type.fromCanonicalForm(desc.getString("type")),
1060
+ desc.getString("sdp")
1048
1061
  );
1049
1062
 
1050
1063
  List<String> receiversIds = new ArrayList<>();
1051
1064
  for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
1052
1065
  receiversIds.add(transceiver.getReceiver().id());
1053
1066
  }
1054
- peerConnection.setRemoteDescription(new SdpObserver() {
1067
+
1068
+ final SdpObserver observer = new SdpObserver() {
1055
1069
  @Override
1056
1070
  public void onCreateSuccess(final SessionDescription sdp) {
1057
1071
  }
1058
1072
 
1059
1073
  @Override
1060
1074
  public void onSetSuccess() {
1061
- WritableMap newSdpMap = Arguments.createMap();
1062
- WritableMap params = Arguments.createMap();
1075
+ ThreadUtils.runOnExecutor(() -> {
1076
+ WritableMap newSdpMap = Arguments.createMap();
1077
+ WritableMap params = Arguments.createMap();
1078
+
1079
+ SessionDescription newSdp = peerConnection.getRemoteDescription();
1080
+ // Be defensive for the rollback cases.
1081
+ if (newSdp != null) {
1082
+ newSdpMap.putString("type", newSdp.type.canonicalForm());
1083
+ newSdpMap.putString("sdp", newSdp.description);
1084
+ }
1063
1085
 
1064
- SessionDescription newSdp = peerConnection.getRemoteDescription();
1065
- // Be defensive for the rollback cases.
1066
- if (newSdp != null) {
1067
- newSdpMap.putString("type", newSdp.type.canonicalForm());
1068
- newSdpMap.putString("sdp", newSdp.description);
1069
- }
1086
+ params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1087
+ params.putMap("sdpInfo", newSdpMap);
1070
1088
 
1071
- params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1072
- params.putMap("sdpInfo", newSdpMap);
1073
-
1074
- WritableArray newTransceivers = Arguments.createArray();
1075
- for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
1076
- if(!receiversIds.contains(transceiver.getReceiver().id())) {
1077
- WritableMap newTransceiver = Arguments.createMap();
1078
- newTransceiver.putInt("transceiverOrder", pco.getNextTransceiverId());
1079
- newTransceiver.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
1080
- newTransceivers.pushMap(newTransceiver);
1089
+ WritableArray newTransceivers = Arguments.createArray();
1090
+ for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
1091
+ if(!receiversIds.contains(transceiver.getReceiver().id())) {
1092
+ WritableMap newTransceiver = Arguments.createMap();
1093
+ newTransceiver.putInt("transceiverOrder", pco.getNextTransceiverId());
1094
+ newTransceiver.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
1095
+ newTransceivers.pushMap(newTransceiver);
1096
+ }
1081
1097
  }
1082
- }
1083
1098
 
1084
- params.putArray("newTransceivers", newTransceivers);
1099
+ params.putArray("newTransceivers", newTransceivers);
1085
1100
 
1086
- callback.invoke(true, params);
1101
+ promise.resolve(params);
1102
+ });
1087
1103
  }
1088
1104
 
1089
1105
  @Override
@@ -1092,9 +1108,13 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1092
1108
 
1093
1109
  @Override
1094
1110
  public void onSetFailure(String s) {
1095
- callback.invoke(false, s);
1111
+ ThreadUtils.runOnExecutor(() -> {
1112
+ promise.reject("E_OPERATION_ERROR", s);
1113
+ });
1096
1114
  }
1097
- }, sdp);
1115
+ };
1116
+
1117
+ peerConnection.setRemoteDescription(observer, sdp);
1098
1118
  });
1099
1119
  }
1100
1120
 
@@ -6,11 +6,14 @@
6
6
  //
7
7
 
8
8
  #import <Foundation/Foundation.h>
9
+ #import "CapturerEventsDelegate.h"
9
10
 
10
11
  NS_ASSUME_NONNULL_BEGIN
11
12
 
12
13
  @interface CaptureController: NSObject
13
14
 
15
+ @property (nonatomic, strong) id<CapturerEventsDelegate> eventsDelegate;
16
+
14
17
  - (void)startCapture;
15
18
  - (void)stopCapture;
16
19
 
@@ -0,0 +1,12 @@
1
+ #import <WebRTC/RTCVideoCapturer.h>
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ @protocol CapturerEventsDelegate
6
+
7
+ /** Called when the capturer is ended and in an irrecoverable state. */
8
+ - (void)capturerDidEnd:(RTCVideoCapturer *)capturer;
9
+
10
+ @end
11
+
12
+ NS_ASSUME_NONNULL_END
@@ -1,17 +1,7 @@
1
- //
2
- // RTCVideoViewManager.m
3
- // TestReact
4
- //
5
- // Created by one on 2015/9/25.
6
- // Copyright © 2015年 Facebook. All rights reserved.
7
- //
8
1
  #import <AVFoundation/AVFoundation.h>
9
2
  #import <objc/runtime.h>
10
3
 
11
4
  #import <React/RCTLog.h>
12
- #if !TARGET_OS_OSX
13
- #import <WebRTC/RTCEAGLVideoView.h>
14
- #endif
15
5
  #import <WebRTC/RTCMediaStream.h>
16
6
  #if !TARGET_OS_OSX
17
7
  #import <WebRTC/RTCMTLVideoView.h>
@@ -130,9 +120,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
130
120
  _videoSize.height = 0;
131
121
  _videoSize.width = 0;
132
122
  #if !TARGET_OS_OSX
133
- [self setNeedsLayout];
123
+ [self setNeedsLayout];
134
124
  #else
135
- self.needsLayout = YES;
125
+ self.needsLayout = YES;
136
126
  #endif
137
127
  }
138
128
  }
@@ -146,37 +136,24 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
146
136
  */
147
137
  - (instancetype)initWithFrame:(CGRect)frame {
148
138
  if (self = [super initWithFrame:frame]) {
149
- #if defined(RTC_SUPPORTS_METAL)
150
139
  #if !TARGET_OS_OSX
151
140
  RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
152
141
  subview.delegate = self;
153
142
  _videoView = subview;
154
143
  #else
155
- RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
156
- subview.wantsLayer = true;
157
- subview.delegate = self;
158
- _videoView = subview;
159
- #endif
160
- #else
161
- #if !TARGET_OS_OSX
162
- RTCEAGLVideoView *subview = [[RTCEAGLVideoView alloc] initWithFrame:CGRectZero];
144
+ RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
145
+ subview.wantsLayer = true;
163
146
  subview.delegate = self;
164
147
  _videoView = subview;
165
- #else
166
- RTCMTLNSVideoView *subview = [[RTCMTLNSVideoView alloc] initWithFrame:CGRectZero];
167
- subview.wantsLayer = true;
168
- subview.delegate = self;
169
- _videoView = subview;
170
- #endif
171
148
  #endif
172
149
 
173
150
  _videoSize.height = 0;
174
151
  _videoSize.width = 0;
175
152
 
153
+ #if !TARGET_OS_OSX
154
+ self.opaque = NO;
155
+ #endif
176
156
 
177
- #if !TARGET_OS_OSX
178
- self.opaque = NO;
179
- #endif
180
157
  [self addSubview:self.videoView];
181
158
  }
182
159
  return self;
@@ -316,9 +293,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
316
293
 
317
294
  _videoTrack = videoTrack;
318
295
 
319
- // Clear the videoView by rendering a 1x1 blank frame.
296
+ // Clear the videoView by rendering a 2x2 blank frame.
320
297
  CVPixelBufferRef pixelBuffer;
321
- CVReturn err = CVPixelBufferCreate(NULL, 1, 1, kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);
298
+ CVReturn err = CVPixelBufferCreate(NULL, 2, 2, kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);
322
299
  if (err == kCVReturnSuccess) {
323
300
  const int kBytesPerPixel = 4;
324
301
  CVPixelBufferLockBaseAddress(pixelBuffer, 0);
@@ -7,6 +7,7 @@
7
7
 
8
8
  #import <Foundation/Foundation.h>
9
9
  #import "CaptureController.h"
10
+ #import "CapturerEventsDelegate.h"
10
11
 
11
12
  NS_ASSUME_NONNULL_BEGIN
12
13
 
@@ -18,6 +18,10 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
18
18
 
19
19
  @end
20
20
 
21
+ @interface ScreenCaptureController (CapturerEventsDelegate) <CapturerEventsDelegate>
22
+ - (void)capturerDidEnd:(RTCVideoCapturer *)capturer;
23
+ @end
24
+
21
25
  @interface ScreenCaptureController (Private)
22
26
 
23
27
  @property (nonatomic, readonly) NSString *appGroupIdentifier;
@@ -44,6 +48,7 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
44
48
  return;
45
49
  }
46
50
 
51
+ self.capturer.eventsDelegate = self;
47
52
  NSString *socketFilePath = [self filePathForApplicationGroupIdentifier:self.appGroupIdentifier];
48
53
  SocketConnection *connection = [[SocketConnection alloc] initWithFilePath:socketFilePath];
49
54
  [self.capturer startCaptureWithConnection:connection];
@@ -53,6 +58,12 @@ NSString* const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
53
58
  [self.capturer stopCapture];
54
59
  }
55
60
 
61
+ // MARK: CapturerEventsDelegate Methods
62
+
63
+ - (void)capturerDidEnd:(RTCVideoCapturer *)capturer {
64
+ [self.eventsDelegate capturerDidEnd:capturer];
65
+ }
66
+
56
67
  // MARK: Private Methods
57
68
 
58
69
  - (NSString *)appGroupIdentifier {
@@ -7,6 +7,7 @@
7
7
 
8
8
  #import <AVFoundation/AVFoundation.h>
9
9
  #import <WebRTC/RTCVideoCapturer.h>
10
+ #import "CapturerEventsDelegate.h"
10
11
 
11
12
  NS_ASSUME_NONNULL_BEGIN
12
13
 
@@ -14,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
14
15
 
15
16
  @interface ScreenCapturer: RTCVideoCapturer
16
17
 
18
+ @property(nonatomic, weak) id<CapturerEventsDelegate> eventsDelegate;
19
+
17
20
  - (instancetype)initWithDelegate:(__weak id<RTCVideoCapturerDelegate>)delegate;
18
21
  - (void)startCaptureWithConnection:(nonnull SocketConnection *)connection;
19
22
  - (void)stopCapture;
@@ -245,6 +245,7 @@ const NSUInteger kMaxReadLength = 10 * 1024;
245
245
  case NSStreamEventEndEncountered:
246
246
  NSLog(@"server stream end encountered");
247
247
  [self stopCapture];
248
+ [self.eventsDelegate capturerDidEnd:self];
248
249
  break;
249
250
  case NSStreamEventErrorOccurred:
250
251
  NSLog(@"server stream error encountered: %@", aStream.streamError.localizedDescription);
@@ -0,0 +1,14 @@
1
+ #import "CapturerEventsDelegate.h"
2
+ #import "CaptureController.h"
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface TrackCapturerEventsEmitter : NSObject<CapturerEventsDelegate>
7
+
8
+ - (instancetype)initWith:(NSString *)trackId
9
+ webRTCModule:(WebRTCModule *)module;
10
+
11
+ - (void)capturerDidEnd:(RTCVideoCapturer *) capturer;
12
+ @end
13
+
14
+ NS_ASSUME_NONNULL_END