forked from CommercialTribe/react-native-opentok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCTOpenTokNetworkTest.m
91 lines (68 loc) · 2.49 KB
/
RCTOpenTokNetworkTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// RCTOpenTokNetworkTest.m
//
// Copyright (c) 2013 TokBox, Inc. All rights reserved.
//
#import "RCTOpenTokNetworkTest.h"
#import "OTNetworkTest.h"
@implementation RCTOpenTokNetworkTest
#pragma mark - Private Vars
OTNetworkTest *_networkTest;
RCTPromiseResolveBlock _resolveNetworkTest;
RCTPromiseRejectBlock _rejectNetworkTest;
#pragma mark - JavaScript Exports
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(testConnection:(NSString *)apiKey
sessionId:(NSString *)sessionId
token:(NSString *)token
duration:(int)duration
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
{
_resolveNetworkTest = resolve;
_rejectNetworkTest = reject;
[self runNetworkTest:apiKey sessionId:sessionId token:token duration:duration];
}
#pragma mark - OpenTok Network Test
- (void)runNetworkTest:(NSString *)apiKey
sessionId:(NSString *)sessionId
token:(NSString *)token
duration:(int)duration
{
_networkTest = [[OTNetworkTest alloc] init];
[_networkTest runConnectivityTestWithApiKey:apiKey
sessionId:sessionId
token:token
executeQualityTest:YES
qualityTestDuration:duration
delegate:self];
}
#pragma mark - OTNetworkTestDelegate Methods
- (void)networkTestDidCompleteWithResult:(enum OTNetworkTestResult)result
error:(OTError *)error
{
NSString *resultMessage = nil;
if(result == OTNetworkTestResultVideoAndVoice) {
resultMessage = @"PASS";
_resolveNetworkTest(resultMessage);
}
else if(result == OTNetworkTestResultVoiceOnly) {
resultMessage = [NSString stringWithFormat:@"Error: %@", error.localizedDescription];
_rejectNetworkTest(@"FAIL", resultMessage, error);
}
else {
resultMessage = [NSString stringWithFormat:@"Error %@", error.localizedDescription];
_rejectNetworkTest(@"FAIL", resultMessage, error);
}
resultMessage = nil;
_networkTest = nil;
_resolveNetworkTest = nil;
_rejectNetworkTest = nil;
}
#pragma mark - Network Test Queue
// Dispatch all these methods on a separate queue
- (dispatch_queue_t)methodQueue
{
return dispatch_queue_create("com.commercialtribe.OpenTok.NetworkTest", DISPATCH_QUEUE_SERIAL);
}
@end