-
Notifications
You must be signed in to change notification settings - Fork 0
/
clappr-chromecast-plugin.js
2276 lines (2023 loc) · 75.6 KB
/
clappr-chromecast-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("clappr"));
else if(typeof define === 'function' && define.amd)
define(["clappr"], factory);
else if(typeof exports === 'object')
exports["ChromecastPlugin"] = factory(require("clappr"));
else
root["ChromecastPlugin"] = factory(root["Clappr"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _clappr = __webpack_require__(1);
var _chromecast_playback = __webpack_require__(2);
var _chromecast_playback2 = _interopRequireDefault(_chromecast_playback);
var _publicStyleScss = __webpack_require__(4);
var _publicStyleScss2 = _interopRequireDefault(_publicStyleScss);
var _lodashAssign = __webpack_require__(6);
var _lodashAssign2 = _interopRequireDefault(_lodashAssign);
var _publicIc_cast_24dpSvg = __webpack_require__(17);
var _publicIc_cast_24dpSvg2 = _interopRequireDefault(_publicIc_cast_24dpSvg);
var _publicIc_cast0_24dpSvg = __webpack_require__(18);
var _publicIc_cast0_24dpSvg2 = _interopRequireDefault(_publicIc_cast0_24dpSvg);
var _publicIc_cast1_24dpSvg = __webpack_require__(19);
var _publicIc_cast1_24dpSvg2 = _interopRequireDefault(_publicIc_cast1_24dpSvg);
var _publicIc_cast2_24dpSvg = __webpack_require__(20);
var _publicIc_cast2_24dpSvg2 = _interopRequireDefault(_publicIc_cast2_24dpSvg);
var _publicIc_cast_connected_24dpSvg = __webpack_require__(21);
var _publicIc_cast_connected_24dpSvg2 = _interopRequireDefault(_publicIc_cast_connected_24dpSvg);
var DEVICE_STATE = {
'IDLE': 0,
'ACTIVE': 1,
'WARNING': 2,
'ERROR': 3
};
var DEFAULT_CLAPPR_APP_ID = '9DFB77C0';
var MIMETYPES = {
'mp4': 'video/mp4',
'ogg': 'video/ogg',
'3gpp': 'video/3gpp',
'webm': 'video/webm',
'mkv': 'video/x-matroska',
'm3u8': 'application/x-mpegurl',
'mpd': 'application/dash+xml'
};
MIMETYPES['ogv'] = MIMETYPES['ogg'];
MIMETYPES['3gp'] = MIMETYPES['3gpp'];
var ChromecastPlugin = (function (_UICorePlugin) {
_inherits(ChromecastPlugin, _UICorePlugin);
if (typeof options !== 'undefined' && options !== null && options.hasOwnProperty('property')) {
// Accede a las propiedades de 'options' aquí
console.log(options.property);
} else {
console.log('La variable "options" no está definida o no tiene la propiedad requerida.');
}
_createClass(ChromecastPlugin, [{
key: 'version',
get: function get() {
return ("0.1.2");
}
}, {
key: 'name',
get: function get() {
return 'chromecast';
}
}, {
key: 'tagName',
get: function get() {
return 'button';
}
}, {
key: 'attributes',
get: function get() {
return {
'class': 'chromecast-button',
'type': 'button'
};
}
}, {
key: 'events',
get: function get() {
return {
'click': 'click'
};
}
}, {
key: 'options',
get: function get() {
return this.core.options.chromecast || (this.core.options.chromecast = {});
}
}, {
key: 'container',
get: function get() {
return this.core.getCurrentContainer ? this.core.getCurrentContainer() : this.core.activeContainer; // Clappr 0.3.0 or greater
}
}, {
key: 'playback',
get: function get() {
return this.core.getCurrentPlayback ? this.core.getCurrentPlayback() : this.core.activePlayback; // Clappr 0.3.0 or greater
}
}], [{
key: 'Movie',
get: function get() {
return 'movie';
}
}, {
key: 'TvShow',
get: function get() {
return 'tv_show';
}
}, {
key: 'Generic',
get: function get() {
return 'none';
}
}, {
key: 'version',
get: function get() {
return ("0.1.2");
}
}]);
function ChromecastPlugin(core) {
_classCallCheck(this, ChromecastPlugin);
_get(Object.getPrototypeOf(ChromecastPlugin.prototype), 'constructor', this).call(this, core);
this.bootTryDelay = this.options.bootTryDelay || 500; // Default is 500 milliseconds between each attempt
this.bootMaxTryCount = this.options.bootMaxTryCount || 6; // Default is 6 attempts (3 seconds)
this.bootTryCount = 0;
if (this.isBootable()) {
this.appId = this.options.appId || DEFAULT_CLAPPR_APP_ID;
this.deviceState = DEVICE_STATE.IDLE;
this.embedScript();
} else {
this.disable();
}
}
_createClass(ChromecastPlugin, [{
key: 'bindEvents',
value: function bindEvents() {
this.listenTo(this.core.mediaControl, _clappr.Events.MEDIACONTROL_RENDERED, this.render);
if (_clappr.Events.CORE_ACTIVE_CONTAINER_CHANGED) {
// Clappr 0.3.0 or greater
this.listenTo(this.core, _clappr.Events.CORE_ACTIVE_CONTAINER_CHANGED, this.containerChanged);
} else {
this.listenTo(this.core.mediaControl, _clappr.Events.MEDIACONTROL_CONTAINERCHANGED, this.containerChanged);
}
if (this.container) {
this.listenTo(this.container, _clappr.Events.CONTAINER_TIMEUPDATE, this.containerTimeUpdate);
this.listenTo(this.container, _clappr.Events.CONTAINER_PLAY, this.containerPlay);
this.listenTo(this.container, _clappr.Events.CONTAINER_ENDED, this.sessionStopped);
}
}
}, {
key: 'isBootable',
value: function isBootable() {
// Browser must be Chrome
if (!_clappr.Browser.isChrome) {
return false;
}
// Chrome lesser than or equals to 71
// does not require secure page
if (_clappr.Browser.version <= 71) {
return true;
}
// Chrome greater than or equals to 72
// require secure page or localhost
return this.isSecure() || this.isLocalhost();
}
}, {
key: 'isLocalhost',
value: function isLocalhost() {
return window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
}
}, {
key: 'isSecure',
value: function isSecure() {
return window.location.protocol === 'https:';
}
}, {
key: 'enable',
value: function enable() {
_get(Object.getPrototypeOf(ChromecastPlugin.prototype), 'enable', this).call(this);
this.render();
this.embedScript();
}
}, {
key: 'embedScript',
value: function embedScript() {
var _this = this;
if (!window.chrome || !window.chrome.cast || !window.chrome.cast.isAvailable) {
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('async', 'async');
script.setAttribute('src', 'https://www.gstatic.com/cv/js/sender/v1/cast_sender.js');
script.onload = function () {
return _this.bootstrapCastApi();
};
document.body.appendChild(script);
} else {
this.bootstrapCastApi();
}
}
}, {
key: 'bootstrapCastApi',
value: function bootstrapCastApi() {
var _this2 = this;
this.bootTryCount++;
if (this.bootTryCount > this.bootMaxTryCount) {
this.bootTryCount = 0;
_clappr.Log.warn('GCastApi bootstrap timeout');
this.disable();
return;
}
// The "chrome" property may not be available immediately on some iOS devices
if (window.chrome) {
this.bootTryCount = 0;
if (window.chrome.cast && window.chrome.cast.isAvailable) {
this.appId = this.appId || DEFAULT_CLAPPR_APP_ID;
this.initializeCastApi();
} else {
window['__onGCastApiAvailable'] = function (loaded, errorInfo) {
if (loaded) {
_this2.appId = _this2.appId || DEFAULT_CLAPPR_APP_ID;
_this2.initializeCastApi();
} else {
_clappr.Log.warn('GCastApi error', errorInfo);
_this2.disable();
}
};
}
} else {
setTimeout(function () {
_this2.bootstrapCastApi();
}, this.bootTryDelay);
}
}
}, {
key: 'initializeCastApi',
value: function initializeCastApi() {
var _this3 = this;
var autoJoinPolicy = chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED;
var sessionRequest = new chrome.cast.SessionRequest(this.appId);
var apiConfig = new chrome.cast.ApiConfig(sessionRequest, function (session) {
return _this3.sessionListener(session);
}, function (e) {
return _this3.receiverListener(e);
}, autoJoinPolicy);
chrome.cast.initialize(apiConfig, function () {
return _clappr.Log.debug(_this3.name, 'init success');
}, function () {
return _clappr.Log.warn(_this3.name, 'init error');
});
}
}, {
key: 'sessionListener',
value: function sessionListener(session) {
_clappr.Log.debug(this.name, 'new session id:' + session.sessionId);
this.newSession(session);
}
}, {
key: 'sessionUpdateListener',
value: function sessionUpdateListener() {
if (this.session) {
_clappr.Log.debug(this.name, this.session.status);
if (this.session.status === chrome.cast.SessionStatus.STOPPED) {
this.sessionStopped();
this.session = null;
}
}
}
}, {
key: 'receiverListener',
value: function receiverListener(e) {
if (e === chrome.cast.ReceiverAvailability.AVAILABLE) {
_clappr.Log.debug(this.name, 'receiver found');
this.show();
} else {
_clappr.Log.debug(this.name, 'receiver list empty');
this.hide();
}
}
}, {
key: 'launchSuccess',
value: function launchSuccess(session) {
this.renderConnected();
clearInterval(this.connectAnimInterval);
this.core.mediaControl.resetKeepVisible();
_clappr.Log.debug(this.name, 'launch success - session: ' + session.sessionId);
this.newSession(session);
}
}, {
key: 'launchError',
value: function launchError(e) {
_clappr.Log.debug(this.name, 'error on launch', e);
this.renderDisconnected();
clearInterval(this.connectAnimInterval);
this.core.mediaControl.resetKeepVisible();
this.container.play();
}
}, {
key: 'loadMediaSuccess',
value: function loadMediaSuccess(how, mediaSession) {
_clappr.Log.debug(this.name, 'new media session', mediaSession, '(', how, ')');
this.originalPlayback = this.playback;
var options = (0, _lodashAssign2['default'])({}, this.originalPlayback.options, {
currentMedia: mediaSession,
mediaControl: this.core.mediaControl,
poster: this.options.poster || this.core.options.poster,
settings: this.originalPlayback.settings
});
this.src = this.originalPlayback.src;
this.playbackProxy = new _chromecast_playback2['default'](options);
this.playbackProxy.render();
this.core.$el.addClass('chromecast-active');
this.mediaSession = mediaSession;
this.originalPlayback.$el.remove();
var container = this.container;
container.$el.append(this.playbackProxy.$el);
container.stopListening();
container.playback = this.playbackProxy;
container.bindEvents();
container.settingsUpdate();
}
}, {
key: 'loadMediaError',
value: function loadMediaError(e) {
_clappr.Log.warn(this.name, 'media error', e);
}
}, {
key: 'newSession',
value: function newSession(session) {
var _this4 = this;
this.session = session;
this.deviceState = DEVICE_STATE.ACTIVE;
this.renderConnected();
session.addUpdateListener(function () {
return _this4.sessionUpdateListener();
});
this.containerPlay();
}
}, {
key: 'sessionStopped',
value: function sessionStopped() {
this.renderDisconnected();
var time = this.currentTime;
var playerState = undefined;
if (this.mediaSession) {
playerState = this.mediaSession.playerState;
this.mediaSession = null;
}
this.core.$el.removeClass('chromecast-active');
this.core.load(this.src || this.core.options.sources);
var container = this.container;
if (this.playbackProxy) {
if (this.playbackProxy.isPlaying() || playerState === 'PAUSED') {
container.once(_clappr.Events.CONTAINER_READY, function () {
container.play();
container.playback.seek(100 * time / container.getDuration());
});
}
this.playbackProxy.stop();
}
}
}, {
key: 'loadMedia',
value: function loadMedia() {
var _this5 = this;
this.container.pause();
var src = this.container.options.src;
_clappr.Log.debug(this.name, 'loading... ' + src);
var mediaInfo = this.createMediaInfo(src);
var request = new chrome.cast.media.LoadRequest(mediaInfo);
request.autoplay = true;
if (this.currentTime) {
request.currentTime = this.currentTime;
}
this.session.loadMedia(request, function (mediaSession) {
return _this5.loadMediaSuccess('loadMedia', mediaSession);
}, function (e) {
return _this5.loadMediaError(e);
});
}
}, {
key: 'createMediaInfo',
value: function createMediaInfo(src) {
var mimeType = ChromecastPlugin.mimeTypeFor(src);
var mediaInfo = new chrome.cast.media.MediaInfo(src);
mediaInfo.contentType = this.options.contentType || mimeType;
mediaInfo.customData = this.options.customData;
var metadata = this.createMediaMetadata();
mediaInfo.metadata = metadata;
return mediaInfo;
}
}, {
key: 'createMediaMetadata',
value: function createMediaMetadata() {
this.options.media || (this.options.media = {});
var type = this.options.media.type;
var metadata = this.createCastMediaMetadata(type);
metadata.title = this.options.media.title;
metadata.subtitle = this.options.media.subtitle;
metadata.releaseDate = this.options.media.releaseDate;
if (type === ChromecastPlugin.TvShow) {
metadata.episode = this.options.media.episode;
metadata.originalAirdate = this.options.media.originalAirdate;
metadata.season = this.options.media.season;
metadata.seriesTitle = this.options.media.seriesTitle;
} else if (type === ChromecastPlugin.Movie) {
metadata.studio = this.options.media.studio;
}
if (this.options.media.images) {
metadata.images = this.options.media.images.map(function (url) {
return new chrome.cast.Image(url);
});
}
if (!metadata.images && this.options.poster) {
metadata.images = [new chrome.cast.Image(this.options.poster)];
}
if (!metadata.images && this.core.options.poster) {
metadata.images = [new chrome.cast.Image(this.core.options.poster)];
}
return metadata;
}
}, {
key: 'createCastMediaMetadata',
value: function createCastMediaMetadata(type) {
switch (type) {
case ChromecastPlugin.Movie:
return new chrome.cast.media.MovieMediaMetadata();
case ChromecastPlugin.TvShow:
return new chrome.cast.media.TvShowMediaMetadata();
default:
return new chrome.cast.media.GenericMediaMetadata();
}
}
}, {
key: 'show',
value: function show() {
this.$el.show();
}
}, {
key: 'hide',
value: function hide() {
this.$el.hide();
}
}, {
key: 'click',
value: function click() {
var _this6 = this;
this.currentTime = this.container.getCurrentTime();
this.container.pause();
chrome.cast.requestSession(function (session) {
return _this6.launchSuccess(session);
}, function (e) {
return _this6.launchError(e);
});
if (!this.session) {
(function () {
var position = 0;
var connectingIcons = [_publicIc_cast0_24dpSvg2['default'], _publicIc_cast1_24dpSvg2['default'], _publicIc_cast2_24dpSvg2['default']];
clearInterval(_this6.connectAnimInterval);
_this6.connectAnimInterval = setInterval(function () {
_this6.$el.html(connectingIcons[position]);
position = (position + 1) % 3;
}, 600);
_this6.core.mediaControl.setKeepVisible();
})();
}
}
}, {
key: 'containerChanged',
value: function containerChanged() {
this.stopListening();
this.bindEvents();
}
}, {
key: 'containerTimeUpdate',
value: function containerTimeUpdate(timeProgress) {
this.currentTime = timeProgress.current;
}
}, {
key: 'containerPlay',
value: function containerPlay() {
if (this.session && (!this.mediaSession || this.mediaSession.playerState === 'IDLE' || this.mediaSession.playerState === 'PAUSED')) {
_clappr.Log.debug(this.name, 'load media');
this.loadMedia();
}
}
}, {
key: 'renderConnected',
value: function renderConnected() {
this.$el.html(_publicIc_cast_connected_24dpSvg2['default']);
}
}, {
key: 'renderDisconnected',
value: function renderDisconnected() {
this.$el.html(_publicIc_cast_24dpSvg2['default']);
}
}, {
key: 'render',
value: function render() {
this.session ? this.renderConnected() : this.renderDisconnected();
this.core.mediaControl.$el.find('.media-control-right-panel[data-media-control]').append(this.$el);
this.$style && this.$style.remove();
this.$style = _clappr.Styler.getStyleFor(_publicStyleScss2['default'], { baseUrl: this.core.options.baseUrl });
this.core.$el.append(this.$style);
return this;
}
}], [{
key: 'mimeTypeFor',
value: function mimeTypeFor(srcUrl) {
var extension = (srcUrl.split('?')[0].match(/.*\.(.*)$/) || [])[1];
if (MIMETYPES[extension]) {
return MIMETYPES[extension];
} else if (srcUrl.indexOf('.ism') > -1) {
return 'application/vnd.ms-sstr+xml';
}
}
}]);
return ChromecastPlugin;
})(_clappr.UICorePlugin);
exports['default'] = ChromecastPlugin;
module.exports = exports['default'];
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _clappr = __webpack_require__(1);
var _publicChromecastHtml = __webpack_require__(3);
var _publicChromecastHtml2 = _interopRequireDefault(_publicChromecastHtml);
var TICK_INTERVAL = 100;
var ChromecastPlayback = (function (_Playback) {
_inherits(ChromecastPlayback, _Playback);
_createClass(ChromecastPlayback, [{
key: 'name',
get: function get() {
return 'chromecast_playback';
}
}, {
key: 'template',
get: function get() {
return (0, _clappr.template)(_publicChromecastHtml2['default']);
}
}, {
key: 'attributes',
get: function get() {
return { 'class': 'chromecast-playback' };
}
}, {
key: 'isReady',
get: function get() {
return true;
}
}]);
function ChromecastPlayback(options) {
var _this = this;
_classCallCheck(this, ChromecastPlayback);
_get(Object.getPrototypeOf(ChromecastPlayback.prototype), 'constructor', this).call(this, options);
this.src = options.src;
this.currentMedia = options.currentMedia;
this.mediaControl = options.mediaControl;
this.currentMedia.addUpdateListener(function () {
return _this.onMediaStatusUpdate();
});
this.settings = options.settings;
var noVolume = function noVolume(name) {
return name != 'volume';
};
this.settings['default'] && (this.settings['default'] = this.settings['default'].filter(noVolume));
this.settings.left && (this.settings.left = this.settings.left.filter(noVolume));
this.settings.right && (this.settings.right = this.settings.right.filter(noVolume));
}
_createClass(ChromecastPlayback, [{
key: 'render',
value: function render() {
var template = this.template();
this.$el.html(template);
if (this.options.poster) {
this.$('.chromecast-playback-background').css('background-image', 'url(' + this.options.poster + ')');
} else {
this.$('.chromecast-playback-background').css('background-color', '#666');
}
}
}, {
key: 'play',
value: function play() {
this.currentMedia.play();
}
}, {
key: 'pause',
value: function pause() {
this.stopTimer();
this.currentMedia.pause();
if (this.getPlaybackType() === _clappr.Playback.LIVE) {
this.trigger(_clappr.Events.PLAYBACK_DVR, true);
}
}
}, {
key: 'stop',
value: function stop() {
this.stopTimer();
this.currentMedia.pause(); // FIXME: properly handle media stop
}
}, {
key: 'seek',
value: function seek(time) {
var _this2 = this;
this.stopTimer();
var request = new chrome.cast.media.SeekRequest();
request.currentTime = time;
this.currentMedia.seek(request, function () {
return _this2.startTimer();
}, function () {
return _clappr.Log.warn('seek failed');
});
if (this.getPlaybackType() === _clappr.Playback.LIVE) {
// assume live if time within 30 seconds of end of live stream
this.trigger(_clappr.Events.PLAYBACK_DVR, time < this.getDuration() - 30);
}
}
}, {
key: 'seekPercentage',
value: function seekPercentage(percentage) {
if (percentage >= 0 && percentage <= 100) {
var duration = this.getDuration();
this.seek(percentage * duration / 100);
}
}
}, {
key: 'startTimer',
value: function startTimer() {
var _this3 = this;
this.timer = setInterval(function () {
return _this3.updateMediaControl();
}, TICK_INTERVAL);
}
}, {
key: 'stopTimer',
value: function stopTimer() {
clearInterval(this.timer);
this.timer = null;
}
}, {
key: 'getDuration',
value: function getDuration() {
return this.currentMedia.media.duration;
}
}, {
key: 'isPlaying',
value: function isPlaying() {
return this.currentMedia.playerState === 'PLAYING' || this.currentMedia.playerState === 'BUFFERING';
}
}, {
key: 'getPlaybackType',
value: function getPlaybackType() {
return !!this.currentMedia.liveSeekableRange ? _clappr.Playback.LIVE : _clappr.Playback.VOD; // eslint-disable-line no-extra-boolean-cast
}
}, {
key: 'onMediaStatusUpdate',
value: function onMediaStatusUpdate() {
this.mediaControl.changeTogglePlay();
if (this.isPlaying() && !this.timer) {
this.startTimer();
}
if (this.currentMedia.playerState === 'BUFFERING') {
this.isBuffering = true;
this.trigger(_clappr.Events.PLAYBACK_BUFFERING, this.name);
} else if (this.currentMedia.playerState === 'PLAYING') {
if (this.isBuffering) {
this.isBuffering = false;
this.trigger(_clappr.Events.PLAYBACK_BUFFERFULL, this.name);
}
if (this.prevState !== this.currentMedia.playerState) {
this.trigger(_clappr.Events.PLAYBACK_PLAY, this.name);
}
} else if (this.currentMedia.playerState === 'IDLE') {
if (this.isBuffering) {
this.isBuffering = false;
this.trigger(_clappr.Events.PLAYBACK_BUFFERFULL, this.name);
}
this.trigger(_clappr.Events.PLAYBACK_ENDED, this.name);
} else if (this.currentMedia.playerState === 'PAUSED') {
if (this.prevState !== this.currentMedia.playerState) {
this.trigger(_clappr.Events.PLAYBACK_PAUSE, this.name);
}
}
this.prevState = this.currentMedia.playerState;
}
}, {
key: 'updateMediaControl',
value: function updateMediaControl() {
var position = this.currentMedia.getEstimatedTime();
var duration = this.currentMedia.media.duration;
this.trigger(_clappr.Events.PLAYBACK_TIMEUPDATE, { current: position, total: duration }, this.name);
}
}, {
key: 'show',
value: function show() {
this.$el.show();
}
}, {
key: 'hide',
value: function hide() {
this.$el.hide();
}
}]);
return ChromecastPlayback;
})(_clappr.Playback);
exports['default'] = ChromecastPlayback;
module.exports = exports['default'];
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = "<div class=chromecast-playback-background></div><div class=chromecast-playback-overlay></div>";
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(5)();
// imports
// module
exports.push([module.id, ".chromecast-playback {\n height: 100%;\n width: 100%; }\n .chromecast-playback .chromecast-playback-background, .chromecast-playback .chromecast-playback-overlay {\n position: absolute;\n height: 100%;\n width: 100%; }\n .chromecast-playback .chromecast-playback-background {\n background-size: contain; }\n .chromecast-playback .chromecast-playback-overlay {\n background-color: #000;\n opacity: 0.4; }\n\n.chromecast-button {\n background: transparent;\n border: 0;\n width: 32px;\n height: 32px;\n font-size: 22px;\n line-height: 32px;\n letter-spacing: 0;\n margin: 0 6px;\n color: #fff;\n opacity: 0.5;\n vertical-align: middle;\n text-align: left;\n cursor: pointer;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n -webkit-transition: all 0.1s ease;\n -moz-transition: all 0.1s ease;\n -o-transition: all 0.1s ease;\n transition: all 0.1s ease; }\n .chromecast-button:hover {\n opacity: 0.75;\n text-shadow: rgba(255, 255, 255, 0.8) 0 0 5px; }\n .chromecast-button:focus {\n outline: none; }\n .chromecast-button svg {\n width: 24px;\n height: 24px; }\n .chromecast-button svg #cast, .chromecast-button svg #cast-on, .chromecast-button svg #Path {\n fill: #fff;\n stroke: #fff;\n stroke-width: 0.5px; }\n", ""]);
// exports
/***/ }),
/* 5 */
/***/ (function(module, exports) {
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
// css base code, injected by the css-loader
module.exports = function() {
var list = [];
// return the list of modules as css string
list.toString = function toString() {
var result = [];
for(var i = 0; i < this.length; i++) {
var item = this[i];
if(item[2]) {
result.push("@media " + item[2] + "{" + item[1] + "}");
} else {
result.push(item[1]);
}
}
return result.join("");
};
// import a list of modules into the list
list.i = function(modules, mediaQuery) {
if(typeof modules === "string")
modules = [[null, modules, ""]];
var alreadyImportedModules = {};
for(var i = 0; i < this.length; i++) {
var id = this[i][0];
if(typeof id === "number")
alreadyImportedModules[id] = true;
}
for(i = 0; i < modules.length; i++) {
var item = modules[i];
// skip already imported module
// this implementation is not 100% perfect for weird media query combinations
// when a module is imported multiple times with different media queries.
// I hope this will never occur (Hey this way we have smaller bundles)
if(typeof item[0] !== "number" || !alreadyImportedModules[item[0]]) {
if(mediaQuery && !item[2]) {
item[2] = mediaQuery;
} else if(mediaQuery) {
item[2] = "(" + item[2] + ") and (" + mediaQuery + ")";
}
list.push(item);
}
}
};
return list;
};
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
/**
* lodash 3.2.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/
var baseAssign = __webpack_require__(7),
createAssigner = __webpack_require__(13),
keys = __webpack_require__(9);
/**
* A specialized version of `_.assign` for customizing assigned values without
* support for argument juggling, multiple sources, and `this` binding `customizer`
* functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} customizer The function to customize assigned values.
* @returns {Object} Returns `object`.
*/
function assignWith(object, source, customizer) {
var index = -1,
props = keys(source),
length = props.length;
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) ||
(value === undefined && !(key in object))) {
object[key] = result;
}
}
return object;
}
/**
* Assigns own enumerable properties of source object(s) to the destination
* object. Subsequent sources overwrite property assignments of previous sources.
* If `customizer` is provided it is invoked to produce the assigned values.
* The `customizer` is bound to `thisArg` and invoked with five arguments:
* (objectValue, sourceValue, key, object, source).
*
* **Note:** This method mutates `object` and is based on
* [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign).
*
* @static
* @memberOf _
* @alias extend
* @category Object
* @param {Object} object The destination object.
* @param {...Object} [sources] The source objects.