@4players/odin-common 2.17.2 → 2.17.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/lib/cjs/utility/codec.js +14 -11
- package/lib/esm/utility/codec.js +14 -11
- package/lib/utility/codec.d.ts +5 -5
- package/package.json +2 -2
package/lib/cjs/utility/codec.js
CHANGED
|
@@ -10,17 +10,17 @@ class VideoCodec {
|
|
|
10
10
|
this.channels = 0;
|
|
11
11
|
this.clockRate = 90000;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
isValid() {
|
|
14
14
|
return validCodecs.includes(this.codec);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
isSupported() {
|
|
17
17
|
var _a, _b, _c;
|
|
18
18
|
if (typeof RTCRtpReceiver === 'undefined' ||
|
|
19
19
|
typeof RTCRtpReceiver.getCapabilities === 'undefined') {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
22
|
-
const expectedMimeType = (0, result_1.unwrapOr)(this.
|
|
23
|
-
const expectedFmtpLine = new Set((0, result_1.unwrapOr)(this.
|
|
22
|
+
const expectedMimeType = (0, result_1.unwrapOr)(this.getMimeType(), '').toLowerCase();
|
|
23
|
+
const expectedFmtpLine = new Set((0, result_1.unwrapOr)(this.getSdpFmtpLine(), '')
|
|
24
24
|
.split(';')
|
|
25
25
|
.map((arg) => arg.trim().toLowerCase()));
|
|
26
26
|
return ((_c = (_b = (_a = RTCRtpReceiver.getCapabilities('video')) === null || _a === void 0 ? void 0 : _a.codecs) === null || _b === void 0 ? void 0 : _b.some((c) => {
|
|
@@ -42,20 +42,23 @@ class VideoCodec {
|
|
|
42
42
|
})) !== null && _c !== void 0 ? _c : false);
|
|
43
43
|
}
|
|
44
44
|
filterSdp(description) {
|
|
45
|
-
if (!this.
|
|
45
|
+
if (!this.isValid()) {
|
|
46
46
|
return description;
|
|
47
47
|
}
|
|
48
48
|
const sdp = (0, sdp_transform_1.parse)(description);
|
|
49
|
-
const payload = (0, result_1.unwrap)(this.
|
|
50
|
-
const config = (0, result_1.unwrap)(this.
|
|
49
|
+
const payload = (0, result_1.unwrap)(this.getPayloadType());
|
|
50
|
+
const config = (0, result_1.unwrap)(this.getSdpFmtpLine());
|
|
51
51
|
sdp.media = sdp.media.map((media) => {
|
|
52
|
+
if (media.type !== 'video') {
|
|
53
|
+
return media;
|
|
54
|
+
}
|
|
52
55
|
media.payloads = '';
|
|
53
56
|
media.rtp = [];
|
|
54
57
|
media.fmtp = [];
|
|
55
58
|
media.rtcpFb = [];
|
|
56
59
|
media.payloads = String(payload);
|
|
57
60
|
media.rtp.push({ payload, codec: this.codec, rate: this.clockRate });
|
|
58
|
-
if (
|
|
61
|
+
if (config.length) {
|
|
59
62
|
media.fmtp.push({ payload, config });
|
|
60
63
|
}
|
|
61
64
|
media.rtcpFb.push({ payload, type: 'goog-remb' });
|
|
@@ -67,7 +70,7 @@ class VideoCodec {
|
|
|
67
70
|
});
|
|
68
71
|
return (0, sdp_transform_1.write)(sdp);
|
|
69
72
|
}
|
|
70
|
-
|
|
73
|
+
getPayloadType() {
|
|
71
74
|
switch (this.codec) {
|
|
72
75
|
case 'VP8':
|
|
73
76
|
return (0, result_1.success)(96);
|
|
@@ -81,7 +84,7 @@ class VideoCodec {
|
|
|
81
84
|
return (0, result_1.failure)('invalid video codec');
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
|
-
|
|
87
|
+
getMimeType() {
|
|
85
88
|
switch (this.codec) {
|
|
86
89
|
case 'VP8':
|
|
87
90
|
return (0, result_1.success)('video/VP8');
|
|
@@ -95,7 +98,7 @@ class VideoCodec {
|
|
|
95
98
|
return (0, result_1.failure)('invalid video codec');
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
|
-
|
|
101
|
+
getSdpFmtpLine() {
|
|
99
102
|
switch (this.codec) {
|
|
100
103
|
case 'VP8':
|
|
101
104
|
return (0, result_1.success)('');
|
package/lib/esm/utility/codec.js
CHANGED
|
@@ -7,17 +7,17 @@ export class VideoCodec {
|
|
|
7
7
|
this.channels = 0;
|
|
8
8
|
this.clockRate = 90000;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
isValid() {
|
|
11
11
|
return validCodecs.includes(this.codec);
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
isSupported() {
|
|
14
14
|
var _a, _b, _c;
|
|
15
15
|
if (typeof RTCRtpReceiver === 'undefined' ||
|
|
16
16
|
typeof RTCRtpReceiver.getCapabilities === 'undefined') {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
-
const expectedMimeType = unwrapOr(this.
|
|
20
|
-
const expectedFmtpLine = new Set(unwrapOr(this.
|
|
19
|
+
const expectedMimeType = unwrapOr(this.getMimeType(), '').toLowerCase();
|
|
20
|
+
const expectedFmtpLine = new Set(unwrapOr(this.getSdpFmtpLine(), '')
|
|
21
21
|
.split(';')
|
|
22
22
|
.map((arg) => arg.trim().toLowerCase()));
|
|
23
23
|
return ((_c = (_b = (_a = RTCRtpReceiver.getCapabilities('video')) === null || _a === void 0 ? void 0 : _a.codecs) === null || _b === void 0 ? void 0 : _b.some((c) => {
|
|
@@ -39,20 +39,23 @@ export class VideoCodec {
|
|
|
39
39
|
})) !== null && _c !== void 0 ? _c : false);
|
|
40
40
|
}
|
|
41
41
|
filterSdp(description) {
|
|
42
|
-
if (!this.
|
|
42
|
+
if (!this.isValid()) {
|
|
43
43
|
return description;
|
|
44
44
|
}
|
|
45
45
|
const sdp = parse(description);
|
|
46
|
-
const payload = unwrap(this.
|
|
47
|
-
const config = unwrap(this.
|
|
46
|
+
const payload = unwrap(this.getPayloadType());
|
|
47
|
+
const config = unwrap(this.getSdpFmtpLine());
|
|
48
48
|
sdp.media = sdp.media.map((media) => {
|
|
49
|
+
if (media.type !== 'video') {
|
|
50
|
+
return media;
|
|
51
|
+
}
|
|
49
52
|
media.payloads = '';
|
|
50
53
|
media.rtp = [];
|
|
51
54
|
media.fmtp = [];
|
|
52
55
|
media.rtcpFb = [];
|
|
53
56
|
media.payloads = String(payload);
|
|
54
57
|
media.rtp.push({ payload, codec: this.codec, rate: this.clockRate });
|
|
55
|
-
if (
|
|
58
|
+
if (config.length) {
|
|
56
59
|
media.fmtp.push({ payload, config });
|
|
57
60
|
}
|
|
58
61
|
media.rtcpFb.push({ payload, type: 'goog-remb' });
|
|
@@ -64,7 +67,7 @@ export class VideoCodec {
|
|
|
64
67
|
});
|
|
65
68
|
return write(sdp);
|
|
66
69
|
}
|
|
67
|
-
|
|
70
|
+
getPayloadType() {
|
|
68
71
|
switch (this.codec) {
|
|
69
72
|
case 'VP8':
|
|
70
73
|
return success(96);
|
|
@@ -78,7 +81,7 @@ export class VideoCodec {
|
|
|
78
81
|
return failure('invalid video codec');
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
|
-
|
|
84
|
+
getMimeType() {
|
|
82
85
|
switch (this.codec) {
|
|
83
86
|
case 'VP8':
|
|
84
87
|
return success('video/VP8');
|
|
@@ -92,7 +95,7 @@ export class VideoCodec {
|
|
|
92
95
|
return failure('invalid video codec');
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
|
|
98
|
+
getSdpFmtpLine() {
|
|
96
99
|
switch (this.codec) {
|
|
97
100
|
case 'VP8':
|
|
98
101
|
return success('');
|
package/lib/utility/codec.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ export declare class VideoCodec {
|
|
|
6
6
|
readonly channels = 0;
|
|
7
7
|
readonly clockRate = 90000;
|
|
8
8
|
constructor(codec: Codec);
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
isValid(): boolean;
|
|
10
|
+
isSupported(): boolean;
|
|
11
11
|
filterSdp(description: string): string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
getPayloadType(): Result<number>;
|
|
13
|
+
getMimeType(): Result<string>;
|
|
14
|
+
getSdpFmtpLine(): Result<string>;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4players/odin-common",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.4",
|
|
4
4
|
"description": "A collection of commonly used type definitions and utility functions across ODIN web projects",
|
|
5
5
|
"author": "Josho Bleicker <josho.bleicker@4players.io> (https://www.4players.io)",
|
|
6
6
|
"homepage": "https://www.4players.io",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test": "testyts"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@msgpack/msgpack": "
|
|
28
|
+
"@msgpack/msgpack": "3.0.0-beta2",
|
|
29
29
|
"sdp-transform": "~2.15.0",
|
|
30
30
|
"uuid": "~11.0.0",
|
|
31
31
|
"zod": "~3.24.0"
|