decord/alpha/source/modules/gateway/GatewayCompressionHandler.tsx

431 lines
12 KiB
TypeScript
Raw Permalink Normal View History

2026-10-13 12:43:34 +00:00
// Module ID: 14281
// Function ID: 14282
// Name: GatewayCompressionHandler
2026-10-13 12:43:34 +00:00
// Dependencies: [17, 14282, 14284, 3, 1382, 14283, 6911, 2]
2026-07-20 16:05:17 +00:00
// Exports: getCompressionHandler
2026-10-13 12:43:34 +00:00
// Module 14281 (GatewayCompressionHandler)
import LoggerDefault from "Logger" /* 3 */;
2026-10-03 08:58:59 +00:00
import react_native from "react-native" /* 17 */;
2026-10-09 10:00:15 +00:00
import PlatformUtils from "PlatformUtils" /* 1382 */;
2026-10-12 06:59:38 +00:00
import ProcessArgs2 from "ProcessArgs" /* 6911 */;
2026-10-13 12:43:34 +00:00
import GatewayZstdUtils from "GatewayZstdUtils" /* 14282 */;
import _mod14284 from "module_14284" /* 14284 */;
import size from "module_2" /* 2 */;
2026-07-23 10:11:24 +00:00
2026-10-03 08:58:59 +00:00
let tmp;
2026-10-13 12:43:34 +00:00
const react_native2 = tmp(14283);
2026-10-03 08:58:59 +00:00
const NativeModules = react_native.NativeModules;
2026-07-29 08:29:29 +00:00
const items = [];
class BaseGatewayCompressionHandler {
2026-10-03 08:58:59 +00:00
constructor(_gatewayEncoding) {
2026-07-29 08:29:29 +00:00
obj = Object.create(new.target.prototype);
obj._onDataReady = null;
2026-10-03 08:58:59 +00:00
obj._gatewayEncoding = _gatewayEncoding;
2026-07-29 08:29:29 +00:00
return obj;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
static canUse() {
return false;
}
bindWebSocket() {
2026-07-29 08:29:29 +00:00
2026-10-03 08:58:59 +00:00
}
feed() {
2026-07-29 08:29:29 +00:00
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
dataReady(_onDataReady) {
this._onDataReady = _onDataReady;
}
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
const prototype = BaseGatewayCompressionHandler.prototype;
class tmp2 extends BaseGatewayCompressionHandler {
constructor(arg0) {
const tmp2 = new tmp(arg0, new.target, tmp, this);
tmp2._decoder = null;
const _gatewayEncoding = tmp2._gatewayEncoding;
if (_gatewayEncoding.wantsString()) {
const _TextDecoder = TextDecoder;
const self = this;
const self2 = this;
const textDecoder = new TextDecoder("utf-8");
tmp2._decoder = textDecoder;
2026-07-29 08:29:29 +00:00
} else {
2026-10-03 08:58:59 +00:00
tmp2._decoder = null;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
obj = GatewayZstdUtils;
tmp2._stream = obj.createZstdContextWeb();
return tmp2;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
static canUse() {
return false;
}
getAlgorithm() {
return "zstd-stream";
}
usesLegacyCompression() {
return false;
}
feed(dataView) {
const self = this;
if (null == this._stream) {
const _Error2 = Error;
const self4 = this;
const self5 = this;
const error = new Error("Trying to decompress with zstd but did not initialize with it");
throw error;
} else {
const _ArrayBuffer = ArrayBuffer;
if (dataView instanceof ArrayBuffer) {
const _stream = self._stream;
const decompressResult = _stream.decompress(dataView);
let decodeResult = decompressResult;
if (null != self._decoder) {
const _decoder = self._decoder;
decodeResult = _decoder.decode(decompressResult);
}
if (null != self._onDataReady) {
self._onDataReady(decodeResult);
}
} else {
const _Error = Error;
const self2 = this;
const self3 = this;
error1 = new Error("Expected array buffer, but got " + typeof dataView);
throw error1;
}
}
}
close() {
2026-07-20 16:05:17 +00:00
2026-10-03 08:58:59 +00:00
}
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
const prototype2 = tmp2.prototype;
let error1 = tmp2;
let arr = items.push(tmp2);
class tmp4 extends BaseGatewayCompressionHandler {
constructor(arg0) {
let _inflate;
let handleFlushEnd;
const tmp2 = new tmp(arg0, new.target, tmp, this);
2026-10-13 12:43:34 +00:00
tmp2._pako = _mod14284;
2026-10-03 08:58:59 +00:00
tmp2._usesZstd = false;
tmp2._zstdDecoder = null;
tmp2._zstdStream = null;
const _gatewayEncoding = tmp2._gatewayEncoding;
const Inflate = tmp2._pako.Inflate;
let str = "";
if (_gatewayEncoding.wantsString()) {
str = "string";
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
obj = { chunkSize: 65536, to: str };
const inflate = new Inflate(obj);
tmp2._inflate = inflate;
({ handleFlushEnd, _inflate } = tmp2);
_inflate.onEnd = handleFlushEnd.bind(tmp2);
return tmp2;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
static canUse() {
return false;
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
getAlgorithm() {
return "zlib-stream";
}
usesLegacyCompression() {
return false;
}
feed(buffer) {
const self = this;
if (null == this._inflate) {
const _Error3 = Error;
const self8 = this;
const self9 = this;
const error = new Error("Trying to feed to closed compression adapter");
2026-07-29 08:29:29 +00:00
throw error;
2026-10-03 08:58:59 +00:00
} else if (null === self._onDataReady) {
const _Error2 = Error;
const self6 = this;
const self7 = this;
error1 = new Error("Cannot feed unless a data ready callback is registered.");
throw error1;
2026-07-29 08:29:29 +00:00
} else {
2026-10-03 08:58:59 +00:00
const _ArrayBuffer = ArrayBuffer;
if (buffer instanceof ArrayBuffer) {
const _DataView = DataView;
const self4 = this;
const self5 = this;
const dataView = new DataView(buffer);
const _inflate = self._inflate;
let Z_SYNC_FLUSH = dataView.byteLength >= 4 && 65535 === dataView.getUint32(dataView.byteLength - 4, false);
const push = _inflate.push;
const tmp5 = dataView.byteLength >= 4 && 65535 === dataView.getUint32(dataView.byteLength - 4, false);
if (Z_SYNC_FLUSH) {
Z_SYNC_FLUSH = self._pako.Z_SYNC_FLUSH;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
push(buffer, Z_SYNC_FLUSH);
2026-07-20 16:05:17 +00:00
} else {
2026-10-03 08:58:59 +00:00
const _Error = Error;
const self2 = this;
const self3 = this;
const error2 = new Error("Expected array buffer, but got " + typeof buffer);
throw error2;
}
}
}
close() {
const self = this;
if (null != this._inflate) {
self._inflate.onEnd = null;
self._inflate.chunks = [];
}
self._inflate = null;
}
handleFlushEnd(arg0) {
const self = this;
const _inflate = this._inflate;
if (null != _inflate) {
if (arg0 !== tmp.Z_OK) {
const _Error = Error;
const _HermesInternal = HermesInternal;
const self6 = this;
const self7 = this;
const error = new Error("zlib error, " + arg0 + ", " + _inflate.strm.msg);
throw error;
} else {
let first;
const chunks = _inflate.chunks;
const _gatewayEncoding = self._gatewayEncoding;
if (_gatewayEncoding.wantsString()) {
let joined;
if (chunks.length > 1) {
joined = chunks.join("");
} else {
joined = chunks[0];
}
first = joined;
} else if (chunks.length > 1) {
2026-07-29 08:29:29 +00:00
let num2 = 0;
let num3 = 0;
let num4 = 0;
2026-10-03 08:58:59 +00:00
if (0 < chunks.length) {
2026-07-29 08:29:29 +00:00
do {
num3 = num3 + chunks[num2].length;
num2 = num2 + 1;
num4 = num3;
2026-10-03 08:58:59 +00:00
} while (num2 < chunks.length);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const _Uint8Array = Uint8Array;
2026-10-03 08:58:59 +00:00
const self4 = this;
const self5 = this;
2026-07-29 08:29:29 +00:00
const uint8Array = new Uint8Array(num4);
let num5 = 0;
let num6 = 0;
2026-10-03 08:58:59 +00:00
first = uint8Array;
if (0 < chunks.length) {
2026-07-29 08:29:29 +00:00
do {
let arr = chunks[num5];
let result = uint8Array.set(arr, num6);
num6 = num6 + arr.length;
num5 = num5 + 1;
first = uint8Array;
2026-10-03 08:58:59 +00:00
} while (num5 < chunks.length);
2026-07-20 16:05:17 +00:00
}
} else {
2026-07-29 08:29:29 +00:00
first = chunks[0];
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
chunks.length = 0;
if (null != self._onDataReady) {
self._onDataReady(first);
2026-07-20 16:05:17 +00:00
}
}
2026-10-03 08:58:59 +00:00
} else {
const self2 = this;
const self3 = this;
obj = new LoggerDefault("GatewayCompressionHandler");
obj.error("flush end happened on closed compression adapter");
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
const prototype3 = tmp4.prototype;
let obj = tmp4;
items.push(tmp4);
class tmp6 extends BaseGatewayCompressionHandler {
constructor() {
const applyArgumentsResult = HermesBuiltin.applyArguments(this, new.target);
2026-10-13 12:43:34 +00:00
applyArgumentsResult._pako = _mod14284;
2026-10-03 08:58:59 +00:00
return applyArgumentsResult;
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
static canUse() {
return false;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
getAlgorithm() {
return null;
}
usesLegacyCompression() {
return true;
}
feed(arg0) {
const self = this;
const _pako = this._pako;
let wantsStringResult = arg0 instanceof ArrayBuffer;
if (wantsStringResult) {
const _gatewayEncoding = self._gatewayEncoding;
wantsStringResult = _gatewayEncoding.wantsString();
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
let inflateResult = arg0;
if (wantsStringResult) {
inflateResult = _pako.inflate(arg0, { to: "string" });
}
if (null == self._onDataReady) {
const _Error = Error;
const self2 = this;
const self3 = this;
const error = new Error("Cannot feed unless a data ready callback is registered.");
throw error;
} else {
self._onDataReady(inflateResult);
2026-07-20 16:05:17 +00:00
}
}
2026-10-03 08:58:59 +00:00
close() {
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
}
const prototype4 = tmp6.prototype;
items.push(tmp6);
class tmp8 extends BaseGatewayCompressionHandler {
constructor(arg0) {
const tmp2 = new tmp(arg0, new.target, tmp);
tmp2._socketId = null;
return tmp2;
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
static canUse() {
let tmp5;
obj = PlatformUtils;
2026-07-29 08:29:29 +00:00
if (obj.isAndroid()) {
2026-10-03 08:58:59 +00:00
tmp5 = null != react_native2.default;
} else {
tmp5 = null != NativeModules.DCDCompressionManager;
}
return tmp5;
}
bindWebSocket(_socketId) {
const self = this;
this.close();
this._socketId = _socketId._socketId;
obj = GatewayZstdUtils;
const supportsZstdResult = obj.supportsZstd();
const obj2 = PlatformUtils;
const isAndroidResult = obj2.isAndroid();
if (supportsZstdResult) {
if (isAndroidResult) {
const _default2 = react_native2.default;
if (_default2 != null) {
const result = _default2.enableZstdStreamSupport(self._socketId);
}
} else {
const DCDCompressionManager2 = NativeModules.DCDCompressionManager;
const result1 = DCDCompressionManager2.enableZstdStreamSupport(self._socketId, 0);
}
} else if (isAndroidResult) {
const _default = react_native2.default;
2026-07-29 08:29:29 +00:00
if (_default != null) {
2026-10-03 08:58:59 +00:00
const result2 = _default.enableZlibStreamSupport(self._socketId);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} else {
const DCDCompressionManager = NativeModules.DCDCompressionManager;
2026-10-03 08:58:59 +00:00
const result3 = DCDCompressionManager.enableZlibStreamSupport(self._socketId);
}
}
getAlgorithm() {
let str = "zlib-stream";
obj = GatewayZstdUtils;
if (obj.supportsZstd()) {
str = "zstd-stream";
}
return str;
}
usesLegacyCompression() {
return false;
}
feed(arg0) {
const self = this;
if (null == this._onDataReady) {
const _Error = Error;
const self2 = this;
const self3 = this;
const error = new Error("Cannot feed unless a data ready callback is registered.");
throw error;
} else if (null !== arg0) {
self._onDataReady(arg0);
}
}
close() {
const _socketId = this._socketId;
this._socketId = null;
if (null !== _socketId) {
obj = PlatformUtils;
const tmp = require;
if (obj.isAndroid()) {
2026-10-13 12:43:34 +00:00
const _default = tmp(14283).default;
2026-10-03 08:58:59 +00:00
if (_default != null) {
const result = _default.disableZlibStreamSupport(_socketId);
}
} else {
const DCDCompressionManager = NativeModules.DCDCompressionManager;
const result1 = DCDCompressionManager.disableZlibStreamSupport(_socketId);
}
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
}
}
2026-10-03 08:58:59 +00:00
const prototype5 = tmp8.prototype;
let c9 = tmp8;
items.push(tmp8);
class NullGatewayCompressionHandler extends BaseGatewayCompressionHandler {
static canUse() {
return true;
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
getAlgorithm() {
return null;
}
usesLegacyCompression() {
return false;
}
feed(arg0) {
const self = this;
if (null == this._onDataReady) {
const _Error = Error;
const self2 = this;
const self3 = this;
const error = new Error("Cannot feed unless a data ready callback is registered.");
throw error;
} else {
self._onDataReady(arg0);
}
}
close() {
2026-07-20 16:05:17 +00:00
2026-10-03 08:58:59 +00:00
}
}
const prototype6 = NullGatewayCompressionHandler.prototype;
2026-07-29 08:29:29 +00:00
items.push(NullGatewayCompressionHandler);
let result = size.fileFinishedImporting("modules/gateway/GatewayCompressionHandler.tsx");
2026-07-20 16:05:17 +00:00
export const getCompressionHandler = function getCompressionHandler(arg0) {
const ProcessArgs = ProcessArgs2.ProcessArgs;
2026-07-20 16:05:17 +00:00
if (ProcessArgs.isDiscordGatewayPlaintextSet()) {
2026-10-03 08:58:59 +00:00
const self4 = this;
return new NullGatewayCompressionHandler(arg0);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
for (const item10014 of items) {
if (item10014.canUse()) {
2026-10-03 08:58:59 +00:00
let self = this;
let self2 = this;
let item100141 = new item10014(arg0);
2026-07-29 08:29:29 +00:00
obj.return();
return item100141;
2026-07-20 16:05:17 +00:00
}
}
2026-10-03 08:58:59 +00:00
const self3 = this;
return new NullGatewayCompressionHandler(arg0);
2026-07-20 16:05:17 +00:00
}
};