larasopp 1.2.22 → 1.2.23
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/lib/Core.js +2 -2
- package/lib/Listener.d.ts +1 -0
- package/lib/Listener.js +21 -2
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -1
- package/lib/types.d.ts +1 -0
- package/package.json +6 -6
package/lib/Core.js
CHANGED
|
@@ -164,12 +164,12 @@ class Core {
|
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
166
|
this.emitListener(json.channel, json.message);
|
|
167
|
-
this.events.emit(json.channel
|
|
167
|
+
this.events.emit(`${json.channel}:${json.event}`, json.message);
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
emitListener(method, channel) {
|
|
171
171
|
if (constants_1.ListenerEvents.includes(method)) {
|
|
172
|
-
this.events.emit(method
|
|
172
|
+
this.events.emit(`${method}:${channel}`, {
|
|
173
173
|
channel
|
|
174
174
|
});
|
|
175
175
|
}
|
package/lib/Listener.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare class Listener extends EventEmmiter.Stack {
|
|
|
5
5
|
private channel;
|
|
6
6
|
private listener?;
|
|
7
7
|
private cacheEvents;
|
|
8
|
+
private hereMap;
|
|
8
9
|
constructor(channel: string, constext: Larasopp);
|
|
9
10
|
listen(event: string, callback: (data: any) => void, withCache?: boolean): this;
|
|
10
11
|
here(callback: (data: any) => void, withCache?: boolean): this;
|
package/lib/Listener.js
CHANGED
|
@@ -31,6 +31,12 @@ class Listener extends easy_event_emitter_1.default.Stack {
|
|
|
31
31
|
writable: true,
|
|
32
32
|
value: void 0
|
|
33
33
|
});
|
|
34
|
+
Object.defineProperty(this, "hereMap", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: new Map()
|
|
39
|
+
});
|
|
34
40
|
this.channel = channel;
|
|
35
41
|
this.context = constext;
|
|
36
42
|
this.cacheEvents = {};
|
|
@@ -39,7 +45,7 @@ class Listener extends easy_event_emitter_1.default.Stack {
|
|
|
39
45
|
listen(event, callback, withCache = false) {
|
|
40
46
|
if (withCache && this.hasCache(event))
|
|
41
47
|
callback(this.getCache(event));
|
|
42
|
-
const listener = this.context.events.addListener(this.channel
|
|
48
|
+
const listener = this.context.events.addListener(`${this.channel}:${event}`, (data) => {
|
|
43
49
|
callback(data);
|
|
44
50
|
if (withCache)
|
|
45
51
|
this.pushCache(event, data);
|
|
@@ -48,7 +54,20 @@ class Listener extends easy_event_emitter_1.default.Stack {
|
|
|
48
54
|
return this;
|
|
49
55
|
}
|
|
50
56
|
here(callback, withCache = true) {
|
|
51
|
-
|
|
57
|
+
const listeners = new easy_event_emitter_1.default.Stack();
|
|
58
|
+
listeners.push(this.joining((join) => {
|
|
59
|
+
this.hereMap.set(join.id, join);
|
|
60
|
+
callback([...this.hereMap.values()]);
|
|
61
|
+
}));
|
|
62
|
+
listeners.push(this.leaving((leave) => {
|
|
63
|
+
this.hereMap.delete(leave.id);
|
|
64
|
+
callback([...this.hereMap.values()]);
|
|
65
|
+
}));
|
|
66
|
+
const hereListener = this.listen('__HERE', (here) => {
|
|
67
|
+
this.hereMap = new Map(here.map((u) => [u.id, u]));
|
|
68
|
+
callback([...this.hereMap.values()]);
|
|
69
|
+
}, withCache);
|
|
70
|
+
return hereListener;
|
|
52
71
|
}
|
|
53
72
|
joining(callback, withCache = false) {
|
|
54
73
|
return this.listen('__JOIN', callback, withCache);
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ declare class Larasopp extends Core {
|
|
|
6
6
|
private readonly channels;
|
|
7
7
|
constructor(config: IConfig);
|
|
8
8
|
private listenResumeSubscribes;
|
|
9
|
+
user(callback: (user: any) => void): void;
|
|
10
|
+
userRefresh(callback: (user: any) => void): void;
|
|
9
11
|
subscribe(channel: string): Listener;
|
|
10
12
|
unsubscribe(channel: string): void;
|
|
11
13
|
trigger<T>(channel: string, event: string, message: T, permission?: TPermissions, waitSubscribe?: boolean): void;
|
package/lib/index.js
CHANGED
|
@@ -25,6 +25,24 @@ class Larasopp extends Core_1.default {
|
|
|
25
25
|
}));
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
user(callback) {
|
|
29
|
+
if (!this.status)
|
|
30
|
+
return;
|
|
31
|
+
this.send({ me: true });
|
|
32
|
+
const listener = this.events.addListener(`__SYSTEM:user`, (e) => {
|
|
33
|
+
callback(e);
|
|
34
|
+
listener.remove();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
userRefresh(callback) {
|
|
38
|
+
if (!this.status)
|
|
39
|
+
return;
|
|
40
|
+
this.send({ me: 'refresh' });
|
|
41
|
+
const listener = this.events.addListener(`__SYSTEM:user-refresh`, (e) => {
|
|
42
|
+
callback(e);
|
|
43
|
+
listener.remove();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
28
46
|
subscribe(channel) {
|
|
29
47
|
const listener = new Listener_1.default(channel, this);
|
|
30
48
|
this.pushListener(channel, listener);
|
|
@@ -49,7 +67,7 @@ class Larasopp extends Core_1.default {
|
|
|
49
67
|
});
|
|
50
68
|
};
|
|
51
69
|
if (waitSubscribe)
|
|
52
|
-
this.events.addListener(event
|
|
70
|
+
this.events.addListener(`${event}:${channel}`, send);
|
|
53
71
|
send();
|
|
54
72
|
}
|
|
55
73
|
pushListener(channel, listener) {
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "larasopp",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.23",
|
|
4
4
|
"description": "Websocket client for laravel",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "jest",
|
|
9
9
|
"build": "tsc",
|
|
10
|
-
"prepublishOnly": "npm run build"
|
|
10
|
+
"prepublishOnly": "npm run test && npm run build"
|
|
11
11
|
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib"
|
|
14
|
+
],
|
|
12
15
|
"jest": {
|
|
13
16
|
"transform": {
|
|
14
17
|
"^.+\\.[t|j]sx?$": "babel-jest"
|
|
15
18
|
}
|
|
16
19
|
},
|
|
17
|
-
"files": [
|
|
18
|
-
"lib"
|
|
19
|
-
],
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
22
|
"url": "git+https://github.com/SergoMorello/larasopp.client.git"
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"typescript": "^5.1.6"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"easy-event-emitter": "^1.
|
|
44
|
+
"easy-event-emitter": "^1.1.5"
|
|
45
45
|
}
|
|
46
46
|
}
|