-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDDPClient.m
More file actions
92 lines (73 loc) · 2.97 KB
/
DDPClient.m
File metadata and controls
92 lines (73 loc) · 2.97 KB
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
92
//
// DDPClient.m
// AwesomeProject
//
// Created by Harrison Harnisch on 4/7/15.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "RCTBridge.h"
#import "RCTConvert.h"
#import "RCTEventDispatcher.h"
#import "DDPClient.h"
#import "ObjectiveDDP.h"
#import <ObjectiveDDP/MeteorClient.h>
@implementation DDPClient
@synthesize meteorClient;
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)connectWithURL:(NSString *)URLString {
RCT_EXPORT();
self.meteorClient = [[MeteorClient alloc] initWithDDPVersion:@"1"];
ObjectiveDDP *ddp = [[ObjectiveDDP alloc] initWithURLString:URLString delegate:self.meteorClient];
self.meteorClient.ddp = ddp;
[self.meteorClient.ddp connectWebSocket];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reportConnection)
name:MeteorClientDidConnectNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reportDisconnection)
name:MeteorClientDidDisconnectNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(added:)
name:@"added"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(changed:)
name:@"changed"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(removed:)
name:@"removed"
object:nil];
}
- (void)subscribe:(NSString *)name {
RCT_EXPORT();
[self.meteorClient addSubscription:name];
}
- (void)added:(NSNotification *)notification {
NSDictionary *added = notification.userInfo;
[_bridge.eventDispatcher sendDeviceEventWithName:@"added"
body:added];
}
- (void)changed:(NSNotification *)notification {
NSDictionary *changed = notification.userInfo;
[_bridge.eventDispatcher sendDeviceEventWithName:@"changed"
body:changed];
}
- (void)removed:(NSNotification *)notification {
NSDictionary *removed = notification.userInfo;
[_bridge.eventDispatcher sendDeviceEventWithName:@"removed"
body:removed];
}
- (void)reportConnection {
NSLog(@"Meteor Client: connected");
}
- (void)reportDisconnection {
NSLog(@"Meteor Client: disconnected");
}
@end