From aa3527dcb0f8830d0378b3fbcb483aa4595849f8 Mon Sep 17 00:00:00 2001 From: Cat Date: Thu, 19 Jan 2017 13:31:05 +0100 Subject: [PATCH] Embed: custom streaminfo --- embed/core.js | 62 ++++++++++++++++++----------- embed/test.html | 2 + src/output/output_http_internal.cpp | 2 +- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/embed/core.js b/embed/core.js index 1afc71c6..3b7c1fba 100644 --- a/embed/core.js +++ b/embed/core.js @@ -745,12 +745,13 @@ function mistPlay(streamName,options) { var local = options; var global = (typeof mistoptions == 'undefined' ? {} : mistoptions); var options = { - host: null, - autoplay: true, - controls: true, - loop: false, - poster: null, - callback: false + host: null, //override mistserver host (default is the host that player.js is loaded from) + autoplay: true, //start playing when loaded + controls: true, //show controls (MistControls when available) + loop: false, //don't loop when the stream has finished + poster: null, //don't show an image before the stream has started + callback: false, //don't call a function when the player has finished building + streaminfo: false //don't use this streaminfo but collect it from the mistserverhost }; for (var i in global) { options[i] = global[i]; @@ -781,28 +782,12 @@ function mistPlay(streamName,options) { } } - //get info js - var info = document.createElement('script'); - info.src = options.host+'/info_'+encodeURIComponent(streamName)+'.js'; - embedLog('Retrieving stream info from '+info.src); - document.head.appendChild(info); - info.onerror = function(){ - options.target.innerHTML = ''; - options.target.removeAttribute('data-loading'); - mistError('Error while loading stream info.'); - protoplay.report({ - type: 'init', - error: 'Failed to load '+info.src - }); - } - info.onload = function(){ + + function onstreaminfo() { options.target.innerHTML = ''; options.target.removeAttribute('data-loading'); embedLog('Stream info was loaded succesfully'); - //clean up info script - document.head.removeChild(info); - //get streaminfo data var streaminfo = mistvideo[streamName]; //embedLog('Stream info contents: '+JSON.stringify(streaminfo)); @@ -1256,4 +1241,33 @@ function mistPlay(streamName,options) { mistError(str); } } + if ((options.streaminfo) && (typeof options.streaminfo == 'object') && ('type' in options.streaminfo) + && ('source' in options.streaminfo) && (options.streaminfo.source.length) + && ('meta' in options.streaminfo) && ('tracks' in options.streaminfo.meta)) { //catch some of the most problematic stuff + if (typeof mistvideo == 'undefined') { mistvideo = {}; } + mistvideo[streamName] = options.streaminfo; + onstreaminfo(); + } + else { + //get info js + var info = document.createElement('script'); + info.src = options.host+'/info_'+encodeURIComponent(streamName)+'.js'; + embedLog('Retrieving stream info from '+info.src); + document.head.appendChild(info); + info.onerror = function(){ + options.target.innerHTML = ''; + options.target.removeAttribute('data-loading'); + mistError('Error while loading stream info.'); + protoplay.report({ + type: 'init', + error: 'Failed to load '+info.src + }); + } + info.onload = function(){ + //clean up info script + document.head.removeChild(info); + + onstreaminfo(); + } + } } diff --git a/embed/test.html b/embed/test.html index ec097278..5e425698 100644 --- a/embed/test.html +++ b/embed/test.html @@ -85,6 +85,8 @@ //tryplayers.push('html5'); tryplayers.push('dashjs'); //tryplayers.push('videojs'); + tryplayers.push('img'); + //tryplayers.push('dashjs'); //tryplayers.push('flash_strobe'); //tryplayers.push('silverlight'); streams = []; diff --git a/src/output/output_http_internal.cpp b/src/output/output_http_internal.cpp index 43d2247a..d9210010 100644 --- a/src/output/output_http_internal.cpp +++ b/src/output/output_http_internal.cpp @@ -580,7 +580,7 @@ namespace Mist { } if (it->asStringRef() == "img"){ #include "img.js.h" - response.append((char*)img, (size_t)img_len); + response.append((char*)img_js, (size_t)img_js_len); used = true; } if (!used) {