2525#import " RMXRemixer.h"
2626
2727static NSString *const kFirebasePath = @" Remixer" ;
28- static NSString *const kFirebaseDeviceKey = @" device_id" ;
2928
3029@implementation RMXFirebaseRemoteController {
30+ NSString *_deviceKey;
3131 FIRDatabaseReference *_ref;
3232 NSMutableDictionary <NSString *, RMXVariable *> *_storedVariables;
3333}
@@ -41,14 +41,13 @@ + (instancetype)sharedInstance {
4141 return sharedInstance;
4242}
4343
44- - (void )setup {
44+ - (void )startObservingUpdates {
45+ _deviceKey = [[[NSUUID UUID ] UUIDString ] substringToIndex: 8 ];
4546 [FIRApp configure ];
4647 _ref = [[FIRDatabase database ] referenceWithPath: kFirebasePath ];
4748 _storedVariables = [NSMutableDictionary dictionary ];
48- }
4949
50- - (void )startObservingUpdates {
51- [[_ref child: kFirebaseDeviceKey ]
50+ [[_ref child: _deviceKey]
5251 observeEventType: FIRDataEventTypeChildChanged
5352 withBlock: ^(FIRDataSnapshot *_Nonnull snapshot) {
5453 NSDictionary *jsonDictionary = snapshot.value ;
@@ -61,27 +60,23 @@ - (void)startObservingUpdates {
6160}
6261
6362- (void )stopObservingUpdates {
64- [[_ref child: kFirebaseDeviceKey ] removeAllObservers ];
65- }
66-
67- - (void )shutDown {
68- // No-op.
63+ [[_ref child: _deviceKey] removeAllObservers ];
6964}
7065
7166- (void )addVariable : (RMXVariable *)variable {
72- [[[_ref child: kFirebaseDeviceKey ] child: variable.key] setValue: [variable toJSON ]];
67+ [[[_ref child: _deviceKey ] child: variable.key] setValue: [variable toJSON ]];
7368}
7469
7570- (void )updateVariable : (RMXVariable *)variable {
76- [[[_ref child: kFirebaseDeviceKey ] child: variable.key] setValue: [variable toJSON ]];
71+ [[[_ref child: _deviceKey ] child: variable.key] setValue: [variable toJSON ]];
7772}
7873
7974- (void )removeVariable : (RMXVariable *)variable {
80- [[[_ref child: kFirebaseDeviceKey ] child: variable.key] removeValue ];
75+ [[[_ref child: _deviceKey ] child: variable.key] removeValue ];
8176}
8277
8378- (void )removeAllVariables {
84- [[_ref child: kFirebaseDeviceKey ] removeValue ];
79+ [[_ref child: _deviceKey ] removeValue ];
8580}
8681
8782@end
0 commit comments