//
//  TrtcPlugin.m
//
//

#import "TrtcPlugin.h"

#import "VideoCallingViewController.h"
// #import "TCLiveRequestManager.h"
// #import <ILiveSDK/ILiveSDK.h>
// #import "TCLiveJoinRoomViewController.h"
// #import <ILiveSDK/ILiveLoginManager.h>
// #import "UIToastView.h"
// #import <ILiveLogReport/ILiveLogReport.h>
#import <TXLiteAVSDK_TRTC/TRTCCloud.h>

#import "Events.h";
#import "CordovaEventKit.h";

@interface TrtcPlugin()
{}
@end

@implementation TrtcPlugin



-(void)joinChannel:(CDVInvokedUrlCommand*)command {
    NSDictionary* params = [command.arguments objectAtIndex:0];
    NSLog(@"TRTC - joinChannel::%@",params);
    CDVPluginResult* pluginResult = nil;
    VideoCallingViewController *vc = [[VideoCallingViewController alloc]
                                      initWithRoomId:[params[@"ROOM_ID"] intValue]
                                      userId:params[@"USER_ID"]
                                      appId:[params[@"SDK_APP_ID"] intValue]
                                      userSig:params[@"USER_SIG"]];
    dispatch_async(dispatch_get_main_queue(), ^{
        if (@available(iOS 13.0, *)){
            vc.modalPresentationStyle = UIModalPresentationFullScreen;
        }
        [self.viewController presentViewController:vc animated:YES completion:nil];
    });
}


-(void)userInfoChange:(CDVInvokedUrlCommand*)command {
    NSDictionary* params = [command.arguments objectAtIndex:0];
    NSLog(@"TRTC - userInfoChange::%@",params);
    [Events fireEvent:@"userinfo.update" extra:params];
}



#ifdef __CORDOVA_4_0_0

- (void)pluginInitialize {
    NSLog(@"TRTC - pluginInitialize ");
    [self initPlugin];
}

#else

- (CDVPlugin*)initWithWebView:(WKWebView*)theWebView{
    NSLog(@"TRTC - initWithWebView ");
    if (self=[super initWithWebView:theWebView]) {
    }
    [self initPlugin];
    return self;
}

#endif

-(void)initPlugin{
    NSLog(@"TRTC - initPlugin ");
    [CordovaEventKit init:self];
}

@end
