forked from CommercialTribe/react-native-opentok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCTOpenTokSessionManager.m
67 lines (54 loc) · 1.87 KB
/
RCTOpenTokSessionManager.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
/**
* Copyright (c) 2015-present, Callstack Sp z o.o.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTOpenTokSessionManager.h"
#import "RCTEventDispatcher.h"
#import <OpenTok/OpenTok.h>
@implementation RCTOpenTokSessionManager {
OTSession *_session;
}
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(connect:(NSString *)apiKey sessionId:(NSString *)sessionId token:(NSString *)token)
{
_session = [[OTSession alloc] initWithApiKey:apiKey sessionId:sessionId delegate:self];
OTError *error = nil;
[_session connectWithToken:token error:&error];
if (error) {
NSLog(@"connect failed with error: (%@)", error);
}
}
RCT_EXPORT_METHOD(sendMessage:(NSString *)message)
{
NSLog(@"signal error %@", message);
OTError* error = nil;
[_session signalWithType:@"message" string:message connection:nil error:&error];
if (error) {
NSLog(@"signal error %@", error);
} else {
NSLog(@"signal sent");
}
}
# pragma mark - OTSession delegate callbacks
- (void)sessionDidConnect:(OTSession*)session {}
- (void)sessionDidDisconnect:(OTSession*)session {}
- (void)session:(OTSession*)session streamCreated:(OTStream *)stream {}
- (void)session:(OTSession*)session streamDestroyed:(OTStream *)stream {}
- (void)session:(OTSession*)session didFailWithError:(OTError*)error {}
- (void)session:(OTSession*)session receivedSignalType:(NSString*)type fromConnection:(OTConnection*)connection withString:(NSString*)string {
NSLog(@"Received signal %@", string);
[self onMessageRecieved:string data:connection.data];
}
- (void)onMessageRecieved:(NSString *)message data:(NSString *)data
{
[self.bridge.eventDispatcher sendAppEventWithName:@"onMessageRecieved"
body:@{
@"message": message,
@"data": data,
}];
}
@end