larasopp 1.2.11 → 1.2.13
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/Listener.d.ts +7 -2
- package/lib/Listener.js +17 -1
- package/lib/Subscribe.d.ts +29 -29
- package/lib/Subscribe.js +107 -107
- package/package.json +1 -1
- package/src/Listener.ts +17 -2
package/lib/Listener.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { type Event as EventListener } from "easy-event-emitter";
|
|
2
2
|
import type Larasopp from ".";
|
|
3
|
-
declare class Listener {
|
|
3
|
+
declare class Listener implements EventListener {
|
|
4
4
|
private readonly context;
|
|
5
5
|
private channel;
|
|
6
6
|
private listeners?;
|
|
7
|
+
private listener?;
|
|
7
8
|
constructor(channel: string, constext: Larasopp);
|
|
8
|
-
listen(event: string, callback: (data: any) => void):
|
|
9
|
+
listen(event: string, callback: (data: any) => void): this;
|
|
10
|
+
here(callback: (data: any) => void): this;
|
|
11
|
+
joining(callback: (data: any) => void): this;
|
|
12
|
+
leaving(callback: (data: any) => void): this;
|
|
9
13
|
unsubscribe(): void;
|
|
10
14
|
remove(): void;
|
|
15
|
+
emit(data: any): void;
|
|
11
16
|
}
|
|
12
17
|
export default Listener;
|
package/lib/Listener.js
CHANGED
|
@@ -20,6 +20,12 @@ class Listener {
|
|
|
20
20
|
writable: true,
|
|
21
21
|
value: void 0
|
|
22
22
|
});
|
|
23
|
+
Object.defineProperty(this, "listener", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
23
29
|
this.channel = channel;
|
|
24
30
|
this.context = constext;
|
|
25
31
|
}
|
|
@@ -29,7 +35,16 @@ class Listener {
|
|
|
29
35
|
}
|
|
30
36
|
const listener = this.context.events.addListener(this.channel + ':' + event, callback);
|
|
31
37
|
this.listeners.push(listener);
|
|
32
|
-
return
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
here(callback) {
|
|
41
|
+
return this.listen('__HERE', callback);
|
|
42
|
+
}
|
|
43
|
+
joining(callback) {
|
|
44
|
+
return this.listen('__JOIN', callback);
|
|
45
|
+
}
|
|
46
|
+
leaving(callback) {
|
|
47
|
+
return this.listen('__LEAVE', callback);
|
|
33
48
|
}
|
|
34
49
|
unsubscribe() {
|
|
35
50
|
this.context.unsubscribe(this.channel);
|
|
@@ -40,5 +55,6 @@ class Listener {
|
|
|
40
55
|
return;
|
|
41
56
|
this.listeners.forEach((listener) => listener.remove());
|
|
42
57
|
}
|
|
58
|
+
emit(data) { }
|
|
43
59
|
}
|
|
44
60
|
exports.default = Listener;
|
package/lib/Subscribe.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { TMessage, TListenerEvents, TListenerCallback, TListen } from "./Core";
|
|
2
|
-
import type { Event, Events } from "easy-event-emitter";
|
|
3
|
-
interface ISubscribe {
|
|
4
|
-
events: Events;
|
|
5
|
-
hasChannel: (channel: string) => boolean;
|
|
6
|
-
pushChannel: (channel: string) => void;
|
|
7
|
-
removeChannel: (channel: string) => void;
|
|
8
|
-
send: <T>(message: TMessage<T>) => void;
|
|
9
|
-
channel: string;
|
|
10
|
-
status: boolean;
|
|
11
|
-
}
|
|
12
|
-
declare class Subscribe {
|
|
13
|
-
private events;
|
|
14
|
-
private currentEvents;
|
|
15
|
-
private hasChannel;
|
|
16
|
-
private pushChannel;
|
|
17
|
-
private removeChannel;
|
|
18
|
-
private status;
|
|
19
|
-
private _channel;
|
|
20
|
-
private send;
|
|
21
|
-
constructor({ events, hasChannel, pushChannel, removeChannel, status, channel, send }: ISubscribe);
|
|
22
|
-
get channel(): string;
|
|
23
|
-
private init;
|
|
24
|
-
listen<T>(event: string, callback: (data: T) => void): TListen;
|
|
25
|
-
private clearEvents;
|
|
26
|
-
remove(): void;
|
|
27
|
-
addListener(event: TListenerEvents, callback: TListenerCallback): Event | undefined;
|
|
28
|
-
}
|
|
29
|
-
export default Subscribe;
|
|
1
|
+
import { TMessage, TListenerEvents, TListenerCallback, TListen } from "./Core";
|
|
2
|
+
import type { Event, Events } from "easy-event-emitter";
|
|
3
|
+
interface ISubscribe {
|
|
4
|
+
events: Events;
|
|
5
|
+
hasChannel: (channel: string) => boolean;
|
|
6
|
+
pushChannel: (channel: string) => void;
|
|
7
|
+
removeChannel: (channel: string) => void;
|
|
8
|
+
send: <T>(message: TMessage<T>) => void;
|
|
9
|
+
channel: string;
|
|
10
|
+
status: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare class Subscribe {
|
|
13
|
+
private events;
|
|
14
|
+
private currentEvents;
|
|
15
|
+
private hasChannel;
|
|
16
|
+
private pushChannel;
|
|
17
|
+
private removeChannel;
|
|
18
|
+
private status;
|
|
19
|
+
private _channel;
|
|
20
|
+
private send;
|
|
21
|
+
constructor({ events, hasChannel, pushChannel, removeChannel, status, channel, send }: ISubscribe);
|
|
22
|
+
get channel(): string;
|
|
23
|
+
private init;
|
|
24
|
+
listen<T>(event: string, callback: (data: T) => void): TListen;
|
|
25
|
+
private clearEvents;
|
|
26
|
+
remove(): void;
|
|
27
|
+
addListener(event: TListenerEvents, callback: TListenerCallback): Event | undefined;
|
|
28
|
+
}
|
|
29
|
+
export default Subscribe;
|
package/lib/Subscribe.js
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class Subscribe {
|
|
4
|
-
constructor({ events, hasChannel, pushChannel, removeChannel, status, channel, send }) {
|
|
5
|
-
Object.defineProperty(this, "events", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
configurable: true,
|
|
8
|
-
writable: true,
|
|
9
|
-
value: void 0
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(this, "currentEvents", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: void 0
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(this, "hasChannel", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true,
|
|
21
|
-
value: void 0
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(this, "pushChannel", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true,
|
|
27
|
-
value: void 0
|
|
28
|
-
});
|
|
29
|
-
Object.defineProperty(this, "removeChannel", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
configurable: true,
|
|
32
|
-
writable: true,
|
|
33
|
-
value: void 0
|
|
34
|
-
});
|
|
35
|
-
Object.defineProperty(this, "status", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
configurable: true,
|
|
38
|
-
writable: true,
|
|
39
|
-
value: void 0
|
|
40
|
-
});
|
|
41
|
-
Object.defineProperty(this, "_channel", {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
configurable: true,
|
|
44
|
-
writable: true,
|
|
45
|
-
value: void 0
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(this, "send", {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true,
|
|
50
|
-
writable: true,
|
|
51
|
-
value: void 0
|
|
52
|
-
});
|
|
53
|
-
this.events = events;
|
|
54
|
-
this.currentEvents = [];
|
|
55
|
-
this.hasChannel = hasChannel;
|
|
56
|
-
this.pushChannel = pushChannel;
|
|
57
|
-
this.removeChannel = removeChannel;
|
|
58
|
-
this.status = status;
|
|
59
|
-
this._channel = channel;
|
|
60
|
-
this.send = send;
|
|
61
|
-
this.init();
|
|
62
|
-
}
|
|
63
|
-
get channel() {
|
|
64
|
-
return this._channel;
|
|
65
|
-
}
|
|
66
|
-
init() {
|
|
67
|
-
this.pushChannel(this.channel);
|
|
68
|
-
if (this.status) {
|
|
69
|
-
this.send({
|
|
70
|
-
subscribe: this.channel
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
const event = this.events.addListener('open', () => {
|
|
75
|
-
this.send({
|
|
76
|
-
subscribe: this.channel
|
|
77
|
-
});
|
|
78
|
-
event.remove();
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
listen(event, callback) {
|
|
83
|
-
const Event = this.events.addListener(this.channel + ':' + event, callback);
|
|
84
|
-
this.currentEvents.push(Event);
|
|
85
|
-
return {
|
|
86
|
-
remove: () => {
|
|
87
|
-
Event.remove();
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
clearEvents() {
|
|
92
|
-
this.currentEvents.forEach((event) => event.remove());
|
|
93
|
-
}
|
|
94
|
-
remove() {
|
|
95
|
-
this.clearEvents();
|
|
96
|
-
this.removeChannel(this.channel);
|
|
97
|
-
if (this.hasChannel(this.channel))
|
|
98
|
-
return;
|
|
99
|
-
this.send({
|
|
100
|
-
unsubscribe: this.channel
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
addListener(event, callback) {
|
|
104
|
-
return this.events.addListener(event + ':' + this.channel, callback);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.default = Subscribe;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Subscribe {
|
|
4
|
+
constructor({ events, hasChannel, pushChannel, removeChannel, status, channel, send }) {
|
|
5
|
+
Object.defineProperty(this, "events", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: void 0
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "currentEvents", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "hasChannel", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "pushChannel", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "removeChannel", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "status", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "_channel", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "send", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
this.events = events;
|
|
54
|
+
this.currentEvents = [];
|
|
55
|
+
this.hasChannel = hasChannel;
|
|
56
|
+
this.pushChannel = pushChannel;
|
|
57
|
+
this.removeChannel = removeChannel;
|
|
58
|
+
this.status = status;
|
|
59
|
+
this._channel = channel;
|
|
60
|
+
this.send = send;
|
|
61
|
+
this.init();
|
|
62
|
+
}
|
|
63
|
+
get channel() {
|
|
64
|
+
return this._channel;
|
|
65
|
+
}
|
|
66
|
+
init() {
|
|
67
|
+
this.pushChannel(this.channel);
|
|
68
|
+
if (this.status) {
|
|
69
|
+
this.send({
|
|
70
|
+
subscribe: this.channel
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const event = this.events.addListener('open', () => {
|
|
75
|
+
this.send({
|
|
76
|
+
subscribe: this.channel
|
|
77
|
+
});
|
|
78
|
+
event.remove();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
listen(event, callback) {
|
|
83
|
+
const Event = this.events.addListener(this.channel + ':' + event, callback);
|
|
84
|
+
this.currentEvents.push(Event);
|
|
85
|
+
return {
|
|
86
|
+
remove: () => {
|
|
87
|
+
Event.remove();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
clearEvents() {
|
|
92
|
+
this.currentEvents.forEach((event) => event.remove());
|
|
93
|
+
}
|
|
94
|
+
remove() {
|
|
95
|
+
this.clearEvents();
|
|
96
|
+
this.removeChannel(this.channel);
|
|
97
|
+
if (this.hasChannel(this.channel))
|
|
98
|
+
return;
|
|
99
|
+
this.send({
|
|
100
|
+
unsubscribe: this.channel
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
addListener(event, callback) {
|
|
104
|
+
return this.events.addListener(event + ':' + this.channel, callback);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.default = Subscribe;
|
package/package.json
CHANGED
package/src/Listener.ts
CHANGED
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
} from "easy-event-emitter";
|
|
4
4
|
import type Larasopp from ".";
|
|
5
5
|
|
|
6
|
-
class Listener {
|
|
6
|
+
class Listener implements EventListener {
|
|
7
7
|
private readonly context: Larasopp;
|
|
8
8
|
private channel: string;
|
|
9
9
|
private listeners?: EventListener[];
|
|
10
|
+
private listener?: EventListener;
|
|
10
11
|
|
|
11
12
|
constructor(channel: string, constext: Larasopp) {
|
|
12
13
|
this.channel = channel;
|
|
@@ -19,7 +20,19 @@ class Listener {
|
|
|
19
20
|
}
|
|
20
21
|
const listener = this.context.events.addListener(this.channel + ':' + event, callback);
|
|
21
22
|
this.listeners.push(listener);
|
|
22
|
-
return
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public here(callback: (data: any) => void) {
|
|
27
|
+
return this.listen('__HERE', callback);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public joining(callback: (data: any) => void) {
|
|
31
|
+
return this.listen('__JOIN', callback);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public leaving(callback: (data: any) => void) {
|
|
35
|
+
return this.listen('__LEAVE', callback);
|
|
23
36
|
}
|
|
24
37
|
|
|
25
38
|
public unsubscribe() {
|
|
@@ -31,6 +44,8 @@ class Listener {
|
|
|
31
44
|
if (!this.listeners) return;
|
|
32
45
|
this.listeners.forEach((listener) => listener.remove());
|
|
33
46
|
}
|
|
47
|
+
|
|
48
|
+
public emit(data: any): void {}
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
export default Listener;
|