Provides an interface for interacting with application context and events. Developers can access the Rocky object with the following line of code:
var rocky = require('rocky');
Attaches an event handler to the specified events. You may subscribe with multiple handlers, but at present there is no way to unsubscribe.
rocky.on('minutechange', function() {...});
Event Type Options
Possible values:
draw
- Provide a RockyDrawCallback as the callback. The draw event is being emitted after each call to requestDraw but at most once for each screen update, even if requestDraw is called frequently the 'draw' event might also fire at other meaningful times (e.g. upon launch).
secondchange
- Provide a RockyTickCallback as the callback. The secondchange event is emitted every time the clock's second changes.
minutechange
- Provide a RockyTickCallback as the callback. The minutechange event is emitted every time the clock's minute changes.
hourchange
- Provide a RockyTickCallback as the callback. The hourchange event is emitted every time the clock's hour changes.
daychange
- Provide a RockyTickCallback as the callback. The daychange event is emitted every time the clock's day changes.
memorypressure
- Provides a RockyMemoryPressureCallback. The event is emitted every time there is a notable change in available system memory. You can see an example implementation of memory pressure handling here.
message
- Provide a RockyMessageCallback as the callback. The message event is emitted every time the application receives a postMessage from the mobile companion.
postmessageconnected
- Provide a RockyPostMessageConnectedCallback as the callback. The event may be emitted immediately upon subscription, if the subsystem is already connected. It is also emitted when connectivity is established.
postmessagedisconnected
- Provide a RockyPostMessageDisconnectedCallback as the callback. The event may be emitted immediately upon subscription, if the subsystem is already disconnected. It is also emitted when connectivity is lost.
postmessageerror
- Provide a RockyPostMessageErrorCallback as the callback. The event is emitted when a transmission error occurrs. The type of error is not provided, but the message has not been delivered.
The event being subscribed to.
A callback function that will be executed when the event occurs. See below for more details.
Attaches an event handler to the specified events. Synonymous with rocky.on().
rocky.addEventListener(type, callback);
The event being subscribed to.
A callback function that will be executed when the event occurs. See below for more details.
Remove an existing event listener previously registered with rocky.on() or rocky.addEventListener().
The type of the event listener to be removed. See rocky.on() for a list of available event types.
The existing developer-defined function that was previously registered.
Remove an existing event handler from the specified events. Synonymous with rocky.removeEventListener().
rocky.off(type, callback);
The type of the event listener to be removed. See rocky.on() for a list of available event types.
The existing developer-defined function that was previously registered.
Sends a message to the mobile companion component. Please be aware that messages should be kept concise. Each message is queued, so postMessage()
can be called multiple times immediately. If there is a momentary loss of connectivity, queued messages may still be delivered, or automatically removed from the queue after a few seconds of failed connectivity. Any transmission failures, or out of memory errors will be raised via the postmessageerror
event.
rocky.postMessage({cmd: 'fetch'});
An object containing the data to deliver to the mobile device. This will be received in the data
field of the event
delivered to the on('message', ...)
handler.
Flags the canvas (display) as requiring a redraw. Invoking this method will cause the draw event to be emitted. Only 1 draw event will occur, regardless of how many times the redraw is requested before the next draw event.
rocky.on('secondchange', function(e) {
rocky.requestDraw();
});
A WatchInfo object containing information about the connected Pebble smartwatch.
console.log(rocky.watchInfo.model);
> pebble_2_hr_lime
A UserPreferences object access to user related settings from the currently connected Pebble smartwatch.
console.log(rocky.userPreferences.contentSize);
> medium
The callback function signature to be used with the postmessageerror
event.
An object containing information about the event:
type
- The type of event which was triggered.
data
- The data failed to send within the message.
The callback function signature to be used with the postmessageconnected
event.
An object containing information about the event:
type
- The type of event which was triggered.
Provides information about the currently connected Pebble smartwatch.
The name of the Pebble model. (e.g. pebble_time_round_silver_20mm)
The name of the Pebble platform. (e.g. basalt)
Not available yet.
An object with the following fields:
major
- The major version of the smartwatch's firmware.
minor
- The minor version of the smartwatch's firmware.
patch
- The patch version of the smartwatch's firmware.
suffix
- The suffix of the smartwatch's firmware. (e.g. beta3)
The callback function signature to be used with the memorypressure
event.
An object containing information about the event:
level
(String) - The current level of memory pressure.
high
- This is a critical level, indicating that the application will be terminated if memory isn't immediately free'd.
Important Notes:
Avoid creating any new objects/arrays/strings when this level is raised.
Drop object properties you don't need using the delete
operator or by assigning undefined
to it.
Don't use the in
operator in the handler for large objects/arrays. Avoid for (var x in y)
due to memory constraints.
Array has large memory requirements for certain operations/methods. Avoid Array.pop()
, Array.slice
and length assignment Array.length = 123
, on large arrays.
normal
- Not yet implemented.
low
- Not yet implemented.
The callback function signature to be used with the postmessagedisconnected
event.
An object containing information about the event:
type
- The type of event which was triggered.
Provides access to user related settings from the currently connected Pebble smartwatch. The size itself will vary between platforms, see the ContentSize guide for more information.
Pebble > System > Notifications > Text Size:
small
- Not available on Emery.
medium
- The default setting.
large
- The default setting on Emery.
x-large
- Only available on Emery.
The callback function signature to be used with the draw event.
An object containing information about the event:
context
- A CanvasRenderingContext2D object that can be used to draw information on the disply.
The callback function signature to be used with the message
event.
An object containing information about the event:
type
- The type of event which was triggered.
data
- The data sent within the message.
The callback function signature to be used with the secondchange
, minutechange
, hourchange
and daychange
events.
In addition to firing these tick events at the appropriate time change, they are also emitted when the application starts.
An object containing information about the event:
date
- A JavaScript date object representing the current time.
Web API by Mozilla Contributors is licensed under CC-BY-SA 2.5.
Do you need some help understanding the something on this page?
You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!