rdh-socket-client 1.0.0

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/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "rdh-socket-client",
3
+ "version": "1.0.0",
4
+ "description": "Client Socket for rdh-socket",
5
+ "main": "src/index.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "author": "RAKOTONDRAMANANA David Henintsoa",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "socket.io-client": "^4.7.2"
14
+ }
15
+ }
package/src/index.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { Options } from "./types";
2
+ import io, { Socket } from 'socket.io-client';
3
+
4
+ export default class RdhClientSocket {
5
+ private options: Options;
6
+ private ws_host: string;
7
+ private status: boolean;
8
+ private socket: Socket;
9
+
10
+ constructor(options: Options) {
11
+ this.ws_host = "https://rdh-websocket.onrender.com"
12
+ this.options = options;
13
+ this.status = false;
14
+ this.init();
15
+ }
16
+
17
+ async init() {
18
+ this.socket = io(this.ws_host, {
19
+ query: this.options
20
+ });
21
+ }
22
+
23
+ channel(channel_name: string): this {
24
+ let finalChannelName = this.options.app_id+'_'+channel_name;
25
+ this.socket.emit('subscribe', {
26
+ channel: finalChannelName
27
+ })
28
+ return this;
29
+ }
30
+
31
+ on(event_name: string, callback: (...args: any[]) => void) {
32
+ this.socket.on(event_name, callback);
33
+ }
34
+
35
+ emit(event_name: string, data: any[]) {
36
+ // this.socket.on(event_name, callback);
37
+ this.socket.emit(event_name, data)
38
+ }
39
+ }
@@ -0,0 +1,6 @@
1
+ // types/options.d.ts
2
+
3
+ export type Options = {
4
+ app_id: string;
5
+ app_key: string;
6
+ };