Skip to content

Instantly share code, notes, and snippets.

@bwhite
Created February 9, 2014 21:27
Show Gist options
  • Save bwhite/8906171 to your computer and use it in GitHub Desktop.
Save bwhite/8906171 to your computer and use it in GitHub Desktop.
[wearscript] Example using the subscribe functionality
<html style="width:100%; height:100%; overflow:hidden">
<head><script src="https://api.picar.us/wearscriptdev/bower_components/msgpack-javascript/msgpack.js"></script></head>
<script>
/* To use, try the following in the playground (HACK_WS may change by then, but use w/e it is now)
HACK_WS.publish('example', 'test');
HACK_WS.publish('example', 'test', {'1': 3});
*/
function example(data) {
WS.log(JSON.stringify(msgpack.unpack(atob(data))));
}
function server() {
WS.subscribe('example', 'example');
}
function main() {
if (WS.scriptVersion(1)) return;
WS.serverConnect('{{WSUrl}}', 'server');
}
window.onload = main;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment