Targeted at Cast version v1
📖 Tip: Make sure you read this first https://developers.google.com/cast/docs/chrome_sender
Add the script tag to your HTML page
<script type="text/javascript" src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
Instead of using window['__onGCastApiAvailable'] = callback
you can use ChromeCast.boot(callback)
.
To determine if the API is available and initialize it, you can provide the callback function before the Cast API loads. It is invoked with loaded == true
when the API loads, or with errorInfo
when load fails (e.g. when no extension is discovered).
ChromeCast.boot(function(loaded:Bool, errorInfo:String):Void
{
trace('ChromeCast: version=${ChromeCast.VERSION}');
trace('ChromeCast: loaded=$loaded, errorInfo=$errorInfo');
});
You initialize the API as follows:
var sessionRequest = new SessionRequest(appId);
var apiConfig = new ApiConfig(sessionRequest, sessionListener, receiverListener);
ChromeCast.initialize(apiConfig, onInitSuccess, onError);
From this point you are good to go and follow the docs.
📖 Tip: Make sure you read this first: https://developers.google.com/cast/docs/custom_receiver
<script src="//www.gstatic.com/cast/sdk/libs/receiver/1.0.0/cast_receiver.js"></script>
var castReceiver = CastReceiverManager.getInstance();
castReceiver.start();
From this point you are good to go and follow the docs.
📖 Tip: Make sure you read this first: https://developers.google.com/cast/docs/gaming
Follow this order of initialization:
- Instantiate GameManager
- Start Custom Receiver
var config = new GameManagerConfig();
config.maxPlayers = 5;
config.applicationName = "Haxe ChromeCast Application";
var gameManager = new GameManager(config);
gameManager.addEventListener(EventType.GAME_MESSAGE_RECEIVED, onGameMessage);
#if debug
// nice simple UI for debugging Cast Receiver.
var debugUI = new DebugUI(gameManager);
debugUI.open();
#end
var castReceiver = CastReceiverManager.getInstance();
castReceiver.start();
From this point you are good to go and follow the docs.
- Package name The package of the Haxe externs are prefixed with
chromecast
instead ofcast
. This is to avoid conflicts with thecast
-keyword in Haxe. As you can see in the extern classes, the@:native
keyword rewrites this package to the expected package.
- I'm not sure if I will maintain the extern classes. It it provides as is. Feel free to do a pull-request.
- Part of the type definitions are created by Mark Knol. I'm not associated with Google. It could be the case stuff is missing, incomplete or even incorrect. I manually collected the Haxe extern classes and copy/pasted the documentation at it.
- Part of the definitions are created by renaudbardet, see https://github.com/renaudbardet/google-cast-receiver-hx-headers I've put it together for convinience.
This software is distributed under the MIT licence which extends only to the headers themselves, the actual software they give access to are the property of Google and may be subject to a different license.