I keep encountering the following error: EXCEPTION: ReferenceError: cast is not defined in [null]
To create a custom Chromecast receiver application, you need to utilize a specific js file that exposes the necessary functionality through a global 'cast' variable:
//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js
Instead of including a script tag in index.html, I am looking to load this script as a module using systemjs.
Since this is an Angular2 and TypeScript application, I aim to import 'cast' in a service called MyService and utilize it.
index.html
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
},
paths: {
'cast': '//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js'
},
meta: {
'//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js': {format: 'global'}
},
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
myService.ts
import {Injectable} from 'angular2/core';
import cast from 'cast';
@Injectable()
export class MyService {
public init = () => {
cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.NONE);
}
...
}
You can clone a sample Angular2 + TypeScript + Chromecast Receiver application from the following link:
https://github.com/rmtuckerphx/angular2-chromecast-receiver-starterkit
Although the provided code does not currently include any implementation to load 'cast' using systemjs, it can easily be modified by updating index.html and cast-receiver-manager.service.ts