@@ -150,7 +150,7 @@ Channel.prototype.getMediaPresentationApp = function (serviceInstance) {
150150 if ( serviceInstance && serviceInstance . mediaPresentationApps ) {
151151 for ( i = 0 ; i < serviceInstance . mediaPresentationApps . length ; i ++ ) {
152152 mediaPresentationApp = serviceInstance . mediaPresentationApps [ i ] ;
153- if ( mediaPresentationApp . contentType == XML_MIME || mediaPresentationApp . contentType == XHTML_MIMR ) {
153+ if ( mediaPresentationApp . contentType == XML_MIME || mediaPresentationApp . contentType == XHTML_MIME ) {
154154 return mediaPresentationApp . url ;
155155 }
156156 }
@@ -175,6 +175,50 @@ Channel.prototype.checkAvailability = function () {
175175 this . availablityTimer = setTimeout ( this . checkAvailability . bind ( this ) , 60 * 1000 ) ;
176176} ;
177177
178+ function UUIDv7 ( ) {
179+ // see https://stackoverflow.com/questions/71816194/uuidv6-v7-v8-in-javascript-browser
180+ return "tttttttt-tttt-7xxx-yxxx-xxxxxxxxxxxx"
181+ . replace ( / [ x y ] / g, function ( c ) {
182+ const r = Math . trunc ( Math . random ( ) * 16 ) ;
183+ const v = c == "x" ? r : ( r & 0x3 ) | 0x8 ;
184+ return v . toString ( 16 ) ;
185+ } )
186+ . replace ( / ^ [ t ] { 8 } - [ t ] { 4 } / , function ( ) {
187+ const unixtimestamp = Date . now ( ) . toString ( 16 ) . padStart ( 12 , "0" ) ;
188+ return unixtimestamp . slice ( 0 , 8 ) + "-" + unixtimestamp . slice ( 8 ) ;
189+ } ) ;
190+ }
191+
192+ function DASHjsVersion5 ( player ) {
193+ var [ major , minor , micro ] = player . getVersion ( ) . split ( "." ) ;
194+ return major >= 5 ;
195+ }
196+
197+ function playDASH ( player , instance ) {
198+ if ( instance == null ) {
199+ player . updateSettings ( { streaming : { cmcd : { enabled : false } } } ) ;
200+ player . attachSource ( null ) ;
201+ return ;
202+ }
203+
204+ if ( instance . hasOwnProperty ( "CMCDinit" ) && instance . CMCDinit != null ) {
205+ var cmcd_vars = { ...instance . CMCDinit } ;
206+ cmcd_vars . sid = UUIDv7 ( ) ;
207+ if ( DASHjsVersion5 ( player ) ) {
208+ cmcd_vars . applyParametersFromMpd = false ;
209+ cmcd_vars . includeInRequests = [ "segment" , "mpd" ] ;
210+ } else {
211+ delete cmcd_vars . version ;
212+ }
213+ player . updateSettings ( {
214+ streaming : { cmcd : cmcd_vars } ,
215+ } ) ;
216+ } else {
217+ player . updateSettings ( { streaming : { cmcd : { enabled : false } } } ) ;
218+ }
219+ player . attachSource ( instance . dashUrl ) ;
220+ }
221+
178222Channel . prototype . channelSelected = function ( ) {
179223 var self = this ;
180224 $ ( "#notification" ) . hide ( ) ;
@@ -193,9 +237,7 @@ Channel.prototype.channelSelected = function () {
193237 $ ( "#notification" ) . removeClass ( ) ;
194238 $ ( "#notification" ) . addClass ( "noservice" ) ;
195239 if ( self . out_of_service_image ) {
196- $ ( "#notification" ) . html (
197- '<img src="' + self . out_of_service_image . mediaUri + '" class="img-fluid position-relative"/>'
198- ) ;
240+ $ ( "#notification" ) . html ( '<img src="' + self . out_of_service_image . mediaUri + '" class="img-fluid position-relative"/>' ) ;
199241 } else {
200242 $ ( "#notification" ) . text ( "Service not available" ) ;
201243 }
@@ -208,21 +250,21 @@ Channel.prototype.channelSelected = function () {
208250 } else if ( self . isProgramAllowed ( ) ) {
209251 $ ( "#parentalpin" ) . hide ( ) ;
210252 if ( self . serviceInstance ) {
211- player . attachSource ( self . serviceInstance . dashUrl ) ;
253+ playDASH ( player , self . serviceInstance ) ;
212254 }
213255 } else {
214- player . attachSource ( null ) ;
256+ playDASH ( player , null ) ;
215257 checkParentalPIN (
216258 "Enter parental PIN to watch service" ,
217259 function ( ) {
218260 $ ( "#notification" ) . hide ( ) ;
219261 try {
220262 if ( player . getSource ( ) != self . serviceInstance . dashUrl ) {
221- player . attachSource ( self . serviceInstance . dashUrl ) ;
263+ playDASH ( player , self . serviceInstance ) ;
222264 }
223265 } catch ( e ) {
224266 //player throws an error is there is no souce attached
225- player . attachSource ( self . serviceInstance . dashUrl ) ;
267+ playDASH ( player , self . serviceInstance ) ;
226268 }
227269 } ,
228270 function ( ) {
@@ -250,11 +292,11 @@ Channel.prototype.programChanged = function () {
250292 $ ( "#notification" ) . hide ( ) ;
251293 try {
252294 if ( player . getSource ( ) != serviceInstance . dashUrl ) {
253- player . attachSource ( serviceInstance . dashUrl ) ;
295+ playDASH ( player , serviceInstance ) ;
254296 }
255297 } catch ( e ) {
256298 //player throws an error is there is no souce attached
257- player . attachSource ( serviceInstance . dashUrl ) ;
299+ playDASH ( player , serviceInstance ) ;
258300 }
259301 } else {
260302 player . attachSource ( null ) ;
@@ -264,11 +306,11 @@ Channel.prototype.programChanged = function () {
264306 $ ( "#notification" ) . hide ( ) ;
265307 try {
266308 if ( player . getSource ( ) != serviceInstance . dashUrl ) {
267- player . attachSource ( serviceInstance . dashUrl ) ;
309+ playDASH ( player , serviceInstance ) ;
268310 }
269311 } catch ( e ) {
270312 //player throws an error is there is no souce attached
271- player . attachSource ( serviceInstance . dashUrl ) ;
313+ playDASH ( player , serviceInstance ) ;
272314 }
273315 } ,
274316 function ( ) {
@@ -482,11 +524,11 @@ Channel.prototype.parentalRatingChanged = function (callback) {
482524 $ ( "#notification" ) . hide ( ) ;
483525 try {
484526 if ( player . getSource ( ) != serviceInstance . dashUrl ) {
485- player . attachSource ( serviceInstance . dashUrl ) ;
527+ playDASH ( player , serviceInstance ) ;
486528 }
487529 } catch ( e ) {
488- //player throws an error is there is no souce attached
489- player . attachSource ( serviceInstance . dashUrl ) ;
530+ //player throws an error if there is no souce attached
531+ playDASH ( player , serviceInstance ) ;
490532 }
491533 } else {
492534 player . attachSource ( null ) ;
@@ -496,11 +538,11 @@ Channel.prototype.parentalRatingChanged = function (callback) {
496538 $ ( "#notification" ) . hide ( ) ;
497539 try {
498540 if ( player . getSource ( ) != serviceInstance . dashUrl ) {
499- player . attachSource ( serviceInstance . dashUrl ) ;
541+ playDASH ( player , serviceInstance ) ;
500542 }
501543 } catch ( e ) {
502544 //player throws an error is there is no souce attached
503- player . attachSource ( serviceInstance . dashUrl ) ;
545+ playDASH ( player , serviceInstance ) ;
504546 }
505547 } ,
506548 function ( ) {
0 commit comments