Sparkling Method SDK - TypeScript
The sparkling-method package provides the JS-side pipe for JS ↔ native method calls.
It is the foundation that all Sparkling method packages (router, storage, media, etc.) are built on.
Install
Quick start
API
pipe.call(methodMap, params, callback, options?)
Call a native method with a callback.
Example:
pipe.callAsync(methodMap, params, options?, timeout?)
Call a native method and return a Promise.
Returns Promise<TResponse> — resolves with response.data when code === 0, rejects otherwise.
Example:
pipe.callWithTimeout(methodMap, params, timeout, options?)
Convenience wrapper for callAsync with a custom timeout.
Returns Promise<TResponse>.
pipe.on(eventName, callback)
Subscribe to a native event.
Returns the EventCallback for use with off().
pipe.off(eventName, callback)
Unsubscribe from a native event.
Types
Response codes
Relationship with method packages
Sparkling method packages (sparkling-navigation, sparkling-storage, sparkling-media, etc.) are
thin wrappers around sparkling-method. They call pipe.call() under the hood with pre-defined
method names like router.open, storage.setItem, media.chooseMedia, etc.
You can use sparkling-method directly for:
- Calling custom native methods you've implemented
- Listening to native events
- Building your own method packages

