1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 03:49:56 +02:00

Fix private broadcasts and add automatic broadcast by default web player

This commit is contained in:
Afterster 2014-02-23 00:42:32 +01:00
parent 54ab51873c
commit 991b16f860
7 changed files with 53 additions and 7 deletions

View file

@ -49,7 +49,7 @@ if ($cargv > 1) {
} }
} }
$app = new Ratchet\App('0.0.0.0', $port); $app = new Ratchet\App('localhost', $port);
$brserver = new Broadcast_Server(); $brserver = new Broadcast_Server();
$brserver->verbose = $verbose; $brserver->verbose = $verbose;
$app->route('/broadcast', $brserver); $app->route('/broadcast', $brserver);

View file

@ -228,7 +228,13 @@ class Broadcast_Server implements MessageComponentInterface
protected function authSid($conn, $sid) protected function authSid($conn, $sid)
{ {
if (Session::exists('stream', $sid)) {
$this->sids[$conn->resourceId] = $sid;
} else {
if ($this->verbose) {
echo "Wrong listener session " . $sid . "\r\n";
}
}
} }
protected function unregisterListener($conn) protected function unregisterListener($conn)

View file

@ -382,6 +382,9 @@ class Update
$update_string = '- Set user field on playlists as optional.<br />'; $update_string = '- Set user field on playlists as optional.<br />';
$version[] = array('version' => '360045','description' => $update_string); $version[] = array('version' => '360045','description' => $update_string);
$update_string = '- Add broadcast web player by default preference.<br />';
$version[] = array('version' => '360046','description' => $update_string);
return $version; return $version;
} }
@ -2297,4 +2300,21 @@ class Update
return true; return true;
} }
/**
* update_360046
*
* Add broadcast web player by default preference
*/
public static function update_360046()
{
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('broadcast_by_default','0','Broadcast web player by default',25,'boolean','streaming')";
Dba::write($sql);
$id = Dba::insert_id();
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'0')";
Dba::write($sql, array($id));
return true;
}
} }

View file

@ -181,6 +181,7 @@ function create_preference_input($name,$value)
case 'stream_beautiful_url': case 'stream_beautiful_url':
case 'share': case 'share':
case 'share_social': case 'share_social':
case 'broadcast_by_default':
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; } if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
echo "<select name=\"$name\">\n"; echo "<select name=\"$name\">\n";
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n"; echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";

View file

@ -71,6 +71,7 @@ class Ampacheflickr {
public function get_photos($search) { public function get_photos($search) {
$photos = array(); $photos = array();
$url = "https://api.flickr.com/services/rest/?&method=flickr.photos.search&api_key=" . $this->api_key . "&per_page=20&content_type=1&text=" . rawurlencode($search . " concert"); $url = "https://api.flickr.com/services/rest/?&method=flickr.photos.search&api_key=" . $this->api_key . "&per_page=20&content_type=1&text=" . rawurlencode($search . " concert");
debug_event($this->name, 'Calling ' . $url, '5');
$request = Requests::get($url); $request = Requests::get($url);
if ($request->status_code == 200) { if ($request->status_code == 200) {
$xml = simplexml_load_string($request->body); $xml = simplexml_load_string($request->body);

View file

@ -54,7 +54,7 @@ switch ($_REQUEST['action']) {
$broadcast = new Broadcast($broadcast_id); $broadcast = new Broadcast($broadcast_id);
if ($broadcast->id) { if ($broadcast->id) {
$broadcast->update_state(false); $broadcast->update_state(false);
$results['broadcast'] = Broadcast::get_broadcast_link($broadcast_id) . '' . $results['broadcast'] = Broadcast::get_broadcast_link() . '' .
'<script type="text/javascript">stopBroadcast();</script>'; '<script type="text/javascript">stopBroadcast();</script>';
} }
break; break;

View file

@ -340,7 +340,7 @@ function startBroadcastListening(broadcast_id)
$('.jp-seek-bar').css('pointer-events', 'none'); $('.jp-seek-bar').css('pointer-events', 'none');
brconn.onopen = function(e) { brconn.onopen = function(e) {
sendBroadcastMessage('AUTH_SID', '<?php echo session_id(); ?>'); sendBroadcastMessage('AUTH_SID', '<?php echo Stream::$session; ?>');
sendBroadcastMessage('REGISTER_LISTENER', broadcast_id); sendBroadcastMessage('REGISTER_LISTENER', broadcast_id);
}; };
} }
@ -407,7 +407,7 @@ function receiveBroadcastMessage(e)
function sendBroadcastMessage(cmd, value) function sendBroadcastMessage(cmd, value)
{ {
if (brconn != null) { if (brconn != null && brconn.readyState == 1) {
var msg = cmd + ':' + value + ';'; var msg = cmd + ':' + value + ';';
brconn.send(msg); brconn.send(msg);
} }
@ -416,7 +416,9 @@ function sendBroadcastMessage(cmd, value)
function stopBroadcast() function stopBroadcast()
{ {
brkey = ''; brkey = '';
if (brconn != null && brconn.readyState == 1) {
brconn.close(); brconn.close();
}
brconn = null; brconn = null;
} }
@ -561,7 +563,23 @@ if ($isVideo) {
<div class="player_actions"> <div class="player_actions">
<?php if (AmpConfig::get('broadcast')) { ?> <?php if (AmpConfig::get('broadcast')) { ?>
<div id="broadcast" class="broadcast"> <div id="broadcast" class="broadcast">
<?php echo Broadcast::get_broadcast_link(); ?> <?php
if (AmpConfig::get('broadcast_by_default')) {
$broadcasts = Broadcast::get_broadcasts($GLOBALS['user']->id);
if (count($broadcasts) < 1) {
$broadcast_id = Broadcast::create(T_('My Broadcast'));
} else {
$broadcast_id = $broadcasts[0];
}
$broadcast = new Broadcast($broadcast_id);
$key = Broadcast::generate_key();
$broadcast->update_state(true, $key);
echo Broadcast::get_unbroadcast_link($broadcast_id) . '<script type="text/javascript">startBroadcast(\'' . $key . '\');</script>';
} else {
echo Broadcast::get_broadcast_link();
}
?>
</div> </div>
<?php } ?> <?php } ?>
<?php if ($iframed) { ?> <?php if ($iframed) { ?>