koding / kite.js

Kite client in JavaScript
kite.koding.com
MIT License
75 stars 16 forks source link

KiteServer #36

Closed gokmen closed 7 years ago

gokmen commented 7 years ago

This PR introduces existing implementation of KiteServer in ES6 and some more improvements and goodies, currently we can do;


import { Kite, KiteServer } from 'kite.js'

const kite = new Kite({
  url: 'http://0.0.0.0:7780',
  autoReconnect: false,
  autoConnect: false,
})

const math = new KiteServer({
  name: 'math',
  auth: false,
  api: {
    square: function(x, callback) {
      callback(null, x * x)
    },
  },
})

kite.on('open', () => {
  kite.tell('square', 5).then(res => // res will become 25)
})

math.listen(7780)
kite.connect()

and current tests as follow;

  constants
    ✓ should expose required constants

  kite.js
    ✓ should provide Kontrol, Kite and KiteServer

  Kite
    getKiteInfo
      ✓ should return default kite info if no option provided

  KiteError
    ✓ should provide a generic Error object

  KiteError.codeIs
    ✓ should support code checking on a given error

  KiteError.codeIsnt
    ✓ should support code checking on a given error

  KiteError.makeProperError
    ✓ should generate a proper error

  KiteServer with SockJS
    ✓ should be able to accept kite connections (51ms)

  KiteServer with WebSocket
    ✓ should be able to accept kite connections

  SockJS Server with WebSocket
    ✓ should be able to accept kite connections

  SockJS Server with XHR
    ✓ should be able to accept kite connections

  WebSocket Server
    ✓ should be able to accept kite connections

  12 passing (160ms)

ps: auth is not implemented/updated yet, so auth: false is a must for now.