Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 295b0ae

Browse files
committed
Update to the latest Proximity SDKs [breaking changes!]
- Proximity Zones are now defined by tags instead of attachments - enter/exit/change actions now receive Proximity Context, which is: - the triggering zone's tag - the identifier of the beacon that triggered the action - the attachments assigned to that beacon Read more in the iOS and Android SDKs' changelogs: iOS: https://github.com/Estimote/iOS-Proximity-SDK/blob/master/CHANGELOG.md#0140---2018-06-19 Android: https://github.com/Estimote/Android-Proximity-SDK/blob/master/CHANGELOG.md#060-june-18-2018
1 parent 30212f6 commit 295b0ae

16 files changed

+275
-232
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repositories {
3030

3131
dependencies {
3232
compile 'com.facebook.react:react-native:+'
33-
compile('com.estimote:proximity-sdk:0.5.1') {
33+
compile('com.estimote:proximity-sdk:0.6.0') {
3434
exclude module: 'support-core-utils'
3535
}
3636
}

android/gradlew

100644100755
File mode changed.

android/src/main/java/com/estimote/react/RNEstimoteProximityModule.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.util.Log;
66

77
import com.estimote.proximity_sdk.proximity.EstimoteCloudCredentials;
8-
import com.estimote.proximity_sdk.proximity.ProximityAttachment;
8+
import com.estimote.proximity_sdk.proximity.ProximityContext;
99
import com.estimote.proximity_sdk.proximity.ProximityObserver;
1010
import com.estimote.proximity_sdk.proximity.ProximityObserverBuilder;
1111
import com.estimote.proximity_sdk.proximity.ProximityZone;
@@ -91,41 +91,40 @@ public void startObservingZones(ReadableArray zonesJSON) {
9191

9292
final String _id = zoneJSON.getString("_id");
9393
double range = zoneJSON.getDouble("range");
94-
String attachmentKey = zoneJSON.getString("attachmentKey");
95-
String attachmentValue = zoneJSON.getString("attachmentValue");
94+
String tag = zoneJSON.getString("tag");
9695

9796
ProximityZone zone = observer.zoneBuilder()
98-
.forAttachmentKeyAndValue(attachmentKey, attachmentValue)
97+
.forTag(tag)
9998
.inCustomRange(range)
100-
.withOnEnterAction(new Function1<ProximityAttachment, Unit>() {
99+
.withOnEnterAction(new Function1<ProximityContext, Unit>() {
101100
@Override
102-
public Unit invoke(ProximityAttachment attachment) {
103-
Log.i(TAG, "onEnterAction, zoneId = " + _id + ", attachment = " + attachment.toString());
101+
public Unit invoke(ProximityContext context) {
102+
Log.i(TAG, "onEnterAction, zoneId = " + _id + ", context = " + context.toString());
104103
WritableMap map = new WritableNativeMap();
105104
map.putString("zoneId", _id);
106-
map.putMap("attachment", attachmentToMap(attachment));
105+
map.putMap("context", contextToMap(context));
107106
sendEvent("Enter", map);
108107
return null;
109108
}
110109
})
111-
.withOnExitAction(new Function1<ProximityAttachment, Unit>() {
110+
.withOnExitAction(new Function1<ProximityContext, Unit>() {
112111
@Override
113-
public Unit invoke(ProximityAttachment attachment) {
114-
Log.i(TAG, "onExitAction, zoneId = " + _id + ", attachment = " + attachment.toString());
112+
public Unit invoke(ProximityContext context) {
113+
Log.i(TAG, "onExitAction, zoneId = " + _id + ", context = " + context.toString());
115114
WritableMap map = new WritableNativeMap();
116115
map.putString("zoneId", _id);
117-
map.putMap("attachment", attachmentToMap(attachment));
116+
map.putMap("context", contextToMap(context));
118117
sendEvent("Exit", map);
119118
return null;
120119
}
121120
})
122-
.withOnChangeAction(new Function1<List<? extends ProximityAttachment>, Unit>() {
121+
.withOnChangeAction(new Function1<List<? extends ProximityContext>, Unit>() {
123122
@Override
124-
public Unit invoke(List<? extends ProximityAttachment> attachments) {
125-
Log.i(TAG, "onChangeAction, zoneId = " + _id + ", attachments = " + attachments.toString());
123+
public Unit invoke(List<? extends ProximityContext> contexts) {
124+
Log.i(TAG, "onChangeAction, zoneId = " + _id + ", contexts = " + contexts.toString());
126125
WritableMap map = new WritableNativeMap();
127126
map.putString("zoneId", _id);
128-
map.putArray("attachments", attachmentsToArray(attachments));
127+
map.putArray("contexts", contextsToArray(contexts));
129128
sendEvent("Change", map);
130129
return null;
131130
}
@@ -159,25 +158,26 @@ public void onCatalystInstanceDestroy() {
159158

160159
// serialization helpers
161160

162-
private WritableMap payloadToMap(Map<String, String> payload) {
161+
private WritableMap attachmentsToMap(Map<String, String> attachments) {
163162
WritableMap map = new WritableNativeMap();
164-
for (Map.Entry<String, String> entry : payload.entrySet()) {
163+
for (Map.Entry<String, String> entry : attachments.entrySet()) {
165164
map.putString(entry.getKey(), entry.getValue());
166165
}
167166
return map;
168167
}
169168

170-
private WritableMap attachmentToMap(ProximityAttachment attachment) {
169+
private WritableMap contextToMap(ProximityContext context) {
171170
WritableMap map = new WritableNativeMap();
172-
map.putString("deviceIdentifier", attachment.getDeviceId());
173-
map.putMap("payload", payloadToMap(attachment.getPayload()));
171+
map.putString("tag", context.getTag());
172+
map.putMap("attachments", attachmentsToMap(context.getAttachments()));
173+
map.putString("deviceIdentifier", context.getInfo().getDeviceId());
174174
return map;
175175
}
176176

177-
private WritableArray attachmentsToArray(List<? extends ProximityAttachment> attachments) {
177+
private WritableArray contextsToArray(List<? extends ProximityContext> contexts) {
178178
WritableArray array = new WritableNativeArray();
179-
for (ProximityAttachment attachment : attachments) {
180-
array.pushMap(attachmentToMap(attachment));
179+
for (ProximityContext context : contexts) {
180+
array.pushMap(contextToMap(context));
181181
}
182182
return array;
183183
}

example/index.js

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,63 @@
11
// @flow
2-
'use strict'
2+
"use strict";
33

4-
import { AppRegistry } from 'react-native'
5-
import App from './App'
4+
import { AppRegistry } from "react-native";
5+
import App from "./App";
66

7-
import * as RNEP from '@estimote/react-native-proximity'
7+
import * as RNEP from "@estimote/react-native-proximity";
88

9-
AppRegistry.registerComponent('example', () => App)
9+
AppRegistry.registerComponent("example", () => App);
1010

11-
12-
13-
// will trigger when the user is within ~ 5 m of any beacon with attachment "type: lobby"
11+
// will trigger when the user is within ~ 5 m of any beacon with tag "lobby"
1412
// you can add attachments to your beacons on https://cloud.estimote.com, in Beacon Settings
15-
const zone1 = new RNEP.ProximityZone(5, 'type', 'lobby')
16-
zone1.onEnterAction = (attachment) => {
17-
console.log('zone1 onEnter')
18-
19-
// each `attachment` has a:
20-
// - `deviceIdentifier`
21-
console.log('zone1 onEnter deviceIdentifier', attachment.deviceIdentifier)
22-
23-
// - `payload`, which is a JavaScript [Map][1] of all the key-value pairs
24-
// assigned to the beacon in Estimote Cloud
25-
// [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
26-
console.log('zone1 "beacon" =>', attachment.payload.get('beacon')) // get individual values
27-
console.log('zone1 all key-values', Array.from(attachment.payload)) // show all key-value pairs
28-
}
29-
zone1.onExitAction = (attachment) => {
30-
console.log('zone1 onExit')
31-
}
32-
zone1.onChangeAction = (attachments) => {
33-
console.log('zone1 onChange')
34-
}
35-
36-
const zone2 = new RNEP.ProximityZone(5, 'type', 'conf_room')
37-
zone2.onEnterAction = (attachment) => {
38-
console.log('zone2 onEnter', attachment)
39-
}
40-
zone2.onExitAction = (attachment) => {
41-
console.log('zone2 onExit', attachment)
42-
}
43-
zone2.onChangeAction = (attachments) => {
44-
console.log('zone2 onChange', attachments)
45-
}
46-
47-
RNEP.locationPermission.request()
48-
.then(permission => {
49-
console.log(`location permission: ${permission}`)
13+
const zone1 = new RNEP.ProximityZone(5, "lobby");
14+
zone1.onEnterAction = context => {
15+
console.log("zone1 onEnter", context);
16+
};
17+
zone1.onExitAction = context => {
18+
console.log("zone1 onExit", context);
19+
};
20+
zone1.onChangeAction = contexts => {
21+
console.log("zone1 onChange", contexts);
22+
};
23+
24+
const zone2 = new RNEP.ProximityZone(5, "conf-room");
25+
zone2.onEnterAction = context => {
26+
console.log("zone2 onEnter", context);
27+
};
28+
zone2.onExitAction = context => {
29+
console.log("zone2 onExit", context);
30+
};
31+
zone2.onChangeAction = contexts => {
32+
console.log("zone2 onChange", contexts);
33+
};
34+
35+
RNEP.locationPermission.request().then(
36+
permission => {
37+
console.log(`location permission: ${permission}`);
5038
if (permission !== RNEP.locationPermission.DENIED) {
5139
// generate Estimote Cloud credentials for your app at:
5240
// https://cloud.estimote.com/#/apps/add/your-own-app
53-
const credentials = new RNEP.CloudCredentials('<#APP ID#>', '<#APP TOKEN#>')
41+
const credentials = new RNEP.CloudCredentials(
42+
"generic-asq",
43+
"8515b509fbac305129e21f8f9fe1d05e"
44+
);
5445

5546
const config = {
5647
// modern versions of Android require a notification informing the user that the app is active in the background
5748
// if you don't need proximity observation to work in the background, you can omit the entire `notification` config
5849
notification: {
59-
title: 'Exploration mode is on',
60-
text: "We'll notify you when you're next to something interesting.",
50+
title: "Exploration mode is on",
51+
text: "We'll notify you when you're next to something interesting."
6152
//icon: 'my_drawable' // if omitted, will default to the app icon (i.e., mipmap/ic_launcher)
6253
}
63-
}
54+
};
6455

65-
RNEP.proximityObserver.initialize(credentials, config)
66-
RNEP.proximityObserver.startObservingZones([zone1, zone2])
56+
RNEP.proximityObserver.initialize(credentials, config);
57+
RNEP.proximityObserver.startObservingZones([zone1, zone2]);
6758
}
68-
}, error => {
69-
console.error('Error when trying to obtain location permission', error)
70-
})
59+
},
60+
error => {
61+
console.error("Error when trying to obtain location permission", error);
62+
}
63+
);

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- EstimoteBluetoothScanning (0.2.0)
3-
- EstimoteProximitySDK (0.12.0):
3+
- EstimoteProximitySDK (0.14.0):
44
- EstimoteBluetoothScanning (~> 0.2.0)
55

66
DEPENDENCIES:
@@ -13,7 +13,7 @@ SPEC REPOS:
1313

1414
SPEC CHECKSUMS:
1515
EstimoteBluetoothScanning: d44e46ebebe4e0e2696c4577168cb8660b5d4ee9
16-
EstimoteProximitySDK: 279e73acff8ee84dc65e3d42e4dea0905e16bebd
16+
EstimoteProximitySDK: 02ddb304db111f50d9005f68268e6cd4e90cc9f4
1717

1818
PODFILE CHECKSUM: f62d8c72393572dd978650878bb2ec07cc0ce8bb
1919

0 commit comments

Comments
 (0)