How does one query the “parameters” sent to a Chro

2019-05-24 10:33发布

问题:

The docs shown on this page demonstrate how to send arbitrary parameters from a sender app to a receiver app:

https://developers.google.com/cast/chrome_sender

Specifically, here:

request.parameters = "v=abcdefg";

But, I don't see how the receiver app is supposed to access those parameters once sent? Does someone have an example of jscript for a receiver to see this string?

回答1:

It looks like Chromecast pulls down the built-in application settings from the following URL: https://clients3.google.com/cast/chromecast/device/config

If you take a look at that file, you'll notice that many of the URLs look like this:

https://www.youtube.com/tv?${POST_DATA}

Notice that ${POST_DATA} is specified as part of the URL that defines the application. I am only guessing, but I would assume that unless your application is setup similarly on Google's whitelist, that you'll be unable to receive that data via the URL.

It may be worth using a channel to send the data you require to your application instead of trying to use request.parameters.



回答2:

This should be passed in the query parameter section of the URL that the receiver loads. For example, if your app URL is:

http://example.com/foo.html

and you set:

request.parameters = "bar=baz";

then the full URL should come out as:

http://example.com/foo.html?bar=baz

From your receiver JavaScript, you can interrogate this value with document.location.search.



标签: google-cast