rtmp、rtc推拉流支持加密
This commit is contained in:
39
Example/SellyCloudSDK/Network/AVApiService.h
Normal file
39
Example/SellyCloudSDK/Network/AVApiService.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// AVApiService.h
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class AVLiveStreamModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^AVApiSuccess)(id _Nullable responseObject);
|
||||
typedef void(^AVApiFailure)(NSError *error);
|
||||
|
||||
@interface AVApiService : NSObject
|
||||
|
||||
+ (instancetype)shared;
|
||||
|
||||
/// GET /live/sdk/alive-list
|
||||
- (void)fetchLiveStreams:(void(^)(NSArray<AVLiveStreamModel *> *streams))success
|
||||
failure:(nullable AVApiFailure)failure;
|
||||
|
||||
/// POST /live/sdk/demo/stream-xor
|
||||
- (void)reportXorKeyWithVhost:(NSString *)vhost
|
||||
app:(NSString *)app
|
||||
stream:(NSString *)stream
|
||||
xorKey:(nullable NSString *)xorKey
|
||||
success:(nullable AVApiSuccess)success
|
||||
failure:(nullable AVApiFailure)failure;
|
||||
|
||||
/// POST /live/sdk/demo/login
|
||||
- (void)loginWithUsername:(NSString *)username
|
||||
password:(NSString *)password
|
||||
success:(void(^)(id responseObject))success
|
||||
failure:(void(^)(NSError *error, NSString * _Nullable serverMessage))failure;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
101
Example/SellyCloudSDK/Network/AVApiService.m
Normal file
101
Example/SellyCloudSDK/Network/AVApiService.m
Normal file
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// AVApiService.m
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
|
||||
#import "AVApiService.h"
|
||||
#import "AVLiveStreamModel.h"
|
||||
#import <AFNetworking/AFNetworking.h>
|
||||
#import <YYModel/YYModel.h>
|
||||
|
||||
static NSString * const kBaseURL = @"http://rtmp.sellycloud.io:8089";
|
||||
|
||||
@interface AVApiService ()
|
||||
@property (nonatomic, strong) AFHTTPSessionManager *manager;
|
||||
@end
|
||||
|
||||
@implementation AVApiService
|
||||
|
||||
+ (instancetype)shared {
|
||||
static AVApiService *instance;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[AVApiService alloc] init];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_manager = [AFHTTPSessionManager manager];
|
||||
_manager.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||
_manager.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||
_manager.requestSerializer.timeoutInterval = 10;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)fetchLiveStreams:(void(^)(NSArray<AVLiveStreamModel *> *streams))success
|
||||
failure:(nullable AVApiFailure)failure {
|
||||
NSString *url = [NSString stringWithFormat:@"%@/live/sdk/alive-list", kBaseURL];
|
||||
[self.manager GET:url parameters:nil headers:nil progress:nil
|
||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
NSLog(@"%@",responseObject);
|
||||
NSArray *streams = [NSArray yy_modelArrayWithClass:AVLiveStreamModel.class json:responseObject[@"list"]];
|
||||
if (success) success(streams ?: @[]);
|
||||
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
||||
NSLog(@"[AVApiService] fetchLiveStreams failed: %@", error.localizedDescription);
|
||||
if (failure) failure(error);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)reportXorKeyWithVhost:(NSString *)vhost
|
||||
app:(NSString *)app
|
||||
stream:(NSString *)stream
|
||||
xorKey:(nullable NSString *)xorKey
|
||||
success:(nullable AVApiSuccess)success
|
||||
failure:(nullable AVApiFailure)failure {
|
||||
NSDictionary *params = @{
|
||||
@"vhost": vhost ?: @"",
|
||||
@"app": app ?: @"",
|
||||
@"stream": stream ?: @"",
|
||||
@"xor_key": xorKey ?: @""
|
||||
};
|
||||
NSString *url = [NSString stringWithFormat:@"%@/live/sdk/demo/stream-xor", kBaseURL];
|
||||
[self.manager POST:url parameters:params headers:nil progress:nil
|
||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
NSLog(@"[AVApiService] reportXorKey success: %@", responseObject);
|
||||
if (success) success(responseObject);
|
||||
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
||||
NSLog(@"[AVApiService] reportXorKey failed: %@", error.localizedDescription);
|
||||
if (failure) failure(error);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loginWithUsername:(NSString *)username
|
||||
password:(NSString *)password
|
||||
success:(void(^)(id responseObject))success
|
||||
failure:(void(^)(NSError *error, NSString * _Nullable serverMessage))failure {
|
||||
NSDictionary *params = @{
|
||||
@"username": username ?: @"",
|
||||
@"password": password ?: @""
|
||||
};
|
||||
NSString *url = [NSString stringWithFormat:@"%@/live/sdk/demo/login", kBaseURL];
|
||||
[self.manager POST:url parameters:params headers:nil progress:nil
|
||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
NSLog(@"[AVApiService] login success");
|
||||
if (success) success(responseObject);
|
||||
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
||||
NSLog(@"[AVApiService] login failed: %@", error.localizedDescription);
|
||||
NSString *serverMessage = nil;
|
||||
NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
|
||||
if (errorData) {
|
||||
NSDictionary *errorDict = [NSJSONSerialization JSONObjectWithData:errorData options:0 error:nil];
|
||||
serverMessage = errorDict[@"message"] ?: errorDict[@"error"] ?: errorDict[@"msg"];
|
||||
}
|
||||
if (failure) failure(error, serverMessage);
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user