silvermine / videojs-chromecast

MIT License
148 stars 75 forks source link

customData not passed to custom receiver. #84

Closed samueleastdev closed 3 years ago

samueleastdev commented 3 years ago

I have a custom receiver setup with the following code.

<html>
<head>

  <script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"></script>

</head>
<body>

    <cast-media-player></cast-media-player>

    <script>

        const context = cast.framework.CastReceiverContext.getInstance();
        const playbackConfig = new cast.framework.PlaybackConfig();
        // Customize the license url for playback
        playbackConfig.licenseUrl = '';
        playbackConfig.protectionSystem = cast.framework.ContentProtection.WIDEVINE;
        playbackConfig.licenseRequestHandler = requestInfo => {
          requestInfo.withCredentials = false;
        };
        context.start({playbackConfig: playbackConfig});

        // Update playback config licenseUrl according to provided value in load request.
        context.getPlayerManager().setMediaPlaybackInfoHandler((loadRequest, playbackConfig) => {

            console.log(loadRequest);

            return playbackConfig;

        });

    </script>
</body>
</html>

I am using the plugin customData to try and send data to the receiver like below.

var customData;

customData = {
    'https://00000000000.cloudfront.net/00000000000/master.mpd': {
        'licenseUrl': 'my license url'
    },
};

options = {
    techOrder: ['chromecast', 'html5'],
    chromecast: {
        requestCustomDataFn: function(source) {
            return customData[source.url];
        }
    },
    plugins: {
        chromecast: {},
    }
};

I am debugging and I am not getting any customData sent below is the console log from the custom receiver loadRequest.

Screenshot 2020-10-18 at 23 56 18
samueleastdev commented 3 years ago

Just wanted to follow up I have built a very simple app to test sending customData and it sends without any issues see below.

<!DOCTYPE html>
<html data-cast-api-enabled="true">
<head>
        <title>Test App</title>
        <script src="//www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
        <form>

            <button type="button" id="castme">Click To Cast</button>
            <button type="button" id="stop">Click To Stop</button>

        </form>
        <script>

            var session = null;

            function sessionListener(e) {

                session = e;
                console.log('New session');
                if (session.media.length != 0) {
                        console.log('Found ' + session.media.length + ' sessions.');
                }

            }

            function receiverListener(e) {

                if( e === 'available' ) {
                        console.log("Chromecast was found on the network.");
                }
                else {
                        console.log("There are no Chromecasts available.");
                }

            }

            function onInitSuccess() {

                console.log("Initialization succeeded");

            }

            function onInitError() {

                console.log("Initialization failed");

            }

            function initializeCastApi() {

                var applicationID = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;
                var sessionRequest = new chrome.cast.SessionRequest('0000000');
                var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
                        sessionListener,
                        receiverListener);
                chrome.cast.initialize(apiConfig, onInitSuccess, onInitError);

            };

            // Start
            function loadMedia() {

                if (!session) {

                    console.log("No session.");
                    return;

                }

                var mediaInfo = new chrome.cast.media.MediaInfo('https://00000000000.cloudfront.net/00000000000/master.mpd');
                mediaInfo.contentType = 'application/dash+xml';
                mediaInfo.customData = {
                    'licenseUrl': 'https://widevine.com/server-url'
                };

                var request = new chrome.cast.media.LoadRequest(mediaInfo);
                request.autoplay = true;

                session.loadMedia(request, onLoadSuccess, onLoadError);

            }

            function onLoadSuccess() {
                    console.log('Successfully loaded video.');
            }

            function onLoadError(e) {
                    console.log('Failed.', e);
            }

            function onRequestSessionSuccess(e) {

                console.log("Successfully created session: " + e.sessionId);
                session = e;
                loadMedia();

            }

            function onLaunchError() {

                console.log("Error connecting to the Chromecast.");

            }

            function launchApp() {

                console.log("Launching the Chromecast App...");
                chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError);

            }

            // Stop
            function stopApp() {
                session.stop(onStopAppSuccess, onStopAppError);
            }

            function onStopAppSuccess() {
                console.log('Successfully stopped app.');
            }

            function onStopAppError() {
                console.log('Error stopping app.');
            }

            $( document ).ready(function(){

                var loadCastInterval = setInterval(function(){

                    if (chrome.cast.isAvailable) {

                            clearInterval(loadCastInterval);
                            initializeCastApi();

                    } else {
                            console.log('Unavailable');
                    }

                }, 1000);

                $('#castme').click(function(){

                    launchApp();

                });

                $('#stop').click(function(){

                    stopApp();

                });

            });

        </script>
</body>
</html>

Screenshot 2020-10-19 at 17 38 34

samueleastdev commented 3 years ago

Found the issue you should probably update the docs.

This

chromecast: {
      requestTitleFn: function(source) { // Not required
         return titles[source.url];
      },
      requestSubtitleFn: function(source) { // Not required
         return subtitles[source.url];
      },
      requestCustomDataFn: function(source) { // Not required
         return customData[source.url];
      }
   },

Needs to be this.

chromecast: {
      requestTitleFn: function(source) { // Not required
         return titles[source.src];
      },
      requestSubtitleFn: function(source) { // Not required
         return subtitles[source.src];
      },
      requestCustomDataFn: function(source) { // Not required
         return customData[source.src];
      }
   },

Thanks ;)