-
Notifications
You must be signed in to change notification settings - Fork 1
Events
BboxIoT service can dispatch various type of events :
event type | event value | source | destination | event description |
---|---|---|---|---|
EVENT_REQUEST | 1 | client | service | a request from client to service |
EVENT_RESPONSE | 2 | service | client | a response given to a request from service to client |
EVENT_SUBSCRIPTION | 3 | client | service | a subscription to a specific set of event type from |
EVENT_INCOMING | 4 | service | all client | a notification event with no specific client destination |
You can subscribe to a Set of EventSubscription with String subscribe(String request, IBluetoothEventListener listener)
.
String request
This is JSON string request featuring a set of EventSubscription
element. EventSubscription
is an enum which contains all subscription types, a client can registrate to.
IBluetoothEventListener listener
This is a listener whose callback will be called on each event pushed by BboxIoT service
event type | event value | event description |
---|---|---|
SCANNING | 1 | subscription for scanning event type |
CONNECTION | 2 | subscription for connection/association event type |
PROPERTIES | 3 | subscription for device properties event type |
BLUETOOTH_STATE | 4 | subscription for bluetooth state change event type |
- example for subscription to Bluetooth scan event ( scan status + device discovery) :
import fr.bouyguestelecom.tv.bboxiot.protocol.bluetooth.IBluetoothEventListener;
import fr.bouyguestelecom.tv.bboxiot.protocol.EventBuilder;
import fr.bouyguestelecom.tv.bboxiot.protocol.IGenericEvent;
import fr.bouyguestelecom.tv.bboxiot.protocol.impl.BluetoothStateEvent;
......
IBboxIotService service = .... ;
......
Set<EventSubscription> subscriptionSet = new HashSet<>();
subscriptionSet.add(EventSubscription.SCANNING);
String request = EventBuilder.buildSubscription(subscriptionSet).toJsonString();
String listenerId = bboxIotService.getBluetoothManager().subscribe(request, new IBluetoothEventListener.Stub() {
public void onEventReceived(int type, int topic, String event) {
IGenericEvent genericEvent = IotEvent.parse(event);
if (genericEvent != null) {
if (genericEvent instanceof ScanStatusChangeEvent) {
ScanStatusChangeEvent btEvent = (ScanStatusChangeEvent) genericEvent;
if (btEvent.getAction() == ScanningAction.SCANNING_ACTION_START) {
// bluetooth scan has started
} else {
// bluetooth scan has been stopped
}
}
else if (genericEvent instanceof ScanItemEvent) {
ScanItemEvent btEvent = (ScanItemEvent) genericEvent;
//this is the new device discovered
BluetoothSmartDevice = btEvent.getItem();
}
}
}
});
-
You will notice that we use
EventBuilder
class to build subscription JSON event which take a Set ofEventSubscription
as input parameter. You can add as muchEventSubscription
entries as you want if you want to subscribe to other subscription types. -
Event is parsed with
IGenericEvent IotEvent.parse(String event)
which will give you an interface you can cast to whichever Event you are interested in.
A call to String subscribe(String request, IBluetoothEventListener listener)
will return a String listener identifier.
When your application is killed, all subscription are cancelled automatically. In some cases, you may want to cancel subscription for a specific event or for a specific listener in an activity of yours.
A call to void unsubscribe(String listenerId)
will unsubscribe the listener identified by listenerId
:
bboxIotService.unsubscribe(listenerId);