Support for Google Chromecast receiver API

0 favourites
  • 11 posts
From the Asset Store
Google Analytics 4 Plugin for Construct 3 enables metrics and analytics for your games easily.
  • Hi guys, new here. FANTASTIC game engine.

    I'm trying to load in the Javascript library, which I've done so like this:

    	instanceProto.onCreate = function()
    	{
    		var self = this;
    		
    		
    		// ===================
    		//
    		// CHROME CAST ENGINE
    		//
    		// ===================
    		
    		console.log("Attempting to load cast_receiver.js");
    		
    		$.ajax({
    		  url: "http://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js",
    		  dataType: "script",
    		  success: function(){
    			console.log("LOADED: cast_receiver.js");
    		  }
    		});
    		
    		console.log("Finished cast_receiver loading");
    [/code:3dqp1161]
    
    I can't figure out how to load this external JS any other way. 
    
    [b]Here is the next bit of code I'm having trouble with: [/b]
    
    [code:3dqp1161]
    // CHROME CAST INIT
    		cast.receiver.logger.setLevelValue(0);
    		window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
    		console.log('Starting Receiver Manager');
    		
    		// 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...");
    		  console.log("Application status is ready...");
    		};
    		
    		console.log('COMPLETE:  Receiver Manager');
    		
    		
    		// 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.google.cast.sample.helloworld');
    			  
    		// handler for the CastMessageBus message event
    		window.messageBus.onMessage = function(event) {
    			console.log('Message [' + event.senderId + ']: ' + event.data);
    			
    			window.messageBus.send(event.senderId, event.data);
    		  
    		  
    		}
    		// initialize the CastReceiverManager with an application status message
    		window.castReceiverManager.start({statusText: "Application is starting"});
    		console.log('Receiver Manager started');
    		
    		
    		console.log("-- Complete --");
    [/code:3dqp1161]
    
    The next question will be how do I make a player move forward? This is the code (from above) that is receiving messages from my Android phone:
    
    [code:3dqp1161]
    		// handler for the CastMessageBus message event
    		window.messageBus.onMessage = function(event) {
    			console.log('Message [' + event.senderId + ']: ' + event.data);
    			
    			window.messageBus.send(event.senderId, event.data);
    		  
                            // ON A NORMAL JAVASCRIPT PAGE I COULD DO THINGS LIKE THIS:
                           $("#player").css({left: "+="+event.data});
    		  
    		}
    [/code:3dqp1161]
    
    Your help is appreciated
  • Recently bought a chromecast and loving it. Great potential as a console for games.

    Two things which might help: have you looked at scirra's google play plugin, which may well load an external library. Also here's an example for tic tac to, https://github.com/googlecast/Cast-TicTacToe-chrome

  • u should use dependencies to load external libraries properly, its in the edittime file.

  • It's not your plugin's responsibility to implement any game logic like moving actual objects. Just expose the conditions/triggers via events, and let the user handle the event how they want (which might for example involve moving an object).

  • Ashley would it be possible to use Chrome-cast via C2

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi Folks, I was able to get it working!

    I was pretty close to making a native plugin for Construct 2. It recognized my app started and all that, but couldn't figure out how to have the Cast API listener always running.

    So I reverted to my nasty hack.

    After exporting the game, I simply edit index.html and add my external javascript API I wrote for Chromecast. Works like a friggin charm. I make heavy use of c2_callFunction("myFucntion", [1,2,3]);

    The more I use Construct 2, the more I absolutely fall in love with this. I'm going to make SO MANY APPS. You guys rock.

  • Ashley - Could you PM me? I'd like to discuss releasing a Chromecast support plugin to the community, if your team is interested.

  • cybertron7 - use the Javascript SDK, it's fully documented and you are free to release it independently. You should also prefer to make a plugin and use the event system instead of using c2_callFunction.

  • Thanks Ashley,

    Like I said, I'm half way with it, but I just can't figure out a few things. C2_callFunction works for now. It's easy enough to transfer my code in natively.

    In time. Thanks,

  • cybertron7, any chance of you releasing a plugin for this? I'd love to create some projects using Google Cast. There are already some great games out there that leverage it, particularly board games like Apples To Apples and Cards Against Humanity.

  • Heya, we never actually got this to work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)