rdh-socket-client 1.1.5 → 1.1.6

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 CHANGED
@@ -1,2 +1,2 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/README.md CHANGED
@@ -1,34 +1,34 @@
1
- # RDH Socket Client
2
-
3
- ## Installation
4
-
5
- To install the RDH Socket Client package, run the following command in your command line:
6
-
7
- ```bash
8
- npm i rdh-socket-client
9
- ```
10
- ## USAGE
11
-
12
- ```js
13
- import rdhClientSocket from 'rdh-socket-client';
14
-
15
- // Initialize the client with your app ID and app key
16
- const client = new rdhClientSocket({
17
- app_id: 'APP_ID',
18
- app_key: 'APP_key'
19
- });
20
-
21
- const client_first_channel = client.channel('channelName');
22
-
23
- // Subscribe to a channel and listen for an event
24
- client_first_channel.on('eventName', (data) => {
25
- console.log(data.message);
26
- });
27
-
28
- // Emit a custom event with data
29
- client_first_channel.emit('myEvent', mydata);
30
-
31
- ```
32
- eplace `APP_ID` and `APP_key` with your actual application ID and key. Make sure to customize the channel name, event name, and data according to your application's requirements.
33
-
1
+ # RDH Socket Client
2
+
3
+ ## Installation
4
+
5
+ To install the RDH Socket Client package, run the following command in your command line:
6
+
7
+ ```bash
8
+ npm i rdh-socket-client
9
+ ```
10
+ ## USAGE
11
+
12
+ ```js
13
+ import rdhClientSocket from 'rdh-socket-client';
14
+
15
+ // Initialize the client with your app ID and app key
16
+ const client = new rdhClientSocket({
17
+ app_id: 'APP_ID',
18
+ app_key: 'APP_key'
19
+ });
20
+
21
+ const client_first_channel = client.channel('channelName');
22
+
23
+ // Subscribe to a channel and listen for an event
24
+ client_first_channel.on('eventName', (data) => {
25
+ console.log(data.message);
26
+ });
27
+
28
+ // Emit a custom event with data
29
+ client_first_channel.emit('myEvent', mydata);
30
+
31
+ ```
32
+ eplace `APP_ID` and `APP_key` with your actual application ID and key. Make sure to customize the channel name, event name, and data according to your application's requirements.
33
+
34
34
  Feel free to explore more features and options provided by the RDH Socket Client package documentation for a comprehensive understanding of its capabilities.
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
- {
2
- "name": "rdh-socket-client",
3
- "version": "1.1.5",
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
- }
1
+ {
2
+ "name": "rdh-socket-client",
3
+ "version": "1.1.6",
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/Channel.ts CHANGED
@@ -1,28 +1,28 @@
1
- import { Socket } from 'socket.io-client';
2
-
3
- export default class Channel {
4
- private channel: string;
5
- private socket: Socket;
6
-
7
- constructor(channel: string, socket: Socket) {
8
- this.channel = channel;
9
- this.socket = socket;
10
- this.init();
11
- }
12
-
13
- init() {
14
- this.socket.emit('subscribe', {
15
- channel: this.channel
16
- })
17
- }
18
-
19
- on(event_name: string, callback: (...args: any[]) => void) {
20
- const real_event = this.channel+"."+event_name;
21
- this.socket.on(real_event, callback);
22
- }
23
-
24
- emit(event_name: string, data: any[]) {
25
- // this.socket.on(event_name, callback);
26
- this.socket.emit(event_name, { data: data, _channel_name: this.channel})
27
- }
1
+ import { Socket } from 'socket.io-client';
2
+
3
+ export default class Channel {
4
+ private channel: string;
5
+ private socket: Socket;
6
+
7
+ constructor(channel: string, socket: Socket) {
8
+ this.channel = channel;
9
+ this.socket = socket;
10
+ this.init();
11
+ }
12
+
13
+ init() {
14
+ this.socket.emit('subscribe', {
15
+ channel: this.channel
16
+ })
17
+ }
18
+
19
+ on(event_name: string, callback: (...args: any[]) => void) {
20
+ const real_event = this.channel+"."+event_name;
21
+ this.socket.on(real_event, callback);
22
+ }
23
+
24
+ emit(event_name: string, data: any[]) {
25
+ // this.socket.on(event_name, callback);
26
+ this.socket.emit(event_name, { data: data, _channel_name: this.channel})
27
+ }
28
28
  }
package/src/index.ts CHANGED
@@ -1,32 +1,32 @@
1
- import Channel from "./Channel";
2
- import { Options } from "./types";
3
- import io, { Socket } from 'socket.io-client';
4
-
5
- export default class RdhClientSocket {
6
- private options: Options;
7
- private ws_host: string;
8
- private socket: Socket;
9
- $
10
- constructor(options: Options) {
11
-
12
- if (!options.app_ws) {
13
- this.ws_host = "https://rdh-websocket.onrender.com"
14
- } else {
15
- this.ws_host = options.app_ws
16
- }
17
-
18
- this.options = options;
19
- this.init();
20
- }
21
-
22
- async init() {
23
- this.socket = io(this.ws_host, {
24
- query: this.options
25
- });
26
- }
27
-
28
- channel(channel_name: string): Channel {
29
- let finalChannelName = this.options.app_id+'_'+channel_name;
30
- return new Channel(finalChannelName, this.socket);
31
- }
1
+ import Channel from "./Channel";
2
+ import { Options } from "./types";
3
+ import io, { Socket } from 'socket.io-client';
4
+
5
+ export default class RdhClientSocket {
6
+ private options: Options;
7
+ private ws_host: string;
8
+ private socket!: Socket;
9
+
10
+ constructor(options: Options) {
11
+
12
+ if (!options.app_ws) {
13
+ this.ws_host = "http://socket.archipoint.mg:10028"
14
+ } else {
15
+ this.ws_host = options.app_ws
16
+ }
17
+
18
+ this.options = options;
19
+ this.init();
20
+ }
21
+
22
+ async init() {
23
+ this.socket = io(this.ws_host, {
24
+ query: this.options
25
+ });
26
+ }
27
+
28
+ channel(channel_name: string): Channel {
29
+ let finalChannelName = this.options.app_id+'_'+channel_name;
30
+ return new Channel(finalChannelName, this.socket);
31
+ }
32
32
  }
@@ -1,7 +1,7 @@
1
- // types/options.d.ts
2
-
3
- export type Options = {
4
- app_id: string;
5
- app_ws: string | null | undefined;
6
- app_key: string;
7
- };
1
+ // types/options.d.ts
2
+
3
+ export type Options = {
4
+ app_id: string;
5
+ app_ws: string | null | undefined;
6
+ app_key: string;
7
+ };