2828
2929#import " VPLuaOSView.h"
3030#import " VPLuaAppletsView.h"
31+ #import " VPLuaDesktopView.h"
3132#import " VPLuaMedia.h"
3233#import " VPLuaVideoInfo.h"
3334#import " VPLuaPage.h"
@@ -59,6 +60,8 @@ @interface VPInterfaceController()
5960
6061@property (nonatomic ) VPLuaAppletsView *appletsView;
6162
63+ @property (nonatomic ) VPLuaDesktopView *desktopView;
64+
6265@property (nonatomic , readwrite , strong ) VPInterfaceControllerConfig *config;
6366
6467@property (nonatomic , assign ) VPIVideoPlayerOrientation orientationType;
@@ -139,6 +142,7 @@ - (void)initViewWithFrame:(CGRect)frame
139142 _view = [[VPInterfaceClickThroughView alloc ] initWithFrame: frame];
140143 [self initOSViewWithFrame: frame];
141144 [self initAppletsViewWithFrame: frame];
145+ [self initDesktopViewWithFrame: frame];
142146}
143147
144148- (void )initOSViewWithFrame : (CGRect)frame {
@@ -183,13 +187,41 @@ - (void)initAppletsViewWithFrame:(CGRect)frame {
183187 vpSize.portraitFullScreenWidth = self.videoPlayerSize .portraitFullScreenWidth ;
184188 vpSize.portraitFullScreenHeight = self.videoPlayerSize .portraitFullScreenHeight ;
185189 vpSize.portraitSmallScreenOriginY = self.videoPlayerSize .portraitSmallScreenOriginY ;
186- _osView .videoPlayerSize = vpSize;
190+ _appletsView .videoPlayerSize = vpSize;
187191 [_appletsView setGetUserInfoBlock: ^NSDictionary *(void ) {
188192 return [weakSelf getUserInfoDictionary ];
189193 }];
190194 [_view addSubview: _appletsView];
191195}
192196
197+ - (void )initDesktopViewWithFrame : (CGRect)frame {
198+
199+ __weak typeof (self) weakSelf = self;
200+ NSString *platformId = nil ;
201+ NSString *videoId = nil ;
202+
203+ platformId = _config.platformID ;
204+ videoId = _config.identifier ;
205+ if (_config.types & VPInterfaceControllerTypeVideoOS) {
206+ [VPLuaSDK setOSType: VPLuaOSTypeVideoOS];
207+ }
208+ else {
209+ [VPLuaSDK setOSType: VPLuaOSTypeLiveOS];
210+ }
211+ _desktopView = [[VPLuaDesktopView alloc ] initWithFrame: frame platformId: platformId videoId: videoId extendInfo: _config.extendDict];
212+ VPLuaVideoPlayerSize *vpSize = [[VPLuaVideoPlayerSize alloc ] init ];
213+ vpSize.portraitSmallScreenHeight = self.videoPlayerSize .portraitSmallScreenHeight ;
214+ vpSize.portraitFullScreenWidth = self.videoPlayerSize .portraitFullScreenWidth ;
215+ vpSize.portraitFullScreenHeight = self.videoPlayerSize .portraitFullScreenHeight ;
216+ vpSize.portraitSmallScreenOriginY = self.videoPlayerSize .portraitSmallScreenOriginY ;
217+ _desktopView.videoPlayerSize = vpSize;
218+ [_desktopView setGetUserInfoBlock: ^NSDictionary *(void ) {
219+ return [weakSelf getUserInfoDictionary ];
220+ }];
221+ [_view addSubview: _desktopView];
222+ [_view bringSubviewToFront: _desktopView];
223+ }
224+
193225- (BOOL )validateSetAttribute {
194226 if (!_canSet) {
195227 // TODO: already start loading, could not set
@@ -229,7 +261,12 @@ - (void)start {
229261 if (_appletsView) {
230262 [_appletsView startLoading ];
231263 }
232-
264+ if (!_desktopView) {
265+ [self initDesktopViewWithFrame: self .view.bounds];
266+ }
267+ if (_desktopView) {
268+ [_desktopView startLoading ];
269+ }
233270 [self registerStatusNotification ];
234271}
235272
@@ -250,6 +287,9 @@ - (void)notifyVideoScreenChanged:(VPIVideoPlayerOrientation)type {
250287 if (_appletsView) {
251288 [_appletsView updateVideoPlayerOrientation: (VPLuaVideoPlayerOrientation)type];
252289 }
290+ if (_desktopView) {
291+ [_desktopView updateVideoPlayerOrientation: (VPLuaVideoPlayerOrientation)type];
292+ }
253293
254294 CGFloat width = 0 ;
255295 CGFloat height = 0 ;
@@ -314,6 +354,12 @@ - (void)stop {
314354 _appletsView = nil ;
315355 }
316356
357+ if (_desktopView) {
358+ [_desktopView stop ];
359+ [_desktopView removeFromSuperview ];
360+ _desktopView = nil ;
361+ }
362+
317363 _canSet = YES ;
318364}
319365
@@ -325,8 +371,8 @@ - (void)pauseVideoAd {
325371 if (_osView) {
326372 [_osView pauseVideoAd ];
327373 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
328- @(VPLuaAdActionTypePause ), @" ActionType " ,
329- @(VPLuaAdEventTypeAction ), @" EventType " ,nil ];
374+ @(VPLuaOSActionTypePause ), @" osActionType " ,
375+ @(VPLuaEventTypeOSAction ), @" eventType " ,nil ];
330376 [_osView callLuaMethod: @" event" data: dict];
331377 }
332378}
@@ -335,8 +381,8 @@ - (void)playVideoAd {
335381 if (_osView) {
336382 [_osView playVideoAd ];
337383 NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
338- @(VPLuaAdActionTypeResume ),@" ActionType " ,
339- @(VPLuaAdEventTypeAction ), @" EventType " ,nil ];
384+ @(VPLuaOSActionTypeResume ),@" osActionType " ,
385+ @(VPLuaEventTypeOSAction ), @" eventType " ,nil ];
340386 [_osView callLuaMethod: @" event" data: dict];
341387 }
342388}
@@ -632,6 +678,10 @@ - (VPUPVideoPlayerSize *)videoPlayerSize {
632678 return vpupSize;
633679}
634680
681+ - (CGRect)videoFrame {
682+ return [self .videoPlayerDelegate videoFrame ];
683+ }
684+
635685- (void )registerRoutes {
636686 [self registerLuaViewRoutes ];
637687}
@@ -673,7 +723,7 @@ - (void)registerLuaViewRoutes {
673723 return YES ;
674724 }];
675725
676- // 跳转小程序 LuaView://applets?appletId=xxxx&type=x(type: 1横屏,2竖屏)
726+ // 跳转小程序 LuaView://applets?appletId=xxxx&type=x(type: 1横屏,2竖屏)&appType=x(appType: 1 lua,2 h5)
677727 // 容器内部跳转 LuaView://applets?appletId=xxxx&template=xxxx.lua&id=xxxx&priority=x
678728 [[VPUPRoutes routesForScheme: VPUPRoutesSDKLuaView] addRoute: @" /applets" handler: ^BOOL (NSDictionary <NSString *,id > * _Nonnull parameters) {
679729
@@ -715,6 +765,37 @@ - (void)registerLuaViewRoutes {
715765
716766 return YES ;
717767 }];
768+
769+ [[VPUPRoutes routesForScheme: VPUPRoutesSDKLuaView] addRoute: @" /desktopLuaView" handler: ^BOOL (NSDictionary <NSString *,id > * _Nonnull parameters) {
770+
771+ if (!weakSelf) {
772+ return NO ;
773+ }
774+ __strong typeof (self) strongSelf = weakSelf;
775+ // 判定osView是否存在,若不存在,先创建
776+ if (!strongSelf.desktopView ) {
777+ [strongSelf initDesktopViewWithFrame: strongSelf.view.bounds];
778+ // TODO MQTT,如果_liveView不存在情况怎么处理
779+
780+ if (!strongSelf.canSet ) {
781+ [strongSelf.desktopView startLoading ];
782+ }
783+ }
784+
785+ id data = [[parameters objectForKey: VPUPRouteUserInfoKey] objectForKey: @" ActionManagerData" ];
786+ if (!data) {
787+ data = [parameters objectForKey: VPUPRouteUserInfoKey];
788+ }
789+
790+ NSDictionary *queryParams = [parameters objectForKey: VPUPRouteQueryParamsKey];
791+ NSString *luaFile = [queryParams objectForKey: @" template" ];
792+ if (!luaFile) {
793+ luaFile = [data objectForKey: @" template" ];
794+ }
795+
796+ [strongSelf.desktopView loadLua: luaFile data: parameters];
797+ return YES ;
798+ }];
718799}
719800
720801- (void )unregisterRoutes {
@@ -783,6 +864,7 @@ - (void)startService:(VPIServiceType )type config:(VPIServiceConfig *)config {
783864 serviceConfig.duration = (VPIVideoAdTimeType)config.duration ;
784865
785866 self.serviceManager .osView = self.osView ;
867+ self.serviceManager .desktopView = self.desktopView ;
786868 self.serviceManager .delegate = self;
787869
788870 [self .serviceManager startService: (VPLuaServiceType)type config: serviceConfig];
0 commit comments