Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOBILE-124: Move from JS to TS #108

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
791 changes: 452 additions & 339 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"axios": "^0.25.0",
"buffer": "^6.0.3",
"fast-deep-equal": "^3.1.3",
"firebase": "^8.10.1",
"firebase": "^9.21.0",
"outliers": "0.0.3",
"rxjs": "^7.5.6",
"semver": "^7.3.8"
Expand Down
117 changes: 53 additions & 64 deletions src/Neurosity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,54 @@ import { ReplaySubject, firstValueFrom } from "rxjs";
import { map, startWith, switchMap } from "rxjs/operators";
import { distinctUntilChanged } from "rxjs/operators";
import isEqual from "fast-deep-equal";
import { CloudClient, createUser } from "./api/index";
import { credentialWithLink, SERVER_TIMESTAMP } from "./api/index";
import { SDKOptions } from "./types/options";
import { STREAMING_MODE, STREAMING_TYPE } from "./types/streaming";
import { Training } from "./types/training";
import { Credentials, EmailAndPassword } from "./types/credentials";
import { CustomToken } from "./types/credentials";
import { Settings, ChangeSettings } from "./types/settings";
import { SignalQuality } from "./types/signalQuality";
import { Kinesis } from "./types/kinesis";
import { Calm } from "./types/calm";
import { Focus } from "./types/focus";
import { getLabels } from "./utils/subscription";
import { BrainwavesLabel, Epoch, PowerByBand, PSD } from "./types/brainwaves";
import { Accelerometer } from "./types/accelerometer";
import { DeviceInfo, OSVersion } from "./types/deviceInfo";
import { DeviceStatus, STATUS } from "./types/status";
import { Action } from "./types/actions";
import { HapticEffects } from "./types/hapticEffects";
import * as errors from "./utils/errors";
import * as platform from "./utils/platform";
import * as hapticEffects from "./utils/hapticEffects";
import { validateOAuthScopeForFunctionName } from "./utils/oauth";
import { validateOAuthScopeForAction } from "./utils/oauth";
import { CloudClient, createUser, credentialWithLink, SERVER_TIMESTAMP } from "./api";
import {
SDKOptions,
STREAMING_MODE,
STREAMING_TYPE,
Training,
Credentials,
EmailAndPassword,
CustomToken,
Settings,
ChangeSettings,
SignalQuality,
Kinesis,
Calm,
Focus,
BrainwavesLabel,
Epoch,
PowerByBand,
PSD,
Accelerometer,
DeviceInfo,
OSVersion,
DeviceStatus,
STATUS,
Action,
HapticEffects,
OAuthConfig,
OAuthQuery,
OAuthQueryResult,
OAuthRemoveResponse,
UserClaims,
Experiment
} from "./types";
import {
getLabels,
validateOAuthScopeForFunctionName,
validateOAuthScopeForAction,
isNode,
getCloudMetric,
TransferDeviceOptions,
errors,
platform,
hapticEffects
} from "./utils";
import { createOAuthURL } from "./api/https/createOAuthURL";
import { getOAuthToken } from "./api/https/getOAuthToken";
import { OAuthConfig, OAuthQuery } from "./types/oauth";
import { OAuthQueryResult, OAuthRemoveResponse } from "./types/oauth";
import { UserClaims } from "./types/user";
import { isNode } from "./utils/is-node";
import { getCloudMetric } from "./utils/metrics";
import { Experiment } from "./types/experiment";
import { TransferDeviceOptions } from "./utils/transferDevice";
import { BluetoothClient, osHasBluetoothSupport } from "./api/bluetooth";
import { BLUETOOTH_CONNECTION } from "./api/bluetooth/types";
import { BLUETOOTH_CONNECTION, BluetoothClient, osHasBluetoothSupport } from "./api/bluetooth";
import {UserWithMetadata} from "./api/firebase";

