-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrtcpfb-line.ts
More file actions
71 lines (63 loc) · 2.03 KB
/
rtcpfb-line.ts
File metadata and controls
71 lines (63 loc) · 2.03 KB
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
/*
* Copyright 2022 Cisco
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NUM, REST } from '../regex-helpers';
import { Line } from './line';
import { PayloadTypeRef } from './payload-type-ref';
/**
* Implementation of an rtcp-fb attribute as defined by https://datatracker.ietf.org/doc/html/rfc4585#section-4.2.
*
* @example
* a=rtcp-fb:96 goog-remb
*/
export class RtcpFbLine extends Line {
payloadType: PayloadTypeRef;
feedback: string;
private static regex = new RegExp(`^rtcp-fb:(${NUM}|\\*) (${REST})`);
/**
* Create an RtcpFbLine from the given values.
*
* @param payloadType - The payload type.
* @param feedback - The feedback name.
*/
constructor(payloadType: PayloadTypeRef, feedback: string) {
super();
this.payloadType = payloadType;
this.feedback = feedback;
}
/**
* Create an RtcpFbLine from the given string.
*
* @param line - The line to parse.
* @returns An RtcpFbLine instance or undefined if parsing failed.
*/
static fromSdpLine(line: string): RtcpFbLine | undefined {
if (!RtcpFbLine.regex.test(line)) {
return undefined;
}
const tokens = line.match(RtcpFbLine.regex) as RegExpMatchArray;
const ptToken = tokens[1];
const payloadType =
ptToken === '*' ? new PayloadTypeRef('*') : new PayloadTypeRef(parseInt(ptToken, 10));
const feedback = tokens[2];
return new RtcpFbLine(payloadType, feedback);
}
/**
* @inheritdoc
*/
toSdpLine(): string {
return `a=rtcp-fb:${this.payloadType} ${this.feedback}`;
}
}