Notion
Example
import { Notion } from "@neurosity/notion";
const notion = new Notion();
Hierarchy
- Notion
Index
Constructors
Accessors
Methods
- accelerometer
- addMarker
- brainwaves
- calm
- createOAuthURL
- deleteUserExperiment
- disconnect
- enableLocalMode
- focus
- getDevices
- getHapticEffects
- getInfo
- getOAuthToken
- getSelectedDevice
- haptics
- isLocalMode
- kinesis
- login
- logout
- onAuthStateChanged
- onDeviceChange
- onUserExperiments
- predictions
- removeOAuthAccess
- selectDevice
- settings
- signalQuality
- status
Constructors
constructor
+ new Notion(options
: NotionOptions): Notion
Defined in Notion.ts:115
Creates new instance of Notion
const notion = new Notion();
Parameters:
Name | Type | Default | Description |
---|---|---|---|
options | NotionOptions | {} |
Returns: Notion
Accessors
training
• get training(): Training
Defined in Notion.ts:990
notion.training.record({
metric: "kinesis",
label: "push"
});
notion.training.stop({
metric: "kinesis",
label: "push"
});
Returns: Training
Training methods
Methods
accelerometer
▸ accelerometer(): Observable‹Accelerometer›
Defined in Notion.ts:653
Observes accelerometer data Supported by Notion 2 and the Crown.
notion.accelerometer().subscribe(accelerometer => {
console.log(accelerometer);
});
// { acceleration: ..., inclination: ..., orientation: ..., pitch: ..., roll: ..., x: ..., y: ..., z: ... }
Returns: Observable‹Accelerometer›
Observable of accelerometer metric events
addMarker
▸ addMarker(label
: string): Promise‹Action›
Defined in Notion.ts:533
Injects an EEG marker to data stream
notion.addMarker("eyes-closed");
// later...
notion.addMarker("eyes-open");
Parameters:
Name | Type | Description |
---|---|---|
label | string | Name the label to inject |
Returns: Promise‹Action›
brainwaves
▸ brainwaves(label
: BrainwavesLabel, ...otherLabels
: BrainwavesLabel[]): Observable‹Epoch | PowerByBand | PSD›
Defined in Notion.ts:724
The raw
brainwaves parameter emits epochs of 16 samples for Crown and 25 for Notion 1 and 2.
Example
notion.brainwaves("raw").subscribe(brainwaves => {
console.log(brainwaves);
});
Raw Unfiltered - The rawUnfiltered
brainwaves parameter emits epochs of 16 samples for Crown and 25 for Notion 1 and 2.
Example
notion.brainwaves("rawUnfiltered").subscribe(brainwaves => {
console.log(brainwaves);
});
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
notion.brainwaves("powerByBand").subscribe(brainwaves => {
console.log(brainwaves);
});
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
notion.brainwaves("psd").subscribe(brainwaves => {
console.log(brainwaves);
});
Parameters:
Name | Type |
---|---|
label | BrainwavesLabel |
...otherLabels | BrainwavesLabel[] |
Returns: Observable‹Epoch | PowerByBand | PSD›
Observable of brainwaves metric events
calm
▸ calm(): Observable‹Calm›
Defined in Notion.ts:761
Example
notion.calm().subscribe(calm => {
console.log(calm.probability);
});
// 0.45
// 0.47
// 0.53
// 0.51
// ...
Returns: Observable‹Calm›
Observable of calm events - awareness/calm alias
createOAuthURL
▸ createOAuthURL(config
: OAuthConfig): Promise‹string›
Defined in Notion.ts:1165
Create OAuth URL 💡 OAuth requires developers to register their apps with Neurosity Read full OAuth guide
Creates client-specific OAuth URL. This is the first step of the OAuth workflow. Use this function to create a URL you can use to redirect users to the Neurosity sign-in page. 💡 This function is designed to only run on the server side for security reasons, as it requires your client secret.
const { Notion } = require("@neurosity/notion");
const notion = new Notion({
autoSelectDevice: false
});
exports.handler = async function (event) {
return notion
.createOAuthURL({
clientId: process.env.NEUROSITY_OAUTH_CLIENT_ID,
clientSecret: process.env.NEUROSITY_OAUTH_CLIENT_SECRET,
redirectUri: process.env.NEUROSITY_OAUTH_CLIENT_REDIRECT_URI,
responseType: "token",
state: Math.random().toString().split(".")[1],
scope: [
"read:devices-info",
"read:devices-status",
"read:signal-quality",
"read:brainwaves"
]
})
.then((url) => ({
statusCode: 200,
body: JSON.stringify({ url })
}))
.catch((error) => ({
statusCode: 400,
body: JSON.stringify(error.response.data)
}));
};
Parameters:
Name | Type |
---|---|
config | OAuthConfig |
Returns: Promise‹string›
custom token
deleteUserExperiment
▸ deleteUserExperiment(experimentId
: string): Promise‹void›
Defined in Notion.ts:1345
Deletes a specific experiment provided an experiment ID
await notion.deleteUserExperiment(experiment.id);
Parameters:
Name | Type | Description |
---|---|---|
experimentId | string | The ID of the Experiment |
Returns: Promise‹void›
void
disconnect
▸ disconnect(): Promise‹void›
Defined in Notion.ts:481
Ends database connection
await notion.disconnect();
Returns: Promise‹void›
enableLocalMode
▸ enableLocalMode(shouldEnable
: boolean): Promise‹boolean›
Defined in Notion.ts:440
Enables/disables local mode
With local mode, device metrics like brainwaves, calm, focus, etc will stream via your local WiFi network and not the default cloud server.
Local Mode is disabled by default, to enable it:
await notion.enableLocalMode(true);
To disable it:
await notion.enableLocalMode(false);
Keep in mind:
- Activity Logging will not work while this setting is enabled.
- Your Notion must be connected to the same WiFi network as this device to establish communication.
- An internet connection is still needed to authenticate, get device status and add metric subscriptions.
- This setting is not global and needs to be set for every Notion app you wish to affect.
Parameters:
Name | Type |
---|---|
shouldEnable | boolean |
Returns: Promise‹boolean›
focus
▸ focus(): Observable‹Focus›
Defined in Notion.ts:852
Example
notion.focus().subscribe(focus => {
console.log(focus.probability);
});
// 0.56
// 0.46
// 0.31
// 0.39
// ...
Returns: Observable‹Focus›
Observable of focus events - awareness/focus alias
getDevices
▸ getDevices(): Promise‹DeviceInfo[]›
Defined in Notion.ts:292
Get user devices
Returns a list of devices claimed by the user authenticated.
const devices = await notion.getDevices();
console.log(devices);
Returns: Promise‹DeviceInfo[]›
getHapticEffects
▸ getHapticEffects(): HapticEffects
Defined in Notion.ts:635
const effects = notion.getHapticEffects();
Returns: HapticEffects
getInfo
▸ getInfo(): Promise‹DeviceInfo›
Defined in Notion.ts:365
const info = await notion.getInfo();
Returns: Promise‹DeviceInfo›
getOAuthToken
▸ getOAuthToken(query
: OAuthQuery): Promise‹OAuthQueryResult›
Defined in Notion.ts:1216
Get OAuth Token 💡 OAuth requires developers to register their apps with Neurosity Read full OAuth guide
Gets client-specific OAuth token for a given userId.
💡 This function is designed to only run on the server side for security reasons, as it requires your client secret.
Here's an example of a cloud function that receives a userId
via query params and loads the client id and client secret securely via environment variables.
const { Notion } = require("@neurosity/notion");
const notion = new Notion({
autoSelectDevice: false
});
exports.handler = async function (event) {
const userId = event.queryStringParameters?.userId;
return notion
.getOAuthToken({
clientId: process.env.NEUROSITY_OAUTH_CLIENT_ID,
clientSecret: process.env.NEUROSITY_OAUTH_CLIENT_SECRET,
userId
})
.then((token) => ({
statusCode: 200,
body: JSON.stringify(token)
}))
.catch((error) => ({
statusCode: 200,
body: JSON.stringify(error.response.data)
}));
};
Parameters:
Name | Type |
---|---|
query | OAuthQuery |
Returns: Promise‹OAuthQueryResult›
custom token
getSelectedDevice
▸ getSelectedDevice(): Promise‹DeviceInfo›
Defined in Notion.ts:346
Get selected device
const selectedDevice = await notion.getSelectedDevice();
console.log(selectedDevice);
Returns: Promise‹DeviceInfo›
haptics
▸ haptics(effects
: any): Promise‹any›
Defined in Notion.ts:589
Queue haptic motor commands
To queue haptic P7 only,
await notion.haptics({
P7: ["tripleClick100"]
});
To queue both motors at the same time
await notion.haptics({
P7: [notion.getHapticEffects().strongClick100],
P8: [notion.getHapticEffects().strongClick100]
});
You can queue different commands to the motors too
const effects = notion.getHapticEffects();
await notion.haptics({
P7: [effects.transitionRampUpLongSmooth1_0_to_100,
effects.transitionRampDownLongSmooth1_100_to_0],
P8: [effects.strongClick100]
});
Parameters:
Name | Type | Description |
---|---|---|
effects | any | Effects to queue. The key of the object passed should be the location of the motor to queue. Each key can be an array of up to 7 commands. There is no haptic support on model version 1, Notion DK1. The Haptic motor's location is positioned in reference to the 10-10 EEG system used to label the channels of the Crown's EEG sensors. Notion 2 and Crown have haptics at P7 and P8. A list of haptic commands can be found on ./utils/hapticCodes.ts - there are about 127 of them! |
Returns: Promise‹any›
isLocalMode
▸ isLocalMode(): Observable‹boolean›
Defined in Notion.ts:389
Observes Local Mode changes
notion.isLocalMode().subscribe(isLocalMode => {
console.log(isLocalMode);
});
Returns: Observable‹boolean›
kinesis
▸ kinesis(label
: string, ...otherLabels
: string[]): Observable‹Kinesis›
Defined in Notion.ts:871
Parameters:
Name | Type |
---|---|
label | string |
...otherLabels | string[] |
Returns: Observable‹Kinesis›
Observable of kinesis metric events
login
▸ login(credentials
: Credentials): Promise‹void›
Defined in Notion.ts:162
Starts user session
await notion.login({
email: "...",
password: "..."
});
Parameters:
Name | Type | Description |
---|---|---|
credentials | Credentials |
Returns: Promise‹void›
logout
▸ logout(): Promise‹void›
Defined in Notion.ts:175
Ends user session
await notion.logout();
// session has ended
Returns: Promise‹void›
onAuthStateChanged
▸ onAuthStateChanged(): Observable‹any›
Defined in Notion.ts:198
Subscribe to auth state changes
Streams the state of the auth session. If user has logged in, the user object will be set. When logged out, the user object will be null.
notion.onAuthStateChanged().subscribe((user) => {
console.log(user);
});
Returns: Observable‹any›
onDeviceChange
▸ onDeviceChange(): Observable‹DeviceInfo›
Defined in Notion.ts:402
Observes selected device
notion.onDeviceChange().subscribe(device => {
console.log(device);
});
Returns: Observable‹DeviceInfo›
onUserExperiments
▸ onUserExperiments(): Observable‹Experiment[]›
Defined in Notion.ts:1331
Observes and returns a list of all Kinesis experiments
and all subsequent experiment changes.
Here's an example of how to get a list of all Kinesis labels that have been trained:
const getUniqueLabels = (experiments) => {
const labels = experiments.flatMap((experiment) => experiment.labels);
// only return unique labels
return [...new Set(labels)];
}
notion.onUserExperiments().subscribe((experiments) => {
console.log(experiments);
console.log("labels", getUniqueLabels(experiments));
});
// [{ id: '...', deviceId: '...', labels: [ 'drop' ], name: 'Lightgray cheetah', timestamp: 1577908381552, totalTrials: 16, userId: '...' }]
// ["drop", "lift", "push"]
Returns: Observable‹Experiment[]›
Observable of experiments
events
predictions
▸ predictions(label
: string, ...otherLabels
: string[]): Observable‹any›
Defined in Notion.ts:895
Parameters:
Name | Type |
---|---|
label | string |
...otherLabels | string[] |
Returns: Observable‹any›
Observable of predictions metric events
removeOAuthAccess
▸ removeOAuthAccess(): Promise‹OAuthRemoveResponse›
Defined in Notion.ts:1242
Remove OAuth Access 💡 OAuth requires developers to register their apps with Neurosity Read full OAuth guide
Removes client-specific OAuth token for a given userId. Requires SDK to be signed in with OAuth custom token.
await notion.removeOAuthAccess().catch((error) => {
// handle error here...
});
Returns: Promise‹OAuthRemoveResponse›
custom token
selectDevice
▸ selectDevice(deviceSelector
: function): Promise‹DeviceInfo›
Defined in Notion.ts:321
Select Device
Rarely necessary, but useful when the user owns multiple devices.
A common use case for manually selecting a device is when you wish to build a device dropdown a user can select from, instead of collecting the Device Id from the user ahead of time.
The 3 steps to manually selecting a device are:
- Set
autoSelectDevice
to false when instantiatingNotion
. - Authenticate with your Neurosity account to access your devices by calling the
notion.login(...)
function. - Call the
notion.selectDevice(...)
function with a device selector function.
const devices = await notion.selectDevice((devices) =>
devices.find((device) => device.deviceNickname === "Notion-A1B")
);
console.log(devices);
If you own multiple devices, and don't pass
autoSelectDevice
, then the first device on the list will be automatically selected.
For more info, check out the "Device Selection" guide.
Parameters:
▪ deviceSelector: function
▸ (devices
: DeviceInfo[]): DeviceInfo
Parameters:
Name | Type |
---|---|
devices | DeviceInfo[] |
Returns: Promise‹DeviceInfo›
settings
▸ settings(): Observable‹Settings›
Defined in Notion.ts:822
Observes last state of settings
and all subsequent settings
changes
notion.settings().subscribe(settings => {
console.log(settings.lsl);
});
// true
// ...
Returns: Observable‹Settings›
Observable of settings
metric events
signalQuality
▸ signalQuality(): Observable‹SignalQuality›
Defined in Notion.ts:791
Observes signal quality data where each property is the name of the channel and the value includes the standard deviation and a status set by the device
notion.signalQuality().subscribe(signalQuality => {
console.log(signalQuality);
});
// { FC6: { standardDeviation: 3.5, status: "good" }, C3: {...}, ... }
Returns: Observable‹SignalQuality›
Observable of signalQuality metric events
status
▸ status(): Observable‹DeviceStatus›
Defined in Notion.ts:929
Observes last state of status
and all subsequent status
changes
notion.status().subscribe(status => {
console.log(status.state);
});
// "online"
// ...
Returns: Observable‹DeviceStatus›
Observable of status
metric events