Example code
Getting started
- Download the latest embedded SDK package.
- Extract the package to your folder of choice.
-
Copy the extracted
js\massivefolder into your app, for example to3rdparty\massive. -
In your app’s main process, import the SDK:
-
Start and wait till the SDK is ready by calling the
initfunction: -
When the user opts in, call the
startfunction: -
Before your app quits, call the
cleanUpfunction: -
When you package your app, keep the SDK’s
prebuildsfolder out ofapp.asar. With electron-builder, add"asarUnpack": ["3rdparty/massive/prebuilds/**"]to thebuildsection ofpackage.json.
Sample apps
See theREADME.md file, docs folder and samples folder in the
embedded SDK package. The samples demonstrate how to integrate the SDK into
your project and use its functionality.
MassiveEmbeddedMinimalis a simple Electron application that demonstrates how to integrate the SDK into a JavaScript project.MassiveEmbeddedElectronis a complete Electron application that also demonstrates the tray, usage statistics and an installer.
API reference
Types
class MassiveError extends Error
The error the SDK’s functions reject with when a call fails.
Properties
code ERR_MASSIVE_ followed by the status, such as
ERR_MASSIVE_INTERNAL_ERROR, or ERR_MASSIVE_UNAVAILABLE when the SDK can’t run
in this process.
status The status of the SDK: INVALID_ARGS, UNINITIALIZED,
INITIALIZING or INTERNAL_ERROR.
operation The function that failed, such as start.
Functions
Every function butisSupported, getUnsupportedReason and getVersion
returns a promise, which rejects with a MassiveError when the call fails.
isSupported(): boolean
Queries whether the SDK can run in this process.
Return value
true if the SDK can run in this process.
getUnsupportedReason(): string | null
Queries why the SDK can’t run in this process.
Return value
The reason as a sentence, or null when the SDK can run.
getVersion(): string
Returns the version of the Massive SDK.
Return value
The version of the Massive SDK in the format major.minor.patch.
setDataBasePath(path: string): Promise<void>
Sets the folder for the SDK’s data and log. Call it before the init function.
Parameters
path An absolute path, or '' for the default folder.
init(apiToken: string): Promise<void>
Initializes the Massive SDK, pending user opt-in, attributed to your API token.
Parameters
apiToken A unique developer identifier obtained from the applications page.
start(): Promise<void>
Allows computing resources to be opportunistically consumed. The user must agree
to easy-to-understand terms of the exchange you’re offering before you call this
function.
stop(): Promise<void>
Disallows computing resources to be consumed.
isStarted(): Promise<boolean>
Queries whether the node runs.
Return value
true while the node runs.
isMonetizing(minutes?: number): Promise<boolean>
Queries whether the node runs and has relayed traffic since it started, or within
the last minutes minutes.
Parameters
minutes How far to look back, in minutes. 0, the default, means since the
node started.
Return value
true if the node has relayed traffic.
getComputationStatistics(options?: StatisticsOptions): Promise<StatisticSample[]>
Returns the usage statistics over a period, cut into samples.
Parameters
options.from, options.to The period, as Dates or milliseconds since
1970. By default, the last 24 hours.
options.samples How many samples to cut the period into. By default, 24.
Return value
One sample per part of the period, with timestamp, cpuUsage,
totalCpuUsage, memoryUsage, totalMemoryUsage, gpuUsedTotal and
networkTraffic.
cleanUp(): Promise<void>
De-initializes and releases all resources acquired by Massive. Call it before
your app quits.