Skip to content

Commit

Permalink
v 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Yazykov committed Jan 27, 2019
1 parent f0a727c commit b218b10
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ crm.Lead.findById( 123 )
.then( lead => lead.remove());
```

## Переподключение

Переподключение к порталу в случае истечения сессии происходит автоматически.
Также доступны настройки:

```javascript
const crm = new AmoCRM({
domain: 'domain',
auth: {
login: 'mylogin',
hash: 'mytesthash',
},
reconnection: {
disabled: true, // по умолчанию false,
checkDelay: 500, // кол-во мс, как часто проверять сессию на предмет истечения. По умолчанию: 60 * 1000
accuracyTime: 1000 // за какое кол-во мс до истечения сессии необходимо переподключиться. По умолчанию: 60 * 1000
}
});
```

## Работа с событиями

В настоящий момент доступны следующие события:
Expand Down
9 changes: 6 additions & 3 deletions dist/base/AmoConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var AmoConnection = function (_EventResource) {
_this._request = request;
_this._options = options;
_this._isConnected = false;
_this._reconnectOptions = Object.assign({ disabled: false }, options.reconnection);
return _this;
}

Expand Down Expand Up @@ -81,7 +82,9 @@ var AmoConnection = function (_EventResource) {
login = _options.login,
password = _options.password,
hash = _options.hash,
reconnection = _options.reconnection,
reconnection = this._reconnectOptions,
checkDelay = reconnection.checkDelay,
accuracyTime = reconnection.accuracyTime,
data = {
USER_LOGIN: login
};
Expand All @@ -102,8 +105,8 @@ var AmoConnection = function (_EventResource) {
saveCookies: true
}
}).then(function (data) {
if (reconnection) {
_this3.reconnectAt(_this3._request.expires, reconnection.checkDelay);
if (!reconnection.disabled) {
_this3.reconnectAt(_this3._request.expires, checkDelay, accuracyTime);
}

_this3._isConnected = data.response.auth === true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amocrm-js",
"version": "1.0.5",
"version": "1.0.6",
"description": "JS Library for AmoCRM",
"main": "dist/AmoCRM.js",
"directories": {
Expand Down
9 changes: 6 additions & 3 deletions src/base/AmoConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AmoConnection extends EventResource {
this._request = request;
this._options = options;
this._isConnected = false;
this._reconnectOptions = Object.assign({ disabled: false }, options.reconnection );
}

get connected() {
Expand Down Expand Up @@ -57,7 +58,9 @@ class AmoConnection extends EventResource {
if ( this._isConnected ) {
return Promise.resolve( true );
}
const { login, password, hash, reconnection } = this._options,
const { login, password, hash } = this._options,
reconnection = this._reconnectOptions,
{ checkDelay, accuracyTime } = reconnection,
data = {
USER_LOGIN: login
};
Expand All @@ -78,8 +81,8 @@ class AmoConnection extends EventResource {
}
})
.then( data => {
if ( reconnection ) {
this.reconnectAt( this._request.expires, reconnection.checkDelay );
if ( !reconnection.disabled ) {
this.reconnectAt( this._request.expires, checkDelay, accuracyTime );
}

this._isConnected = data.response.auth === true;
Expand Down

0 comments on commit b218b10

Please sign in to comment.