This package has been deprecated

Author message:

No longer maintained

websocket-promise

1.0.1 • Public • Published

WebSocket-Promise

WebSocket-Promise is an extremely lightweight Promise wrapper for native HTML5 WebSockets written in JS. It provides an easy to use API on both the Browser and Server Side.

WebSocket-Promise internally uses Le-Emitter for the Browser-Sided event emitting part, You can replace it with an EventEmitter of your choice.

Hello World

Node

var WebSocketP = require('websocket-promise')
var Server = new WebSocketP({port: 8090})
Server.onConnection(function(Client){
  Client.on('Hello', function(Job){
    console.log(Job.Message) // "World"
    Job.Response = 'World'
  })
})

Browser

var Connection = new WebSocketP("ws://localhost:8090")
Connection.Request("Hello", "World").then(function(Response){
  console.log(Response) // "World"
})

API

enum JobType = {Broadcast, Reply, Request}
type Job = shape(Type => JobType, SubType => string, Message => Mixed, ?ID => String, EXCHANGE => true)
class Server{
  constructor(Options: Object) // Available Options: https://github.com/websockets/ws/blob/master/lib/WebSocketServer.js#L25
  onConnection(Callback: Function<ServerClient>): void
  Broadcast(Type: String, Message: Any): void
}
class ServerClient{
  on(Type: String, Callback: Function): Disposable
  request(Type: String, Message): Promise
  terminate(): void
}
class WebSocketP{ // Available under same name in browser
  on(Type: String, Callback: Function): Disposable
  request(Type: String, Message): Promise
  terminate(): void
}

License

This project is licensed under the terms of MIT License. See the License file for more info.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

  • Version
    Downloads (Last 7 Days)
    • Published

Package Sidebar

Install

npm i websocket-promise

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • steelbrain