Skip to content

Commit ff81d03

Browse files
Merge pull request #747 from inplayer-org/bug/iot-token-validity
IOT token validity changed from 60 to 30 minutes
2 parents eac196c + f79aaa5 commit ff81d03

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [3.12.1] - 03-12-2021
6+
## Changes
7+
8+
- IOT token validity changed from 60 to 30 minutes
9+
510
# [3.12.0] - 28-09-2021
611
## Changes
712

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inplayer-org/inplayer.js",
3-
"version": "3.11.2",
3+
"version": "3.12.0",
44
"author": "InPlayer",
55
"license": "MIT",
66
"description": "A Javascript SDK for Inplayer's RESTful API",
@@ -89,4 +89,4 @@
8989
"webpack-bundle-analyzer": "^4.1.0",
9090
"webpack-cli": "^3.3.12"
9191
}
92-
}
92+
}

src/factories/notifications.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ApiConfig, Request } from '../models/Config';
44
import BaseExtend from '../extends/base';
55
import tokenStorage from './tokenStorage';
66

7-
const ONE_HOUR = 60 * 60 * 1000;
7+
const HALF_HOUR = 30 * 60 * 1000;
88

99
class Notifications extends BaseExtend {
1010
subscription: any;
@@ -68,11 +68,9 @@ class Notifications extends BaseExtend {
6868

6969
const iamCreds = JSON.parse(inplayerIotCreds);
7070

71-
if (
72-
iamCreds
73-
&& iamCreds.expiresAt
74-
&& new Date().getMilliseconds() - iamCreds.expiresAt > ONE_HOUR // TODO: check if should be ms
75-
) {
71+
const now = new Date().getTime();
72+
73+
if (iamCreds?.expiresAt && now < iamCreds.expiresAt) {
7674
this.handleSubscribe(iamCreds, callbackParams, accountUuid);
7775

7876
return true;
@@ -82,7 +80,10 @@ class Notifications extends BaseExtend {
8280

8381
await tokenStorage.setItem(
8482
this.config.INPLAYER_IOT_KEY,
85-
JSON.stringify(resp),
83+
JSON.stringify({
84+
...resp,
85+
expiresAt: new Date().getTime() + HALF_HOUR,
86+
}),
8687
);
8788

8889
this.handleSubscribe(resp, callbackParams, accountUuid);

0 commit comments

Comments
 (0)