ScreenStreamPlugin.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // ScreenStreamPlugin.m
  3. // Runner
  4. //
  5. // Created by Drew on 2019/5/9.
  6. // Copyright © 2019 The Chromium Authors. All rights reserved.
  7. //
  8. #import "ScreenStreamPlugin.h"
  9. #import <ReplayKit/ReplayKit.h>
  10. #import <NotificationCenter/NotificationCenter.h>
  11. @interface ScreenStreamPlugin() <FlutterPlugin>
  12. @property (nonatomic) UIViewController *viewController;
  13. @end
  14. @implementation ScreenStreamPlugin
  15. + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  16. FlutterMethodChannel* channel = [FlutterMethodChannel
  17. methodChannelWithName:@"screen_stream"
  18. binaryMessenger:[registrar messenger]];
  19. UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  20. ScreenStreamPlugin* instance = [[ScreenStreamPlugin alloc] initWithViewController:viewController];
  21. [registrar addMethodCallDelegate:instance channel:channel];
  22. }
  23. - (instancetype)initWithViewController:(UIViewController *)viewController {
  24. self = [super init];
  25. if(self) {
  26. self.viewController = viewController;
  27. }
  28. return self;
  29. }
  30. - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
  31. if ([@"start" isEqualToString:call.method]) {
  32. NSString *playerInfoId = [call.arguments[@"playerInfoId"] stringValue];
  33. NSString *rtmpUrl = [NSString stringWithFormat:@"rtmp://47.96.141.102:1935/myapp/%@", playerInfoId];
  34. NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.izouma.wnnaBattle"];
  35. [userDefaults setValue:rtmpUrl forKey:@"rtmpUrl"];
  36. [userDefaults synchronize];
  37. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("PUSH_START"), NULL, nil, YES);
  38. if (@available(iOS 12.0, *) ) {
  39. }
  40. result(@"success");
  41. } else if ([@"stop" isEqualToString:call.method]) {
  42. NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.izouma.wnnaBattle"];
  43. [userDefaults removeObjectForKey:@"rtmpUrl"];
  44. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("PUSH_STOP"), NULL, nil, YES);
  45. result(@"success");
  46. } else if ([@"prepare" isEqualToString:call.method]) {
  47. result(@"success");
  48. }
  49. }
  50. @end