rubjs 2.7.3 → 2.7.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rubjs",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
4
4
  "main": "rubjs/index.js",
5
5
  "types": "rubjs/index.d.ts",
6
6
  "keywords": [
@@ -14,6 +14,7 @@ declare class VoiceChatClient {
14
14
  private isPaused;
15
15
  private lastPosition;
16
16
  private intervalId?;
17
+ private isManualSkip;
17
18
  constructor();
18
19
  play(filePath?: string): Promise<void>;
19
20
  stop(): void;
@@ -21,6 +22,7 @@ declare class VoiceChatClient {
21
22
  next(): void;
22
23
  previous(): void;
23
24
  addToPlaylist(filePath: string): void;
25
+ removeFromPlaylist(filePath: string): void;
24
26
  joinVoiceChat(chatGuid: string, voiceChatId: string, client: Client): Promise<void>;
25
27
  private clearIntervals;
26
28
  }
@@ -19,6 +19,7 @@ class VoiceChatClient {
19
19
  this.currentIndex = 0;
20
20
  this.isPaused = false;
21
21
  this.lastPosition = 0;
22
+ this.isManualSkip = false;
22
23
  this.pc = new wrtc_1.RTCPeerConnection();
23
24
  this.source = new wrtc_1.nonstandard.RTCAudioSource();
24
25
  this.track = this.source.createTrack();
@@ -37,18 +38,28 @@ class VoiceChatClient {
37
38
  throw new Error("Voice chat not initialized. Call `joinVoiceChat` first.");
38
39
  }
39
40
  this.isPaused = false;
41
+ this.isManualSkip = false;
40
42
  this.buffer = Buffer.alloc(0);
41
43
  const seekArgs = this.lastPosition > 0 ? ["-ss", this.lastPosition.toString()] : [];
42
44
  this.ffmpeg = (0, child_process_1.spawn)("ffmpeg", [
43
- "-loglevel", "quiet",
45
+ "-loglevel",
46
+ "quiet",
44
47
  "-re",
45
- "-threads", "1", // کاهش مصرف رم و پردازش
48
+ "-threads",
49
+ "1",
50
+ "-protocol_whitelist",
51
+ "file,http,https,tcp,tls",
46
52
  ...seekArgs,
47
- "-i", filePath,
48
- "-acodec", "pcm_s16le",
49
- "-ar", "48000",
50
- "-ac", "1",
51
- "-f", "s16le",
53
+ "-i",
54
+ filePath,
55
+ "-acodec",
56
+ "pcm_s16le",
57
+ "-ar",
58
+ "48000",
59
+ "-ac",
60
+ "1",
61
+ "-f",
62
+ "s16le",
52
63
  "pipe:1",
53
64
  ]);
54
65
  this.ffmpeg.stdout.on("data", (chunk) => {
@@ -64,8 +75,12 @@ class VoiceChatClient {
64
75
  this.lastPosition += 0.02;
65
76
  }
66
77
  });
67
- this.ffmpeg.on("close", () => this.next());
68
- this.ffmpeg.on("exit", () => this.next());
78
+ this.ffmpeg.on("close", (code) => {
79
+ if (!this.isManualSkip && code !== null && !this.isPaused) {
80
+ this.next();
81
+ }
82
+ this.isManualSkip = false;
83
+ });
69
84
  });
70
85
  }
71
86
  stop() {
@@ -73,7 +88,7 @@ class VoiceChatClient {
73
88
  this.ffmpeg.kill();
74
89
  this.ffmpeg = undefined;
75
90
  this.isPaused = true;
76
- this.buffer = Buffer.alloc(0); // پاک کردن بافر برای کاهش مصرف رم
91
+ this.buffer = Buffer.alloc(0);
77
92
  }
78
93
  }
79
94
  resume() {
@@ -82,21 +97,36 @@ class VoiceChatClient {
82
97
  }
83
98
  next() {
84
99
  if (this.playlist.length > this.currentIndex + 1) {
85
- this.currentIndex++;
100
+ this.isManualSkip = true;
101
+ this.stop();
102
+ this.currentIndex += 1;
86
103
  this.lastPosition = 0;
87
- this.play();
104
+ this.isPaused = true;
105
+ this.play(this.playlist[this.currentIndex]);
88
106
  }
89
107
  }
90
108
  previous() {
91
109
  if (this.currentIndex > 0) {
110
+ this.isManualSkip = true;
111
+ this.stop();
92
112
  this.currentIndex--;
93
113
  this.lastPosition = 0;
114
+ this.isPaused = true;
94
115
  this.play();
95
116
  }
96
117
  }
97
118
  addToPlaylist(filePath) {
98
119
  this.playlist.push(filePath);
99
120
  }
121
+ removeFromPlaylist(filePath) {
122
+ const index = this.playlist.indexOf(filePath);
123
+ if (index !== -1) {
124
+ this.playlist.splice(index, 1);
125
+ if (index <= this.currentIndex && this.currentIndex > 0) {
126
+ this.currentIndex--;
127
+ }
128
+ }
129
+ }
100
130
  joinVoiceChat(chatGuid, voiceChatId, client) {
101
131
  return __awaiter(this, void 0, void 0, function* () {
102
132
  this.chatGuid = chatGuid;