Commit 5d2df23a authored by Steve Johnson's avatar Steve Johnson

moved dial to php; updated license

parent 207435ec
<!--
Copyright (C) 2014 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
overflow:hidden;
}
div{
height:720PX;
width:1280PX;
text-align:center;
border:0px solid silver;
display: table-cell;
vertical-align:middle;
color:#FFFFFF;
background-color:#000000;
background-image: url('mseLogo.png');
background-position: center;
background-repeat: no-repeat;
font-weight:bold;
font-family:Verdana, Geneva, sans-serif;
font-size:40px;
}
</style>
<title>Cast MSE</title>
</head>
<body>
<DIV id="splash"></DIV>
<script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script type="text/javascript" src="msecast.js"></script>
<script type="text/javascript">
window.onload = function() {
cast.receiver.logger.setLevelValue(0);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
console.log('Starting Receiver Manager');
// handler for the 'ready' event
castReceiverManager.onReady = function(event) {
console.log('Received Ready event: ' + JSON.stringify(event.data));
window.castReceiverManager.setApplicationState("Waiting for MSE Container Load...");
};
// handler for 'senderconnected' event
castReceiverManager.onSenderConnected = function(event) {
console.log('Received Sender Connected event: ' + event.data);
console.log(window.castReceiverManager.getSender(event.data).userAgent);
};
// handler for 'senderdisconnected' event
castReceiverManager.onSenderDisconnected = function(event) {
console.log('Received Sender Disconnected event: ' + event.data);
if (window.castReceiverManager.getSenders().length == 0) {
window.close();
}
};
// handler for 'systemvolumechanged' event
castReceiverManager.onSystemVolumeChanged = function(event) {
console.log('Received System Volume Changed event: ' + event.data['level'] + ' ' +
event.data['muted']);
};
// create a CastMessageBus to handle messages for a custom namespace
window.messageBus =
window.castReceiverManager.getCastMessageBus(castNamespace);
// handler for the CastMessageBus message event
window.messageBus.onMessage = function(event) {
console.log('Message [' + event.senderId + ']: ' + event.data);
// display the message from the sender
displayText(event.data);
// inform all senders on the CastMessageBus of the incoming message event
// sender message listener will be invoked
window.messageBus.send(event.senderId, event.data);
}
// initialize the CastReceiverManager with an application status message
window.castReceiverManager.start({statusText: "Application is starting"});
console.log('Receiver Manager started');
};
// utility function to display the text message in the input field
function displayText(text) {
console.log(text);
document.getElementById("message").innerHTML=text;
window.castReceiverManager.setApplicationState(text);
};
</script>
</body>
</html>
\ No newline at end of file
<!--
Copyright (C) 2014 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<style type="text/css">
html, body, #wrapper {
height:100%;
width: 100%;
margin: 0;
padding: 0;
border: 0;
}
#wrapper td {
vertical-align: middle;
text-align: center;
}
input {
font-family: "Arial", Arial, sans-serif;
font-size: 40px;
font-weight: bold;
}
.border {
border: 2px solid #cccccc;
border-radius: 5px;
}
.border:focus {
outline: none;
border-color: #8ecaed;
box-shadow: 0 0 5px #8ecaed;
}
</style>
<script type="text/javascript" src="//www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
<script type="text/javascript">
var applicationID = '40C1105B'; //794B7BBF';
var namespace = 'urn:x-cast:com.google.cast.sample.helloworld';
var session = null;
/**
* Call initialization for Cast
*/
if (!chrome.cast || !chrome.cast.isAvailable) {
setTimeout(initializeCastApi, 1000);
}
/**
* initialization
*/
function initializeCastApi() {
var sessionRequest = new chrome.cast.SessionRequest(applicationID);
var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
sessionListener,
receiverListener);
chrome.cast.initialize(apiConfig, onInitSuccess, onError);
};
/**
* initialization success callback
*/
function onInitSuccess() {
appendMessage("onInitSuccess");
}
/**
* initialization error callback
*/
function onError(message) {
appendMessage("onError: "+JSON.stringify(message));
}
/**
* generic success callback
*/
function onSuccess(message) {
appendMessage("onSuccess: "+message);
}
/**
* callback on success for stopping app
*/
function onStopAppSuccess() {
appendMessage('onStopAppSuccess');
}
/**
* session listener during initialization
*/
function sessionListener(e) {
appendMessage('New session ID:' + e.sessionId);
session = e;
session.addUpdateListener(sessionUpdateListener);
session.addMessageListener(namespace, receiverMessage);
}
/**
* listener for session updates
*/
function sessionUpdateListener(isAlive) {
var message = isAlive ? 'Session Updated' : 'Session Removed';
message += ': ' + session.sessionId;
appendMessage(message);
if (!isAlive) {
session = null;
}
};
/**
* utility function to log messages from the receiver
* @param {string} namespace The namespace of the message
* @param {string} message A message string
*/
function receiverMessage(namespace, message) {
appendMessage("receiverMessage: "+namespace+", "+message);
};
/**
* receiver listener during initialization
*/
function receiverListener(e) {
if( e === 'available' ) {
appendMessage("receiver found");
}
else {
appendMessage("receiver list empty");
}
}
/**
* stop app/session
*/
function stopApp() {
session.stop(onStopAppSuccess, onError);
}
/**
* send a message to the receiver using the custom namespace
* receiver CastMessageBus message handler will be invoked
* @param {string} message A message string
*/
function sendMessage(message) {
if (session!=null) {
session.sendMessage(namespace, message, onSuccess.bind(this, "Message sent: " + message), onError);
}
else {
chrome.cast.requestSession(function(e) {
session = e;
session.sendMessage(namespace, message, onSuccess.bind(this, "Message sent: " + message), onError);
}, onError);
}
}
/**
* append message to debug message window
* @param {string} message A message string
*/
function appendMessage(message) {
console.log(message);
var dw = document.getElementById("debugmessage");
dw.innerHTML += '\n' + JSON.stringify(message);
};
/**
* utility function to handle text typed in by user in the input field
*/
function update() {
sendMessage(document.getElementById("input").value);
}
/**
* handler for the transcribed text from the speech input
* @param {string} words A transcibed speech string
*/
function transcribe(words) {
sendMessage(words);
}
</script>
</head>
<body>
<table id="wrapper">
<tr>
<td>
<form method="get" action="JavaScript:update();">
<input id="input" class="border" type="text" size="30" onwebkitspeechchange="transcribe(this.value)" x-webkit-speech/>
</form>
</td>
</tr>
</table>
<!-- Debbugging output -->
<div style="margin:10px; visibility:hidden;">
<textarea rows="20" cols="70" id="debugmessage">
</textarea>
</div>
<script type="text/javascript">
document.getElementById("input").focus();
</script>
</body>
</html>
<?php
/* discovery.php
*
* Web proxy for local device discovery
*
* Copyright CableLabs 2014. All rights reserved.
*/
require '../utils.php';
function subnet_addr($ipaddr) {
$octets = explode(".", $ipaddr);
$leftByte = intval($octets[0]);
// check for class A, where first octet is 1-127
if (($leftByte & 128) == 0) {return "{$octets[0]}.00.00.00";} //class A
// check for class C, where first octet is 192-223
if (($leftByte & 192) == 192) {return "{$octets[0]}.{$octets[1]}.{$octets[2]}.00";} //class C
// check for class B, where first octet is 128-191
if (($leftByte & 128) == 128) {return "{$octets[0]}.{$octets[1]}.00.00";} //class B
return ipAddr;
}
// Purge aged discovery records
foreach (glob('./subnets/*') as $file)
{
$filelastmodified = filemtime($file);
$delta = time()-$filelastmodified;
// Note: Discovery Proxy (mseproxy) should update every 30 seconds.
if ($delta > 45)
{
unlink($file);
}
}
// Check query params for special actions
if (isset($_GET['list'])) {
// GET from web client application (remote SDOM device)
header('HTTP/1.0 200 OK');
header('Content-type: application/json');
$subnet = subnet_addr(remote_ipaddress());
$subnets_dir = dirname(__FILE__).'/subnets/';
$discovery_file = $subnets_dir.'/'.$subnet;
if (!file_exists($discovery_file)) {
echo '{"bridges" : [], "devices" : [], "subnet" : "'.remote_ipaddress().'"}';
}
else {
$server_list = file_get_contents($discovery_file);
echo $server_list;
}
}
else if (isset($_GET['update'])) {
// POST from discovery proxy
header('HTTP/1.0 200 OK');
$post_data = file_get_contents("php://input");
$server_list = json_decode($post_data, true);
// Add our subnet to the object (informational)
$subnet = subnet_addr(remote_ipaddress());
$server_list['subnet'] = $subnet;
// Add empty arrays if missing.
$empty_array = array();
if (!isset($server_list['devices'])) {
$server_list['devices'] = $empty_array;
}
if (!isset($server_list['bridges'])) {
$server_list['bridges'] = $empty_array;
}
$json = json_encode($server_list);
$subnets_dir = dirname(__FILE__).'/subnets/';
$discovery_file = $subnets_dir.'/'.$subnet;
$fp = fopen($discovery_file, 'w');
fwrite($fp, $json);
fclose($fp);
}
else {
header('HTTP/1.0 400 Bad Request');
echo "HTTP/1.0 400 Bad Request";
}
?>
\ No newline at end of file
......@@ -130,7 +130,7 @@ var Url = (function() {
};
obj.discovery = function() {
return resolveURL("discovery", "html/dial/discovery.php");
return resolveURL("discovery", "php/dial/discovery.php");
};
obj.help = function(page) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment