-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypes.ts
More file actions
107 lines (84 loc) · 2.57 KB
/
Types.ts
File metadata and controls
107 lines (84 loc) · 2.57 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* eslint-disable no-unused-vars */
export const PROTOCOL_NAME = "WEBRTSP";
export const Protocol = {
WEBRTSP_0_2: PROTOCOL_NAME + "/0.2",
} as const;
export type Protocol = typeof Protocol[keyof typeof Protocol];
const DEFAULT_PROTOCOL = Protocol.WEBRTSP_0_2;
export const Method = {
OPTIONS: "OPTIONS",
LIST: "LIST",
DESCRIBE: "DESCRIBE",
SETUP: "SETUP",
PLAY: "PLAY",
SUBSCRIBE: "SUBSCRIBE",
RECORD: "RECORD",
TEARDOWN: "TEARDOWN",
GET_PARAMETER: "GET_PARAMETER",
SET_PARAMETER: "SET_PARAMETER",
} as const;
export type Method = typeof Method[keyof typeof Method];
export const ContentType = {
TEXT_PARAMETERS: "text/parameters",
APPLICATION_SDP: "application/sdp",
APPLICATION_ICE_CANDIDATE: "application/x-ice-candidate",
} as const;
export const StatusCode = {
OK: 200,
} as const;
export const ReasonPhrase = {
OK: "OK",
} as const;
export type CSeq = number
export class HeaderFields extends Map<string, string> {}
export class Options extends Set<Method> {}
export class Parameters extends Map<string, string> {}
export class URI2Description extends Map<string, string> {} // uri -> description
export class Request {
readonly method: Method;
readonly uri: string;
readonly protocol: Protocol = DEFAULT_PROTOCOL;
readonly cseq: CSeq;
readonly session?: string;
headerFields = new HeaderFields();
body: string = "";
constructor(method: Method, uri: string, cseq: CSeq, session?: string) {
this.method = method;
this.uri = uri;
this.cseq = cseq;
if(session)
this.session = session;
}
get contentType(): string | undefined {
return this.headerFields.get("content-type");
}
set contentType(contentType: string) {
this.headerFields.set("content-type", contentType);
}
}
export class Response {
readonly protocol: Protocol = DEFAULT_PROTOCOL;
readonly statusCode: number;
readonly reasonPhrase: string;
readonly cseq: CSeq;
readonly session?: string;
headerFields = new HeaderFields();
body: string = "";
constructor(
statusCode: number,
reasonPhrase: string,
cseq: CSeq,
session: string | undefined
) {
this.statusCode = statusCode;
this.reasonPhrase = reasonPhrase;
this.cseq = cseq;
this.session = session;
}
get contentType(): string | undefined {
return this.headerFields.get("content-type");
}
set contentType(contentType: string) {
this.headerFields.set("content-type", contentType);
}
}