File tree 6 files changed +65
-84
lines changed
6 files changed +65
-84
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6
6
* LICENSE file in the root directory of this source tree.
7
7
*/
8
8
9
- #import " RCTBridgeModule.h"
10
- #import " RCTOpenTokSession.h "
9
+ #import " RCTBridgeModule.h"
10
+ #import < OpenTok/OpenTok.h >
11
11
12
- @interface RCTOpenTokSessionManager : NSObject <RCTBridgeModule>
13
- @end
12
+ @interface RCTOpenTokSessionManager : NSObject <RCTBridgeModule, OTSessionDelegate>
13
+
14
+ @end
Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
#import " RCTOpenTokSessionManager.h"
10
- #import " RCTOpenTokSession.h"
10
+ #import " RCTEventDispatcher.h"
11
+ #import < OpenTok/OpenTok.h>
11
12
12
- @implementation RCTOpenTokSessionManager
13
+ @implementation RCTOpenTokSessionManager {
14
+ OTSession *_session;
15
+ }
13
16
14
17
RCT_EXPORT_MODULE ();
15
18
16
- RCT_EXPORT_METHOD ();
19
+ RCT_EXPORT_METHOD (connect:(NSString *)apiKey sessionId:(NSString *)sessionId token:(NSString *)token)
20
+ {
21
+ _session = [[OTSession alloc ] initWithApiKey: apiKey sessionId: sessionId delegate: self ];
22
+
23
+ OTError *error = nil ;
24
+ [_session connectWithToken: token error: &error];
25
+
26
+ if (error) {
27
+ NSLog (@" connect failed with error: (%@ )" , error);
28
+ } else {
29
+ NSLog (@" session created" );
30
+ }
31
+ }
32
+
33
+ RCT_EXPORT_METHOD (sendMessage:(NSString *)message)
34
+ {
35
+ OTError* error = nil ;
36
+ [_session signalWithType: type string: message connection: nil error: &error)];
37
+ if (error) {
38
+ NSLog (@" signal error %@ " , error);
39
+ } else {
40
+ NSLog (@" signal sent" );
41
+ }
42
+ }
43
+
44
+ # pragma mark - OTSession delegate callbacks
45
+ - (void )session : (OTSession*)session receivedSignalType : (NSString *)type fromConnection : (OTConnection*)connection withString : (NSString *)string {
46
+ NSLog (@" Received signal %@ " , string);
47
+ [self onMessageRecieved: string];
48
+ }
49
+
50
+ - (void )onMessageRecieved : (NSString *)message
51
+ {
52
+ [self .bridge.eventDispatcher sendAppEventWithName: @" onMessageRecieved"
53
+ body: @{@" message" : message}];
54
+ }
17
55
18
56
@end
Original file line number Diff line number Diff line change
1
+ import { NativeModules , NativeAppEventEmitter } from 'react-native' ;
2
+ const SessionManager = NativeModules . RCTOpenTokSessionManager ;
3
+
4
+ const listener = null ;
5
+
6
+ console . log ( NativeModules ) ;
7
+
8
+ export const connect = SessionManager . connect ;
9
+ export const sendMessage = SessionManager . sendMessage ;
10
+
11
+ export const onMessageRecieved = ( callback ) => {
12
+ listener = NativeAppEventEmitter . addListener (
13
+ 'onMessageRecieved' ,
14
+ ( e ) => callback ( e . message )
15
+ ) ;
16
+ } ;
17
+
18
+ export const stopListener = ( ) => listener . remove ( ) ;
Original file line number Diff line number Diff line change @@ -10,3 +10,4 @@ import { requireNativeComponent } from 'react-native';
10
10
11
11
export const PublisherView = require ( './PublisherView' ) . default ;
12
12
export const SubscriberView = require ( './SubscriberView' ) . default ;
13
+ export const Session = require ( './Session' ) ;
You can’t perform that action at this time.
0 commit comments