mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-09-26 19:51:26 +08:00
webrtc: add authentication parameters to publisher.js and reader.js (#5026)
add user, pass and token configuration parameters.
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
* @typedef Conf
|
||||
* @type {object}
|
||||
* @property {string} url - absolute URL of the WHIP endpoint.
|
||||
* @property {string} user - username.
|
||||
* @property {string} pass - password.
|
||||
* @property {string} token - token.
|
||||
* @property {MediaStream} stream - stream that contains outgoing tracks.
|
||||
* @property {string} videoCodec - outgoing video codec.
|
||||
* @property {number} videoBitrate - outgoing video bitrate.
|
||||
@@ -276,9 +279,23 @@ class MediaMTXWebRTCPublisher {
|
||||
}
|
||||
}
|
||||
|
||||
#authHeader() {
|
||||
if (this.conf.user !== undefined && this.conf.user !== '') {
|
||||
const credentials = btoa(`${this.conf.user}:${this.conf.pass}`);
|
||||
return {'Authorization': `Basic ${credentials}`};
|
||||
}
|
||||
if (this.conf.token !== undefined && this.conf.token !== '') {
|
||||
return {'Authorization': `Bearer ${this.conf.token}`};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
#requestICEServers() {
|
||||
return fetch(this.conf.url, {
|
||||
method: 'OPTIONS',
|
||||
headers: {
|
||||
...this.#authHeader(),
|
||||
},
|
||||
})
|
||||
.then((res) => MediaMTXWebRTCPublisher.#linkToIceServers(res.headers.get('Link')));
|
||||
}
|
||||
@@ -325,6 +342,7 @@ class MediaMTXWebRTCPublisher {
|
||||
return fetch(this.conf.url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...this.#authHeader(),
|
||||
'Content-Type': 'application/sdp',
|
||||
},
|
||||
body: offer,
|
||||
|
@@ -14,6 +14,9 @@
|
||||
* @typedef Conf
|
||||
* @type {object}
|
||||
* @property {string} url - absolute URL of the WHEP endpoint.
|
||||
* @property {string} user - username.
|
||||
* @property {string} pass - password.
|
||||
* @property {string} token - token.
|
||||
* @property {OnError} onError - called when there's an error.
|
||||
* @property {OnTrack} onTrack - called when there's a track available.
|
||||
*/
|
||||
@@ -403,9 +406,23 @@ class MediaMTXWebRTCReader {
|
||||
});
|
||||
}
|
||||
|
||||
#authHeader() {
|
||||
if (this.conf.user !== undefined && this.conf.user !== '') {
|
||||
const credentials = btoa(`${this.conf.user}:${this.conf.pass}`);
|
||||
return {'Authorization': `Basic ${credentials}`};
|
||||
}
|
||||
if (this.conf.token !== undefined && this.conf.token !== '') {
|
||||
return {'Authorization': `Bearer ${this.conf.token}`};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
#requestICEServers() {
|
||||
return fetch(this.conf.url, {
|
||||
method: 'OPTIONS',
|
||||
headers: {
|
||||
...this.#authHeader(),
|
||||
},
|
||||
})
|
||||
.then((res) => MediaMTXWebRTCReader.#linkToIceServers(res.headers.get('Link')));
|
||||
}
|
||||
@@ -446,7 +463,10 @@ class MediaMTXWebRTCReader {
|
||||
|
||||
return fetch(this.conf.url, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/sdp'},
|
||||
headers: {
|
||||
...this.#authHeader(),
|
||||
'Content-Type': 'application/sdp',
|
||||
},
|
||||
body: offer,
|
||||
})
|
||||
.then((res) => {
|
||||
|
Reference in New Issue
Block a user