#WebSocket Server API#
This repository is the home of the Web Socket Server API specification being worked on by the Client and Server JavaScript APIs Community Group for Packaged Web apps and Server-Side JS implementations. This API is considered for implementation in Wakanda Server
##Concepts##
This specification reuse concepts and content from the following W3C recommendations or Draft:
- The WebSocket API: compatible with WebSocket the Interface and its JS Binding
- Web Workers: multiple connections handling via ports as in SharedWorker interface
- Raw Socket API: Packages Web App Security context and TCPServerSocket Interface
- HTML5 Web Messaging: handling port and origin
In Short, the proposed WebSocketServer
interface looks like the WebSocket
interface but messaging behave with the SharedWorker
port mechanism.
##How to use?##
###Dedicated Socket Workers###
var webSocketMetaData = self.webSocket;
self.onmessage = function (msgEvent) {
self.postMessage(message);
};
###Shared Socket Workers###
self.onconnect = function handleClient(event) {
var port = event.ports[0];
var webSocketMetaData = event.webSocket;
// handle client messages
port.onmessage = function handleMessage(msgEvent) {
// send a message to a specific client
port.postMessage(message);
}
};
##Interfaces##
Interface WebSocketServer {
void addWebSocketHandler(String workerPath, String id, Boolean dedicatedOrShared)
void removeWebSocketHandler(String id)
}
Interface WebSocketWorkerScope: DedicatedWorkerGlobalScope {
readonly attribute WebSocketMeta webSocket
}
Interface WebSocketSharedWorkerScope: SharedWorkerGlobalScope {
}
Interface WebSocketMeta {
readonly attribute DOMString url;
// ready state
const unsigned short CONNECTING = 0;
const unsigned short OPEN = 1;
const unsigned short CLOSING = 2;
const unsigned short CLOSED = 3;
readonly attribute unsigned short readyState;
readonly attribute unsigned long bufferedAmount;
// networking
readonly attribute DOMString extensions;
readonly attribute DOMString protocol;
// messaging
attribute DOMString binaryType;
}
It is possible to connect to WebSocket SharedWorkers using the standard SharedWorker constructor with the same ID. In this situation the event parameter of the 'onconnect' handler won't have the specific "webSocket" property
##How to contribute?##
Every one is welcome to contribute to this specification. If not already a member, start by joining the community group, which is open to anyone, and present yourself community group mailing list. Then create an issue on the github repository and mention it in another amail to the mailing list. You may join a pull request with edition suggestions.
##Useful links##
- The specification: http://w3c-jseverywhere.github.io/websocket-server/
- A related wiki page: http://www.w3.org/community/jseverywhere/wiki/Web_Sockets
- The Community Group homepage: http://w3.org/community/jseverywhere
- The Community Group mailing-list: http://lists.w3.org/Archives/Public/public-jseverywhere/