summary refs log tree commit diff
path: root/assets/webrtc.js
blob: 40cb237a68c7b0ea6ac4e9734cd5f65884376f4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
	This file is used to patch client version 134842 ( and probably a lot more ) to send additional info when using webrtc.
	If you want to use it, throw it into the `preload-plugins` folder.
	TODO: Make it so this file is not required for webrtc.
	
	Do note that webrtc, as of 17/12/2022, is not implemented yet in fosscord/fosscord-server.
*/

(this.webpackChunkdiscord_app = this.webpackChunkdiscord_app || []).push([
	[[228974]],
	{
		632540: (module, exports, req) => {
			window.find = (filter, options = {}) => {
				const { cacheOnly = false } = options;
				for (let i in req.c) {
					if (req.c.hasOwnProperty(i)) {
						let m = req.c[i].exports;
						if (m && m.__esModule && m.default && filter(m.default)) return m.default;
						if (m && filter(m)) return m;
					}
				}
				if (cacheOnly) {
					console.warn("Cannot find loaded module in cache");
					return null;
				}
				console.warn("Cannot find loaded module in cache. Loading all modules may have unexpected side effects");
				for (let i = 0; i < req.m.length; ++i) {
					let m = req(i);
					if (m && m.__esModule && m.default && filter(m.default)) return m.default;
					if (m && filter(m)) return m;
				}
				console.warn("Cannot find module");
				return null;
			};
			window.findByUniqueProperties = (propNames, options) =>
				find((module) => propNames.every((prop) => module[prop] !== undefined), options);
			window.findByDisplayName = (displayName, options) => find((module) => module.displayName === displayName, options);
			window.req = req;

			init();
		}
	},
	(t) => t(632540)
]);

function retry(callback) {
	return new Promise((resolve) => {
		const interval = setInterval(() => {
			const mod = callback();
			if (!mod) return;

			clearInterval(interval);
			resolve(mod);
		}, 50);
	});
}

async function init() {
	const SDP = await retry(() => findByUniqueProperties(["truncateSDP"]));
	const StringManipulator = findByUniqueProperties(["uniq"]);

	const truncateSDP = SDP.truncateSDP;
	SDP.truncateSDP = (e) => {
		const result = truncateSDP(e);
		const i = result.codecs.find((x) => x.name === "VP8");
		const a = new RegExp("^a=ice|a=extmap|opus|VP8|fingerprint|" + i?.rtxPayloadType + " rtx", "i");
		return {
			sdp: StringManipulator(e)
				.split(/\r\n/)
				.filter(function (e) {
					return a.test(e);
				})
				.uniq()
				.join("\n"),
			codecs: result.codecs
		};
	};
	// SDP.generateUnifiedSessionDescription = (e) => {
	// 	console.log(e);
	// 	return new RTCSessionDescription({ sdp: e.baseSDP.replace(/sendonly/g, "recvonly"), type: "answer" });
	// };
}