【发布时间】:2015-03-23 10:32:21
【问题描述】:
我尝试为 chromecast 编写一些 webapps 以将我自己的网站投射到 chromecast。 chrome 桌面上的一切都很棒。我能够连接到 chromecast 发送消息和...
但是当我从手机上的 chrome 浏览器加载网站时,每次我想向我的接收者发送消息时,它总是说连接到 chromecast。
我不想为手机编写应用程序并希望将其保留在 webapp 上。
这是来自 SDK Developer 的示例代码。
<head>
<script type="text/javascript" src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
<meta charset="utf-8">
</script>
<script type="text/javascript">
var applicationID = 'HIDDEN';
var namespace = 'urn:x-cast:com.google.cast.test';
var session = null;
var sessionID = 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);
sessionID = session.sessionId;
}
/**
* 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");
// load();
}
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>
我调用函数 transcribe 并将消息发送到我编写的 chrome 接收器。它在桌面版本上完美运行。但是在电话上它一直说连接到 chrome cast。
有人知道在手机上工作是否有强制设置?
【问题讨论】:
-
我知道很多人会告诉我桌面和ios的演员表不一样,我必须使用IOS API。这是示例:github.com/googlecast/CastHelloText-ios 但是我不想创建一个应用程序,我只想在桌面以及任何手机、平板电脑上使用我的 web 应用程序......那么该怎么做呢?
标签: android chromecast