# Pebble Developer Documentation: /docs/pebblekit-js/ SDK 4.33.1. 2 pages. Index: https://developer.repebble.com/llms.txt # Pebble Source: https://developer.repebble.com/docs/pebblekit-js/Pebble/ The Pebble namespace is where all of the Pebble specific methods and properties exist. This class contains methods belonging to PebbleKit JS and allows bi-directional communication with a C or JavaScript watchapp, as well as managing the user's timeline subscriptions, creating AppGlance slices and obtaining information about the currently connected watch. ### Methods Pebble.addEventListener(type, callback) Adds a listener for PebbleKit JS events, such as when an `AppMessage` is received or the configuration view is opened or closed. #### Event Type Options Possible values: - `ready` - The watchapp has been launched and the PebbleKit JS component is now ready to receive events. - `appmessage` - The watch sent an `AppMessage` to PebbleKit JS. The AppMessage `Dictionary` is contained in the payload property (i.e: `event.payload`). The payload consists of key-value pairs, where the keys are strings containing integers (e.g: "0"), or aliases for keys defined in package.json (e.g: "KEY\_EXAMPLE"). Values should be integers, strings or byte arrays (arrays of characters). - `showConfiguration` - The user has requested the app's configuration webview to be displayed. This can occur either upon the app's initial install or when the user taps 'Settings' in the 'My Pebble' view within the phone app. - `webviewclosed` - The configuration webview was closed by the user. If the webview had a response, it will be contained in the response property (i.e: `event.response`). This response can be used to feed back user preferences to the watchapp. #### Parameters String type The type of the event, from the list described above. EventCallback callback The developer defined [EventCallback](#EventCallback) to receive any events of the type specified that occur. Pebble.removeEventListener(type, callback) Remove an existing event listener previously registered with [Pebble.addEventListener()](#addEventListener). #### Parameters String type The type of the event listener to be removed. See [Pebble.addEventListener()](#addEventListener) for a list of available event types. Function callback The existing developer-defined function that was previously registered. Pebble.showSimpleNotificationOnPebble(title, body) Show a simple modal notification on the connected watch. #### Parameters String title The title of the notification String body The main content of the notification Pebble.sendAppMessage(data, onSuccess, onFailure) Send an AppMessage to the app running on the watch. Messages should be in the form of JSON objects containing key-value pairs. See Pebble.sendAppMessage() for valid key and value data types. `Pebble.sendAppMessage = function(data, onSuccess, onFailure) { };` #### Parameters Object data A JSON object containing key-value pairs to send to the watch. Values in arrays that are greater then 255 will be mod 255 before sending. AppMessageAckCallback onSuccess A developer-defined [AppMessageAckCallback](#AppMessageAckCallback) callback to run if the watch acknowledges (ACK) this message. AppMessageOnFailure onFailure A developer-defined [AppMessageNackCallback](#AppMessageNackCallback) callback to run if the watch does NOT acknowledge (NACK) this message. #### Returns The transaction id for this message Pebble.getTimelineToken(onSuccess, onFailure) The Pebble mobile app returns a token only for apps installed from the appstore. Sideloaded apps receive the failure callback. The timeline web API is no longer available, so the token cannot be used to push pins. Use [insertTimelinePin](#insertTimelinePin) instead. Get the user's timeline token for this app. This is a string and is unique per user per app. Note: In order for timeline tokens to be available, the app must be submitted to the Pebble appstore, but does not need to be public. Read more in the [timeline guides](https://developer.repebble.com/guides/pebble-timeline/timeline-js.md). #### Parameters TimelineTokenCallback onSuccess A developer-defined [TimelineTokenCallback](#TimelineTokenCallback) callback to handle a successful attempt to get the timeline token. Function onFailure A developer-defined callback to handle a failed attempt to get the timeline token. Pebble.timelineSubscribe(topic, onSuccess, onFailure) Not supported in the Pebble mobile app. The timeline web API is no longer available and the callbacks never fire. Use [insertTimelinePin](#insertTimelinePin) instead. Subscribe the user to a timeline topic for your app. This can be used to filter the different pins a user could receive according to their preferences, as well as maintain groups of users. #### Parameters String topic The desired topic to be subscribed to. Users will receive all pins pushed to this topic. Function onSuccess A developer-defined callback to handle a successful subscription attempt. Function onFailure A developer-defined callback to handle a failed subscription attempt. Pebble.timelineUnsubscribe(topic, onSuccess, onFailure) Not supported in the Pebble mobile app. The timeline web API is no longer available and the callbacks never fire. Use [insertTimelinePin](#insertTimelinePin) instead. Unsubscribe the user from a timeline topic for your app. Once unsubscribed, the user will no longer receive any pins pushed to this topic. #### Parameters String topic The desired topic to be unsubscribed from. Function onSuccess A developer-defined callback to handle a successful unsubscription attempt. Function onFailure A developer-defined callback to handle a failed unsubscription attempt. Pebble.timelineSubscriptions(onSuccess, onFailure) Not supported in the Pebble mobile app. The timeline web API is no longer available and the callbacks never fire. Use [insertTimelinePin](#insertTimelinePin) instead. Obtain a list of topics that the user is currently subscribed to. The length of the list should be checked to determine whether the user is subscribed to at least one topic. `Pebble.timelineSubscriptions(function(topics) { console.log(topics); }, function() { console.log('error'); } );` #### Parameters TimelineTopicsCallback onSuccess The developer-defined function to process the retuned list of topic strings. Function onFailure The developer-defined function to gracefully handle any errors in obtaining the user's subscriptions. Pebble.insertTimelinePin(pin) Insert a pin into the user's timeline. The pin is created by the newPebble app and synced to the watch, so no timeline token, API key orappstore listing is required and sideloaded apps can use it. The pin isassociated with your app, and its `id` only needs to be unique withinyour app - inserting a pin with an existing `id` updates that pin. Thenew Pebble app does not support the timeline web API, so this is how newapps should create pins. Read more in the[local pins guide](https://developer.repebble.com/guides/pebble-timeline/timeline-local-pins.md). #### Parameters Object pin The pin to insert, in the format described in[Creating Pins](https://developer.repebble.com/guides/pebble-timeline/pin-structure.md). A JSONstring of the same object is also accepted. Pebble.deleteTimelinePin(id) Remove a pin previously added with[insertTimelinePin](#insertTimelinePin) from the user's timeline. #### Parameters String id The `id` of the pin to delete. Pebble.getActiveWatchInfo() Obtain an object containing information on the currently connected Pebble smartwatch. #### Returns A [WatchInfo](#WatchInfo) object detailing the currently connected Pebble watch. Pebble.getAccountToken() Returns a unique account token that is associated with the Pebble account of the current user. #### Returns A string that is guaranteed to be identical across devices if the user owns several Pebble or several mobile devices. From the developer's perspective, the account token of a user is identical across platforms and across all the developer's watchapps. If the user is not logged in, this function will return an empty string (''). Pebble.getWatchToken() Returns a a unique token that can be used to identify a Pebble device. #### Returns A string that is is guaranteed to be identical for each Pebble device for the same app across different mobile devices. The token is unique to your app and cannot be used to track Pebble devices across applications. Pebble.appGlanceReload(appGlanceSlices, onSuccess, onFailure) Not supported in the Pebble mobile app. The callbacks never fire. Use the [C AppGlance API](https://developer.repebble.com/guides/user-interfaces/appglance-c.md) from the watchapp instead. Triggers a reload of the app glance which first clears any existing slices and then adds the provided slices. #### Parameters AppGlanceSlice appGlanceSlices [AppGlanceSlice](#AppGlanceSlice) JSON objects to add to the app glance. AppGlanceReloadSuccessCallback onSuccess The developer-defined callback which is called if the reload operation succeeds. AppGlanceReloadFailureCallback onFailure The developer-defined callback which is called if the reload operation fails. Pebble.openURL(url) When an app is marked as configurable, the PebbleKit JS component must implement `Pebble.openURL()` in the `showConfiguration` event handler. The Pebble mobile app will launch the supplied URL to allow the user to configure the watchapp or watchface. See the [App Configuration guide](https://developer.repebble.com/guides/user-interfaces/app-configuration-static.md). #### Parameters String url The URL of the static configuration page. Pebble.enumeratePlugins() Returns the installed plugins. Each entry has `uuid`, `name`, `sources` and `actions`, copied from the plugin's manifest. Returns an empty array when the call fails. **Preview.** Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the [Plugins (Preview) guide](https://developer.repebble.com/guides/plugins.md). #### Returns An array of plugin descriptions. Pebble.subscribeToSource(config) Subscribes to one item of one category and delivers every update to `config.onData` as an envelope with `pluginUuid`, `validUntilMs` and `instances`. Throws when `category` or `item` is missing. Failures the Pebble mobile app detects, such as no plugin for the item or a missing permission, are reported to `config.onError` as `{ code, message }`. **Preview.** Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the [Plugins (Preview) guide](https://developer.repebble.com/guides/plugins.md). #### Parameters Object config An object with `category` and `item` (required), and optional `properties` (array of property names), `plugin` (UUID of a preferred plugin), `iconPixelSize` (`{ w, h }`, needed for `icon` and `image` shapes), `onData` and `onError` callbacks. #### Returns A subscription object with an `unsubscribe()` method. The subscription also ends when the app's JavaScript stops. Pebble.invokeAction(config) Invokes one action on one plugin. The returned Promise always resolves: with `{ ok: true, text, refreshed }` on success, or `{ ok: false, code, message }`, with text, refreshed and message omitted when the plugin did not set them. Throws when `plugin` or `action` is missing. Actions never fall back to another plugin. **Preview.** Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the [Plugins (Preview) guide](https://developer.repebble.com/guides/plugins.md). #### Parameters Object config An object with `plugin` (the plugin's UUID) and `action` (required), `args` (an object matching the action's parameters schema, default `{}`) and `timeoutMs` (1 to 60000, default 15000). #### Returns A Promise that resolves with the action result. Pebble.sendConfigMessage(message) Pushes a message to the app's own settings page while that page is open. The page receives it as a `message` event with `e.target` set to `"pkjs"` and `e.data` set to the message. There is no reply, and nothing happens when no page is open. **Preview.** Does nothing useful until the plugins preview is turned on in the Pebble mobile app. The API will change. See the [Plugins (Preview) guide](https://developer.repebble.com/guides/plugins.md). #### Parameters Object message Any JSON value to deliver to the page. ### Typedefs Pebble.TimelineTopicsCallback(List) Called when the user's list of subscriptions is available for processing by the developer. #### Parameters List of topic strings that the user is subscribed to Pebble.AppGlanceReloadFailureCallback(AppGlanceSlices) Called when AppGlanceReload has failed. #### Parameters AppGlanceSlice AppGlanceSlices An [AppGlanceSlice](#AppGlanceSlice) object containing the app glance slices. Pebble.AppMessageAckCallback(data) Called when an AppMessage is acknowledged by the watch. #### Parameters Object data An object containing the callback data. This contains the `transactionId` which is the transaction ID of the message. Pebble.AppMessageNackCallback(data, error) Called when an AppMessage is not acknowledged by the watch. #### Parameters Object data An object containing the callback data. This contains the `transactionId` which is the transaction ID of the message String error The error message Pebble.EventCallback(event) Called when an event of any type previously registered occurs. The parameters are different depending on the type of event, shown in brackets for each parameter listed here. #### Parameters Object event An object containing the event information, including: - `type` - The type of event fired, from the list in the description of [Pebble.addEventListener()](#addEventListener). - `payload` - The dictionary sent over `AppMessage` consisting of key-value pairs. - `response` - The contents of the URL navigated to when the configuration page was closed, after the anchor. This may be encoded, which will require use of decodeURIComponent() before reading as an object. Pebble.TimelineTokenCallback(token) Called when the user's timeline token is available. #### Parameters String token The user's token. Pebble.AppGlanceReloadSuccessCallback(AppGlanceSlices) Called when AppGlanceReload is successful. #### Parameters AppGlanceSlice AppGlanceSlices An [AppGlanceSlice](#AppGlanceSlice) object containing the app glance slices. WatchInfo Provides information about the connected Pebble smartwatch. #### Properties platform The hardware platform, such as `basalt` or `emery`. model The watch model, such as `pebble_black` language The user's currently selected language on this watch. firmware An object containing information about the watch's firmware version, including: - `major` - The major version - `minor` - The minor version - `patch` - The patch version - `suffix` - Any additional version information, such as `beta3` AppGlanceSlice The structure of an app glance. #### Properties expirationTime Optional ISO date-time string of when the entry should expire and no longer be shown in the app glance. layout An object containing: - `icon` - URI string of the icon to display in the app glance, e.g. system://images/ALARM\_CLOCK. - `subtitleTemplateString` - Template string that will be displayed in the subtitle of the app glance. --- # PebbleKit JavaScript Documentation Source: https://developer.repebble.com/docs/pebblekit-js/ PebbleKit JS is a JavaScript component of the Pebble SDK which runs within the Pebble mobile application. It provides access to GPS, storage and Internet connectivity to applications running on Pebble smartwatches. Want to create apps or faces for Pebble written entirely in JS? For that, use [Alloy](https://developer.repebble.com/guides/alloy.md). The PebbleKit JS API is provided via the `Pebble` namespace: * * * #### [Pebble](https://developer.repebble.com/docs/pebblekit-js/Pebble.md) * * * PebbleKit JS also provides access to the following standard JS functionality: - [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) - [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) - [Geolocation](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation) - [LocalStorage](https://developer.mozilla.org/en-US/docs/Web/API/LocalStorage)