ScreenCaptureController.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // From https://github.com/react-native-webrtc/react-native-webrtc (MIT License)
  2. // SPDX-FileCopyrightText: 2023 React-Native-WebRTC authors
  3. // SPDX-License-Identifier: MIT
  4. #include <sys/socket.h>
  5. #include <sys/un.h>
  6. #import "ScreenCaptureController.h"
  7. #import "ScreenCapturer.h"
  8. #import "SocketConnection.h"
  9. #import "NCAppBranding.h"
  10. #import "NextcloudTalk-Swift.h"
  11. NSString *const kRTCScreensharingSocketFD = @"rtc_SSFD";
  12. @interface ScreenCaptureController ()
  13. @property(nonatomic, retain) ScreenCapturer *capturer;
  14. @end
  15. @interface ScreenCaptureController (CapturerEventsDelegate)<CapturerEventsDelegate>
  16. - (void)capturerDidEnd:(RTCVideoCapturer *)capturer;
  17. @end
  18. @interface ScreenCaptureController (Private)
  19. @property(nonatomic, readonly) NSString *appGroupIdentifier;
  20. @end
  21. @implementation ScreenCaptureController
  22. - (instancetype)initWithCapturer:(nonnull ScreenCapturer *)capturer {
  23. self = [super init];
  24. if (self) {
  25. self.capturer = capturer;
  26. }
  27. return self;
  28. }
  29. - (void)dealloc {
  30. [self.capturer stopCapture];
  31. }
  32. - (void)startCapture {
  33. self.capturer.eventsDelegate = self;
  34. NSString *socketFilePath = [self filePathForApplicationGroupIdentifier:groupIdentifier];
  35. SocketConnection *connection = [[SocketConnection alloc] initWithFilePath:socketFilePath];
  36. [self.capturer startCaptureWithConnection:connection];
  37. }
  38. - (void)stopCapture {
  39. [self.capturer stopCapture];
  40. }
  41. // MARK: CapturerEventsDelegate Methods
  42. - (void)capturerDidEnd:(RTCVideoCapturer *)capturer {
  43. [self.eventsDelegate capturerDidEnd:capturer];
  44. }
  45. // MARK: Private Methods
  46. - (NSString *)filePathForApplicationGroupIdentifier:(nonnull NSString *)identifier {
  47. NSURL *sharedContainer =
  48. [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:identifier];
  49. NSString *socketFilePath = [[sharedContainer URLByAppendingPathComponent:kRTCScreensharingSocketFD] path];
  50. return socketFilePath;
  51. }
  52. @end