const defaultOptions = {
timesync: false,
Expand Down Expand Up @@ -108,7 +121,7 @@ export class Neurosity {

/**
* Creates new instance of the Neurosity SDK
*
*
* ```typescript
* const neurosity = new Neurosity();
* ```
Expand Down Expand Up @@ -387,10 +400,6 @@ export class Neurosity {
return await this.cloudClient.logout();
}

/**
* @internal
* Not user facing.
*/
public __getApp() {
return this.cloudClient.__getApp();
}
Expand All @@ -406,14 +415,10 @@ export class Neurosity {
* });
* ```
*/
public onAuthStateChanged(): Observable<any> {
public onAuthStateChanged(): Observable<UserWithMetadata> {
return this.cloudClient.onAuthStateChanged();
}

/**
* @internal
* Not user facing yet
*/
public addDevice(deviceId: string): Promise<void> {
const [hasOAuthError, OAuthError] = validateOAuthScopeForFunctionName(
this.cloudClient.userClaims,
Expand All @@ -427,10 +432,6 @@ export class Neurosity {
return this.cloudClient.addDevice(deviceId);
}

/**
* @internal
* Not user facing yet
*/
public removeDevice(deviceId: string): Promise<void> {
const [hasOAuthError, OAuthError] = validateOAuthScopeForFunctionName(
this.cloudClient.userClaims,
Expand Down Expand Up @@ -461,10 +462,6 @@ export class Neurosity {
return this.cloudClient.transferDevice(options);
}

/**
* @internal
* Not user facing yet
*/
public onUserDevicesChange(): Observable<DeviceInfo[]> {
const [hasOAuthError, OAuthError] = validateOAuthScopeForFunctionName(
this.cloudClient.userClaims,
Expand All @@ -478,10 +475,7 @@ export class Neurosity {
return this.cloudClient.onUserDevicesChange();
}

/**
* @internal
* Not user facing yet
*/

public onUserClaimsChange(): Observable<UserClaims> {
return this.cloudClient.onUserClaimsChange();
}
Expand Down Expand Up @@ -627,9 +621,6 @@ export class Neurosity {

/**
* <StreamingModes wifi={true} bluetooth={true} />
*
* @internal
* Not user facing
*/
private async dispatchAction(action: Action): Promise<Action> {
if (!(await this.cloudClient.didSelectDevice())) {
Expand Down Expand Up @@ -834,7 +825,7 @@ export class Neurosity {

/**
* <StreamingModes wifi={true} bluetooth={true} />
*
*
* The `raw` brainwaves parameter emits epochs of 16 samples for Crown and 25 for Notion 1 and 2.
*
* Example
Expand All @@ -844,7 +835,7 @@ export class Neurosity {
* });
* ```
*
* Raw Unfiltered - The `rawUnfiltered` brainwaves parameter emits epochs of 16 samples for Crown and 25 for Notion 1 and 2.
* Raw Unfiltered - The `rawUnfiltered` brainwaves parameter emits epochs of 16 samples for Crown and 25 for Notion 1 and 2.

* Example
* ```typescript
Expand All @@ -854,7 +845,7 @@ export class Neurosity {
* ```
*
* Power By Band - The `powerByBand` brainwaves parameter emits epochs 4 times a second. Every frequency label (e.g. beta) contains an average power value per channel.
*
*
* Example
* ```typescript
* neurosity.brainwaves("powerByBand").subscribe(brainwaves => {
Expand All @@ -863,7 +854,7 @@ export class Neurosity {
* ```
*
* Power Spectral Density (PSD) - The `psd` brainwaves parameter emits epochs 4 times a second. Every frequency label (e.g. alpha) contains the computed FFT (Fast Fourier transform) value per channel (see the `psd` property), as well as the frequency ranges (see the `freqs` property).
*
*
* Example
* ```typescript
* neurosity.brainwaves("psd").subscribe(brainwaves => {
Expand Down Expand Up @@ -1157,8 +1148,6 @@ export class Neurosity {
}

/**
* @internal
* Not user facing yet
*
* <StreamingModes wifi={true} />
*
Expand Down
2 changes: 1 addition & 1 deletion src/api/bluetooth/BluetoothTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Observable, Subject } from "rxjs";
import { BLUETOOTH_CONNECTION, TRANSPORT_TYPE } from "./types";
import { Action } from "../../types/actions";
import { DeviceInfo, OSVersion } from "../../types/deviceInfo";
import { Peripheral } from "./react-native/types/BleManagerTypes";
import { Peripheral } from "./react-native";

export type DeviceNicknameOrPeripheral = string | Peripheral;

Expand Down
1 change: 1 addition & 0 deletions src/api/bluetooth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./web/WebBluetoothTransport";
export * from "./react-native/ReactNativeTransport";
export * from "./utils/osHasBluetoothSupport";
export * from "./types/index";
export * from "./constants";
11 changes: 7 additions & 4 deletions src/api/bluetooth/react-native/ReactNativeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import { create6DigitPin } from "../utils/create6DigitPin";
import { TextCodec } from "../utils/textCodec";
import { ActionOptions, SubscribeOptions } from "../types";
import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
import { BleManager } from "./types/BleManagerTypes";
import { Peripheral, PeripheralInfo } from "./types/BleManagerTypes";
import { NativeEventEmitter } from "./types/ReactNativeTypes";
import { PlatformOSType } from "./types/ReactNativeTypes";
import {
PlatformOSType,
NativeEventEmitter,
BleManager,
Peripheral,
PeripheralInfo
} from "./types";
import { DEFAULT_ACTION_RESPONSE_TIMEOUT } from "../constants";
import { CHARACTERISTIC_UUIDS_TO_NAMES } from "../constants";
import { ANDROID_MAX_MTU } from "../constants";
Expand Down
2 changes: 2 additions & 0 deletions src/api/bluetooth/react-native/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./types"
export * from "./ReactNativeTransport"
2 changes: 2 additions & 0 deletions src/api/bluetooth/react-native/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./BleManagerTypes"
export * from "./ReactNativeTypes"
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./Neurosity";
export * from "./api/bluetooth";
export * from "./types/streaming";
export * from "./types";
25 changes: 25 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export * from "./accelerometer"
export * from "./actions"
export * from "./awareness"
export * from "./brainwaves"
export * from "./calm"
export * from "./client"
export * from "./credentials"
export * from "./deviceInfo"
export * from "./experiment"
export * from "./focus"
export * from "./hapticEffects"
export * from "./kinesis"
export * from "./marker"
export * from "./metrics"
export * from "./oauth"
export * from "./options"
export * from "./sample"
export * from "./settings"
export * from "./signalQuality"
export * from "./skill"
export * from "./status"
export * from "./streaming"
export * from "./subscriptions"
export * from "./training"
export * from "./user"
2 changes: 2 additions & 0 deletions src/types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface Settings {
lsl: boolean;
supportAccess: boolean;
activityLogging: boolean;
researchProgram: boolean;
}

/**
Expand All @@ -11,4 +12,5 @@ export interface ChangeSettings {
lsl?: boolean;
supportAccess?: boolean;
activityLogging?: boolean;
researchProgram?: boolean;
}
13 changes: 13 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export * as errors from "./errors"
export * from "./filterInternalKeys"
export * as hapticEffects from "./hapticEffects"
export * from "./heartbeat"
export * from "./is-node"
export * from "./metrics"
export * from "./oauth"
export * from "./pick"
export * from "./pipes"
export * as platform from "./platform"
export * from "./subscription"
export * from "./transferDevice"
export * from "./whileOnline"