Skip to content

Commit

Permalink
added git action
Browse files Browse the repository at this point in the history
  • Loading branch information
naveenrobo committed Jun 2, 2021
1 parent 603dc80 commit 7621a16
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 35 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Node.js Package
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v2
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
# Defaults to the user or organization that owns the workflow file
scope: '@teamdotworld'
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 1 addition & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ android {
buildConfigField "int", "PUSH_NOTIFICATION_ID", PUSH_NOTIFICATION_ID
buildConfigField "String", "PUSH_NOTIFICATION_CHANNEL_NAME", PUSH_NOTIFICATION_CHANNEL_NAME

buildConfigField "long", "SCAN_DURATION", SCAN_DURATION
buildConfigField "long", "MIN_SCAN_INTERVAL", MIN_SCAN_INTERVAL
buildConfigField "long", "MAX_SCAN_INTERVAL", MAX_SCAN_INTERVAL
buildConfigField "long", "HEALTH_CHECK_INTERVAL", HEALTH_CHECK_INTERVAL
buildConfigField "long", "MAX_QUEUE_TIME", MAX_QUEUE_TIME
buildConfigField "long", "BM_CHECK_INTERVAL", BM_CHECK_INTERVAL
Expand All @@ -61,7 +58,7 @@ android {

buildConfigField "String", "V2_CHARACTERISTIC_ID", V2_CHARACTERISTIC_ID

buildConfigField "String", "LOCATION", LOCATION
buildConfigField "String", "PUBLIC_KEY", PUBLIC_KEY

}

Expand Down
23 changes: 3 additions & 20 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ BleAdvertiser_kotlinVersion=1.5.0
BleAdvertiser_compileSdkVersion=29
BleAdvertiser_buildToolsVersion=29.0.2
BleAdvertiser_targetSdkVersion=29

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
Expand All @@ -24,42 +23,26 @@ android.useAndroidX=true
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official


STAGING_SERVICE_UUID="fd05a570-274a-4b1f-a5a3-eb52e5e02b8b"
PROD_SERVICE_UUID=""


SERVICE_FOREGROUND_NOTIFICATION_ID=771579
SERVICE_FOREGROUND_CHANNEL_ID="DW Trace Updates"
SERVICE_FOREGROUND_CHANNEL_NAME="DW Trace Foreground Service"

PUSH_NOTIFICATION_ID=771578
PUSH_NOTIFICATION_CHANNEL_NAME="OpenTrace Notifications"

#service configurations
SCAN_DURATION=3000
MIN_SCAN_INTERVAL=4000
MAX_SCAN_INTERVAL=5000

HEALTH_CHECK_INTERVAL=900000
ADVERTISING_DURATION=180000
ADVERTISING_INTERVAL=2000

MAX_QUEUE_TIME=5000
BM_CHECK_INTERVAL=540000
PURGE_INTERVAL=86400000
PURGE_TTL=1814400000

CONNECTION_TIMEOUT=6000
BLACKLIST_DURATION=120000

V2_CHARACTERISTIC_ID = "53447ca9-1e5b-448e-ab7b-bd9438c048af"

NOTIFY_SERVICE_ID = "afecf75a-0f7e-450f-85e0-5683c92fe321"

V2_CHARACTERISTIC_ID="53447ca9-1e5b-448e-ab7b-bd9438c048af"
NOTIFY_SERVICE_ID="afecf75a-0f7e-450f-85e0-5683c92fe321"
MANUFACTURER_ID=1023
LOCATION="Naveen Home"

PUBLIC_KEY="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAooDxEsQ0VGa80Yp5fwczAIEq7fuQF6cQqaD+czcBRK0UhH0FXjxTFKfA9OlFMHF/GH4n1vvne/rPFEl2sVhxJucbV9g7dwv70WyZNXODqIdX4dqyn3Y7Uz6h3gX9lUYtjW5KFBtEysJl3Vtq4gQyGfKZbjxnreI/BU+Xbjg9QqhQ0T93UFNluZKPf0o9ki+BFSD3gc1NnyUhfa7ncCFaSRkd8/fyNeR/zaKUN/W4+MMiZ9huCh2+ZIrQ2fiIZIX8gqWjwZ2tH39Cquy3pzkOtFOavVOw1di9fdqicq5L4YUdoakNItuAirOgcHOfa8s2L6piOxNiPqnZ9++nqn9WQQIDAQAB"
CAN_ADVERTISE=false
CAN_SCAN=true
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.util.Log
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import dev.dotworld.ble.AppPreferences
import dev.dotworld.ble.Utils

class BleAdvertiserModule(reactContext: ReactApplicationContext) :
Expand All @@ -13,24 +14,32 @@ class BleAdvertiserModule(reactContext: ReactApplicationContext) :
private const val TAG = "BleAdvertiserModule"
}

init {
AppPreferences.init(reactContext.applicationContext)
}

override fun getName(): String {
return "BleAdvertiser"
}

@ReactMethod
fun setUserId(userId: String) {
Log.i(TAG, "setUserId: $userId")
AppPreferences.userId = userId
}

@ReactMethod
fun resetUserId() {
Log.i(TAG, "resetUserId")
AppPreferences.userId = null
}

