Skip to content

Commit

Permalink
Merge pull request #1146 from sodface/cometd
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelherger authored Aug 17, 2024
2 parents 4bd557e + 499e58b commit aa6b64e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changelog9.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h2><a name="v9.0.0" id="v9.0.0"></a>Introducing... Lyrion Music Server Version
<ul>
<li><a href="https://github.com/LMS-Community/slimserver/issues/1027">#1027</a> - Play count increase with in-track jumps (thanks @darrel-k!)</li>
<li><a href="https://github.com/LMS-Community/slimserver/pull/1116">#1116</a> - Fix album info track count when there are more than 50 tracks in an album (thanks @darrel-k!)</li>
<li><a href="https://github.com/LMS-Community/slimserver/pull/1146">#1146</a> - Restore partial Cometd support for CLI clients (thanks @sodface!)</li>
</ul>
<br />

Expand Down
26 changes: 14 additions & 12 deletions Slim/Web/Cometd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ sub webHandler {
sub handler {
my ( $conn, $message ) = @_;

my $isCLI = !$conn->[HTTP_RESPONSE];

if ( !$message ) {
sendResponse(
@{$conn},
Expand Down Expand Up @@ -188,7 +190,7 @@ sub handler {

# Register client with HTTP connection
if ( $clid ) {
if ( ref $conn eq 'ARRAY' ) {
if ( ref $conn eq 'ARRAY' && !$isCLI ) {
$conn->[HTTP_CLIENT]->clid( $clid );
}
}
Expand All @@ -209,7 +211,7 @@ sub handler {

# Detect the language Jive wants content returned in
my ($lang, $ua);
if ( ref $conn ) {
if ( ref $conn && !$isCLI ) {
if ( my $al = $conn->[HTTP_RESPONSE]->request->header('Accept-Language') ) {
$lang = uc $al;
}
Expand Down Expand Up @@ -576,7 +578,7 @@ sub handler {

# If the request was not async, tell the manager to deliver the results to all subscribers
if ( exists $result->{data} ) {
if ( $conn->[HTTP_CLIENT]->transport && $conn->[HTTP_CLIENT]->transport eq 'long-polling' ) {
if ( $isCLI || $conn->[HTTP_CLIENT]->transport && $conn->[HTTP_CLIENT]->transport eq 'long-polling' ) {
push @{$events}, $result;
}
else {
Expand Down Expand Up @@ -638,16 +640,16 @@ sub sendResponse {

$out ||= [];

# Add any additional pending events
push @{$out}, ( $manager->get_pending_events( $httpClient->clid ) );
if ($httpResponse) {
# Add any additional pending events
push @{$out}, ( $manager->get_pending_events( $httpClient->clid ) );

# Add special first event for /meta/(re)connect if set
# Note: calling first_event will remove the event from httpClient
if ( my $first = $httpClient->first_event ) {
unshift @{$out}, $first;
}
# Add special first event for /meta/(re)connect if set
# Note: calling first_event will remove the event from httpClient
if ( my $first = $httpClient->first_event ) {
unshift @{$out}, $first;
}

if ($httpResponse) {
if ( $httpClient->transport && $httpClient->transport eq 'long-polling' ) {
# Finish a long-poll cycle by sending all pending events and removing the timer
Slim::Utils::Timers::killTimers($httpClient, \&sendResponse);
Expand All @@ -658,7 +660,7 @@ sub sendResponse {
else {
# For CLI, don't send anything if there are no events
if ( scalar @{$out} ) {
sendCLIResponse( $httpClient, $httpResponse, $out );
sendCLIResponse( $httpClient, $out );
}
}
}
Expand Down

0 comments on commit aa6b64e

Please sign in to comment.