@zygout/eris 0.19.0 → 0.19.2
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/LICENSE +20 -20
- package/README.md +71 -80
- package/esm.mjs +72 -72
- package/index.d.ts +4407 -4397
- package/index.js +75 -75
- package/lib/Client.js +4708 -4683
- package/lib/Constants.d.ts +990 -988
- package/lib/Constants.js +1163 -1161
- package/lib/command/Command.js +552 -552
- package/lib/command/CommandClient.js +460 -460
- package/lib/errors/DiscordHTTPError.js +63 -63
- package/lib/errors/DiscordRESTError.js +77 -77
- package/lib/gateway/Shard.js +3029 -3029
- package/lib/gateway/ShardManager.js +164 -164
- package/lib/rest/Endpoints.js +172 -172
- package/lib/rest/RequestHandler.js +459 -459
- package/lib/structures/ApplicationCommand.js +125 -125
- package/lib/structures/AutoModerationRule.js +143 -143
- package/lib/structures/AutocompleteInteraction.js +80 -80
- package/lib/structures/Base.js +81 -81
- package/lib/structures/CategoryChannel.js +77 -77
- package/lib/structures/Channel.js +98 -98
- package/lib/structures/CommandInteraction.js +473 -473
- package/lib/structures/ComponentInteraction.js +538 -538
- package/lib/structures/DMChannel.js +278 -278
- package/lib/structures/Entitlement.js +77 -77
- package/lib/structures/ExtendedUser.js +46 -46
- package/lib/structures/ForumChannel.js +24 -24
- package/lib/structures/GroupChannel.js +106 -106
- package/lib/structures/Guild.js +1677 -1677
- package/lib/structures/GuildAuditLogEntry.js +190 -190
- package/lib/structures/GuildChannel.js +128 -128
- package/lib/structures/GuildIntegration.js +99 -99
- package/lib/structures/GuildPreview.js +97 -97
- package/lib/structures/GuildScheduledEvent.js +176 -176
- package/lib/structures/GuildTemplate.js +76 -76
- package/lib/structures/GuildTextableChannel.js +260 -260
- package/lib/structures/Interaction.js +133 -133
- package/lib/structures/Invite.js +143 -143
- package/lib/structures/Lobby.js +108 -108
- package/lib/structures/LobbyMember.js +59 -59
- package/lib/structures/MediaChannel.js +216 -216
- package/lib/structures/Member.js +371 -371
- package/lib/structures/Message.js +708 -708
- package/lib/structures/ModalSubmitInteraction.js +478 -478
- package/lib/structures/NewsChannel.js +34 -34
- package/lib/structures/NewsThreadChannel.js +12 -12
- package/lib/structures/Permission.js +80 -80
- package/lib/structures/PermissionOverwrite.js +32 -32
- package/lib/structures/PingInteraction.js +39 -39
- package/lib/structures/PrivateThreadChannel.js +25 -25
- package/lib/structures/PublicThreadChannel.js +26 -26
- package/lib/structures/Role.js +163 -163
- package/lib/structures/SKU.js +80 -80
- package/lib/structures/SoundboardSound.js +79 -79
- package/lib/structures/StageChannel.js +59 -59
- package/lib/structures/StageInstance.js +55 -55
- package/lib/structures/Subscription.js +69 -69
- package/lib/structures/TextChannel.js +202 -202
- package/lib/structures/ThreadChannel.js +143 -143
- package/lib/structures/ThreadMember.js +59 -59
- package/lib/structures/UnavailableGuild.js +26 -26
- package/lib/structures/UnknownInteraction.js +502 -502
- package/lib/structures/User.js +296 -296
- package/lib/structures/VoiceChannel.js +166 -166
- package/lib/structures/VoiceState.js +84 -84
- package/lib/util/BrowserWebSocket.js +76 -76
- package/lib/util/Bucket.js +89 -89
- package/lib/util/Collection.js +202 -202
- package/lib/util/MultipartData.js +70 -70
- package/lib/util/Opus.js +33 -33
- package/lib/util/SequentialBucket.js +83 -83
- package/lib/util/emitDeprecation.js +26 -26
- package/lib/voice/Piper.js +300 -300
- package/lib/voice/SharedStream.js +238 -238
- package/lib/voice/VoiceConnection.js +1440 -1440
- package/lib/voice/VoiceConnectionManager.js +151 -151
- package/lib/voice/VoiceDataStream.js +22 -22
- package/lib/voice/streams/BaseTransformer.js +40 -40
- package/lib/voice/streams/DCAOpusTransformer.js +78 -78
- package/lib/voice/streams/FFmpegDuplex.js +192 -192
- package/lib/voice/streams/FFmpegOggTransformer.js +35 -35
- package/lib/voice/streams/FFmpegPCMTransformer.js +26 -26
- package/lib/voice/streams/OggOpusTransformer.js +108 -108
- package/lib/voice/streams/PCMOpusTransformer.js +61 -61
- package/lib/voice/streams/VolumeTransformer.js +50 -50
- package/lib/voice/streams/WebmOpusTransformer.js +258 -258
- package/package.json +83 -82
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const Base = require("../structures/Base");
|
|
4
|
-
const Collection = require("../util/Collection");
|
|
5
|
-
|
|
6
|
-
class VoiceConnectionManager extends Collection {
|
|
7
|
-
constructor(vcObject) {
|
|
8
|
-
super(vcObject || require("./VoiceConnection"));
|
|
9
|
-
this.pendingGuilds = {};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
join(guildID, channelID, options) {
|
|
13
|
-
const connection = this.get(guildID);
|
|
14
|
-
if (connection && connection.ws) {
|
|
15
|
-
connection.switchChannel(channelID);
|
|
16
|
-
if (connection.ready) {
|
|
17
|
-
return Promise.resolve(connection);
|
|
18
|
-
} else {
|
|
19
|
-
return new Promise((res, rej) => {
|
|
20
|
-
const disconnectHandler = (err) => {
|
|
21
|
-
connection.removeListener("ready", readyHandler);
|
|
22
|
-
connection.removeListener("error", errorHandler);
|
|
23
|
-
rej(err || new Error("Disconnected"));
|
|
24
|
-
};
|
|
25
|
-
const readyHandler = () => {
|
|
26
|
-
connection.removeListener("disconnect", disconnectHandler);
|
|
27
|
-
connection.removeListener("error", errorHandler);
|
|
28
|
-
res(connection);
|
|
29
|
-
};
|
|
30
|
-
const errorHandler = (err) => {
|
|
31
|
-
connection.removeListener("disconnect", disconnectHandler);
|
|
32
|
-
connection.removeListener("ready", readyHandler);
|
|
33
|
-
connection.disconnect();
|
|
34
|
-
rej(err);
|
|
35
|
-
};
|
|
36
|
-
connection.once("ready", readyHandler).once("disconnect", disconnectHandler).once("error", errorHandler);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return new Promise((res, rej) => {
|
|
41
|
-
this.pendingGuilds[guildID] = {
|
|
42
|
-
channelID: channelID,
|
|
43
|
-
options: options || {},
|
|
44
|
-
res: res,
|
|
45
|
-
rej: rej,
|
|
46
|
-
timeout: setTimeout(() => {
|
|
47
|
-
delete this.pendingGuilds[guildID];
|
|
48
|
-
rej(new Error("Voice connection timeout"));
|
|
49
|
-
}, 10000),
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
leave(guildID) {
|
|
55
|
-
const connection = this.get(guildID);
|
|
56
|
-
if (!connection) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
connection.disconnect();
|
|
60
|
-
connection._destroy();
|
|
61
|
-
this.remove(connection);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
switch(guildID, channelID) {
|
|
65
|
-
const connection = this.get(guildID);
|
|
66
|
-
if (!connection) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
connection.switchChannel(channelID);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
voiceServerUpdate(data) {
|
|
73
|
-
if (this.pendingGuilds[data.guild_id] && this.pendingGuilds[data.guild_id].timeout) {
|
|
74
|
-
clearTimeout(this.pendingGuilds[data.guild_id].timeout);
|
|
75
|
-
this.pendingGuilds[data.guild_id].timeout = null;
|
|
76
|
-
}
|
|
77
|
-
let connection = this.get(data.guild_id);
|
|
78
|
-
if (!connection) {
|
|
79
|
-
if (!this.pendingGuilds[data.guild_id]) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const options = this.pendingGuilds[data.guild_id].options;
|
|
83
|
-
connection = this.add(new this.baseObject(data.guild_id, {
|
|
84
|
-
daveEncryption: options.daveEncryption,
|
|
85
|
-
decryptionFailureTolerance: options.decryptionFailureTolerance,
|
|
86
|
-
shard: data.shard,
|
|
87
|
-
opusOnly: options.opusOnly,
|
|
88
|
-
shared: options.shared,
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
connection.connect({
|
|
92
|
-
channel_id: (this.pendingGuilds[data.guild_id] || connection).channelID,
|
|
93
|
-
endpoint: data.endpoint,
|
|
94
|
-
token: data.token,
|
|
95
|
-
session_id: data.session_id,
|
|
96
|
-
user_id: data.user_id,
|
|
97
|
-
});
|
|
98
|
-
if (!this.pendingGuilds[data.guild_id] || this.pendingGuilds[data.guild_id].waiting) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
this.pendingGuilds[data.guild_id].waiting = true;
|
|
102
|
-
const disconnectHandler = (err) => {
|
|
103
|
-
connection = this.get(data.guild_id);
|
|
104
|
-
if (connection) {
|
|
105
|
-
connection.removeListener("ready", readyHandler);
|
|
106
|
-
connection.removeListener("error", errorHandler);
|
|
107
|
-
}
|
|
108
|
-
if (this.pendingGuilds[data.guild_id]) {
|
|
109
|
-
this.pendingGuilds[data.guild_id].rej(err || new Error("Disconnected"));
|
|
110
|
-
delete this.pendingGuilds[data.guild_id];
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const readyHandler = () => {
|
|
114
|
-
connection = this.get(data.guild_id);
|
|
115
|
-
if (connection) {
|
|
116
|
-
connection.removeListener("disconnect", disconnectHandler);
|
|
117
|
-
connection.removeListener("error", errorHandler);
|
|
118
|
-
}
|
|
119
|
-
if (this.pendingGuilds[data.guild_id]) {
|
|
120
|
-
this.pendingGuilds[data.guild_id].res(connection);
|
|
121
|
-
delete this.pendingGuilds[data.guild_id];
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const errorHandler = (err) => {
|
|
125
|
-
connection = this.get(data.guild_id);
|
|
126
|
-
if (connection) {
|
|
127
|
-
connection.removeListener("disconnect", disconnectHandler);
|
|
128
|
-
connection.removeListener("ready", readyHandler);
|
|
129
|
-
connection.disconnect();
|
|
130
|
-
}
|
|
131
|
-
if (this.pendingGuilds[data.guild_id]) {
|
|
132
|
-
this.pendingGuilds[data.guild_id].rej(err);
|
|
133
|
-
delete this.pendingGuilds[data.guild_id];
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
connection.once("ready", readyHandler).once("disconnect", disconnectHandler).once("error", errorHandler);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
toString() {
|
|
140
|
-
return "[VoiceConnectionManager]";
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
toJSON(props = []) {
|
|
144
|
-
return Base.prototype.toJSON.call(this, [
|
|
145
|
-
"pendingGuilds",
|
|
146
|
-
...props,
|
|
147
|
-
]);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
module.exports = VoiceConnectionManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Base = require("../structures/Base");
|
|
4
|
+
const Collection = require("../util/Collection");
|
|
5
|
+
|
|
6
|
+
class VoiceConnectionManager extends Collection {
|
|
7
|
+
constructor(vcObject) {
|
|
8
|
+
super(vcObject || require("./VoiceConnection"));
|
|
9
|
+
this.pendingGuilds = {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
join(guildID, channelID, options) {
|
|
13
|
+
const connection = this.get(guildID);
|
|
14
|
+
if (connection && connection.ws) {
|
|
15
|
+
connection.switchChannel(channelID);
|
|
16
|
+
if (connection.ready) {
|
|
17
|
+
return Promise.resolve(connection);
|
|
18
|
+
} else {
|
|
19
|
+
return new Promise((res, rej) => {
|
|
20
|
+
const disconnectHandler = (err) => {
|
|
21
|
+
connection.removeListener("ready", readyHandler);
|
|
22
|
+
connection.removeListener("error", errorHandler);
|
|
23
|
+
rej(err || new Error("Disconnected"));
|
|
24
|
+
};
|
|
25
|
+
const readyHandler = () => {
|
|
26
|
+
connection.removeListener("disconnect", disconnectHandler);
|
|
27
|
+
connection.removeListener("error", errorHandler);
|
|
28
|
+
res(connection);
|
|
29
|
+
};
|
|
30
|
+
const errorHandler = (err) => {
|
|
31
|
+
connection.removeListener("disconnect", disconnectHandler);
|
|
32
|
+
connection.removeListener("ready", readyHandler);
|
|
33
|
+
connection.disconnect();
|
|
34
|
+
rej(err);
|
|
35
|
+
};
|
|
36
|
+
connection.once("ready", readyHandler).once("disconnect", disconnectHandler).once("error", errorHandler);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return new Promise((res, rej) => {
|
|
41
|
+
this.pendingGuilds[guildID] = {
|
|
42
|
+
channelID: channelID,
|
|
43
|
+
options: options || {},
|
|
44
|
+
res: res,
|
|
45
|
+
rej: rej,
|
|
46
|
+
timeout: setTimeout(() => {
|
|
47
|
+
delete this.pendingGuilds[guildID];
|
|
48
|
+
rej(new Error("Voice connection timeout"));
|
|
49
|
+
}, 10000),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
leave(guildID) {
|
|
55
|
+
const connection = this.get(guildID);
|
|
56
|
+
if (!connection) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
connection.disconnect();
|
|
60
|
+
connection._destroy();
|
|
61
|
+
this.remove(connection);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
switch(guildID, channelID) {
|
|
65
|
+
const connection = this.get(guildID);
|
|
66
|
+
if (!connection) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
connection.switchChannel(channelID);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
voiceServerUpdate(data) {
|
|
73
|
+
if (this.pendingGuilds[data.guild_id] && this.pendingGuilds[data.guild_id].timeout) {
|
|
74
|
+
clearTimeout(this.pendingGuilds[data.guild_id].timeout);
|
|
75
|
+
this.pendingGuilds[data.guild_id].timeout = null;
|
|
76
|
+
}
|
|
77
|
+
let connection = this.get(data.guild_id);
|
|
78
|
+
if (!connection) {
|
|
79
|
+
if (!this.pendingGuilds[data.guild_id]) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const options = this.pendingGuilds[data.guild_id].options;
|
|
83
|
+
connection = this.add(new this.baseObject(data.guild_id, {
|
|
84
|
+
daveEncryption: options.daveEncryption,
|
|
85
|
+
decryptionFailureTolerance: options.decryptionFailureTolerance,
|
|
86
|
+
shard: data.shard,
|
|
87
|
+
opusOnly: options.opusOnly,
|
|
88
|
+
shared: options.shared,
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
connection.connect({
|
|
92
|
+
channel_id: (this.pendingGuilds[data.guild_id] || connection).channelID,
|
|
93
|
+
endpoint: data.endpoint,
|
|
94
|
+
token: data.token,
|
|
95
|
+
session_id: data.session_id,
|
|
96
|
+
user_id: data.user_id,
|
|
97
|
+
});
|
|
98
|
+
if (!this.pendingGuilds[data.guild_id] || this.pendingGuilds[data.guild_id].waiting) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.pendingGuilds[data.guild_id].waiting = true;
|
|
102
|
+
const disconnectHandler = (err) => {
|
|
103
|
+
connection = this.get(data.guild_id);
|
|
104
|
+
if (connection) {
|
|
105
|
+
connection.removeListener("ready", readyHandler);
|
|
106
|
+
connection.removeListener("error", errorHandler);
|
|
107
|
+
}
|
|
108
|
+
if (this.pendingGuilds[data.guild_id]) {
|
|
109
|
+
this.pendingGuilds[data.guild_id].rej(err || new Error("Disconnected"));
|
|
110
|
+
delete this.pendingGuilds[data.guild_id];
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const readyHandler = () => {
|
|
114
|
+
connection = this.get(data.guild_id);
|
|
115
|
+
if (connection) {
|
|
116
|
+
connection.removeListener("disconnect", disconnectHandler);
|
|
117
|
+
connection.removeListener("error", errorHandler);
|
|
118
|
+
}
|
|
119
|
+
if (this.pendingGuilds[data.guild_id]) {
|
|
120
|
+
this.pendingGuilds[data.guild_id].res(connection);
|
|
121
|
+
delete this.pendingGuilds[data.guild_id];
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const errorHandler = (err) => {
|
|
125
|
+
connection = this.get(data.guild_id);
|
|
126
|
+
if (connection) {
|
|
127
|
+
connection.removeListener("disconnect", disconnectHandler);
|
|
128
|
+
connection.removeListener("ready", readyHandler);
|
|
129
|
+
connection.disconnect();
|
|
130
|
+
}
|
|
131
|
+
if (this.pendingGuilds[data.guild_id]) {
|
|
132
|
+
this.pendingGuilds[data.guild_id].rej(err);
|
|
133
|
+
delete this.pendingGuilds[data.guild_id];
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
connection.once("ready", readyHandler).once("disconnect", disconnectHandler).once("error", errorHandler);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
toString() {
|
|
140
|
+
return "[VoiceConnectionManager]";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
toJSON(props = []) {
|
|
144
|
+
return Base.prototype.toJSON.call(this, [
|
|
145
|
+
"pendingGuilds",
|
|
146
|
+
...props,
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
module.exports = VoiceConnectionManager;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
let EventEmitter;
|
|
4
|
-
try {
|
|
5
|
-
EventEmitter = require("eventemitter3");
|
|
6
|
-
} catch {
|
|
7
|
-
EventEmitter = require("events").EventEmitter;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents a voice data stream
|
|
12
|
-
* @extends EventEmitter
|
|
13
|
-
* @prop {String} type The targeted voice data type for the stream, either "opus" or "pcm"
|
|
14
|
-
*/
|
|
15
|
-
class VoiceDataStream extends EventEmitter {
|
|
16
|
-
constructor(type) {
|
|
17
|
-
super();
|
|
18
|
-
this.type = type;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = VoiceDataStream;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
let EventEmitter;
|
|
4
|
+
try {
|
|
5
|
+
EventEmitter = require("eventemitter3");
|
|
6
|
+
} catch {
|
|
7
|
+
EventEmitter = require("events").EventEmitter;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents a voice data stream
|
|
12
|
+
* @extends EventEmitter
|
|
13
|
+
* @prop {String} type The targeted voice data type for the stream, either "opus" or "pcm"
|
|
14
|
+
*/
|
|
15
|
+
class VoiceDataStream extends EventEmitter {
|
|
16
|
+
constructor(type) {
|
|
17
|
+
super();
|
|
18
|
+
this.type = type;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = VoiceDataStream;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const util = require("util");
|
|
4
|
-
const Base = require("../../structures/Base");
|
|
5
|
-
const TransformStream = require("stream").Transform;
|
|
6
|
-
|
|
7
|
-
class BaseTransformer extends TransformStream {
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
if (options.allowHalfOpen === undefined) {
|
|
10
|
-
options.allowHalfOpen = true;
|
|
11
|
-
}
|
|
12
|
-
if (options.highWaterMark === undefined) {
|
|
13
|
-
options.highWaterMark = 0;
|
|
14
|
-
}
|
|
15
|
-
super(options);
|
|
16
|
-
this.manualCB = false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setTransformCB(cb) {
|
|
20
|
-
if (this.manualCB) {
|
|
21
|
-
this.transformCB();
|
|
22
|
-
this._transformCB = cb;
|
|
23
|
-
} else {
|
|
24
|
-
cb();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
transformCB() {
|
|
29
|
-
if (this._transformCB) {
|
|
30
|
-
this._transformCB();
|
|
31
|
-
this._transformCB = null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
[util.inspect.custom]() {
|
|
36
|
-
return Base.prototype[util.inspect.custom].call(this);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = BaseTransformer;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const util = require("util");
|
|
4
|
+
const Base = require("../../structures/Base");
|
|
5
|
+
const TransformStream = require("stream").Transform;
|
|
6
|
+
|
|
7
|
+
class BaseTransformer extends TransformStream {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
if (options.allowHalfOpen === undefined) {
|
|
10
|
+
options.allowHalfOpen = true;
|
|
11
|
+
}
|
|
12
|
+
if (options.highWaterMark === undefined) {
|
|
13
|
+
options.highWaterMark = 0;
|
|
14
|
+
}
|
|
15
|
+
super(options);
|
|
16
|
+
this.manualCB = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setTransformCB(cb) {
|
|
20
|
+
if (this.manualCB) {
|
|
21
|
+
this.transformCB();
|
|
22
|
+
this._transformCB = cb;
|
|
23
|
+
} else {
|
|
24
|
+
cb();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
transformCB() {
|
|
29
|
+
if (this._transformCB) {
|
|
30
|
+
this._transformCB();
|
|
31
|
+
this._transformCB = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
[util.inspect.custom]() {
|
|
36
|
+
return Base.prototype[util.inspect.custom].call(this);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = BaseTransformer;
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const BaseTransformer = require("./BaseTransformer");
|
|
4
|
-
|
|
5
|
-
class DCAOpusTransformer extends BaseTransformer {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
super(options);
|
|
8
|
-
|
|
9
|
-
this._remainder = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
process(buffer) {
|
|
13
|
-
if (buffer.length - buffer._index < 2) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const opusLen = buffer.readInt16LE(buffer._index);
|
|
18
|
-
buffer._index += 2;
|
|
19
|
-
|
|
20
|
-
if (buffer.length - buffer._index < opusLen) {
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
buffer._index += opusLen;
|
|
25
|
-
this.push(buffer.subarray(buffer._index - opusLen, buffer._index));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_transform(chunk, enc, cb) {
|
|
29
|
-
if (this._remainder) {
|
|
30
|
-
chunk = Buffer.concat([this._remainder, chunk]);
|
|
31
|
-
this._remainder = null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!this.head) {
|
|
35
|
-
if (chunk.length < 4) {
|
|
36
|
-
this._remainder = chunk;
|
|
37
|
-
return cb();
|
|
38
|
-
} else {
|
|
39
|
-
const dcaVersion = chunk.subarray(0, 4);
|
|
40
|
-
if (dcaVersion[0] !== 68 || dcaVersion[1] !== 67 || dcaVersion[2] !== 65) { // DCA0 or invalid
|
|
41
|
-
this.head = true; // Attempt to play as if it were a DCA0 file
|
|
42
|
-
} else if (dcaVersion[3] === 49) { // DCA1
|
|
43
|
-
if (chunk.length < 8) {
|
|
44
|
-
this._remainder = chunk;
|
|
45
|
-
return cb();
|
|
46
|
-
}
|
|
47
|
-
const jsonLength = chunk.subarray(4, 8).readInt32LE(0);
|
|
48
|
-
if (chunk.length < 8 + jsonLength) {
|
|
49
|
-
this._remainder = chunk;
|
|
50
|
-
return cb();
|
|
51
|
-
}
|
|
52
|
-
const jsonMetadata = chunk.subarray(8, 8 + jsonLength);
|
|
53
|
-
this.emit("debug", jsonMetadata);
|
|
54
|
-
chunk = chunk.subarray(8 + jsonLength);
|
|
55
|
-
this.head = true;
|
|
56
|
-
} else {
|
|
57
|
-
this.emit("error", new Error("Unsupported DCA version: " + dcaVersion.toString()));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
chunk._index = 0;
|
|
63
|
-
|
|
64
|
-
while (chunk._index < chunk.length) {
|
|
65
|
-
const offset = chunk._index;
|
|
66
|
-
const ret = this.process(chunk);
|
|
67
|
-
if (ret) {
|
|
68
|
-
this._remainder = chunk.subarray(offset);
|
|
69
|
-
cb();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.setTransformCB(cb);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
module.exports = DCAOpusTransformer;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const BaseTransformer = require("./BaseTransformer");
|
|
4
|
+
|
|
5
|
+
class DCAOpusTransformer extends BaseTransformer {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
super(options);
|
|
8
|
+
|
|
9
|
+
this._remainder = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
process(buffer) {
|
|
13
|
+
if (buffer.length - buffer._index < 2) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const opusLen = buffer.readInt16LE(buffer._index);
|
|
18
|
+
buffer._index += 2;
|
|
19
|
+
|
|
20
|
+
if (buffer.length - buffer._index < opusLen) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
buffer._index += opusLen;
|
|
25
|
+
this.push(buffer.subarray(buffer._index - opusLen, buffer._index));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_transform(chunk, enc, cb) {
|
|
29
|
+
if (this._remainder) {
|
|
30
|
+
chunk = Buffer.concat([this._remainder, chunk]);
|
|
31
|
+
this._remainder = null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!this.head) {
|
|
35
|
+
if (chunk.length < 4) {
|
|
36
|
+
this._remainder = chunk;
|
|
37
|
+
return cb();
|
|
38
|
+
} else {
|
|
39
|
+
const dcaVersion = chunk.subarray(0, 4);
|
|
40
|
+
if (dcaVersion[0] !== 68 || dcaVersion[1] !== 67 || dcaVersion[2] !== 65) { // DCA0 or invalid
|
|
41
|
+
this.head = true; // Attempt to play as if it were a DCA0 file
|
|
42
|
+
} else if (dcaVersion[3] === 49) { // DCA1
|
|
43
|
+
if (chunk.length < 8) {
|
|
44
|
+
this._remainder = chunk;
|
|
45
|
+
return cb();
|
|
46
|
+
}
|
|
47
|
+
const jsonLength = chunk.subarray(4, 8).readInt32LE(0);
|
|
48
|
+
if (chunk.length < 8 + jsonLength) {
|
|
49
|
+
this._remainder = chunk;
|
|
50
|
+
return cb();
|
|
51
|
+
}
|
|
52
|
+
const jsonMetadata = chunk.subarray(8, 8 + jsonLength);
|
|
53
|
+
this.emit("debug", jsonMetadata);
|
|
54
|
+
chunk = chunk.subarray(8 + jsonLength);
|
|
55
|
+
this.head = true;
|
|
56
|
+
} else {
|
|
57
|
+
this.emit("error", new Error("Unsupported DCA version: " + dcaVersion.toString()));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
chunk._index = 0;
|
|
63
|
+
|
|
64
|
+
while (chunk._index < chunk.length) {
|
|
65
|
+
const offset = chunk._index;
|
|
66
|
+
const ret = this.process(chunk);
|
|
67
|
+
if (ret) {
|
|
68
|
+
this._remainder = chunk.subarray(offset);
|
|
69
|
+
cb();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.setTransformCB(cb);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = DCAOpusTransformer;
|