WebAPI/WebSocketOverApps

From MozillaWiki
< WebAPI
Revision as of 10:48, 14 July 2013 by Thinker (talk | contribs) (Created page with "WebSocketOverApp API provides WebSocket connections between any pair of Apps on a device. An WebApp can create WebSocket connections to other Apps on the device, so they can ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

WebSocketOverApp API provides WebSocket connections between any pair of Apps on a device. An WebApp can create WebSocket connections to other Apps on the device, so they can pass messages through the connection.

API

Client Side

var ws = WebSocket("wsapp://appid/", ["intentAsProtocol"]);
ws.onopen = function () {...};
ws.onerror = function () {...};
ws.onclose = function () {...};

Server Side =

navigator.mozSetMessageHandler("wsconnect", function (request) {
  var ws = request.value;
  if (ws.clientProtocols.indexOf("intentAsProtocol") == -1) {
    return;
  }
  ws.accept("intentAsProtocol");
});

Manifest

{
  "name": "my application",
  ...
  "wsapp": {
    servers: ["server app1", "server app2", ...]
  }
}

Use Case