rubjs 2.7.4 → 2.7.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/package.json
CHANGED
@@ -15,11 +15,12 @@ declare class VoiceChatClient {
|
|
15
15
|
private lastPosition;
|
16
16
|
private intervalId?;
|
17
17
|
private isManualSkip;
|
18
|
-
|
18
|
+
private getAnyMusicCallback;
|
19
|
+
constructor(getAnyMusicCallback?: () => Promise<string>);
|
19
20
|
play(filePath?: string): Promise<void>;
|
20
21
|
stop(): void;
|
21
22
|
resume(): void;
|
22
|
-
next(): void
|
23
|
+
next(): Promise<void>;
|
23
24
|
previous(): void;
|
24
25
|
addToPlaylist(filePath: string): void;
|
25
26
|
removeFromPlaylist(filePath: string): void;
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const child_process_1 = require("child_process");
|
13
13
|
const wrtc_1 = require("wrtc");
|
14
14
|
class VoiceChatClient {
|
15
|
-
constructor() {
|
15
|
+
constructor(getAnyMusicCallback) {
|
16
16
|
this.buffer = Buffer.alloc(0);
|
17
17
|
this.frameSize = 960;
|
18
18
|
this.playlist = [];
|
@@ -24,14 +24,20 @@ class VoiceChatClient {
|
|
24
24
|
this.source = new wrtc_1.nonstandard.RTCAudioSource();
|
25
25
|
this.track = this.source.createTrack();
|
26
26
|
this.pc.addTrack(this.track);
|
27
|
+
this.getAnyMusicCallback = getAnyMusicCallback;
|
27
28
|
}
|
28
29
|
play(filePath) {
|
29
30
|
return __awaiter(this, void 0, void 0, function* () {
|
30
31
|
if (this.ffmpeg)
|
31
32
|
this.stop();
|
32
33
|
if (!filePath) {
|
33
|
-
if (this.playlist.length === 0)
|
34
|
-
|
34
|
+
if (this.playlist.length === 0) {
|
35
|
+
if (this.getAnyMusicCallback) {
|
36
|
+
this.playlist = [yield this.getAnyMusicCallback()];
|
37
|
+
}
|
38
|
+
else
|
39
|
+
return;
|
40
|
+
}
|
35
41
|
filePath = this.playlist[this.currentIndex];
|
36
42
|
}
|
37
43
|
if (!this.chatGuid || !this.voiceChatId || !this.client) {
|
@@ -75,12 +81,27 @@ class VoiceChatClient {
|
|
75
81
|
this.lastPosition += 0.02;
|
76
82
|
}
|
77
83
|
});
|
78
|
-
this.ffmpeg.on("close", (code) => {
|
84
|
+
this.ffmpeg.on("close", (code) => __awaiter(this, void 0, void 0, function* () {
|
79
85
|
if (!this.isManualSkip && code !== null && !this.isPaused) {
|
80
|
-
this.next();
|
86
|
+
yield this.next();
|
81
87
|
}
|
82
88
|
this.isManualSkip = false;
|
83
|
-
});
|
89
|
+
}));
|
90
|
+
this.clearIntervals();
|
91
|
+
this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
92
|
+
try {
|
93
|
+
yield this.client.getGroupVoiceChatUpdates(this.chatGuid, this.voiceChatId);
|
94
|
+
}
|
95
|
+
catch (_a) { }
|
96
|
+
}), 10 * 1000);
|
97
|
+
this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
98
|
+
try {
|
99
|
+
if (this.isPaused)
|
100
|
+
return;
|
101
|
+
yield this.client.sendVoiceChatActivity(this.chatGuid, this.voiceChatId, this.client.userGuid);
|
102
|
+
}
|
103
|
+
catch (_a) { }
|
104
|
+
}), 2 * 1000);
|
84
105
|
});
|
85
106
|
}
|
86
107
|
stop() {
|
@@ -96,14 +117,22 @@ class VoiceChatClient {
|
|
96
117
|
this.play();
|
97
118
|
}
|
98
119
|
next() {
|
99
|
-
|
100
|
-
this.
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
121
|
+
if (this.playlist.length > this.currentIndex + 1) {
|
122
|
+
this.isManualSkip = true;
|
123
|
+
this.stop();
|
124
|
+
this.currentIndex += 1;
|
125
|
+
this.lastPosition = 0;
|
126
|
+
this.isPaused = true;
|
127
|
+
this.play(this.playlist[this.currentIndex]);
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
if (this.getAnyMusicCallback) {
|
131
|
+
this.playlist = [...this.playlist, yield this.getAnyMusicCallback()];
|
132
|
+
yield this.next();
|
133
|
+
}
|
134
|
+
}
|
135
|
+
});
|
107
136
|
}
|
108
137
|
previous() {
|
109
138
|
if (this.currentIndex > 0) {
|
@@ -138,19 +167,6 @@ class VoiceChatClient {
|
|
138
167
|
const sdpAnswer = connect.sdp_answer_data;
|
139
168
|
yield this.pc.setRemoteDescription(new wrtc_1.RTCSessionDescription({ type: "answer", sdp: sdpAnswer }));
|
140
169
|
yield client.setVoiceChatState(chatGuid, voiceChatId);
|
141
|
-
this.clearIntervals();
|
142
|
-
this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
143
|
-
try {
|
144
|
-
yield client.getGroupVoiceChatUpdates(chatGuid, voiceChatId);
|
145
|
-
}
|
146
|
-
catch (_a) { }
|
147
|
-
}), 10 * 1000);
|
148
|
-
this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
149
|
-
try {
|
150
|
-
yield client.sendVoiceChatActivity(chatGuid, voiceChatId, client.userGuid);
|
151
|
-
}
|
152
|
-
catch (_a) { }
|
153
|
-
}), 2 * 1000);
|
154
170
|
});
|
155
171
|
}
|
156
172
|
clearIntervals() {
|