3 Commits
Author SHA1 Message Date
Richard Ramos be88a968d2 v0.0.9 2023-01-03 13:51:13 -04:00
Richard Ramos 5071665637 fix: format 2023-01-03 13:49:46 -04:00
Richard Ramos 31ef19c3da fix: use date for timestamps 2023-01-03 13:48:29 -04:00
18 changed files with 90 additions and 398 deletions
+2 -2
View File
@@ -67,6 +67,6 @@ android/keystores/debug.keystore
lib/
tmp/
gowaku-sources.jar
gowaku.aar
android/libs/gowaku-sources.jar
android/libs/gowaku.aar
ios/Gowaku.xcframework
+5 -9
View File
@@ -6,19 +6,15 @@ Waku React Native
npm install @waku/react-native
```
Edit `settings.gradle` from your app and add:
```
include ':gowaku'
project(':gowaku').projectDir = new File(rootProject.projectDir, './../node_modules/@waku/react-native/android/gowaku')
```
## Usage
```js
import * as waku from "@waku/react-native";
```
import { multiply } from "@waku/react-native";
See also [Fixing `route ip+net: netlinkrib: permission denied` in android](android-netlink.md)
// ...
const result = await multiply(3, 7);
```
## Contributing
-214
View File
@@ -1,214 +0,0 @@
# Fixing `route ip+net: netlinkrib: permission denied` in android
The details for this error can be seen in https://github.com/ipfs-shipyard/gomobile-ipfs/issues/68, and happens when targeting android API version +30. (`targetSdkVersion 30` in your `gradle.properties` / `build.gradle`) In this issue a possible solution was described which involved all the steps shown below. I have modified these to take in account that we are using +Go 1.18 as well as using a newer version of the Android NDK. These instructions should be used until https://github.com/golang/go/issues/40569 is fixed and a new gomobile version is released that includes this fix
### Installing the requirements to build go-waku for android
These instructions assume that you are running Ubuntu, have NodeJS installed, and don't have any of the go and android required software installed. `root` access is required. Paths containing `/home/YOUR_USER` are referenced in different places. Replace `YOUR_USER` with your username (obtained with `whoami`). Don't blindly copy/paste the commands (It's not a good practice anyway)
**Installing required dependencies**
```
sudo apt update
sudo apt install build-essential unzip openjdk-11-jdk
```
**Installing Go 1.18**
```
wget https://go.dev/dl/go1.18.6.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.18.6.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
```
**Installing the Android NDK 25**
```
mkdir -p /home/YOUR_USER/Android/Sdk/
wget https://dl.google.com/android/repository/android-ndk-r25b-linux.zip
unzip android-ndk-r25b-linux.zip
mv -r android-ndk-r25b /home/YOUR_USER/Android/Sdk/ndk
export ANDROID_NDK_HOME=/home/YOUR_USER/Android/Sdk/ndk
```
**Installing the Android SDK command line tools and android-30**
```
mkdir /home/YOUR_USER/Android/Sdk/cmdline-tools
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip
unzip commandlinetools-linux-8512546_latest.zip
mv cmdline-tools /home/YOUR_USER/Android/Sdk/cmdline-tools/latest
export PATH=$PATH:/home/YOUR_USER/Android/Sdk/cmdline-tools/latest/bin
sdkmanager "platform-tools" "platforms;android-30"
```
### Building go-waku for android
```
mkdir -p /home/YOUR_USER/go/src/github.com/waku-org
cd /home/YOUR_USER/go/src/github.com/status-im
git clone https://github.com/waku-org/go-waku
cd go-waku
echo "replace github.com/multiformats/go-multiaddr v0.7.0 => github.com/waku-org/go-multiaddr v0.0.0-20230105211400-b3bd508cf855" >> go.mod
export GO111MODULE=off
go get golang.org/x/mobile/cmd/gobind
go get golang.org/x/mobile/cmd/gomobile
export GO111MODULE=on
gomobile init
export GO111MODULE=off
gomobile bind -v -target=android -androidapi=23 -ldflags="-s -w" -v -o ./build/lib/gowaku.aar ./mobile
```
### Edit waku-react-native
```
mkdir -p /home/YOUR_USER/waku
cd /home/YOUR_USER/waku
git clone https://github.com/waku-org/waku-react-native
cd waku-react-native
npm install
./download-gowaku.sh
cp /home/YOUR_USER/go/src/github.com/waku-org/build/lib/gowaku.aar ./android/libs/.
```
### Edit your react-native project
**Edit packages.json**
Set `@waku/react-native` to the absolute path of your local copy of `waku-react-native` downloaded in the previous step
```json
...
"dependencies": {
"@waku/react-native": "file:/home/YOUR_USER/waku/waku-react-native/",
}
...
```
And execute `npm install` (or `yarn`) to link your local dependency
**Edit metro.config.js**
```js
const { getDefaultConfig } = require('expo/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const path = require('path');
const root = '/home/YOUR_USER/waku/waku-react-native/';
const pak = require(root + 'package.json');
module.exports = {
// ...
watchFolders: [root],
resolver: {
blacklistRE: exclusionList(
Object
.keys({...pak.peerDependencies})
.map(m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`))
),
extraNodeModules: new Proxy(
{},
{
get: (target, name) => {
if (target.hasOwnProperty(name)) {
return target[name]
}
return path.join(process.cwd(), `node_modules/${name}`)
},
},
),
},
}
```
If you're using `expo`, in `waku-react-native`'s example app, you can see an example configuration achieving the same result
**Edit your application `android/build.gradle`**
Add `gowaku.aar` to the list of dependencies
```js
...
dependencies {
implementation files("$rootDir/../node_modules/@waku/react-native/android/libs/gowaku.aar")
}
...
```
**Edit `MainApplication.java`**
```java
// Add the following imports
import go.Seq;
import java.lang.StringBuilder;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
...
@Override
public void onCreate() {
// ...
// Add this line so that if RunOnJVM() with golang.org/x/mobile/app to call JAVA from GO,
// will not cause error "no current JVM"
Seq.setContext(getApplicationContext());
}
...
// Add this function
// To fix [x/mobile: Calling net.InterfaceAddrs() fails on Android SDK 30](https://github.com/golang/go/issues/40569)
// Ref to getInterfaces() in https://github.com/tailscale/tailscale-android/pull/21/files
//
// Returns details of the interfaces in the system, encoded as a single string for ease
// of JNI transfer over to the Go environment.
//
// Example:
// rmnet_data0 10 2000 true false false false false | fe80::4059:dc16:7ed3:9c6e%rmnet_data0/64
// dummy0 3 1500 true false false false false | fe80::1450:5cff:fe13:f891%dummy0/64
// wlan0 30 1500 true true false false true | fe80::2f60:2c82:4163:8389%wlan0/64 10.1.10.131/24
// r_rmnet_data0 21 1500 true false false false false | fe80::9318:6093:d1ad:ba7f%r_rmnet_data0/64
// rmnet_data2 12 1500 true false false false false | fe80::3c8c:44dc:46a9:9907%rmnet_data2/64
// r_rmnet_data1 22 1500 true false false false false | fe80::b6cd:5cb0:8ae6:fe92%r_rmnet_data1/64
// rmnet_data1 11 1500 true false false false false | fe80::51f2:ee00:edce:d68b%rmnet_data1/64
// lo 1 65536 true false true false false | ::1/128 127.0.0.1/8
// v4-rmnet_data2 68 1472 true true false true true | 192.0.0.4/32
//
// Where the fields are:
// name ifindex mtu isUp hasBroadcast isLoopback isPointToPoint hasMulticast | ip1/N ip2/N ip3/N;
String getInterfacesAsString() {
List<NetworkInterface> interfaces;
try {
interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
} catch (Exception e) {
return "";
}
StringBuilder sb = new StringBuilder("");
for (NetworkInterface nif : interfaces) {
try {
// Android doesn't have a supportsBroadcast() but the Go net.Interface wants
// one, so we say the interface has broadcast if it has multicast.
sb.append(String.format(java.util.Locale.ROOT, "%s %d %d %b %b %b %b %b |", nif.getName(),
nif.getIndex(), nif.getMTU(), nif.isUp(), nif.supportsMulticast(),
nif.isLoopback(), nif.isPointToPoint(), nif.supportsMulticast()));
for (InterfaceAddress ia : nif.getInterfaceAddresses()) {
// InterfaceAddress == hostname + "/" + IP
String[] parts = ia.toString().split("/", 0);
if (parts.length > 1) {
sb.append(String.format(java.util.Locale.ROOT, "%s/%d ", parts[1], ia.getNetworkPrefixLength()));
}
}
} catch (Exception e) {
// TODO(dgentry) should log the exception not silently suppress it.
continue;
}
sb.append("\n");
}
return sb.toString();
}
...
```
After this step, build your app. The error should have dissapeared.
In `adb logcat` you will see this message instead `avc: denied { bind } for scontext=u:r:untrusted_app` which seems to be due to Android restrictions which prevents Waku from obtaining the IP address of the device, but it will still be able to connect to other devices succesfully.
+2 -2
View File
@@ -133,8 +133,8 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation project(":gowaku")
// From node_modules
implementation files('libs/gowaku.aar')
// From node_modules
}
if (isNewArchitectureEnabled()) {
-2
View File
@@ -1,2 +0,0 @@
configurations.maybeCreate("default")
artifacts.add("default", file('gowaku.aar'))
View File
-1
View File
@@ -1 +0,0 @@
include ':gowaku'
+2 -2
View File
@@ -41,8 +41,8 @@ if [ "$DOWNLOAD_ANDROID" = true ]; then
exit 1
fi
rm -f ../android/gowaku/gowaku*
tar xvfz ${ANDROID_TAR} -C ../android/gowaku
rm -f ../android/libs/gowaku*
tar xvfz ${ANDROID_TAR} -C ../android/libs
fi
if [ "$DOWNLOAD_IOS" = true ]; then
+2 -2
View File
@@ -39,7 +39,7 @@ export default function App() {
}
console.log('The node ID:', await peerID());
await relaySubscribe();
await relaySubscribe();
onMessage((event) => {
setResult(
@@ -92,7 +92,7 @@ export default function App() {
// TO RETRIEVE HISTORIC MESSAGES:
console.log('Retrieving messages from store node');
const query = new StoreQuery();
query.contentFilters.push(new ContentFilter('ABC'));
query.contentFilters.push(new ContentFilter('test-rramos'));
const queryResult = await storeQuery(
query,
'16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm'
-3
View File
@@ -15,6 +15,3 @@ if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true")
include(":ReactAndroid:hermes-engine")
project(":ReactAndroid:hermes-engine").projectDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../ReactAndroid/hermes-engine");
}
include ':gowaku'
project(':gowaku').projectDir = new File(rootProject.projectDir, './../node_modules/@waku/react-native/android/gowaku')
+1 -26
View File
@@ -1,29 +1,4 @@
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const path = require('path');
const pak = require('../package.json');
const root = path.resolve(__dirname, '..');
const modules = Object.keys({
...pak.peerDependencies,
});
let config = getDefaultConfig(__dirname);
config.projectRoot = __dirname;
config.watchFolders = [root];
config.resolver = {
blacklistRE: exclusionList(
modules.map(
(m) => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
)
),
extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
};
module.exports = config;
module.exports = getDefaultConfig(__dirname);
+25 -63
View File
@@ -8,7 +8,7 @@
"name": "@waku/react-native-example",
"version": "0.0.1",
"dependencies": {
"@waku/react-native": "file:../",
"@waku/react-native": "^0.0.8",
"expo": "~47.0.8",
"expo-splash-screen": "~0.17.5",
"expo-status-bar": "~1.4.2",
@@ -19,42 +19,6 @@
"@babel/core": "^7.12.9"
}
},
"..": {
"name": "@waku/react-native",
"version": "0.0.12",
"license": "MIT",
"dependencies": {
"base-64": "^1.0.0",
"big-integer": "^1.6.51"
},
"devDependencies": {
"@arkweid/lefthook": "^0.7.7",
"@babel/eslint-parser": "^7.18.2",
"@commitlint/config-conventional": "^17.0.2",
"@react-native-community/eslint-config": "^3.0.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/base-64": "^1.0.0",
"@types/jest": "^28.1.2",
"@types/react": "~17.0.21",
"@types/react-native": "0.68.0",
"commitlint": "^17.0.2",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.1",
"pod-install": "^0.1.0",
"prettier": "^2.0.5",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native-builder-bob": "^0.18.3",
"release-it": "^15.0.0",
"typescript": "^4.5.2"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
}
},
"node_modules/@ampproject/remapping": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.0.tgz",
@@ -3837,8 +3801,16 @@
"license": "MIT"
},
"node_modules/@waku/react-native": {
"resolved": "..",
"link": true
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/@waku/react-native/-/react-native-0.0.8.tgz",
"integrity": "sha512-Ybef43I+B5as2F5UBZhS4Jmk6T9Fstp3kpMkQcAlsa+A/AeEYN1uKFT3ykBXUa5jPGDtreDYhRbOOdmA0ptOiQ==",
"dependencies": {
"base-64": "^1.0.0"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
}
},
"node_modules/@xmldom/xmldom": {
"version": "0.7.9",
@@ -4336,6 +4308,11 @@
"node": ">=0.10.0"
}
},
"node_modules/base-64": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz",
"integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg=="
},
"node_modules/base/node_modules/define-property": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz",
@@ -14044,31 +14021,11 @@
}
},
"@waku/react-native": {
"version": "file:..",
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/@waku/react-native/-/react-native-0.0.8.tgz",
"integrity": "sha512-Ybef43I+B5as2F5UBZhS4Jmk6T9Fstp3kpMkQcAlsa+A/AeEYN1uKFT3ykBXUa5jPGDtreDYhRbOOdmA0ptOiQ==",
"requires": {
"@arkweid/lefthook": "^0.7.7",
"@babel/eslint-parser": "^7.18.2",
"@commitlint/config-conventional": "^17.0.2",
"@react-native-community/eslint-config": "^3.0.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/base-64": "^1.0.0",
"@types/jest": "^28.1.2",
"@types/react": "~17.0.21",
"@types/react-native": "0.68.0",
"base-64": "^1.0.0",
"big-integer": "^1.6.51",
"commitlint": "^17.0.2",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.1",
"pod-install": "^0.1.0",
"prettier": "^2.0.5",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native-builder-bob": "^0.18.3",
"release-it": "^15.0.0",
"typescript": "^4.5.2"
"base-64": "^1.0.0"
}
},
"@xmldom/xmldom": {
@@ -14430,6 +14387,11 @@
}
}
},
"base-64": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz",
"integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg=="
},
"base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
+1 -1
View File
@@ -10,7 +10,7 @@
"web": "expo start --web"
},
"dependencies": {
"@waku/react-native": "file:../",
"@waku/react-native": "^0.0.8",
"expo": "~47.0.8",
"expo-splash-screen": "~0.17.5",
"expo-status-bar": "~1.4.2",
+1 -1
View File
@@ -1 +1 @@
0.3.1
0.3.0
+4
View File
@@ -1,6 +1,10 @@
pre-commit:
parallel: true
commands:
lint:
files: git diff --name-only @{push}
glob: "*.{js,ts,jsx,tsx}"
run: npx eslint {files}
types:
files: git diff --name-only @{push}
glob: "*.{js,ts, jsx, tsx}"
+6 -8
View File
@@ -1,16 +1,15 @@
{
"name": "@waku/react-native",
"version": "0.1.0",
"version": "0.0.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@waku/react-native",
"version": "0.1.0",
"version": "0.0.9",
"license": "MIT",
"dependencies": {
"base-64": "^1.0.0",
"big-integer": "^1.6.51"
"base-64": "^1.0.0"
},
"devDependencies": {
"@arkweid/lefthook": "^0.7.7",
@@ -5213,8 +5212,8 @@
},
"node_modules/big-integer": {
"version": "1.6.51",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz",
"integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==",
"dev": true,
"license": "Unlicense",
"engines": {
"node": ">=0.6"
}
@@ -19922,8 +19921,7 @@
},
"big-integer": {
"version": "1.6.51",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz",
"integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg=="
"dev": true
},
"bl": {
"version": "5.0.0",
+27 -28
View File
@@ -1,6 +1,6 @@
{
"name": "@waku/react-native",
"version": "0.1.0",
"version": "0.0.9",
"description": "Waku React Native",
"author": "Status Research & Development GMBH",
"authors": [
@@ -54,31 +54,31 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@arkweid/lefthook": "^0.7.7",
"@babel/eslint-parser": "^7.18.2",
"@commitlint/config-conventional": "^17.0.2",
"@react-native-community/eslint-config": "^3.0.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/base-64": "^1.0.0",
"@types/jest": "^28.1.2",
"@types/react": "~17.0.21",
"@types/react-native": "0.68.0",
"commitlint": "^17.0.2",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.1",
"pod-install": "^0.1.0",
"prettier": "^2.0.5",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native-builder-bob": "^0.18.3",
"release-it": "^15.0.0",
"typescript": "^4.5.2"
},
"resolutions": {
"@types/react": "17.0.21"
},
"@arkweid/lefthook": "^0.7.7",
"@babel/eslint-parser": "^7.18.2",
"@commitlint/config-conventional": "^17.0.2",
"@react-native-community/eslint-config": "^3.0.2",
"@release-it/conventional-changelog": "^5.0.0",
"@types/base-64": "^1.0.0",
"@types/jest": "^28.1.2",
"@types/react": "~17.0.21",
"@types/react-native": "0.68.0",
"commitlint": "^17.0.2",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^28.1.1",
"pod-install": "^0.1.0",
"prettier": "^2.0.5",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native-builder-bob": "^0.18.3",
"release-it": "^15.0.0",
"typescript": "^4.5.2"
},
"resolutions": {
"@types/react": "17.0.21"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
@@ -158,7 +158,6 @@
]
},
"dependencies": {
"base-64": "^1.0.0",
"big-integer": "^1.6.51"
"base-64": "^1.0.0"
}
}
+12 -34
View File
@@ -1,6 +1,5 @@
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
import { decode, encode } from 'base-64';
import bigInt from 'big-integer';
const LINKING_ERROR =
`The package '@waku/react-native' doesn't seem to be linked. Make sure: \n\n` +
@@ -19,7 +18,11 @@ const ReactNative = NativeModules.ReactNative
}
);
const OneMillion = bigInt(1000000);
export function multiply(a: number, b: number): Promise<number> {
return ReactNative.multiply(a, b);
}
const OneMillion = BigInt(1_000_000);
export class WakuMessage {
payload: Uint8Array = new Uint8Array();
@@ -33,7 +36,7 @@ export class WakuMessage {
contentTopic: this.contentTopic,
version: this.version,
timestamp: this.timestamp
? bigInt(this.timestamp.valueOf()).multiply(OneMillion).toString(10)
? (BigInt(this.timestamp.valueOf()) * OneMillion).toString(10)
: 0,
payload: b64encoded,
};
@@ -51,10 +54,7 @@ export function onMessage(cb: (arg0: any) => void) {
let signal = JSON.parse(event.signal);
let msg = signal.event.wakuMessage;
signal.event.wakuMessage = new WakuMessage();
signal.event.wakuMessage.timestamp =
msg.timestamp != 0
? new Date(bigInt(msg.timestamp).divide(OneMillion).toJSNumber())
: undefined;
signal.event.wakuMessage.timestamp = msg.timestamp;
signal.event.wakuMessage.version = msg.version || 0;
signal.event.wakuMessage.contentTopic = msg.contentTopic;
signal.event.wakuMessage.payload = new Uint8Array(
@@ -165,10 +165,7 @@ export function relayPublish(
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg).replace(
/"timestamp":"([0-9]+)"/,
`"timestamp":$1`
);
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.relayPublish(messageJSON, pubsubTopic, timeoutMs)
);
@@ -518,10 +515,7 @@ export function lightpushPublish(
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg).replace(
/"timestamp":"([0-9]+)"/,
`"timestamp":$1`
);
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.lightpushPublish(
messageJSON,
@@ -721,15 +715,13 @@ export function storeQuery(
pubsubTopic: query.pubsubTopic,
contentFilters: query.contentFilters,
startTime: query.startTime
? bigInt(query.startTime.valueOf()).multiply(OneMillion).toString(10)
? (BigInt(query.startTime.valueOf()) * OneMillion).toString(10)
: 0,
endTime: query.endTime
? bigInt(query.endTime.valueOf()).multiply(OneMillion).toString(10)
? (BigInt(query.endTime.valueOf()) * OneMillion).toString(10)
: 0,
pagingOptions: query.pagingOptions,
})
.replace(/"startTime":"([0-9]+)"/, `"startTime":$1`)
.replace(/"endTime":"([0-9]+)"/, `"endTime":$1`);
});
let response = JSON.parse(
await ReactNative.storeQuery(queryJSON, peerID, timeoutMs)
);
@@ -737,20 +729,6 @@ export function storeQuery(
if (response.error) {
reject(response.error);
} else {
if (response.result.messages) {
for (let i = 0; i < response.result.messages.length; i++) {
const t = response.result.messages[i].timestamp;
response.result.messages[i].timestamp =
t != 0
? new Date(bigInt(t).divide(OneMillion).toJSNumber())
: undefined;
response.result.messages[i].payload = new Uint8Array(
decode(response.result.messages[i].payload ?? [])
.split('')
.map((c) => c.charCodeAt(0))
);
}
}
resolve(response.result);
}
});