sg-socket-client
Web socket client for SUGOS
Last updated a month ago by realglobe .
Apache-2.0 · Repository · Bugs · Original npm · Tarball
$ cnpm install sg-socket-client 
SYNC missed versions from official npm registry.

sg-socket-client

Build Status npm Version JS Standard

Web socket client for SUGOS

Installation

$ npm install sg-socket-client --save

Usage

'use strict'

const sgSocketClient = require('sg-socket-client')
const co = require('co')

let socket = sgSocketClient('http://localhost:8084')
socket.on('connect', () => { /* ... */ })
socket.on('my:event', () => { /* ... */ })
socket.on('disconnect', () => { /* ... */ })

// Using call extension
co(function * () {
  // Wait for ack
  let result = socket.call('my:event', { foo: 'bar' })
  console.log(result)
})

// Using locking extension

co(function * () {
  // Resource to lock.
  let resource = 'screen'
  
  // Start locking
  // Throws error if another client lock the resource
  yield socket.lock(resource)

  // Stop locking
  yield socket.unlock(resource)
})

License

This software is released under the Apache-2.0 License.

Links

Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 24
Dependencies (4)
Dev Dependencies (16)

Copyright 2014 - 2016 © taobao.org |