npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

WatchWorker

v0.0.2

Published

Messaging APIs for communication with JavaScript Worker between watchOS and iOS.

Downloads

5

Readme

WatchWorker Plugin for Cordova

This is an experimental plugin for asynchronous communication between a smartwatch and its encountered mobile using HTML5 SharedWorker APIs.

Prequisites

For iOS

This plugin is ONLY available for iOS9.3, so please make sure that the deployment target is set to version 9.3 in your Xcode project (both project settings and target settings).

Please replace the contents in AppDelegate.m file within your Xcode project by the following lines.

#import "AppDelegate.h"
#import "MainViewController.h"
#import "{PRODUCT_NAME}-Swift.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    // Launch JavaScript execution context for WatchKit apps
    [[WatchWorker sharedInstance] initializeWatchWorkerWithUrl:@"ApplicationScope.js"];
    // Launch WatchConnectivity session to allow WatchConnectivity communication
    [[WCMessageService sharedInstance] startServiceOnSuccess:nil onError:nil];
    // We launch cordova WebView at last
    self.viewController = [[MainViewController alloc] init];
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

Messaging

Initialization

You must initialize watchworker first to evaluate your script file in the new JavaScript context.

/**
 * Initialize a worker instance for smartwatch
 * @parameter   {string}    url (currently is the filename of your script, without a suffix)
 * @parameter   {callback}  onSuccess
 * @parameter   {callback}  onError
 */
watchworker.initialize(url, onSuccess, onError);

Message Sender

// Please ensure that watchworker has been successfully initialized
 watchworker.initialize(url, function() {
     /**
      * Post a message to smartwatch
      * @parameter   {string}    message
      * @parameter   {callback}  onSuccess
      * @parameter   {callback}  onError
      */
      watchworker.postMessage(message, onSuccess, onError);
 }, onError);

Message Listener

// Please ensure that watchworker has been successfully initialized
 watchworker.initialize(url, function() {
     /**
      * Add event listener to watchworker
      * @parameter   {string}    type
      * @parameter   {callback}  callback
      */
      watchworker.addEventListener(type, callback);
      // An example
      watchworker.addEventListener("message", function(message) {
          // TODO: message handler
      });

    /**
     * Remove event listeners from watchworker
     * @parameter   {string}    type
     * @parameter   {callback}  onSuccess
     * @parameter   {callback}  onError
     */
     watchworker.removeEventListener(type, onSuccess, onError);
 }, onError);

Example

// On worker successfully initialized
var onSuccess = function () {
    watchworker.addEventListener("message", function (message) {
        // Receiving message
    });
    watchworker.addEventListener("error", function (error) {
        // Receiving error
    });
    watchworker.postMessage("Message from web view!");
};
// On worker initialization error
var onError = function () {};
// Initialize with a context inside script file named ApplicationScope.js
watchworker.initialize("ApplicationScope.js", onSuccess, onError);