Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.0.0
version: 2.0.1
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: Provides BluetoothLowEnergy module for Titanium applications.
Expand Down
8 changes: 8 additions & 0 deletions android/src/appcelerator/ble/TiBLECentralManagerProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ public void cancelPeripheralConnection(KrollDict dict)
bleService.cancelPeripheralConnection(peripheralProxy);
}

@Kroll.method
public void requestMtu(KrollDict dict)
{
if (dict != null && dict.containsKey("mtu")) {
bleService.requestMtu(dict.getInt("mtu"));
}
}

public void cleanup()
{
try {
Expand Down
5 changes: 5 additions & 0 deletions android/src/appcelerator/ble/TiBLEManageCentralService.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public void handleBluetoothTurnedOff()
centralOperationManager.handleDisconnection(BluetoothGatt.GATT_FAILURE);
}

public void requestMtu(int value)
{
centralOperationManager.requestMtu(value);
}

public void readValueForCharacteristic(TiBLECharacteristicProxy characteristicProxy)
{
centralOperationManager.readValueForCharacteristic(characteristicProxy);
Expand Down
23 changes: 22 additions & 1 deletion android/src/appcelerator/ble/TiBleCentralOperationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import android.content.Context;
import android.os.Build;
import android.util.Log;
import androidx.annotation.RequiresApi;
import java.util.UUID;
import org.appcelerator.kroll.KrollDict;
import ti.modules.titanium.BufferProxy;

@SuppressLint("LongLogTag")
@SuppressLint({ "LongLogTag", "MissingPermission" })
public class TiBleCentralOperationManager
{

Expand Down Expand Up @@ -102,6 +103,13 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri
super.onDescriptorWrite(gatt, descriptor, status);
handleOnDescriptorWrite(descriptor, status);
}

@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status)
{
super.onMtuChanged(gatt, mtu, status);
handleOnMtuChanged(mtu, status);
}
});
connectionState = ConnectionState.Connecting;
}
Expand Down Expand Up @@ -240,6 +248,13 @@ private void handleOnDescriptorWrite(BluetoothGattDescriptor descriptor, int sta
peripheralProxy.fireEvent(KeysConstants.didWriteValueForDescriptor.name(), dict);
}

private void handleOnMtuChanged(int mtu, int status)
{
KrollDict dict = new KrollDict();
dict.put("mtu", mtu);
peripheralProxy.fireEvent("mtuChanged", dict);
}

public void cancelPeripheralConnection()
{
connectionState = ConnectionState.Disconnecting;
Expand Down Expand Up @@ -267,6 +282,12 @@ public void requestConnectionPriority(int priority)
}
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void requestMtu(int value)
{
bluetoothGatt.requestMtu(value);
}

public void discoverServices()
{
bluetoothGatt.discoverServices();
Expand Down
28 changes: 21 additions & 7 deletions apidoc/CentralManager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ properties:
type: Array<Modules.BLE.Peripheral>
platforms: [android, iphone, ipad]
since: "1.0.0"

methods:
- name: isAccessFineLocationPermissionGranted
summary: Determines whether the ACCESS_FINE_LOCATION permission is granted or not.
Expand All @@ -45,6 +45,11 @@ methods:
since: "1.0.0"
platforms: [android]

- name: requestMtu
summary: Request MTU change
since: "2.0.1"
platforms: [android]

- name: createPeripheral
summary: Creates a Modules.BLE.Peripheral class object with the given address.
since: "1.0.0"
Expand Down Expand Up @@ -118,7 +123,7 @@ methods:
summary: A list of services UUIDs.
optional: true
returns:
type: void
type: void

- name: cancelPeripheralConnection
summary: Cancels an active or pending connection to peripheral. Note that this is non-blocking, and any Peripheral
Expand All @@ -131,7 +136,7 @@ methods:
summary: peripheral object which connnection will be canceled
optional: false
returns:
type: void
type: void

- name: connectPeripheral
summary: Initiates a connection to peripheral. Connection attempts never time out and, depending on the outcome, will result
Expand All @@ -150,7 +155,7 @@ methods:
all available dictionary keys are defined as Modules.BLE.CONNECT_PERIPHERAL_OPTIONS_KEY_*
optional: true
returns:
type: void
type: void

events:
- name: didUpdateState
Expand All @@ -167,12 +172,21 @@ events:
- name: state
type: Number
summary: state of central manager


- name: mtu
summary: Fired after an MTU request
platforms: [android]
since: "2.0.1"
properties:
- name: mtu
type: Number
summary: MTU value


- name: willRestoreState
summary: A event called when centrel manager will restore state
description: |
For apps that opt-in to state preservation and restoration, this is the first event invoked when your app is relaunched into
For apps that opt-in to state preservation and restoration, this is the first event invoked when your app is relaunched into
the background to complete some Bluetooth-related task. Use this method to synchronize your app's state with the state of the
Bluetooth system.
platforms: [iphone, ipad]
Expand Down Expand Up @@ -232,7 +246,7 @@ events:
summary: The error domain; only present if an error occurred..
- name: errorDescription
type: String
summary: The error description; only peresent if an
summary: The error description; only peresent if an

- name: didDisconnectPeripheral
summary: This event is called when a peripheral disconnected.
Expand Down