从 Google Chrome 发送时跳过 Chromecast 选择

Skip Chromecast selection when sending from Google Chrome

我正在尝试将数据发送到 chromecast,但我想将数据直接发送到某个 Chromecast,而不是在 Google 中 selecting Chrome.

我想在发送数据之前跳过 Chromecast selection。

这是要避免的。

我不想 select 强制转换,而是直接向其强制转换数据。

我一直在检查我们从 chrome.cast.initialize 获得的 session 对象,它 return 是这样的:

      {
        "sessionId": "b59f1754-fd13-48cd-b237-4952a69cade4",
        "appId": "5B797F56",
        "displayName": "url-cast-sender",
        "statusText": "URL Cast ready...",
        "receiver": {
          "label": "rTflOUigItAIYPwoZZ87Uv5oK8yI.",
          "friendlyName": "Sala de Juntas",
          "capabilities": [
            "video_out",
            "audio_out"
          ],
          "volume": {
            "controlType": "attenuation",
            "level": 1,
            "muted": false,
            "stepInterval": 0.05000000074505806
          },
          "receiverType": "cast",
          "isActiveInput": null,
          "displayStatus": null
        },
        "senderApps": [],
        "namespaces": [
          {
            "name": "urn:x-cast:com.google.cast.debugoverlay"
          },
          {
            "name": "urn:x-cast:com.url.cast"
          }
        ],
        "media": [],
        "status": "connected",
        "transportId": "b59f1754-fd13-48cd-b237-4952a69cade4"
      };

如您所见,那里有 label,我一直在尝试使用它,但一无所获。

页面请求连接到 chromecast 的方式如下:

// click handlers
document.getElementById('requestSession').onclick = function () {
  chrome.cast.requestSession(sessionListener, onErr);
};

这似乎是在 Google Chrome 中打开 selection 警报的部分。

我的作品是 url-cast-receiver and you can check a demo here 的分支。

原来从前端部分是不可能的。

所以我最终使用了一个名为 SharpCaster created by Tapanila, in which there is a controller that allows you to do this kind of stuff, here 的库,您可以找到它的示例。

在让它工作时遇到了一些麻烦,还在存储库中打开了一个问题,但最终我自己修复了它,issue #141.

WebPageCastingTester.cs

using System.Linq;
using System.Threading.Tasks;
using SharpCaster.Controllers;
using SharpCaster.Services;
using Xunit;

namespace SharpCaster.Test
{
    public class WebPageCastingTester
    {
        private ChromecastService _chromecastService;
        public WebPageCastingTester()
        {
            _chromecastService = ChromecastService.Current;
            var device = _chromecastService.StartLocatingDevices().Result;
            _chromecastService.ConnectToChromecast(device.First()).Wait(2000);
        }

        [Fact]
        public async void TestingLaunchingSharpCasterDemo()
        {
            var controller =  await _chromecastService.ChromeCastClient.LaunchWeb();
            await Task.Delay(4000);
            Assert.NotNull(_chromecastService.ChromeCastClient.ChromecastStatus.Applications.First(x => x.AppId == WebController.WebAppId));
            await controller.LoadUrl("https://www.windytv.com/");
            await Task.Delay(4000);
            Assert.Equal(_chromecastService.ChromeCastClient.ChromecastStatus.Applications.First(x => x.AppId == WebController.WebAppId).StatusText,
                "Now Playing: https://www.windytv.com/");
        }
    }
}