rdh-socket-client 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/index.ts +22 -5
- package/src/types/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rdh-socket-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Client Socket for rdh-socket",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"author": "RAKOTONDRAMANANA David Henintsoa",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"axios": "^1.6.2",
|
|
13
14
|
"socket.io-client": "^4.7.2"
|
|
14
15
|
}
|
|
15
16
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import axios from "axios";
|
|
1
2
|
import Channel from "./Channel";
|
|
2
3
|
import { Options } from "./types";
|
|
3
4
|
import io, { Socket } from 'socket.io-client';
|
|
@@ -5,28 +6,44 @@ import io, { Socket } from 'socket.io-client';
|
|
|
5
6
|
export default class RdhClientSocket {
|
|
6
7
|
private options: Options;
|
|
7
8
|
private ws_host: string;
|
|
8
|
-
private status: boolean;
|
|
9
9
|
private socket: Socket;
|
|
10
|
+
private api_url: string;
|
|
10
11
|
|
|
11
12
|
constructor(options: Options) {
|
|
12
|
-
|
|
13
|
+
this.api_url = "https://rdh-socket.wuaze.com/api/subscribe"
|
|
14
|
+
|
|
15
|
+
if (!options.app_ws) {
|
|
13
16
|
this.ws_host = "https://rdh-websocket.onrender.com"
|
|
14
17
|
} else {
|
|
15
|
-
this.ws_host =
|
|
18
|
+
this.ws_host = options.app_ws
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
this.options = options;
|
|
19
|
-
this.status = false;
|
|
20
22
|
this.init();
|
|
23
|
+
|
|
24
|
+
this.socket.on('warning_from_server', (message) => {
|
|
25
|
+
throw new Error(message);
|
|
26
|
+
})
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
async init() {
|
|
24
|
-
|
|
30
|
+
const status = await this.verifyToken()
|
|
31
|
+
this.options.status = status;
|
|
25
32
|
this.socket = io(this.ws_host, {
|
|
26
33
|
query: this.options
|
|
27
34
|
});
|
|
28
35
|
}
|
|
29
36
|
|
|
37
|
+
async verifyToken() {
|
|
38
|
+
const fullURL = this.api_url+`?app_id=${this.options.app_id}&app_key=${this.options.app_key}`
|
|
39
|
+
|
|
40
|
+
return await axios.get(fullURL).then(response => {
|
|
41
|
+
return response.data.status;
|
|
42
|
+
}).catch(() => {
|
|
43
|
+
return false;
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
channel(channel_name: string): Channel {
|
|
31
48
|
let finalChannelName = this.options.app_id+'_'+channel_name;
|
|
32
49
|
return new Channel(finalChannelName, this.socket);
|