尝试启动自定义接收器应用程序时,偶尔会使用错误代码15调用onApplicationConnectionFailed。其他时候,应用程序成功启动,但永远不会调用onApplicationConnected。
我想也许这是我的发送者应用程序代码,但我将所有连接逻辑切换到现在使用Cast Companion Library,我仍然看到相同的问题。
我已经在浏览器中加载了接收器应用程序,但我没有看到任何javascript错误。
这是window.onload的接收器应用程序代码:
window.onload = function() {
cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
console.log('Starting Receiver Manager');
// initialize the CastReceiverManager with an application status message
window.castReceiverManager.start({statusText: "Application is starting"});
// handler for the 'ready' event
castReceiverManager.onReady = function(event) {
console.log('Received Ready event: ' + JSON.stringify(event.data));
window.castReceiverManager.setApplicationState("Application status is ready...");
};
// 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(
'urn:x-cast:com.wolfgang.chromecasttest.app');
// handler for the CastMessageBus message event
window.messageBus.onMessage = function(event) {
console.log('Message [' + event.senderId + ']: ' + event.data);
// display the message from the sender
var sentMessage = JSON.parse(event.data);
if(sentMessage.command == 'MESSAGE'){
displayText(sentMessage.payload);
window.messageBus.send(event.senderId, sentMessage.payload);
} else if(sentMessage.command == 'AUDIO_UPDATE'){
console.log('GOT BASE64 AUDIO: ' + sentMessage.payload);
translateAudio(sentMessage.payload);
window.messageBus.send(event.senderId, 'Audio Update Received');
} else if(sentMessage.command == 'IPUPDATE'){
deviceIP = sentMessage.payload;
reloadImage();
} else{
window.messageBus.send(event.senderId, 'Invalid Message Sent');
}
// inform all senders on the CastMessageBus of the incoming message event
// sender message listener will be invoked
}
console.log('Receiver Manager started');
};