Skip to content

Commit 4d09867

Browse files
committed
Update README.md
1 parent 3c2df6c commit 4d09867

File tree

1 file changed

+132
-1
lines changed

1 file changed

+132
-1
lines changed

Readme.md

+132-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,138 @@
33
[![Build Status](https://travis-ci.org/koding/kite.js.svg?branch=master)](https://travis-ci.org/koding/kite.js)
44
[![NPM version](https://img.shields.io/npm/v/kite.js.svg?style=flat-square)](https://www.npmjs.com/package/kite.js)
55

6-
[kite](https://github.com/koding/kite) for browser.
6+
[kite](https://github.com/koding/kite) for node.js and browser.
7+
8+
# Installation
9+
10+
```sh
11+
npm install kite.js
12+
```
13+
14+
or via git:
15+
16+
```sh
17+
git clone git://github.com/koding/kite.js.git
18+
npm i
19+
```
20+
21+
This would automatically fire the initial build for you. Or else once you clone the repository you can do:
22+
23+
```sh
24+
npm run bundle
25+
```
26+
27+
which generates a bundle for the browser, and you can find the output under `./dist/`
28+
29+
# Getting started
30+
31+
In node:
32+
``` js
33+
const { Kite, Kontrol } = require('kite.js');
34+
```
35+
36+
In the browser:
37+
``` html
38+
<script src="./dist/bundle.js"></script>
39+
```
40+
will expose `Kite` and `Kontrol` over `window`
41+
42+
# API
43+
44+
## Kite
45+
46+
You can use the `Kite` constructor with a URL:
47+
48+
```js
49+
const { Kite } = require('kite');
50+
let k = new Kite('ws://my-math-service.com');
51+
k.tell('square', 4).then(console.log.bind(console));
52+
// logs "16"
53+
```
54+
55+
### `kite.connect()`
56+
57+
Open a connection to the remote service. Called the first time in the constructor.
58+
59+
### `kite.disconnect()`
60+
61+
Close the connection, if it is open.
62+
63+
### `kite.tell(method, params)`
64+
65+
Send an RPC to the remote service, and receive the response. Returns a Promise.
66+
67+
68+
## Kontrol
69+
70+
Parameters can be like following for `Kontrol`;
71+
72+
```javascript
73+
var params = {
74+
query: { /* kontrol query */ }
75+
who: { /* kite.who query */ }
76+
}
77+
```
78+
79+
You need a valid query object to work with Kontrol; The kontrol query is used by kontrol to select matching kites by the following criteria, which are order from general to specific:
80+
81+
```go
82+
type KontrolQuery struct {
83+
username string
84+
environment string
85+
name string
86+
version string
87+
region string
88+
hostname string
89+
id string
90+
}
91+
```
92+
93+
The order matters, and more general criteria cannot be omitted. In other words, if you want to query by `name`, you must also provide values for `username` and `environment`; if you want to query by region, you need to provide values for all of `username`, `environment`, `name` and `version`.
94+
95+
### Kite Descriptors
96+
97+
Kite Descriptors are provided by Kontrol, and looks like this:
98+
99+
```javascript
100+
let kiteDescriptor = {
101+
kite: {
102+
name: "A Kite Name",
103+
version: "1.0.0"
104+
},
105+
token: "A token provided by kontrol",
106+
url: "wss://example.com/sample-kite"
107+
};
108+
```
109+
110+
### `kite.who`
111+
112+
Kites can implement custom load-balancing strategies for other instances of their kind. This works by delegation: First kontrol will query for any kite matching the given criteria; If it matches one, it will forward the kite.who query to the `kite.who` method a matching kite. The contents of the kite.who query are application-layer concerns, and are not scrutinized by kontrol, which merely forwards them along to the target kite. The target kite can treat this information however it likes, but is required to respond to the `kite.who` method with a new query that will match the kite which is designated to be the new target kite. It is acceptable for the kite to respond with a query matching itself.
113+
114+
This can be useful if the kite is using some kind of session state. If a given kite has already allocated resources or has some state stored locally, the user can be reconnected to that instance via this mechanism.
115+
116+
### `kontrol.fetchKites(params)`
117+
118+
This method will respond with any kites that matched the query, after any potential load balancing negotiation.
119+
The matching kites will not be connected. You can connect to one by calling its `.connect()` method.
120+
121+
### `kontrol.fetchKite(params)`
122+
123+
This works by querying using fetchKites, and then simply choosing one of the kites matching the given query, after load balancing negotiation.
124+
125+
### `kontrol.watchKites(params)`
126+
127+
This works like `fetchKites`, but will also stream through any updates matching the query as they occur. It will respond with an additional parameter, the `watcherID` which is a numeric handle that can be used to cancel that `watchKites` operation.
128+
129+
This feature won't work in conjunction with `kite.who`
130+
131+
### `kontrol.cancelWatcher(id)`
132+
133+
Given the numeric `watcherID` handle provided by `watchKites`, `cancelWatcher` can be used to clear the associated watch operation.
134+
135+
### `kontrol.createKite(kiteDescriptor)`
136+
137+
Given a kite descriptor, this method will instantiate a proper `Kite` instance.
7138

8139

9140
# License

0 commit comments

Comments
 (0)