Skip to content

Commit

Permalink
Merge pull request #282 from sfroment/dev/sfromnet/ios-bluetooth
Browse files Browse the repository at this point in the history
IOS ble library
  • Loading branch information
gfanton committed Sep 21, 2018
2 parents 50d41cf + abf8958 commit 2596177
Show file tree
Hide file tree
Showing 7 changed files with 677 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -42,3 +42,6 @@ indent_size = 2

[*.diff]
indent_size = 1

[*.m]
indent_size = 2
23 changes: 23 additions & 0 deletions client/react-native/mobile/ios/berty/BertyBluetoothModule.h
@@ -0,0 +1,23 @@
//
// BertyBluetoothModule.h
// bluetooth
//
// Created by sacha on 04/09/2018.
// Copyright © 2018 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

#import "BertyCentralManager.h"

NS_ASSUME_NONNULL_BEGIN

@interface BertyBluetoothModule : RCTEventEmitter <RCTBridgeModule>

@property(nonatomic, strong) BertyCentralManager* bcm;

@end

NS_ASSUME_NONNULL_END
63 changes: 63 additions & 0 deletions client/react-native/mobile/ios/berty/BertyBluetoothModule.m
@@ -0,0 +1,63 @@
//
// BertyBluetoothModule.m
// bluetooth
//
// Created by sacha on 04/09/2018.
// Copyright © 2018 Facebook. All rights reserved.
//

#import "BertyBluetoothModule.h"

@implementation BertyBluetoothModule

RCT_EXPORT_MODULE();

- (instancetype)init {
self = [super init];
if (self) {
self.bcm = [[BertyCentralManager alloc] initWithSender:self];
}
return self;
}

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
}

+ (BOOL)requiresMainQueueSetup
{
return YES;
}

- (NSArray<NSString *> *)supportedEvents
{
return @[@"NEW_DEVICE", @"NEW_MESSAGE"];
}

RCT_EXPORT_METHOD(updateValue)
{
[self.bcm updateValue];
}

RCT_EXPORT_METHOD(startDiscover)
{
[self.bcm discover];
}

RCT_EXPORT_METHOD(subscribe)
{
[self.bcm subscribe];
}

RCT_EXPORT_METHOD(connect:(NSString *)addr)
{
[self.bcm connect:addr];
}

RCT_EXPORT_METHOD(writeTo:(NSString *)addr msg:(NSString *)msg)
{
[self.bcm writeTo:addr msg:msg];
}

@end
37 changes: 37 additions & 0 deletions client/react-native/mobile/ios/berty/BertyCentralManager.h
@@ -0,0 +1,37 @@
//
// BertyCentralManager.h
// bluetooth
//
// Created by sacha on 05/09/2018.
// Copyright © 2018 Facebook. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import <React/RCTEventEmitter.h>
#import "BertyPeripheral.h"
#import "BertyDevice.h"

@interface BertyCentralManager : NSObject <CBCentralManagerDelegate, CBPeripheralDelegate, CBPeripheralManagerDelegate>

@property (nonatomic, strong) NSMutableDictionary *connectedDevice;
@property (nonatomic, strong) NSMutableDictionary *discoveredDevice;
@property (nonatomic, strong) CBCentralManager *centralManager;
@property (nonatomic, strong) CBPeripheralManager *peripheralManager;
@property (nonatomic, strong) CBMutableService *bertyService;
@property (nonatomic, strong) CBMutableCharacteristic *bertyReaderCharacteristic;
@property (nonatomic, strong) CBMutableCharacteristic *bertyCounterReaderCharacteristic;
@property (nonatomic, strong) CBUUID *serviceUUID;
@property (nonatomic, strong) CBUUID *readerUUID;
@property (nonatomic, strong) CBUUID *readerCounterUUID;
@property (nonatomic, strong) NSMutableArray<NSData*>* toSend;
@property (nonatomic, weak) id sender;

- (instancetype)initWithSender:(id)sender;
- (void)discover;
- (void)connect:(NSString *)name;
- (void)writeTo:(NSString *)addr msg:(NSString *)msg;
- (void)subscribe;
- (void) updateValue ;
@end

0 comments on commit 2596177

Please sign in to comment.