CNLivePlayerManager.m 2.27 KB
//
//  CNLivePlayerManager.m
//  CNLivePlayer_Example
//
//  Created by CNLive-zxw on 2019/7/26.
//  Copyright © 2019 153993236@qq.com. All rights reserved.
//

#import "CNLivePlayerManager.h"
#import <libksygpulive/KSYGPUStreamerKit.h>
#import "CNLivePlayerConst.h"

@interface CNLivePlayerManager()
/**
 *  应用ID(只读)
 */
@property (nonatomic, copy, readwrite) NSString *appId;

/**
 *  应用KEY(只读)
 */
@property (nonatomic, copy, readwrite) NSString *appKey;

/**
 *  是否是测试环境
 */
@property (nonatomic, assign, readwrite) BOOL isTestEnvironment;

@end

@implementation CNLivePlayerManager
static CNLivePlayerManager * _instance = nil;
+ (CNLivePlayerManager *)manager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
        //清除播放器鉴权缓存
        [CNLivePlayerManager clearAuthentication];

    });
    
    return _instance;
}

+ (void)setAppId:(NSString *)appId appKey:(NSString *)appKey {
    [CNLivePlayerManager setAppId:appId appKey:appKey isTestEnvironment:NO];

}

+ (void)setAppId:(NSString *)appId appKey:(NSString *)appKey isTestEnvironment:(BOOL)isTestEnvironment{
    [[CNLivePlayerManager manager] setAppId:appId appKey:appKey isTestEnvironment:isTestEnvironment];
    
}

#pragma mark - 私有方法
- (void)setAppId:(NSString *)appId appKey:(NSString *)appKey {
    [self setAppId:appId appKey:appKey isTestEnvironment:NO];
}

- (void)setAppId:(NSString *)appId appKey:(NSString *)appKey isTestEnvironment:(BOOL)isTestEnvironment {
    self.appId  = appId ? [NSString stringWithFormat:@"%@",appId] : @"";
    self.appKey = appKey ? [NSString stringWithFormat:@"%@",appKey] : @"";
    self.isTestEnvironment = isTestEnvironment;
}

+ (NSString *)getVersion {
    KSYGPUStreamerKit *kit = [[KSYGPUStreamerKit alloc] init];
    NSString *str = [[[kit.streamerBase getKSYVersion] componentsSeparatedByString:@"-"] lastObject];
    return [NSString stringWithFormat:@"%@_%@", PlayerSDKVersion,str];
}

+ (void)clearAuthentication {
    NSDictionary *authenticationDic = [[NSUserDefaults standardUserDefaults] objectForKey:kCNLivePlayerSDKAuthentication];
    if (authenticationDic) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:kCNLivePlayerSDKAuthentication];
    }
}

@end