Skip to content

Commit f9700d6

Browse files
ossrs-aiwinlinvip
authored andcommitted
AI: Some small improvements.
1 parent 6e93dd7 commit f9700d6

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

trunk/research/players/js/srs.sdk.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ function SrsRtcWhipWhepAsync() {
3434
self.displayStream = null;
3535
self.userStream = null;
3636

37+
// Store the WHIP session resource URL from Location header for cleanup.
38+
self.resourceUrl = null;
39+
3740
// See https://datatracker.ietf.org/doc/draft-ietf-wish-whip/
3841
// @url The WebRTC url to publish with, for example:
3942
// http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream
@@ -111,6 +114,14 @@ function SrsRtcWhipWhepAsync() {
111114
if (xhr.status !== 200 && xhr.status !== 201) return reject(xhr);
112115
const data = xhr.responseText;
113116
console.log("Got answer: ", data);
117+
118+
// Extract Location header for WHIP session resource URL.
119+
const location = xhr.getResponseHeader('Location');
120+
if (location) {
121+
self.resourceUrl = new URL(location, url).href;
122+
console.log(`WHIP session resource URL: ${self.resourceUrl}`);
123+
}
124+
114125
return data.code ? reject(xhr) : resolve(data);
115126
}
116127
xhr.open('POST', url, true);
@@ -159,6 +170,14 @@ function SrsRtcWhipWhepAsync() {
159170
if (xhr.status !== 200 && xhr.status !== 201) return reject(xhr);
160171
const data = xhr.responseText;
161172
console.log("Got answer: ", data);
173+
174+
// Extract Location header for WHEP session resource URL.
175+
const location = xhr.getResponseHeader('Location');
176+
if (location) {
177+
self.resourceUrl = new URL(location, url).href;
178+
console.log(`WHEP session resource URL: ${self.resourceUrl}`);
179+
}
180+
162181
return data.code ? reject(xhr) : resolve(data);
163182
}
164183
xhr.open('POST', url, true);
@@ -190,6 +209,25 @@ function SrsRtcWhipWhepAsync() {
190209
});
191210
self.userStream = null;
192211
}
212+
213+
// Send DELETE request to WHIP session resource URL to cleanup server resources.
214+
if (self.resourceUrl) {
215+
const xhr = new XMLHttpRequest();
216+
xhr.open('DELETE', self.resourceUrl, true);
217+
xhr.onload = function() {
218+
if (xhr.readyState !== xhr.DONE) return;
219+
if (xhr.status === 200) {
220+
console.log(`WHIP session deleted: ${self.resourceUrl}`);
221+
} else {
222+
console.warn(`Failed to delete WHIP session: ${self.resourceUrl}, status: ${xhr.status}`);
223+
}
224+
};
225+
xhr.onerror = function() {
226+
console.warn(`Error deleting WHIP session: ${self.resourceUrl}`);
227+
};
228+
xhr.send();
229+
self.resourceUrl = null;
230+
}
193231
};
194232

195233
// The callback when got local stream.

trunk/src/app/srs_app_rtc_api.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,26 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter *w, ISrsHtt
491491
vcodec = r->query_get("codec");
492492
}
493493
string acodec = r->query_get("acodec");
494+
// For client to specifies whether encrypt by SRTP.
495+
string srtp = r->query_get("encrypt");
496+
string dtls = r->query_get("dtls");
494497

495-
srs_trace("RTC publish %s, api=%s, tid=%s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, vcodec=%s, acodec=%s",
498+
srs_trace("RTC publish %s, api=%s, tid=%s, clientip=%s, app=%s, stream=%s, offer=%dB, eip=%s, vcodec=%s, acodec=%s, srtp=%s, dtls=%s",
496499
streamurl.c_str(), api.c_str(), tid.c_str(), clientip.c_str(), ruc.req_->app_.c_str(), ruc.req_->stream_.c_str(),
497-
remote_sdp_str.length(), eip.c_str(), vcodec.c_str(), acodec.c_str());
500+
remote_sdp_str.length(), eip.c_str(), vcodec.c_str(), acodec.c_str(), srtp.c_str(), dtls.c_str());
498501

499502
ruc.eip_ = eip;
500503
ruc.vcodec_ = vcodec;
501504
ruc.acodec_ = acodec;
502505
ruc.publish_ = true;
503-
ruc.dtls_ = ruc.srtp_ = true;
506+
507+
// For client to specifies whether encrypt by SRTP.
508+
ruc.dtls_ = (dtls != "false");
509+
if (srtp.empty()) {
510+
ruc.srtp_ = config_->get_rtc_server_encrypt();
511+
} else {
512+
ruc.srtp_ = (srtp != "false");
513+
}
504514

505515
// TODO: FIXME: It seems remote_sdp doesn't represents the full SDP information.
506516
ruc.remote_sdp_str_ = remote_sdp_str;

0 commit comments

Comments
 (0)