@sentiance-react-native/user-context 6.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/android/build.gradle +32 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +2 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/sentiance/react/bridge/usercontext/SentianceUserContextConverter.java +210 -0
- package/android/src/main/java/com/sentiance/react/bridge/usercontext/SentianceUserContextEmitter.java +31 -0
- package/android/src/main/java/com/sentiance/react/bridge/usercontext/SentianceUserContextModule.java +74 -0
- package/android/src/main/java/com/sentiance/react/bridge/usercontext/SentianceUserContextPackage.java +30 -0
- package/android/src/main/java/com/sentiance/react/bridge/usercontext/utils/ErrorCodes.java +5 -0
- package/lib/index.d.ts +198 -0
- package/lib/index.js +9 -0
- package/lib/user-context.js +35 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
## Installation
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npm i @sentiance-react-native/core
|
|
5
|
+
|
|
6
|
+
npm i @sentiance-react-native/user-context
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
### Importing the package
|
|
12
|
+
|
|
13
|
+
You can import the entire contents of the package for use under a namespace of your choosing:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import * as SentianceUserContext from "@sentiance-react-native/user-context";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
or you can require specific functionality using named imports:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import {
|
|
23
|
+
getUserContext,
|
|
24
|
+
listenUserContextUpdates
|
|
25
|
+
} from "@sentiance-react-native/user-context";
|
|
26
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
plugins {
|
|
2
|
+
id "com.android.library"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
def coreProj
|
|
6
|
+
if (findProject(':core')) {
|
|
7
|
+
coreProj = project(':core')
|
|
8
|
+
} else if (findProject(':sentiance-react-native_core')) {
|
|
9
|
+
// Starting from RN 0.61, the @ sign is stripped from project names
|
|
10
|
+
coreProj = project(':sentiance-react-native_core')
|
|
11
|
+
} else if (findProject(':@sentiance-react-native_core')) {
|
|
12
|
+
// On RN 0.60, the @ sign is not stripped from project names
|
|
13
|
+
coreProj = project(':@sentiance-react-native_core')
|
|
14
|
+
} else {
|
|
15
|
+
throw new GradleException('Could not find the @sentiance-react-native/core package, have you installed it?')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply from: "$coreProj.projectDir/package-json-reader.gradle"
|
|
19
|
+
apply from: "$coreProj.projectDir/sentiance-version-finder.gradle"
|
|
20
|
+
|
|
21
|
+
def corePackageJson = PackageJson.of(coreProj)
|
|
22
|
+
applyAndroidVersionsFrom(corePackageJson)
|
|
23
|
+
def sentianceSdkVersion = getSentianceSdkVersion()
|
|
24
|
+
|
|
25
|
+
dependencies {
|
|
26
|
+
api coreProj
|
|
27
|
+
|
|
28
|
+
implementation(platform("com.sentiance:sdk-bom:${sentianceSdkVersion}"))
|
|
29
|
+
api("com.sentiance:sdk-user-context") { transitive = true }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
applyReactNativeDependency()
|
|
File without changes
|
package/android/gradlew
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2015 the original author or authors.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
|
|
19
|
+
##############################################################################
|
|
20
|
+
##
|
|
21
|
+
## Gradle start up script for UN*X
|
|
22
|
+
##
|
|
23
|
+
##############################################################################
|
|
24
|
+
|
|
25
|
+
# Attempt to set APP_HOME
|
|
26
|
+
# Resolve links: $0 may be a link
|
|
27
|
+
PRG="$0"
|
|
28
|
+
# Need this for relative symlinks.
|
|
29
|
+
while [ -h "$PRG" ] ; do
|
|
30
|
+
ls=`ls -ld "$PRG"`
|
|
31
|
+
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
32
|
+
if expr "$link" : '/.*' > /dev/null; then
|
|
33
|
+
PRG="$link"
|
|
34
|
+
else
|
|
35
|
+
PRG=`dirname "$PRG"`"/$link"
|
|
36
|
+
fi
|
|
37
|
+
done
|
|
38
|
+
SAVED="`pwd`"
|
|
39
|
+
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
40
|
+
APP_HOME="`pwd -P`"
|
|
41
|
+
cd "$SAVED" >/dev/null
|
|
42
|
+
|
|
43
|
+
APP_NAME="Gradle"
|
|
44
|
+
APP_BASE_NAME=`basename "$0"`
|
|
45
|
+
|
|
46
|
+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
47
|
+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
48
|
+
|
|
49
|
+
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
50
|
+
MAX_FD="maximum"
|
|
51
|
+
|
|
52
|
+
warn () {
|
|
53
|
+
echo "$*"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
die () {
|
|
57
|
+
echo
|
|
58
|
+
echo "$*"
|
|
59
|
+
echo
|
|
60
|
+
exit 1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# OS specific support (must be 'true' or 'false').
|
|
64
|
+
cygwin=false
|
|
65
|
+
msys=false
|
|
66
|
+
darwin=false
|
|
67
|
+
nonstop=false
|
|
68
|
+
case "`uname`" in
|
|
69
|
+
CYGWIN* )
|
|
70
|
+
cygwin=true
|
|
71
|
+
;;
|
|
72
|
+
Darwin* )
|
|
73
|
+
darwin=true
|
|
74
|
+
;;
|
|
75
|
+
MINGW* )
|
|
76
|
+
msys=true
|
|
77
|
+
;;
|
|
78
|
+
NONSTOP* )
|
|
79
|
+
nonstop=true
|
|
80
|
+
;;
|
|
81
|
+
esac
|
|
82
|
+
|
|
83
|
+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Determine the Java command to use to start the JVM.
|
|
87
|
+
if [ -n "$JAVA_HOME" ] ; then
|
|
88
|
+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
|
89
|
+
# IBM's JDK on AIX uses strange locations for the executables
|
|
90
|
+
JAVACMD="$JAVA_HOME/jre/sh/java"
|
|
91
|
+
else
|
|
92
|
+
JAVACMD="$JAVA_HOME/bin/java"
|
|
93
|
+
fi
|
|
94
|
+
if [ ! -x "$JAVACMD" ] ; then
|
|
95
|
+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
96
|
+
|
|
97
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
98
|
+
location of your Java installation."
|
|
99
|
+
fi
|
|
100
|
+
else
|
|
101
|
+
JAVACMD="java"
|
|
102
|
+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
103
|
+
|
|
104
|
+
Please set the JAVA_HOME variable in your environment to match the
|
|
105
|
+
location of your Java installation."
|
|
106
|
+
fi
|
|
107
|
+
|
|
108
|
+
# Increase the maximum file descriptors if we can.
|
|
109
|
+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
|
110
|
+
MAX_FD_LIMIT=`ulimit -H -n`
|
|
111
|
+
if [ $? -eq 0 ] ; then
|
|
112
|
+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
|
113
|
+
MAX_FD="$MAX_FD_LIMIT"
|
|
114
|
+
fi
|
|
115
|
+
ulimit -n $MAX_FD
|
|
116
|
+
if [ $? -ne 0 ] ; then
|
|
117
|
+
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
|
118
|
+
fi
|
|
119
|
+
else
|
|
120
|
+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
|
121
|
+
fi
|
|
122
|
+
fi
|
|
123
|
+
|
|
124
|
+
# For Darwin, add options to specify how the application appears in the dock
|
|
125
|
+
if $darwin; then
|
|
126
|
+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
130
|
+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
131
|
+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
132
|
+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
133
|
+
|
|
134
|
+
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
135
|
+
|
|
136
|
+
# We build the pattern for arguments to be converted via cygpath
|
|
137
|
+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
138
|
+
SEP=""
|
|
139
|
+
for dir in $ROOTDIRSRAW ; do
|
|
140
|
+
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
141
|
+
SEP="|"
|
|
142
|
+
done
|
|
143
|
+
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
144
|
+
# Add a user-defined pattern to the cygpath arguments
|
|
145
|
+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
146
|
+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
147
|
+
fi
|
|
148
|
+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
149
|
+
i=0
|
|
150
|
+
for arg in "$@" ; do
|
|
151
|
+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
152
|
+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
153
|
+
|
|
154
|
+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
155
|
+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
156
|
+
else
|
|
157
|
+
eval `echo args$i`="\"$arg\""
|
|
158
|
+
fi
|
|
159
|
+
i=`expr $i + 1`
|
|
160
|
+
done
|
|
161
|
+
case $i in
|
|
162
|
+
0) set -- ;;
|
|
163
|
+
1) set -- "$args0" ;;
|
|
164
|
+
2) set -- "$args0" "$args1" ;;
|
|
165
|
+
3) set -- "$args0" "$args1" "$args2" ;;
|
|
166
|
+
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
167
|
+
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
168
|
+
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
169
|
+
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
170
|
+
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
171
|
+
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
172
|
+
esac
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# Escape application args
|
|
176
|
+
save () {
|
|
177
|
+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
|
178
|
+
echo " "
|
|
179
|
+
}
|
|
180
|
+
APP_ARGS=`save "$@"`
|
|
181
|
+
|
|
182
|
+
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
|
183
|
+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
|
184
|
+
|
|
185
|
+
exec "$JAVACMD" "$@"
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
@rem
|
|
2
|
+
@rem Copyright 2015 the original author or authors.
|
|
3
|
+
@rem
|
|
4
|
+
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
@rem you may not use this file except in compliance with the License.
|
|
6
|
+
@rem You may obtain a copy of the License at
|
|
7
|
+
@rem
|
|
8
|
+
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
@rem
|
|
10
|
+
@rem Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
@rem See the License for the specific language governing permissions and
|
|
14
|
+
@rem limitations under the License.
|
|
15
|
+
@rem
|
|
16
|
+
|
|
17
|
+
@if "%DEBUG%" == "" @echo off
|
|
18
|
+
@rem ##########################################################################
|
|
19
|
+
@rem
|
|
20
|
+
@rem Gradle startup script for Windows
|
|
21
|
+
@rem
|
|
22
|
+
@rem ##########################################################################
|
|
23
|
+
|
|
24
|
+
@rem Set local scope for the variables with windows NT shell
|
|
25
|
+
if "%OS%"=="Windows_NT" setlocal
|
|
26
|
+
|
|
27
|
+
set DIRNAME=%~dp0
|
|
28
|
+
if "%DIRNAME%" == "" set DIRNAME=.
|
|
29
|
+
set APP_BASE_NAME=%~n0
|
|
30
|
+
set APP_HOME=%DIRNAME%
|
|
31
|
+
|
|
32
|
+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
33
|
+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
34
|
+
|
|
35
|
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
36
|
+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
37
|
+
|
|
38
|
+
@rem Find java.exe
|
|
39
|
+
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
40
|
+
|
|
41
|
+
set JAVA_EXE=java.exe
|
|
42
|
+
%JAVA_EXE% -version >NUL 2>&1
|
|
43
|
+
if "%ERRORLEVEL%" == "0" goto execute
|
|
44
|
+
|
|
45
|
+
echo.
|
|
46
|
+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
47
|
+
echo.
|
|
48
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
49
|
+
echo location of your Java installation.
|
|
50
|
+
|
|
51
|
+
goto fail
|
|
52
|
+
|
|
53
|
+
:findJavaFromJavaHome
|
|
54
|
+
set JAVA_HOME=%JAVA_HOME:"=%
|
|
55
|
+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
56
|
+
|
|
57
|
+
if exist "%JAVA_EXE%" goto execute
|
|
58
|
+
|
|
59
|
+
echo.
|
|
60
|
+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
61
|
+
echo.
|
|
62
|
+
echo Please set the JAVA_HOME variable in your environment to match the
|
|
63
|
+
echo location of your Java installation.
|
|
64
|
+
|
|
65
|
+
goto fail
|
|
66
|
+
|
|
67
|
+
:execute
|
|
68
|
+
@rem Setup the command line
|
|
69
|
+
|
|
70
|
+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@rem Execute Gradle
|
|
74
|
+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
75
|
+
|
|
76
|
+
:end
|
|
77
|
+
@rem End local scope for the variables with windows NT shell
|
|
78
|
+
if "%ERRORLEVEL%"=="0" goto mainEnd
|
|
79
|
+
|
|
80
|
+
:fail
|
|
81
|
+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
82
|
+
rem the _cmd.exe /c_ return code!
|
|
83
|
+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
|
84
|
+
exit /b 1
|
|
85
|
+
|
|
86
|
+
:mainEnd
|
|
87
|
+
if "%OS%"=="Windows_NT" endlocal
|
|
88
|
+
|
|
89
|
+
:omega
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.usercontext;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments;
|
|
4
|
+
import com.facebook.react.bridge.WritableArray;
|
|
5
|
+
import com.facebook.react.bridge.WritableMap;
|
|
6
|
+
import com.sentiance.sdk.ondevice.api.Attribute;
|
|
7
|
+
import com.sentiance.sdk.ondevice.api.GeoLocation;
|
|
8
|
+
import com.sentiance.sdk.ondevice.api.event.Event;
|
|
9
|
+
import com.sentiance.sdk.ondevice.api.event.StationaryEvent;
|
|
10
|
+
import com.sentiance.sdk.ondevice.api.event.TransportEvent;
|
|
11
|
+
import com.sentiance.sdk.ondevice.api.segment.Segment;
|
|
12
|
+
import com.sentiance.sdk.ondevice.api.venue.Venue;
|
|
13
|
+
import com.sentiance.sdk.ondevice.api.venue.VenueCandidate;
|
|
14
|
+
import com.sentiance.sdk.ondevice.api.venue.Visit;
|
|
15
|
+
import com.sentiance.sdk.usercontext.api.RequestUserContextError;
|
|
16
|
+
import com.sentiance.sdk.usercontext.api.RequestUserContextFailureReason;
|
|
17
|
+
import com.sentiance.sdk.usercontext.api.UserContext;
|
|
18
|
+
import com.sentiance.sdk.usercontext.api.UserContextUpdateCriteria;
|
|
19
|
+
import com.sentiance.sdk.util.DateTime;
|
|
20
|
+
|
|
21
|
+
import java.util.List;
|
|
22
|
+
import java.util.Map;
|
|
23
|
+
|
|
24
|
+
public class SentianceUserContextConverter {
|
|
25
|
+
|
|
26
|
+
public static WritableMap convertGeoLocation(GeoLocation location) {
|
|
27
|
+
WritableMap locationMap = Arguments.createMap();
|
|
28
|
+
|
|
29
|
+
locationMap.putString("latitude", String.valueOf(location.getLatitude()));
|
|
30
|
+
locationMap.putString("longitude", String.valueOf(location.getLongitude()));
|
|
31
|
+
locationMap.putString("accuracy", String.valueOf(location.getAccuracyInMeters()));
|
|
32
|
+
|
|
33
|
+
return locationMap;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private static WritableMap convertSegment(Segment segment) {
|
|
37
|
+
WritableMap map = Arguments.createMap();
|
|
38
|
+
|
|
39
|
+
map.putString("category", segment.getCategory().name());
|
|
40
|
+
map.putString("subcategory", segment.getSubcategory().name());
|
|
41
|
+
map.putString("type", segment.getType().name());
|
|
42
|
+
map.putInt("id", segment.getType().getUniqueId());
|
|
43
|
+
map.putString("startTime", segment.getStartTime().toString());
|
|
44
|
+
map.putString("startTimeEpoch", "" + segment.getStartTime().getEpochTime() / 1000);
|
|
45
|
+
|
|
46
|
+
DateTime endTime = segment.getEndTime();
|
|
47
|
+
if (endTime != null) {
|
|
48
|
+
map.putString("endTime", endTime.toString());
|
|
49
|
+
map.putString("endTimeEpoch", "" + segment.getEndTime().getEpochTime() / 1000);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
WritableArray attributes = Arguments.createArray();
|
|
53
|
+
for (Attribute attribute : segment.getAttributes()) {
|
|
54
|
+
WritableMap a = Arguments.createMap();
|
|
55
|
+
a.putString("name", attribute.getName());
|
|
56
|
+
a.putDouble("value", attribute.getValue());
|
|
57
|
+
attributes.pushMap(a);
|
|
58
|
+
}
|
|
59
|
+
map.putArray("attributes", attributes);
|
|
60
|
+
|
|
61
|
+
return map;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private static WritableMap convertEvent(Event event) {
|
|
65
|
+
WritableMap map = Arguments.createMap();
|
|
66
|
+
|
|
67
|
+
map.putString("startTime", event.getStartTime().toString());
|
|
68
|
+
if (event.getEndTime() != null) {
|
|
69
|
+
map.putString("endTime", event.getEndTime().toString());
|
|
70
|
+
|
|
71
|
+
Long durationInSeconds = event.getDurationInSeconds();
|
|
72
|
+
if (durationInSeconds != null) {
|
|
73
|
+
map.putInt("durationInSeconds", (int) (long) durationInSeconds);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
map.putString("type", event.getEventType().toString());
|
|
78
|
+
|
|
79
|
+
if (event instanceof StationaryEvent) {
|
|
80
|
+
addStationaryEventInfo(map, (StationaryEvent) event);
|
|
81
|
+
} else if (event instanceof TransportEvent) {
|
|
82
|
+
addTransportEventInfo(map, (TransportEvent) event);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return map;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public static WritableArray convertCriteriaList(List<UserContextUpdateCriteria> criteria) {
|
|
89
|
+
WritableArray array = Arguments.createArray();
|
|
90
|
+
for (UserContextUpdateCriteria criterion : criteria) {
|
|
91
|
+
array.pushString(criterion.toString());
|
|
92
|
+
}
|
|
93
|
+
return array;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public static WritableMap convertUserContext(UserContext userContext) {
|
|
97
|
+
WritableMap userContextMap = Arguments.createMap();
|
|
98
|
+
|
|
99
|
+
// Events
|
|
100
|
+
WritableArray eventArray = Arguments.createArray();
|
|
101
|
+
for (Event event : userContext.getEvents()) {
|
|
102
|
+
eventArray.pushMap(convertEvent(event));
|
|
103
|
+
}
|
|
104
|
+
userContextMap.putArray("events", eventArray);
|
|
105
|
+
|
|
106
|
+
// Segments
|
|
107
|
+
WritableArray segmentsArray = Arguments.createArray();
|
|
108
|
+
for (Segment segment : userContext.getActiveSegments()) {
|
|
109
|
+
segmentsArray.pushMap(convertSegment(segment));
|
|
110
|
+
}
|
|
111
|
+
userContextMap.putArray("activeSegments", segmentsArray);
|
|
112
|
+
|
|
113
|
+
// Last know location
|
|
114
|
+
if (userContext.getLastKnownLocation() != null) {
|
|
115
|
+
userContextMap.putMap("lastKnownLocation", convertGeoLocation(userContext.getLastKnownLocation()));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Home
|
|
119
|
+
if (userContext.getHome() != null) {
|
|
120
|
+
userContextMap.putMap("home", convertVenue(userContext.getHome()));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Work
|
|
124
|
+
if (userContext.getWork() != null) {
|
|
125
|
+
userContextMap.putMap("work", convertVenue(userContext.getWork()));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return userContextMap;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public static String stringifyGetUserContextError(RequestUserContextError error) {
|
|
132
|
+
RequestUserContextFailureReason reason = error.getReason();
|
|
133
|
+
String details = "";
|
|
134
|
+
switch (reason) {
|
|
135
|
+
case NO_USER:
|
|
136
|
+
details = "No Sentiance user present on the device.";
|
|
137
|
+
break;
|
|
138
|
+
case FEATURE_NOT_ENABLED:
|
|
139
|
+
details = "Feature not enabled. Contact Sentiance support to enable it.";
|
|
140
|
+
break;
|
|
141
|
+
case USER_DISABLED_REMOTELY:
|
|
142
|
+
details = "The user is disabled remotely.";
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
return String.format("Reason: %s - %s", reason.name(), details);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private static void addStationaryEventInfo(WritableMap map, StationaryEvent event) {
|
|
149
|
+
if (event.getLocation() != null) {
|
|
150
|
+
map.putMap("location", convertGeoLocation(event.getLocation()));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
map.putString("venueSignificance", event.getVenueSignificance().toString());
|
|
154
|
+
|
|
155
|
+
WritableArray venueCandidatesArray = Arguments.createArray();
|
|
156
|
+
for (VenueCandidate candidate : event.getVenueCandidates()) {
|
|
157
|
+
venueCandidatesArray.pushMap(convertVenueCandidate(candidate));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
map.putArray("venueCandidates", venueCandidatesArray);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private static WritableMap convertVenueCandidate(VenueCandidate candidate) {
|
|
164
|
+
WritableMap venueCandidateMap = Arguments.createMap();
|
|
165
|
+
venueCandidateMap.putMap("venue", convertVenue(candidate.getVenue()));
|
|
166
|
+
venueCandidateMap.putDouble("likelihood", candidate.getLikelihood());
|
|
167
|
+
|
|
168
|
+
WritableArray visitsArray = Arguments.createArray();
|
|
169
|
+
for (Visit visit : candidate.getVisits()) {
|
|
170
|
+
visitsArray.pushMap(convertVisit(visit));
|
|
171
|
+
}
|
|
172
|
+
venueCandidateMap.putArray("visits", visitsArray);
|
|
173
|
+
return venueCandidateMap;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private static WritableMap convertVenue(Venue venue) {
|
|
177
|
+
WritableMap venueMap = Arguments.createMap();
|
|
178
|
+
|
|
179
|
+
if (venue.getName() != null) {
|
|
180
|
+
venueMap.putString("name", venue.getName());
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
venueMap.putMap("location", convertGeoLocation(venue.getLocation()));
|
|
184
|
+
|
|
185
|
+
WritableMap venueLabelsMap = Arguments.createMap();
|
|
186
|
+
for (Map.Entry<String, String> entry : venue.getLabels().entrySet()) {
|
|
187
|
+
venueLabelsMap.putString(entry.getKey(), entry.getValue());
|
|
188
|
+
}
|
|
189
|
+
venueMap.putMap("venueLabels", venueLabelsMap);
|
|
190
|
+
|
|
191
|
+
return venueMap;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private static WritableMap convertVisit(Visit visit) {
|
|
195
|
+
WritableMap visitMap = Arguments.createMap();
|
|
196
|
+
visitMap.putString("startTime", visit.getStartTime().toString());
|
|
197
|
+
visitMap.putString("startTimeEpoch", "" + visit.getStartTime().getEpochTime());
|
|
198
|
+
|
|
199
|
+
visitMap.putString("endTime", visit.getEndTime().toString());
|
|
200
|
+
visitMap.putString("endTimeEpoch", "" + visit.getEndTime().getEpochTime());
|
|
201
|
+
|
|
202
|
+
visitMap.putInt("durationInSeconds", (int) visit.getDurationInSeconds());
|
|
203
|
+
|
|
204
|
+
return visitMap;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private static void addTransportEventInfo(WritableMap map, TransportEvent event) {
|
|
208
|
+
map.putString("transportMode", event.getTransportMode().toString());
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.usercontext;
|
|
2
|
+
|
|
3
|
+
import static com.sentiance.react.bridge.usercontext.SentianceUserContextConverter.convertCriteriaList;
|
|
4
|
+
import static com.sentiance.react.bridge.usercontext.SentianceUserContextConverter.convertUserContext;
|
|
5
|
+
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.Arguments;
|
|
9
|
+
import com.facebook.react.bridge.WritableMap;
|
|
10
|
+
import com.sentiance.react.bridge.core.base.AbstractSentianceEmitter;
|
|
11
|
+
import com.sentiance.sdk.usercontext.api.UserContext;
|
|
12
|
+
import com.sentiance.sdk.usercontext.api.UserContextUpdateCriteria;
|
|
13
|
+
|
|
14
|
+
import java.util.List;
|
|
15
|
+
|
|
16
|
+
class SentianceUserContextEmitter extends AbstractSentianceEmitter {
|
|
17
|
+
|
|
18
|
+
private static final String USER_CONTEXT_EVENT = "SENTIANCE_USER_CONTEXT_UPDATE_EVENT";
|
|
19
|
+
|
|
20
|
+
public SentianceUserContextEmitter(Context context) {
|
|
21
|
+
super(context);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void sendUserContext(List<UserContextUpdateCriteria> criteria, UserContext userContext) {
|
|
25
|
+
WritableMap map = Arguments.createMap();
|
|
26
|
+
map.putMap("userContext", convertUserContext(userContext));
|
|
27
|
+
map.putArray("criteria", convertCriteriaList(criteria));
|
|
28
|
+
|
|
29
|
+
sendEvent(USER_CONTEXT_EVENT, map);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/android/src/main/java/com/sentiance/react/bridge/usercontext/SentianceUserContextModule.java
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.usercontext;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.bridge.Promise;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
9
|
+
import com.sentiance.react.bridge.core.base.AbstractSentianceModule;
|
|
10
|
+
import com.sentiance.react.bridge.usercontext.utils.ErrorCodes;
|
|
11
|
+
import com.sentiance.sdk.usercontext.api.RequestUserContextError;
|
|
12
|
+
import com.sentiance.sdk.usercontext.api.UserContext;
|
|
13
|
+
import com.sentiance.sdk.usercontext.api.UserContextApi;
|
|
14
|
+
import com.sentiance.sdk.usercontext.api.UserContextUpdateListener;
|
|
15
|
+
|
|
16
|
+
public class SentianceUserContextModule extends AbstractSentianceModule {
|
|
17
|
+
|
|
18
|
+
private static final String NATIVE_MODULE_NAME = "SentianceUserContext";
|
|
19
|
+
|
|
20
|
+
private final SentianceUserContextEmitter emitter;
|
|
21
|
+
private @Nullable
|
|
22
|
+
UserContextUpdateListener mUserContextUpdateListener;
|
|
23
|
+
|
|
24
|
+
public SentianceUserContextModule(ReactApplicationContext reactContext) {
|
|
25
|
+
super(reactContext);
|
|
26
|
+
emitter = new SentianceUserContextEmitter(reactContext);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@NonNull
|
|
30
|
+
@Override
|
|
31
|
+
public String getName() {
|
|
32
|
+
return NATIVE_MODULE_NAME;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@ReactMethod
|
|
36
|
+
@SuppressWarnings("unused")
|
|
37
|
+
public void requestUserContext(final Promise promise) {
|
|
38
|
+
if (rejectIfNotInitialized(promise)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
UserContextApi.getInstance(reactContext)
|
|
43
|
+
.requestUserContext()
|
|
44
|
+
.addOnCompleteListener(pendingOperation -> {
|
|
45
|
+
if (pendingOperation.isSuccessful()) {
|
|
46
|
+
UserContext userContext = pendingOperation.getResult();
|
|
47
|
+
promise.resolve(SentianceUserContextConverter.convertUserContext(userContext));
|
|
48
|
+
} else {
|
|
49
|
+
RequestUserContextError error = pendingOperation.getError();
|
|
50
|
+
promise.reject(ErrorCodes.E_SDK_REQUEST_USER_CONTEXT_ERROR,
|
|
51
|
+
SentianceUserContextConverter.stringifyGetUserContextError(error));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@ReactMethod
|
|
57
|
+
@SuppressWarnings("unused")
|
|
58
|
+
public void listenUserContextUpdates(Promise promise) {
|
|
59
|
+
if (rejectIfNotInitialized(promise)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
UserContextApi userContextApi = UserContextApi.getInstance(reactContext);
|
|
64
|
+
|
|
65
|
+
if (mUserContextUpdateListener != null) {
|
|
66
|
+
userContextApi.removeUserContextUpdateListener(mUserContextUpdateListener);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
mUserContextUpdateListener = emitter::sendUserContext;
|
|
70
|
+
|
|
71
|
+
userContextApi.addUserContextUpdateListener(mUserContextUpdateListener);
|
|
72
|
+
promise.resolve(true);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.usercontext;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.ReactPackage;
|
|
6
|
+
import com.facebook.react.bridge.NativeModule;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.Collections;
|
|
12
|
+
import java.util.List;
|
|
13
|
+
|
|
14
|
+
public class SentianceUserContextPackage implements ReactPackage {
|
|
15
|
+
|
|
16
|
+
@NonNull
|
|
17
|
+
@Override
|
|
18
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
19
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
20
|
+
SentianceUserContextModule module = new SentianceUserContextModule(reactContext);
|
|
21
|
+
modules.add(module);
|
|
22
|
+
return modules;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@NonNull
|
|
26
|
+
@Override
|
|
27
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
28
|
+
return Collections.emptyList();
|
|
29
|
+
}
|
|
30
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
declare module "sentiance-react-native-user-context" {
|
|
2
|
+
import {EmitterSubscription} from "react-native";
|
|
3
|
+
|
|
4
|
+
export type SegmentCategory = "LEISURE" | "MOBILITY" | "WORK_LIFE";
|
|
5
|
+
export type SegmentSubcategory =
|
|
6
|
+
"COMMUTE"
|
|
7
|
+
| "DRIVING"
|
|
8
|
+
| "ENTERTAINMENT"
|
|
9
|
+
| "FAMILY"
|
|
10
|
+
| "HOME"
|
|
11
|
+
| "SHOPPING"
|
|
12
|
+
| "SOCIAL"
|
|
13
|
+
| "TRANSPORT"
|
|
14
|
+
| "TRAVEL"
|
|
15
|
+
| "WELLBEING"
|
|
16
|
+
| "WINING_AND_DINING"
|
|
17
|
+
| "WORK";
|
|
18
|
+
export type SegmentType =
|
|
19
|
+
"AGGRESSIVE_DRIVER"
|
|
20
|
+
| "ANTICIPATIVE_DRIVER"
|
|
21
|
+
| "BAR_GOER"
|
|
22
|
+
| "BEAUTY_QUEEN"
|
|
23
|
+
| "BRAND_LOYAL__BAR"
|
|
24
|
+
| "BRAND_LOYAL__CAFE"
|
|
25
|
+
|
|
|
26
|
+
"BRAND_LOYAL__RESTAURANT"
|
|
27
|
+
| "BRAND_LOYAL__RETAIL"
|
|
28
|
+
| "BRAND_LOYALTY"
|
|
29
|
+
| "BRAND_LOYALTY__GAS_STATIONS"
|
|
30
|
+
|
|
|
31
|
+
"BRAND_LOYALTY__RESTAURANT_BAR"
|
|
32
|
+
| "BRAND_LOYALTY__SUPERMARKET"
|
|
33
|
+
| "CITY_DRIVER"
|
|
34
|
+
| "CITY_HOME"
|
|
35
|
+
| "CITY_WORKER"
|
|
36
|
+
|
|
|
37
|
+
"CLUBBER"
|
|
38
|
+
| "CULTURE_BUFF"
|
|
39
|
+
| "DIE_HARD_DRIVER"
|
|
40
|
+
| "DISTRACTED_DRIVER"
|
|
41
|
+
| "DO_IT_YOURSELVER"
|
|
42
|
+
| "DOG_WALKER"
|
|
43
|
+
| "EARLY_BIRD"
|
|
44
|
+
|
|
|
45
|
+
"EASY_COMMUTER"
|
|
46
|
+
| "EFFICIENT_DRIVER"
|
|
47
|
+
| "FASHIONISTA"
|
|
48
|
+
| "FOODIE"
|
|
49
|
+
| "FREQUENT_FLYER"
|
|
50
|
+
| "FULLTIME_WORKER"
|
|
51
|
+
| "GAMER"
|
|
52
|
+
|
|
|
53
|
+
"GREEN_COMMUTER"
|
|
54
|
+
| "HEALTHY_BIKER"
|
|
55
|
+
| "HEALTHY_WALKER"
|
|
56
|
+
| "HEAVY_COMMUTER"
|
|
57
|
+
| "HOME_BOUND"
|
|
58
|
+
| "HOMEBODY"
|
|
59
|
+
| "HOMEWORKER"
|
|
60
|
+
|
|
|
61
|
+
"ILLEGAL_DRIVER"
|
|
62
|
+
| "LATE_WORKER"
|
|
63
|
+
| "LEGAL_DRIVER"
|
|
64
|
+
| "LONG_COMMUTER"
|
|
65
|
+
| "MOBILITY"
|
|
66
|
+
| "MOBILITY__HIGH"
|
|
67
|
+
| "MOBILITY__LIMITED"
|
|
68
|
+
|
|
|
69
|
+
"MOBILITY__MODERATE"
|
|
70
|
+
| "MOTORWAY_DRIVER"
|
|
71
|
+
| "MUSIC_LOVER"
|
|
72
|
+
| "NATURE_LOVER"
|
|
73
|
+
| "NIGHT_OWL"
|
|
74
|
+
| "NIGHTWORKER"
|
|
75
|
+
| "NORMAL_COMMUTER"
|
|
76
|
+
|
|
|
77
|
+
"PARTTIME_WORKER"
|
|
78
|
+
| "PET_OWNER"
|
|
79
|
+
| "PHYSICAL_ACTIVITY__HIGH"
|
|
80
|
+
| "PHYSICAL_ACTIVITY__LIMITED"
|
|
81
|
+
| "PHYSICAL_ACTIVITY__MODERATE"
|
|
82
|
+
|
|
|
83
|
+
"PUBLIC_TRANSPORTS_COMMUTER"
|
|
84
|
+
| "PUBLIC_TRANSPORTS_USER"
|
|
85
|
+
| "RECENTLY_CHANGED_JOB"
|
|
86
|
+
| "RECENTLY_MOVED_HOME"
|
|
87
|
+
| "RESTO_LOVER"
|
|
88
|
+
|
|
|
89
|
+
"RESTO_LOVER__AMERICAN"
|
|
90
|
+
| "RESTO_LOVER__ASIAN"
|
|
91
|
+
| "RESTO_LOVER__BARBECUE"
|
|
92
|
+
| "RESTO_LOVER__FASTFOOD"
|
|
93
|
+
| "RESTO_LOVER__FRENCH"
|
|
94
|
+
|
|
|
95
|
+
"RESTO_LOVER__GERMAN"
|
|
96
|
+
| "RESTO_LOVER__GREEK"
|
|
97
|
+
| "RESTO_LOVER__GRILL"
|
|
98
|
+
| "RESTO_LOVER__INTERNATIONAL"
|
|
99
|
+
| "RESTO_LOVER__ITALIAN"
|
|
100
|
+
|
|
|
101
|
+
"RESTO_LOVER__MEDITERRANEAN"
|
|
102
|
+
| "RESTO_LOVER__MEXICAN"
|
|
103
|
+
| "RESTO_LOVER__SEAFOOD"
|
|
104
|
+
| "RESTO_LOVER__SNACK"
|
|
105
|
+
| "RURAL_HOME"
|
|
106
|
+
|
|
|
107
|
+
"RURAL_WORKER"
|
|
108
|
+
| "SHOPAHOLIC"
|
|
109
|
+
| "SHORT_COMMUTER"
|
|
110
|
+
| "SLEEP_DEPRIVED"
|
|
111
|
+
| "SOCIAL_ACTIVITY"
|
|
112
|
+
| "SOCIAL_ACTIVITY__HIGH"
|
|
113
|
+
|
|
|
114
|
+
"SOCIAL_ACTIVITY__LIMITED"
|
|
115
|
+
| "SOCIAL_ACTIVITY__MODERATE"
|
|
116
|
+
| "SPORTIVE"
|
|
117
|
+
| "STUDENT"
|
|
118
|
+
| "TOWN_HOME"
|
|
119
|
+
| "TOWN_WORKER"
|
|
120
|
+
|
|
|
121
|
+
"UBER_PARENT"
|
|
122
|
+
| "WORK_LIFE_BALANCE"
|
|
123
|
+
| "WORK_TRAVELLER"
|
|
124
|
+
| "WORKAHOLIC";
|
|
125
|
+
|
|
126
|
+
export interface Event {
|
|
127
|
+
startTime: string,
|
|
128
|
+
endTime: string | null,
|
|
129
|
+
durationInSeconds: number | null,
|
|
130
|
+
type: string,
|
|
131
|
+
// stationary event fields
|
|
132
|
+
location: EventLocation | null,
|
|
133
|
+
venueSignificance: string | null,
|
|
134
|
+
venueCandidates: VenueCandidate[] | null,
|
|
135
|
+
// transport event fields
|
|
136
|
+
transportMode: "UNKNOWN" | "BYCICLE" | "WALKING" | "RUNNING" | "VEHICLE" | "RAIL" | null
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface EventLocation {
|
|
140
|
+
latitude: string,
|
|
141
|
+
longitude: string,
|
|
142
|
+
accuracy: string,
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface VenueCandidate {
|
|
146
|
+
venue: Venue,
|
|
147
|
+
likelihood: number,
|
|
148
|
+
visits: Visit[],
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface Venue {
|
|
152
|
+
name: string | null,
|
|
153
|
+
location: EventLocation | null,
|
|
154
|
+
venueLabels: VenueLabels,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface VenueLabels {
|
|
158
|
+
[label: string]: string
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface Visit {
|
|
162
|
+
startTime: string,
|
|
163
|
+
endTime: string,
|
|
164
|
+
durationInSeconds: number,
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface Segment {
|
|
168
|
+
category: SegmentCategory;
|
|
169
|
+
subcategory: SegmentSubcategory;
|
|
170
|
+
type: SegmentType;
|
|
171
|
+
id: number;
|
|
172
|
+
startTime: string;
|
|
173
|
+
endTime: string | null;
|
|
174
|
+
attributes: SegmentAttribute[];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface SegmentAttribute {
|
|
178
|
+
name: string,
|
|
179
|
+
value: number
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface UserContext {
|
|
183
|
+
events: Event[],
|
|
184
|
+
activeSegments: Segment[],
|
|
185
|
+
lastKnownLocation: EventLocation | null;
|
|
186
|
+
home: Venue | null;
|
|
187
|
+
work: Venue | null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface SentianceUserContext {
|
|
191
|
+
requestUserContext(): Promise<UserContext>;
|
|
192
|
+
|
|
193
|
+
addUserContextUpdateListener(onUserContextUpdated: (userContext: UserContext) => void): Promise<EmitterSubscription>;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const SentianceUserContext: SentianceUserContext;
|
|
197
|
+
export default SentianceUserContext;
|
|
198
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import userContext from './user-context';
|
|
2
|
+
|
|
3
|
+
const requestUserContext = () => userContext.requestUserContext();
|
|
4
|
+
const addUserContextUpdateListener = userContext._addUserContextUpdateListener;
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
requestUserContext,
|
|
8
|
+
addUserContextUpdateListener
|
|
9
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const {NativeModules, NativeEventEmitter, Platform} = require("react-native");
|
|
2
|
+
const {varToString} = require("@sentiance-react-native/core/lib/utils")
|
|
3
|
+
const {SentianceUserContext, SentianceCore} = NativeModules;
|
|
4
|
+
|
|
5
|
+
const SDK_USER_CONTEXT_UPDATE_EVENT = "SENTIANCE_USER_CONTEXT_UPDATE_EVENT";
|
|
6
|
+
|
|
7
|
+
var userContextModule
|
|
8
|
+
if (Platform.OS === 'android') {
|
|
9
|
+
if (!SentianceUserContext) {
|
|
10
|
+
const nativeModuleName = varToString({SentianceUserContext});
|
|
11
|
+
throw `Could not locate the native ${nativeModuleName} module.
|
|
12
|
+
Make sure that your native code is properly linked, and that the module name you specified is correct.`;
|
|
13
|
+
}
|
|
14
|
+
userContextModule = SentianceUserContext
|
|
15
|
+
} else {
|
|
16
|
+
if (!SentianceCore) {
|
|
17
|
+
const nativeModuleName = varToString({SentianceCore});
|
|
18
|
+
throw `Could not locate the native ${nativeModuleName} module.
|
|
19
|
+
Make sure that your native code is properly linked, and that the module name you specified is correct.`;
|
|
20
|
+
}
|
|
21
|
+
userContextModule = SentianceCore
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SENTIANCE_EMITTER = new NativeEventEmitter(userContextModule);
|
|
25
|
+
|
|
26
|
+
const _addUserContextUpdateListener = async (onUserContextUpdated) => {
|
|
27
|
+
await userContextModule.listenUserContextUpdates();
|
|
28
|
+
return SENTIANCE_EMITTER.addListener(SDK_USER_CONTEXT_UPDATE_EVENT, (data) => {
|
|
29
|
+
onUserContextUpdated(data);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
userContextModule._addUserContextUpdateListener = _addUserContextUpdateListener;
|
|
34
|
+
|
|
35
|
+
export default userContextModule;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sentiance-react-native/user-context",
|
|
3
|
+
"version": "6.0.0-beta.9",
|
|
4
|
+
"description": "React Native Sentiance - This module provides an easy API to add user context awareness into your apps.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"lint": "npx eslint lib/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"react-native",
|
|
13
|
+
"user-context",
|
|
14
|
+
"sentiance"
|
|
15
|
+
],
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@sentiance-react-native/core": "6.0.0-beta.9"
|
|
18
|
+
},
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "",
|
|
21
|
+
"homepage": "https://github.com/sentiance/react-native-sentiance/user-context#readme",
|
|
22
|
+
"repository": "github:sentiance/react-native-sentiance",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
}
|
|
26
|
+
}
|