Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

#### Bug fixes

- [ [#226](https://github.com/kuzzleio/sdk-javascript/pull/226) ] Network error handling ([stafyniaksacha](https://github.com/stafyniaksacha))
- [ [#226](https://github.com/kuzzleio/sdk-javascript/pull/226) ] Protocol error handling ([stafyniaksacha](https://github.com/stafyniaksacha))
- [ [#222](https://github.com/kuzzleio/sdk-javascript/pull/222) ] NetworkError payload should be an Error object ([scottinet](https://github.com/scottinet))
- [ [#214](https://github.com/kuzzleio/sdk-javascript/pull/214) ] createIndex should only return response.result ([ballinette](https://github.com/ballinette))

Expand Down
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,24 @@ The SDK supports different protocols. When instantiating, you must choose the pr

Example:
```js
const { Kuzzle } = require('kuzzle-sdk');
const {
Kuzzle,
Websocket,
Http,
SocketIO
} = require('kuzzle-sdk');

const kuzzle = new Kuzzle('websocket', { host: 'localhost', port: 7512 });
const kuzzle = new Kuzzle(
new Websocket({ host: 'localhost', port: 7512 })
);

kuzzle.connect()
.then(() => {
// You are now connected to your Kuzzle instance.
return kuzzle.server.now();
})
.then(serverTime => console.log(serverTime))
.catch(error => console.error(error));
try {
const serverTime = kuzzle.server.now();

console.log(serverTime);
} catch (error) {
console.error(error);
}
```

## Installation
Expand Down Expand Up @@ -92,9 +99,9 @@ import { Kuzzle } from 'kuzzle-sdk/dist/kuzzle.js'
```

## Protocols used
Actually, the SDK support 3 protocols: `http`, `websocket` et `socketio`.
Actually, the SDK support 3 protocols: `Http`, `Websocket` and `SocketIO`.

Websocket and Socket.IO protocols implement the whole Kuzzle API, while HTTP protocol does not implement realtime features (rooms and subscriptions).
Websocket and Socket.IO protocols implement the whole Kuzzle API, while **HTTP protocol does not implement realtime features** (rooms and subscriptions).
While Socket.IO offers better compatibility with older web browsers, our raw WebSocket implementation is about 20% faster.

#### NodeJS
Expand All @@ -109,22 +116,22 @@ We also recommend to use the `webSocket` or `http` protocol, but some old browse
let kuzzle;

if ('WebSocket' in window && window.WebSocket.CLOSING === 2) {
kuzzle = new Kuzzle('websocket', { host: 'localhost' });
kuzzle = new Kuzzle(new Websocket({ host: 'localhost' }));
} else {
kuzzle = new Kuzzle('socketio', { host: 'localhost' });
kuzzle = new Kuzzle(new SocketIO({ host: 'localhost' }));
}
```

#### Custom protocol

The SDK also proposes to create custom protocols.

There are two ways to write these protocols, the first is to inherit the `KuzzleAbstractNetwork` class provided with the SDK and implement only the `connect` and `send` methods.
There are two ways to write these protocols, the first is to inherit the `KuzzleAbstractProtocol` class provided with the SDK and implement only the `connect` and `send` methods.

```js
const { KuzzleAbstractNetwork } = require('kuzzle-sdk');
const { KuzzleAbstractProtocol } = require('kuzzle-sdk');

class MyCustomProtocol extends KuzzleAbstractNetwork {
class MyCustomProtocol extends KuzzleAbstractProtocol {
connect() {
// (...) do custom connection steps...

Expand Down
11 changes: 7 additions & 4 deletions features/support/world.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const {setWorldConstructor} = require('cucumber');
const Kuzzle = require('../../src/Kuzzle');
const
{ setWorldConstructor } = require('cucumber'),
{
Kuzzle,
Websocket
} = require('../../index');

class World {
constructor () {
this.kuzzle = new Kuzzle('websocket', {host: 'localhost', port: 7512});
this.kuzzle = new Kuzzle(new Websocket({ host: 'localhost', port: 7512 }));

this.index = null;
this.collection = null;
Expand All @@ -23,4 +27,3 @@ class World {
}

setWorldConstructor(World);

16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const
Kuzzle = require('./src/Kuzzle'),
KuzzleAbstractNetwork = require('./src/networkWrapper/protocols/abstract/common'),
{
Http,
Websocket,
SocketIO
} = require('./src/protocols'),
KuzzleAbstractProtocol = require('./src/protocols/abstract/common'),
KuzzleEventEmitter = require('./src/eventEmitter');

if (typeof window !== 'undefined' && typeof BUILT === 'undefined') {
Expand All @@ -10,4 +15,11 @@ if (typeof window !== 'undefined' && typeof BUILT === 'undefined') {
'Learn more at https://github.com/kuzzleio/sdk-javascript/tree/master#browser');
}

module.exports = {Kuzzle, KuzzleAbstractNetwork, KuzzleEventEmitter};
module.exports = {
Kuzzle,
Http,
Websocket,
SocketIO,
KuzzleAbstractProtocol,
KuzzleEventEmitter
};
Loading