@ReactMethod
fun startService() {
Log.i(TAG, "Start Service")
Utils.startBluetoothMonitoringService(reactApplicationContext)
if (AppPreferences.userId != null) {
Utils.startBluetoothMonitoringService(reactApplicationContext)
}
}

}
28 changes: 28 additions & 0 deletions android/src/main/java/dev/dotworld/ble/AppPreferences.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.dotworld.ble

import android.content.Context
import android.content.SharedPreferences

object AppPreferences {
private const val NAME = "beambox"
private const val MODE = Context.MODE_PRIVATE
private lateinit var preferences: SharedPreferences

private val USER_ID = Pair("user_id", null)

fun init(context: Context) {
preferences = context.getSharedPreferences(NAME, MODE)
}

private inline fun SharedPreferences.edit(operation: (SharedPreferences.Editor) -> Unit) {
val editor = edit()
operation(editor)
editor.apply()
}

var userId: String?
get() = preferences.getString(USER_ID.first, USER_ID.second)
set(value) = preferences.edit {
it.putString(USER_ID.first, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,27 @@ class GattServer constructor(val context: Context, serviceUUIDString: String) {
}

device?.let {

Log.i(TAG, "onCharacteristicReadRequest from ${device.address}")

if (BlueTrace.supportsCharUUID(characteristic?.uuid)) {
characteristic?.uuid?.let { charUUID ->
val bluetraceImplementation = BlueTrace.getImplementation(charUUID)
val base = readPayloadMap.getOrPut(device.address) {
val base = readPayloadMap.getOrPut(device.address, {
bluetraceImplementation.peripheral.prepareReadRequestData(
bluetraceImplementation.versionInt
)
}
})
val value = base.copyOfRange(offset, base.size)
Log.i(
TAG,
"onCharacteristicReadRequest from ${device.address} - $requestId- $offset - ${
String(
value,
Charsets.UTF_8
)
}"
)
bluetoothGattServer?.sendResponse(
device,
requestId,
Expand All @@ -76,6 +87,7 @@ class GattServer constructor(val context: Context, serviceUUIDString: String) {
value
)
}

} else {
Log.i(TAG, "unsupported characteristic UUID from ${device.address}")
bluetoothGattServer?.sendResponse(
Expand All @@ -84,6 +96,7 @@ class GattServer constructor(val context: Context, serviceUUIDString: String) {
)
}
}

}

override fun onCharacteristicWriteRequest(
Expand All @@ -103,7 +116,7 @@ class GattServer constructor(val context: Context, serviceUUIDString: String) {
responseNeeded,
offset,
value
)
);
Log.i(TAG, "onCharacteristicWriteRequest: ")
value?.let {
Log.i(TAG, "onCharacteristicWriteRequest: ${String(it)}")
Expand All @@ -122,7 +135,9 @@ class GattServer constructor(val context: Context, serviceUUIDString: String) {
}

fun startServer(): Boolean {

bluetoothGattServer = bluetoothManager.openGattServer(context, gattServerCallback)

bluetoothGattServer?.let {
it.clearServices()
return true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package dev.dotworld.ble.protocol.v2

import android.content.res.Resources
import android.os.Build
import android.util.Log
import com.reactnativebleadvertiser.R
import com.google.gson.Gson
import com.reactnativebleadvertiser.BuildConfig
import dev.dotworld.ble.AppPreferences
import dev.dotworld.ble.Utils
import dev.dotworld.ble.protocol.BlueTraceProtocol
import dev.dotworld.ble.protocol.PeripheralInterface
import dev.dotworld.ble.streetpass.CentralDevice
import dev.dotworld.ble.streetpass.ConnectionRecord
import dev.dotworld.ble.streetpass.PeripheralDevice
import java.util.*


class BlueTraceV2 : BlueTraceProtocol(
Expand All @@ -23,10 +26,12 @@ class V2Peripheral : PeripheralInterface {
}

override fun prepareReadRequestData(protocolVersion: Int): ByteArray {
val publicKey = Resources.getSystem().getString(R.string.public_key)
return V2ReadRequestPayload(
v = protocolVersion,
id = "test",//Utils.encryptByPublicKey("test-${Date()}", publicKey),
id = Utils.encryptByPublicKey(
Gson().toJson(UserData(AppPreferences.userId ?: "", Date())),
BuildConfig.PUBLIC_KEY
),
o = "DW",
peripheral = PeripheralDevice(Build.MODEL, "SELF")
).getPayload()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package dev.dotworld.ble.protocol.v2

import android.os.Parcelable
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import dev.dotworld.ble.streetpass.PeripheralDevice
import kotlinx.parcelize.Parcelize
import java.util.*

//acting as peripheral
class V2ReadRequestPayload(
Expand All @@ -27,3 +30,6 @@ class V2ReadRequestPayload(
}
}
}

@Parcelize
data class UserData(val id: String, val date: Date = Date()) : Parcelable
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-ble-advertiser",
"version": "0.1.0",
"name": "@teamdotworld/rn-ble-advertiser",
"version": "1.0.0",
"description": "Advertise given message using BLE",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -36,7 +36,10 @@
"ios",
"android"
],
"repository": "https://github.com/TeamDotworld/react-native-ble-advertiser",
"repository": {
"type": "git",
"url": "https://github.com/TeamDotworld/react-native-ble-advertiser.git"
},
"author": "Naveen Sakthivel <naveen@dotworld.in> (https://dotworld.in)",
"license": "MIT",
"bugs": {
Expand Down

0 comments on commit 7621a16

Please sign in to comment.