-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathurl-generator.ts
More file actions
111 lines (97 loc) · 3.48 KB
/
url-generator.ts
File metadata and controls
111 lines (97 loc) · 3.48 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
108
109
110
111
import config from '../config';
// Extract hostname from API endpoint
const getServerHostname = (): string => {
try {
const url = new URL(config.apiEndpoint);
return url.hostname;
} catch {
// Fallback if API endpoint is not a valid URL
return 'localhost';
}
};
// Check if we're accessing via FQDN (through nginx proxy)
const isAccessingViaFqdn = (): boolean => {
const hostname = window.location.hostname;
// If hostname is an IP address or localhost, we're accessing directly
return !(
hostname === 'localhost' ||
hostname === '127.0.0.1' ||
/^(\d{1,3}\.){3}\d{1,3}$/.test(hostname)
);
};
// Check if a port is configured (not empty and not a placeholder)
const isPortConfigured = (port: string): boolean => {
return !!(port && port !== '' && !port.includes('{{'));
};
// Generate SRT Player URL
export const generatePlayerUrl = (playerId: string): string => {
const hostname = getServerHostname();
const port = config.srtPlayerPort;
return `srt://${hostname}:${port}?streamid=${playerId}`;
};
// Generate SRT Publisher URL
export const generatePublisherUrl = (publisherId: string): string => {
const hostname = getServerHostname();
const port = config.srtSenderPort;
return `srt://${hostname}:${port}?streamid=${publisherId}`;
};
// Generate SRTLA Publisher URL
export const generateSrtlaPublisherUrl = (publisherId: string): string => {
const hostname = getServerHostname();
const port = config.srtlaPort;
return `srtla://${hostname}:${port}?streamid=${publisherId}`;
};
// Generate Stats URL
export const generateStatsUrl = (playerId: string): string => {
const hostname = getServerHostname();
// If accessing via FQDN (nginx proxy), use the standard HTTP port without explicit port number
if (isAccessingViaFqdn()) {
const protocol = window.location.protocol; // Use same protocol as current page
return `${protocol}//${hostname}/stats/${playerId}?legacy=1`;
}
// For direct IP access, include the port
const port = config.slsStatsPort;
return `http://${hostname}:${port}/stats/${playerId}?legacy=1`;
};
// URL information for display
export interface UrlInfo {
label: string;
url: string;
description: string;
icon: string;
}
// Get all URLs for a stream
export const getStreamUrls = (streamId: { publisher: string; player: string }): UrlInfo[] => {
const urls: UrlInfo[] = [
{
label: 'SRT Publisher',
url: generatePublisherUrl(streamId.publisher),
description: 'Use this URL to publish your stream via SRT',
icon: 'bi-broadcast'
}
];
// Only add SRTLA URL if SRTLA port is configured
if (isPortConfigured(config.srtlaPort)) {
urls.push({
label: 'SRTLA Publisher',
url: generateSrtlaPublisherUrl(streamId.publisher),
description: 'Use this URL to publish your stream via SRTLA (with bonding support)',
icon: 'bi-broadcast-pin'
});
}
urls.push(
{
label: 'SRT Player',
url: generatePlayerUrl(streamId.player),
description: 'Use this URL to play the stream via SRT',
icon: 'bi-play-circle'
},
{
label: 'Statistics',
url: generateStatsUrl(streamId.player),
description: 'View real-time statistics for this stream',
icon: 'bi-graph-up'
}
);
return urls;
};