Skip to content

Commit

Permalink
Merge pull request #131 from radiohertz/fix-rtmp-token-issue
Browse files Browse the repository at this point in the history
fix: rtmp server failing to connect when auth is configured
  • Loading branch information
harlanc authored May 17, 2024
2 parents 7df491b + 7147f23 commit 477e412
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions protocol/rtmp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] - ReleaseDate

- Fix: RTMP Auth failing due to empty string query string in packet

## [0.6.3] - 2021-03-15
- Upgrade failure library.
- Support querying more detailed statistic data.
Expand Down
31 changes: 27 additions & 4 deletions protocol/rtmp/src/session/server_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,11 @@ impl ServerSession {

let app_name = command_obj.get("app");
self.app_name = match app_name {
Some(Amf0ValueType::UTF8String(app)) => app.clone(),
Some(Amf0ValueType::UTF8String(app)) => {
// the value can weirdly have the query params, lets just remove it
// example: live/stream?token=123
app.split(&['?', '/']).next().unwrap_or(app).to_string()
}
_ => {
return Err(SessionError {
value: SessionErrorValue::NoAppName,
Expand Down Expand Up @@ -672,9 +676,28 @@ impl ServerSession {
}
};

(self.stream_name, self.query) =
RtmpUrlParser::parse_stream_name_with_query(&stream_name_with_query);

if !stream_name_with_query.is_empty() {
(self.stream_name, self.query) =
RtmpUrlParser::parse_stream_name_with_query(&stream_name_with_query);
} else {
log::warn!("stream_name_with_query is empty, extracing info from swf_url instead...");
let mut url = RtmpUrlParser::new(
self.connect_properties
.swf_url
.clone()
.unwrap_or("".to_string()),
);

match url.parse_url() {
Ok(_) => {
self.stream_name = url.stream_name;
self.query = url.query;
}
Err(e) => {
log::warn!("Failed to parse swf_url: {e}");
}
}
}
if let Some(auth) = &self.auth {
auth.authenticate(&self.stream_name, &self.query, false)?
}
Expand Down

0 comments on commit 477e412

Please sign in to comment.