Skip to content

Commit 46d4893

Browse files
author
Aschen
committed
Merge branch '7-dev' of github.com:kuzzleio/sdk-javascript into 7-dev
2 parents e82d00d + d86473c commit 46d4893

File tree

10 files changed

+425
-48
lines changed

10 files changed

+425
-48
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
code: true
3+
type: page
4+
title: constructor
5+
description: Creates a new Observer object
6+
order: 50
7+
---
8+
9+
# Constructor
10+
11+
Use this constructor to create a new Observer instance.
12+
13+
## Arguments
14+
15+
```js
16+
Observer(sdk, [options]);
17+
```
18+
19+
<br/>
20+
21+
| Argument | Type | Description |
22+
|-----------|-------------------|--------------------------------|
23+
| `sdk` | <pre>Kuzzle</pre> | SDK instanciated and connected |
24+
| `options` | <pre>object</pre> | Additional options |
25+
26+
### options
27+
28+
Observer options.
29+
30+
| Property | Type<br/>(default) | Description |
31+
|----------------|--------------------------------|--------------------------------------------------------------|
32+
| `pullingDelay` | <pre>number</pre><br/>(`5000`) | Refresh delay in ms when the SDK is using the HTTP protocol. |
33+
34+
## Usage
35+
36+
```js
37+
const observer = new Observer(sdk);
38+
```

doc/7/core-classes/observer/introduction/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ await observer.stop('nyc-open-data', 'yellow-taxi');
3535
A good frontend practice is to instantiate one observer for the actual page
3636
and/or component(s) displaying realtime documents and to dispose them when
3737
they are not displayed anymore.
38+
39+
## Using HTTP protocol
40+
41+
<SinceBadge version="auto-version"/>
42+
43+
If the SDK is using the HTTP protocol, then documents are retrieved through the [document.mGet](/sdk/js/7/controllers/document/m-get) method every specified interval (default is 5 sec).
44+
45+
This interval can be modified with the `pullingDelay` option of the constructor.

doc/7/essentials/realtime-application/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,13 @@ let realtimeResult = await observer.search('nyc-open-data', 'yellow-taxi', { que
101101
// Dispose ressources for all managed realtime documents of this collection
102102
await observer.stop('nyc-open-data', 'yellow-taxi');
103103
```
104+
105+
### HTTP support for realtime documents
106+
107+
<SinceBadge version="auto-version"/>
108+
109+
If the SDK is using the HTTP protocol, then the realtime controller cannot be used.
110+
111+
Instead, the [document.mGet](/sdk/js/7/controllers/document/m-get) method will be used every 5 seconds to retrieve documents from Kuzzle.
112+
113+
The pulling delay can be modified using the `pullingDelay` option of the constructor.

src/Kuzzle.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { JSONObject } from './types';
1818
import { RequestPayload } from './types/RequestPayload';
1919
import { ResponsePayload } from './types/ResponsePayload';
2020
import { RequestTimeoutError } from './RequestTimeoutError';
21+
import { BaseProtocolRealtime } from './protocols/abstract/Realtime';
2122

2223
// Defined by webpack plugin
2324
declare const SDKVERSION: any;
@@ -403,12 +404,14 @@ export class Kuzzle extends KuzzleEventEmitter {
403404
}
404405

405406
get autoReconnect () {
406-
return this.protocol.autoReconnect;
407+
const protocol = this.protocol as BaseProtocolRealtime;
408+
return protocol.autoReconnect;
407409
}
408410

409411
set autoReconnect (value) {
410412
this._checkPropertyType('autoReconnect', 'boolean', value);
411-
this.protocol.autoReconnect = value;
413+
const protocol = this.protocol as BaseProtocolRealtime;
414+
protocol.autoReconnect = value;
412415
}
413416

414417
get autoReplay () {
@@ -498,7 +501,8 @@ export class Kuzzle extends KuzzleEventEmitter {
498501
}
499502

500503
get reconnectionDelay () {
501-
return this.protocol.reconnectionDelay;
504+
const protocol = this.protocol as BaseProtocolRealtime;
505+
return protocol.reconnectionDelay;
502506
}
503507

504508
get replayInterval () {

0 commit comments

Comments
 (0)