reverb-ws-client 1.0.3 → 1.0.5
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/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +38 -21
- package/dist/index.mjs +38 -21
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -29,10 +29,12 @@ declare class Channel {
|
|
|
29
29
|
private client;
|
|
30
30
|
private listeners;
|
|
31
31
|
private subscribed;
|
|
32
|
+
private logger;
|
|
32
33
|
constructor(name: string, client: ReverbClient);
|
|
33
34
|
subscribe(): Promise<void>;
|
|
34
35
|
listen(event: string, callback: EventCallback): this;
|
|
35
36
|
stopListening(event: string, callback?: EventCallback): this;
|
|
37
|
+
unsubscribe(): void;
|
|
36
38
|
handleEvent(event: string, data: unknown): void;
|
|
37
39
|
getName(): string;
|
|
38
40
|
}
|
|
@@ -50,6 +52,7 @@ declare class ReverbClient {
|
|
|
50
52
|
presence(name: string): Channel;
|
|
51
53
|
send(data: PusherOutgoingMessage | object): void;
|
|
52
54
|
getSocketId(): string | null;
|
|
55
|
+
getOptions(): ReverbClientOptions;
|
|
53
56
|
authorize(socketId: string, channelName: string): Promise<AuthResponse>;
|
|
54
57
|
private getChannel;
|
|
55
58
|
private handleMessage;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,10 +29,12 @@ declare class Channel {
|
|
|
29
29
|
private client;
|
|
30
30
|
private listeners;
|
|
31
31
|
private subscribed;
|
|
32
|
+
private logger;
|
|
32
33
|
constructor(name: string, client: ReverbClient);
|
|
33
34
|
subscribe(): Promise<void>;
|
|
34
35
|
listen(event: string, callback: EventCallback): this;
|
|
35
36
|
stopListening(event: string, callback?: EventCallback): this;
|
|
37
|
+
unsubscribe(): void;
|
|
36
38
|
handleEvent(event: string, data: unknown): void;
|
|
37
39
|
getName(): string;
|
|
38
40
|
}
|
|
@@ -50,6 +52,7 @@ declare class ReverbClient {
|
|
|
50
52
|
presence(name: string): Channel;
|
|
51
53
|
send(data: PusherOutgoingMessage | object): void;
|
|
52
54
|
getSocketId(): string | null;
|
|
55
|
+
getOptions(): ReverbClientOptions;
|
|
53
56
|
authorize(socketId: string, channelName: string): Promise<AuthResponse>;
|
|
54
57
|
private getChannel;
|
|
55
58
|
private handleMessage;
|
package/dist/index.js
CHANGED
|
@@ -24,16 +24,40 @@ __export(index_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
26
|
|
|
27
|
+
// src/logger.ts
|
|
28
|
+
var Logger = class {
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
this.options = options;
|
|
31
|
+
}
|
|
32
|
+
options;
|
|
33
|
+
log(...args) {
|
|
34
|
+
if (!this.options.debug) return;
|
|
35
|
+
console.log(...args);
|
|
36
|
+
}
|
|
37
|
+
warn(...args) {
|
|
38
|
+
if (!this.options.debug) return;
|
|
39
|
+
console.warn(...args);
|
|
40
|
+
}
|
|
41
|
+
error(...args) {
|
|
42
|
+
if (!this.options.debug) return;
|
|
43
|
+
console.error(...args);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
27
47
|
// src/Channel.ts
|
|
28
48
|
var Channel = class {
|
|
29
49
|
constructor(name, client) {
|
|
30
50
|
this.name = name;
|
|
31
51
|
this.client = client;
|
|
52
|
+
this.logger = new Logger({
|
|
53
|
+
debug: this.client.getOptions().debug ?? false
|
|
54
|
+
});
|
|
32
55
|
}
|
|
33
56
|
name;
|
|
34
57
|
client;
|
|
35
58
|
listeners = /* @__PURE__ */ new Map();
|
|
36
59
|
subscribed = false;
|
|
60
|
+
logger;
|
|
37
61
|
async subscribe() {
|
|
38
62
|
if (this.subscribed) return;
|
|
39
63
|
const isPrivate = this.name.startsWith("private-");
|
|
@@ -65,7 +89,7 @@ var Channel = class {
|
|
|
65
89
|
}
|
|
66
90
|
this.listeners.get(event).add(callback);
|
|
67
91
|
this.subscribe().catch((err) => {
|
|
68
|
-
|
|
92
|
+
this.logger.error("[Reverb] subscribe failed", err);
|
|
69
93
|
});
|
|
70
94
|
return this;
|
|
71
95
|
}
|
|
@@ -78,6 +102,16 @@ var Channel = class {
|
|
|
78
102
|
}
|
|
79
103
|
return this;
|
|
80
104
|
}
|
|
105
|
+
unsubscribe() {
|
|
106
|
+
this.client.send({
|
|
107
|
+
event: "pusher:unsubscribe",
|
|
108
|
+
data: {
|
|
109
|
+
channel: this.name
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
this.listeners.clear();
|
|
113
|
+
this.subscribed = false;
|
|
114
|
+
}
|
|
81
115
|
handleEvent(event, data) {
|
|
82
116
|
const callbacks = this.listeners.get(event);
|
|
83
117
|
if (!callbacks) return;
|
|
@@ -96,26 +130,6 @@ var Channel = class {
|
|
|
96
130
|
}
|
|
97
131
|
};
|
|
98
132
|
|
|
99
|
-
// src/logger.ts
|
|
100
|
-
var Logger = class {
|
|
101
|
-
constructor(options = {}) {
|
|
102
|
-
this.options = options;
|
|
103
|
-
}
|
|
104
|
-
options;
|
|
105
|
-
log(...args) {
|
|
106
|
-
if (!this.options.debug) return;
|
|
107
|
-
console.log(...args);
|
|
108
|
-
}
|
|
109
|
-
warn(...args) {
|
|
110
|
-
if (!this.options.debug) return;
|
|
111
|
-
console.warn(...args);
|
|
112
|
-
}
|
|
113
|
-
error(...args) {
|
|
114
|
-
if (!this.options.debug) return;
|
|
115
|
-
console.error(...args);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
133
|
// src/ConnectionManager.ts
|
|
120
134
|
var ConnectionManager = class {
|
|
121
135
|
constructor(options, onMessage) {
|
|
@@ -236,6 +250,9 @@ var ReverbClient = class {
|
|
|
236
250
|
getSocketId() {
|
|
237
251
|
return this.socketId;
|
|
238
252
|
}
|
|
253
|
+
getOptions() {
|
|
254
|
+
return this.options;
|
|
255
|
+
}
|
|
239
256
|
authorize(socketId, channelName) {
|
|
240
257
|
if (!this.options.authorizer) {
|
|
241
258
|
throw new Error("[Reverb] authorizer is required for private channels");
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
|
+
// src/logger.ts
|
|
2
|
+
var Logger = class {
|
|
3
|
+
constructor(options = {}) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
}
|
|
6
|
+
options;
|
|
7
|
+
log(...args) {
|
|
8
|
+
if (!this.options.debug) return;
|
|
9
|
+
console.log(...args);
|
|
10
|
+
}
|
|
11
|
+
warn(...args) {
|
|
12
|
+
if (!this.options.debug) return;
|
|
13
|
+
console.warn(...args);
|
|
14
|
+
}
|
|
15
|
+
error(...args) {
|
|
16
|
+
if (!this.options.debug) return;
|
|
17
|
+
console.error(...args);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
1
21
|
// src/Channel.ts
|
|
2
22
|
var Channel = class {
|
|
3
23
|
constructor(name, client) {
|
|
4
24
|
this.name = name;
|
|
5
25
|
this.client = client;
|
|
26
|
+
this.logger = new Logger({
|
|
27
|
+
debug: this.client.getOptions().debug ?? false
|
|
28
|
+
});
|
|
6
29
|
}
|
|
7
30
|
name;
|
|
8
31
|
client;
|
|
9
32
|
listeners = /* @__PURE__ */ new Map();
|
|
10
33
|
subscribed = false;
|
|
34
|
+
logger;
|
|
11
35
|
async subscribe() {
|
|
12
36
|
if (this.subscribed) return;
|
|
13
37
|
const isPrivate = this.name.startsWith("private-");
|
|
@@ -39,7 +63,7 @@ var Channel = class {
|
|
|
39
63
|
}
|
|
40
64
|
this.listeners.get(event).add(callback);
|
|
41
65
|
this.subscribe().catch((err) => {
|
|
42
|
-
|
|
66
|
+
this.logger.error("[Reverb] subscribe failed", err);
|
|
43
67
|
});
|
|
44
68
|
return this;
|
|
45
69
|
}
|
|
@@ -52,6 +76,16 @@ var Channel = class {
|
|
|
52
76
|
}
|
|
53
77
|
return this;
|
|
54
78
|
}
|
|
79
|
+
unsubscribe() {
|
|
80
|
+
this.client.send({
|
|
81
|
+
event: "pusher:unsubscribe",
|
|
82
|
+
data: {
|
|
83
|
+
channel: this.name
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
this.listeners.clear();
|
|
87
|
+
this.subscribed = false;
|
|
88
|
+
}
|
|
55
89
|
handleEvent(event, data) {
|
|
56
90
|
const callbacks = this.listeners.get(event);
|
|
57
91
|
if (!callbacks) return;
|
|
@@ -70,26 +104,6 @@ var Channel = class {
|
|
|
70
104
|
}
|
|
71
105
|
};
|
|
72
106
|
|
|
73
|
-
// src/logger.ts
|
|
74
|
-
var Logger = class {
|
|
75
|
-
constructor(options = {}) {
|
|
76
|
-
this.options = options;
|
|
77
|
-
}
|
|
78
|
-
options;
|
|
79
|
-
log(...args) {
|
|
80
|
-
if (!this.options.debug) return;
|
|
81
|
-
console.log(...args);
|
|
82
|
-
}
|
|
83
|
-
warn(...args) {
|
|
84
|
-
if (!this.options.debug) return;
|
|
85
|
-
console.warn(...args);
|
|
86
|
-
}
|
|
87
|
-
error(...args) {
|
|
88
|
-
if (!this.options.debug) return;
|
|
89
|
-
console.error(...args);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
107
|
// src/ConnectionManager.ts
|
|
94
108
|
var ConnectionManager = class {
|
|
95
109
|
constructor(options, onMessage) {
|
|
@@ -210,6 +224,9 @@ var ReverbClient = class {
|
|
|
210
224
|
getSocketId() {
|
|
211
225
|
return this.socketId;
|
|
212
226
|
}
|
|
227
|
+
getOptions() {
|
|
228
|
+
return this.options;
|
|
229
|
+
}
|
|
213
230
|
authorize(socketId, channelName) {
|
|
214
231
|
if (!this.options.authorizer) {
|
|
215
232
|
throw new Error("[Reverb] authorizer is required for private channels");
|