初始chromecast设置

时间:2013-10-05 21:47:07

标签: chromecast

很高兴终于有时间尝试开发我的chromecast但是唉...似乎甚至无法开始。

我填写了白名单请求,收到了周五确认的电子邮件(正好赶上周末!),然后我开始查看示例,根据我发现的一些想要让hello世界正常工作。

  1. 配置了chrome cast以通过Mac chromecast应用程序将序列发送到谷歌
  2. 将开发者菜单中的网址列入白名单
  3. 验证接收者代码实际上与注册所述的URL相同(从确认电子邮件中复制粘贴并且有效)。
  4. 我会从服务器或本地主机打开我的发件人HTML,但我似乎无法显示chromecast(是的,我在同一个网络上)。

    我在代码中添加了日志,以验证是否收到了事件消息并且未收到该消息,因此我猜测扩展程序无法验证应用程序ID。

    我可以查看扩展程序的日志吗?

    这是发件人代码:

        <!DOCTYPE html>
    <html data-cast-api-enabled="true">
    <head>
    <title>Hello sender!</title>
    </head>
    <body>
        <div class="receiver-div">
                    <h3>Choose A Receiver</h3>
                    <ul class="receiver-list">
                        <li>Looking for receivers...</li>
                    </ul>
                </div>
        <button class="kill" disabled>Kill the Connection</button>
    </body>
    <script src="http://underscorejs.org/underscore-min.js"></script>
    <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    
    <script>
            var cast_api,
                cv_activity,
                receiverList,
                $killSwitch = $('.kill');
                console.log("initializing script");
    
            window.addEventListener('message', function(event) {
                console.log('Message received of type'+event.data.event);
                if (event.source === window && event.data &&
                        event.data.source === 'CastApi' &&
                        event.data.event === 'Hello') {
                    initializeApi();
                }
            });
    
            initializeApi = function() {
                    console.log('Initialize API called');
                if (!cast_api) {
                    console.log("no cast api yet")
                    cast_api = new cast.Api();
                    cast_api.addReceiverListener('myidstring here', onReceiverList);
                }
            };
    
            onReceiverList = function(list) {
                console.log('on receiverlist called');
                if (list.length > 0) {
                    receiverList = list;
                    $('.receiver-list').empty();
                    receiverList.forEach(function(receiver) {
                        $listItem = $('<li><a href="#" data-id="' + receiver.id + '">' + receiver.name + '</a></li>');
                        $listItem.on('click', receiverClicked);
                        $('.receiver-list').append($listItem);
                    });
                }
            };
    
            receiverClicked = function(e) {
                e.preventDefault();
    
                var $target = $(e.target),
                    receiver = _.find(receiverList, function(receiver) {
                        return receiver.id === $target.data('id');
                    });
    
                doLaunch(receiver);
            };
    
            doLaunch = function(receiver) {
                if (!cv_activity) {
                    var request = new cast.LaunchRequest('still my id string here', receiver);
    
                    $killSwitch.prop('disabled', false);
    
                    cast_api.launch(request, onLaunch);
                }
            };
    
            onLaunch = function(activity) {
                if (activity.status === 'running') {
                    cv_activity = activity;
    
                    cast_api.sendMessage(cv_activity.activityId, 'charz', {type: 'HelloWorld'});
                }
            };
    
            $killSwitch.on('click', function() {
                cast_api.stopActivity(cv_activity.activityId, function(){
                    cv_activity = null;
    
                    $killSwitch.prop('disabled', true);
                });
            });
        </script>
    </html>
    

    唯一记录的是“初始化脚本”行。

    提前谢谢你,

    CR。

    编辑: 我将阿里的答案标记为答案,因为他让我走上修复它的道路: 调试意味着白名单已经完成,让我看看我身边的配置:

    1. file://网址不起作用
    2. 当我在本地设置自己的网络服务器时,使用localhost / sender.html它会立即生效。
    3. 白名单必须是完整的,不包括协议(显然)。我将我的网址列为http://myserver/mypath/sender.html,并且无效,最后添加myserver/mypath/sender.html使其完美无缺。
    4. 也许可以更新文档以反映这个??

1 个答案:

答案 0 :(得分:3)

尝试访问http://<chromecast-ip>:9222以查看您的设备是否已正确列入白名单。您应该会看到一个页面,其中包含一个简单的链接,可以为您的接收器打开chrome调试器。

相关问题