@mux/mux-player 0.1.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +281 -0
  2. package/LICENSE +9 -0
  3. package/README.md +231 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +87 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +161 -0
  8. package/coverage/lcov-report/prettify.css +1 -0
  9. package/coverage/lcov-report/prettify.js +2 -0
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +196 -0
  12. package/coverage/lcov-report/src/dialog.ts.html +247 -0
  13. package/coverage/lcov-report/src/errors.ts.html +574 -0
  14. package/coverage/lcov-report/src/helpers.ts.html +478 -0
  15. package/coverage/lcov-report/src/html.ts.html +580 -0
  16. package/coverage/lcov-report/src/index.html +251 -0
  17. package/coverage/lcov-report/src/index.ts.html +2941 -0
  18. package/coverage/lcov-report/src/logger.ts.html +163 -0
  19. package/coverage/lcov-report/src/media-chrome/dialog.ts.html +661 -0
  20. package/coverage/lcov-report/src/media-chrome/index.html +131 -0
  21. package/coverage/lcov-report/src/media-chrome/time-display.ts.html +295 -0
  22. package/coverage/lcov-report/src/media-theme-mux/icons/airplay.svg.html +109 -0
  23. package/coverage/lcov-report/src/media-theme-mux/icons/captions-off.svg.html +100 -0
  24. package/coverage/lcov-report/src/media-theme-mux/icons/captions-on.svg.html +100 -0
  25. package/coverage/lcov-report/src/media-theme-mux/icons/fullscreen-enter.svg.html +100 -0
  26. package/coverage/lcov-report/src/media-theme-mux/icons/fullscreen-exit.svg.html +100 -0
  27. package/coverage/lcov-report/src/media-theme-mux/icons/index.html +326 -0
  28. package/coverage/lcov-report/src/media-theme-mux/icons/pause.svg.html +100 -0
  29. package/coverage/lcov-report/src/media-theme-mux/icons/pip-enter.svg.html +100 -0
  30. package/coverage/lcov-report/src/media-theme-mux/icons/pip-exit.svg.html +100 -0
  31. package/coverage/lcov-report/src/media-theme-mux/icons/play.svg.html +100 -0
  32. package/coverage/lcov-report/src/media-theme-mux/icons/seek-backward.svg.html +124 -0
  33. package/coverage/lcov-report/src/media-theme-mux/icons/seek-forward.svg.html +124 -0
  34. package/coverage/lcov-report/src/media-theme-mux/icons/volume-high.svg.html +103 -0
  35. package/coverage/lcov-report/src/media-theme-mux/icons/volume-low.svg.html +103 -0
  36. package/coverage/lcov-report/src/media-theme-mux/icons/volume-medium.svg.html +103 -0
  37. package/coverage/lcov-report/src/media-theme-mux/icons/volume-off.svg.html +103 -0
  38. package/coverage/lcov-report/src/media-theme-mux/icons.ts.html +184 -0
  39. package/coverage/lcov-report/src/media-theme-mux/index.html +146 -0
  40. package/coverage/lcov-report/src/media-theme-mux/media-theme-mux.ts.html +1279 -0
  41. package/coverage/lcov-report/src/media-theme-mux/styles.css.html +586 -0
  42. package/coverage/lcov-report/src/styles.css.html +211 -0
  43. package/coverage/lcov-report/src/template.ts.html +463 -0
  44. package/coverage/lcov-report/src/utils.ts.html +385 -0
  45. package/coverage/lcov-report/src/video-api.ts.html +979 -0
  46. package/coverage/lcov.info +4058 -0
  47. package/dist/index.cjs.js +1432 -0
  48. package/dist/index.mjs +709 -0
  49. package/dist/mux-player.js +1478 -0
  50. package/dist/mux-player.mjs +1478 -0
  51. package/dist/tsconfig.tsbuildinfo +1 -0
  52. package/dist/types/dialog.d.ts +6 -0
  53. package/dist/types/errors.d.ts +6 -0
  54. package/dist/types/helpers.d.ts +26 -0
  55. package/dist/types/html.d.ts +18 -0
  56. package/dist/types/index.d.ts +199 -0
  57. package/dist/types/logger.d.ts +5 -0
  58. package/dist/types/media-chrome/dialog.d.ts +12 -0
  59. package/dist/types/media-chrome/time-display.d.ts +9 -0
  60. package/dist/types/media-theme-mux/icons.d.ts +15 -0
  61. package/dist/types/media-theme-mux/media-theme-mux.d.ts +29 -0
  62. package/dist/types/template.d.ts +5 -0
  63. package/dist/types/utils.d.ts +10 -0
  64. package/dist/types/video-api.d.ts +64 -0
  65. package/dist/types-ts3.4/dialog.d.ts +6 -0
  66. package/dist/types-ts3.4/errors.d.ts +6 -0
  67. package/dist/types-ts3.4/helpers.d.ts +26 -0
  68. package/dist/types-ts3.4/html.d.ts +18 -0
  69. package/dist/types-ts3.4/index.d.ts +180 -0
  70. package/dist/types-ts3.4/logger.d.ts +5 -0
  71. package/dist/types-ts3.4/media-chrome/dialog.d.ts +12 -0
  72. package/dist/types-ts3.4/media-chrome/time-display.d.ts +9 -0
  73. package/dist/types-ts3.4/media-theme-mux/icons.d.ts +15 -0
  74. package/dist/types-ts3.4/media-theme-mux/media-theme-mux.d.ts +29 -0
  75. package/dist/types-ts3.4/template.d.ts +5 -0
  76. package/dist/types-ts3.4/utils.d.ts +10 -0
  77. package/dist/types-ts3.4/video-api.d.ts +53 -0
  78. package/lang/en.json +32 -0
  79. package/lang/nl.json +31 -0
  80. package/package.json +107 -0
  81. package/src/dialog.ts +54 -0
  82. package/src/errors.ts +163 -0
  83. package/src/helpers.ts +131 -0
  84. package/src/html.ts +165 -0
  85. package/src/index.ts +952 -0
  86. package/src/logger.ts +26 -0
  87. package/src/media-chrome/dialog.ts +192 -0
  88. package/src/media-chrome/time-display.ts +70 -0
  89. package/src/media-theme-mux/icons/airplay.svg +8 -0
  90. package/src/media-theme-mux/icons/captions-off.svg +5 -0
  91. package/src/media-theme-mux/icons/captions-on.svg +5 -0
  92. package/src/media-theme-mux/icons/fullscreen-enter.svg +5 -0
  93. package/src/media-theme-mux/icons/fullscreen-exit.svg +5 -0
  94. package/src/media-theme-mux/icons/pause.svg +5 -0
  95. package/src/media-theme-mux/icons/pip-enter.svg +5 -0
  96. package/src/media-theme-mux/icons/pip-exit.svg +5 -0
  97. package/src/media-theme-mux/icons/play.svg +5 -0
  98. package/src/media-theme-mux/icons/seek-backward.svg +13 -0
  99. package/src/media-theme-mux/icons/seek-forward.svg +13 -0
  100. package/src/media-theme-mux/icons/volume-high.svg +6 -0
  101. package/src/media-theme-mux/icons/volume-low.svg +6 -0
  102. package/src/media-theme-mux/icons/volume-medium.svg +6 -0
  103. package/src/media-theme-mux/icons/volume-off.svg +6 -0
  104. package/src/media-theme-mux/icons.ts +33 -0
  105. package/src/media-theme-mux/media-theme-mux.ts +398 -0
  106. package/src/media-theme-mux/styles.css +167 -0
  107. package/src/styles.css +42 -0
  108. package/src/template.ts +126 -0
  109. package/src/types.d.ts +52 -0
  110. package/src/utils.ts +100 -0
  111. package/src/video-api.ts +298 -0
  112. package/test/errors.test.js +169 -0
  113. package/test/helpers.test.js +78 -0
  114. package/test/player.test.js +696 -0
  115. package/test/template.test.js +70 -0
  116. package/test/utils.test.js +21 -0
  117. package/test/web-test-runner.config.mjs +29 -0
  118. package/tsconfig.json +21 -0
@@ -0,0 +1,169 @@
1
+ import { fixture, assert } from '@open-wc/testing';
2
+ import { MediaError } from '../src/index.ts';
3
+ import { getErrorLogs } from '../src/errors.ts';
4
+
5
+ describe('errors', () => {
6
+ it("doesn't propagate non-fatal error events", async function () {
7
+ this.timeout(5000);
8
+
9
+ const player = await fixture(`<mux-player
10
+ playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"
11
+ stream-type="on-demand"
12
+ muted
13
+ ></mux-player>`);
14
+
15
+ let fired;
16
+ player.addEventListener('error', () => {
17
+ fired = true;
18
+ });
19
+
20
+ player.media.dispatchEvent(
21
+ new CustomEvent('error', {
22
+ detail: { code: 0, data: {} },
23
+ })
24
+ );
25
+
26
+ assert(fired !== true, 'the error handler was not fired');
27
+ });
28
+
29
+ it('does propagate fatal error events', async function () {
30
+ const player = await fixture(`<mux-player
31
+ playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"
32
+ stream-type="on-demand"
33
+ muted
34
+ ></mux-player>`);
35
+
36
+ let fired;
37
+ player.addEventListener('error', () => {
38
+ fired = true;
39
+ });
40
+
41
+ player.media.dispatchEvent(
42
+ new CustomEvent('error', {
43
+ detail: { code: MediaError.MEDIA_ERR_DECODE, fatal: true },
44
+ })
45
+ );
46
+
47
+ assert(fired === true, 'the error handler was fired');
48
+ });
49
+
50
+ it('default message for MediaError.MEDIA_ERR_ABORTED', function () {
51
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_ABORTED);
52
+ const { dialog } = getErrorLogs(error);
53
+ assert.equal(dialog.message, 'You aborted the media playback');
54
+ });
55
+
56
+ it('default message for MediaError.MEDIA_ERR_NETWORK', function () {
57
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_NETWORK);
58
+ const { dialog } = getErrorLogs(error);
59
+ assert.equal(dialog.title, 'Network Error');
60
+ assert.equal(dialog.message, 'A network error caused the media download to fail.');
61
+ });
62
+
63
+ it('default message for MediaError.MEDIA_ERR_DECODE', function () {
64
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_DECODE);
65
+ const { dialog } = getErrorLogs(error);
66
+ assert.equal(dialog.title, 'Media Error');
67
+ assert.equal(
68
+ dialog.message,
69
+ 'A media error caused playback to be aborted. The media could be corrupt or your browser does not support this format.'
70
+ );
71
+ });
72
+
73
+ it('default title for MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED', function () {
74
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED);
75
+ const { dialog } = getErrorLogs(error);
76
+ assert.equal(dialog.title, 'Source Not Supported');
77
+ });
78
+
79
+ it('default title for any error', function () {
80
+ const error = new MediaError(undefined, 0);
81
+ const { dialog } = getErrorLogs(error);
82
+ assert.equal(dialog.title, 'Error');
83
+ });
84
+
85
+ it('offline error logs', function () {
86
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_DECODE);
87
+ const offline = true;
88
+ const { dialog } = getErrorLogs(error, offline);
89
+ assert.equal(dialog.title, 'Your device appears to be offline');
90
+ assert.equal(dialog.message, 'Check your internet connection and try reloading this video.');
91
+ });
92
+
93
+ it('412 response code message for MediaError.MEDIA_ERR_NETWORK', function () {
94
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_NETWORK);
95
+ error.data = { response: { code: 412 } };
96
+
97
+ const { dialog } = getErrorLogs(error);
98
+ assert.equal(String(dialog.message), 'The live stream or video file are not yet ready.');
99
+ });
100
+
101
+ it('404 response code message for MediaError.MEDIA_ERR_NETWORK', function () {
102
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_NETWORK);
103
+ error.data = { response: { code: 404 } };
104
+
105
+ const { dialog } = getErrorLogs(error);
106
+ assert.equal(String(dialog.message), '');
107
+ });
108
+
109
+ it('403 response code message for MediaError.MEDIA_ERR_NETWORK', function () {
110
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_NETWORK);
111
+ error.data = { response: { code: 403 } };
112
+
113
+ const { dialog, devlog } = getErrorLogs(error);
114
+ assert.equal(String(dialog.title), 'Invalid playback URL');
115
+ assert.equal(
116
+ String(dialog.message),
117
+ 'The video URL or playback-token are formatted with incorrect or incomplete information.'
118
+ );
119
+ assert.equal(
120
+ String(devlog.message),
121
+ '403 error trying to access this playback URL. If this is a signed URL, you might need to provide a playback-token.'
122
+ );
123
+ });
124
+
125
+ it('403 response code message w/ expired token for MediaError.MEDIA_ERR_NETWORK', function () {
126
+ const playbackId = 'bzeU5fRA47S01KDzrObYiiZvzj00j5E00dCVbt3oRzmfF00';
127
+ const playbackToken =
128
+ 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik96VU90ek1nUWhPbkk2MDJ6SlFQbU52THR4MDBnSjJqTlBxN0tTTzAxQlozelEifQ.eyJleHAiOjE2NDgwNzY0MDQsImF1ZCI6InYiLCJzdWIiOiJiemVVNWZSQTQ3UzAxS0R6ck9iWWlpWnZ6ajAwajVFMDBkQ1ZidDNvUnptZkYwMCJ9.kNn4tWOCffu01tIEw8AtWPtkuAGQrE3K33CyEhG54l4S8JaNRJvrxZNP_zbp42vHPtoa8GbsvQ3DogHUeoQYVOnFObpakhkoRmuA5sNXcDEtKWh_t20fJ84ZED_LOj2LBIrlXabeb3oZoprPWs3ovDVh8nJrm-GC90rfA4twMqDwKNSE0ZTt9O1mYjJ0ZyyFqqyMnY-gkOg8db7OJV-flKwEDSYK8VkwARz1kxIJKSslQt_9QT8is3CyL3m5Hp1NozgRdJ55-9KO-K6vmdla6GDFnAcChGT6AFI_MWKHsQWcJtaZQ3vZLKkZUR29ZYpmxkigxzuu2XK8OvY070NXJg';
129
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_NETWORK);
130
+ error.data = { response: { code: 403 } };
131
+
132
+ const { dialog, devlog } = getErrorLogs(error, false, playbackId, playbackToken);
133
+ assert.equal(String(dialog.title), 'Video URL has expired');
134
+ assert.equal(String(dialog.message), 'The video’s secured playback-token has expired.');
135
+ assert.include(
136
+ String(devlog.message),
137
+ 'This playback is using signed URLs and the playback-token has expired. Expired at:'
138
+ );
139
+ });
140
+
141
+ it('403 response code message w/ playback id mismatch for MediaError.MEDIA_ERR_NETWORK', function () {
142
+ const playbackId = 'bos2bPV3qbFgpVPaQ900Xd5UcdM6WXTmz02WZSz01nJ00tY_blabla';
143
+ const playbackToken =
144
+ 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik96VU90ek1nUWhPbkk2MDJ6SlFQbU52THR4MDBnSjJqTlBxN0tTTzAxQlozelEifQ.eyJleHAiOjE5NjE2MDE2MjgsImF1ZCI6InYiLCJzdWIiOiJib3MyYlBWM3FiRmdwVlBhUTkwMFhkNVVjZE02V1hUbXowMldaU3owMW5KMDB0WSJ9.OUegJAmrlvD9BhzUhogrup_mYRBYNG2ocqmJZK2lKPLFmP1jLKi99Lj_9ZQqIXgmoYeXo2jKr3WFMO8nbGwtZFKU2_szq1EWlj4mBgdWXfAP5amC92qkm87nIuNFM2WVANGlBksmj8uOmYNIuPh1Ctti1qiJEYkf-JthWFFpaR_2TlQJ7g0bmRPzk3nOPDtqZnJBfTVm3n4Kp7Cr27a_VBA6zpoW6DwjJ6_uPkm6TAxXjw7VWNd3YVLs7S_jgs8q3t9DPpAN57q94syVQtEUkRh4tlDX-gdIrJDi9nFB1fIBh45pD01PvrAWzZXKKE9YSW7dnktqSUy81kcu2F_gXA';
145
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_NETWORK);
146
+ error.data = { response: { code: 403 } };
147
+
148
+ const { dialog, devlog } = getErrorLogs(error, false, playbackId, playbackToken);
149
+ assert.equal(String(dialog.title), 'Video URL is formatted incorrectly');
150
+ assert.equal(
151
+ String(dialog.message),
152
+ 'The video’s playback ID does not match the one encoded in the playback-token.'
153
+ );
154
+ assert.include(String(devlog.message), 'and the playback ID encoded in the playback-token');
155
+ });
156
+
157
+ it('403 response code message w/ token type mismatch for MediaError.MEDIA_ERR_NETWORK', function () {
158
+ const playbackId = 'bos2bPV3qbFgpVPaQ900Xd5UcdM6WXTmz02WZSz01nJ00tY';
159
+ const playbackToken =
160
+ 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik96VU90ek1nUWhPbkk2MDJ6SlFQbU52THR4MDBnSjJqTlBxN0tTTzAxQlozelEifQ.eyJleHAiOjE5NjE2MDE3MzYsImF1ZCI6InQiLCJzdWIiOiJib3MyYlBWM3FiRmdwVlBhUTkwMFhkNVVjZE02V1hUbXowMldaU3owMW5KMDB0WSJ9.gDe_efqmRB5E3e4ag6in8MfMK-Vn3c_3B4M-BiWw6lg2aaf2BOTv7ltxhn2cvg4G0iFi-esRjhDlHbMRTxwTGavsx8TRLFtJ8vyBzToaFQbQMrn9OZztq_XrCEwqkD8bUAVtdOT1YB606OZyy6XO-CxdMRrKMUsM-cGrfv0TxvzJjThJBY4SzFv_whtYRxqAypZojROU7IiTbqcsk_cSrRMjB7WyAOAvyPNKnr6RkVEuMJtlCtaf_e4DIJHebZUZb3JmVTG4jIWrD1QkN7uLUwCPPRvGhXwhet9JaJPyC5lmkcb9YmH-15V6GOpwSg7sDMGC3YS4aIb_RtVkan0t-w';
161
+ const error = new MediaError(undefined, MediaError.MEDIA_ERR_NETWORK);
162
+ error.data = { response: { code: 403 } };
163
+
164
+ const { dialog, devlog } = getErrorLogs(error, false, playbackId, playbackToken);
165
+ assert.equal(String(dialog.title), 'Video URL is formatted incorrectly');
166
+ assert.equal(String(dialog.message), 'The playback-token is formatted with incorrect information.');
167
+ assert.include(String(devlog.message), 'The playback-token has an incorrect aud value: ');
168
+ });
169
+ });
@@ -0,0 +1,78 @@
1
+ import { assert } from '@open-wc/testing';
2
+ import { getSrcFromPlaybackId, getPosterURLFromPlaybackId, getStoryboardURLFromPlaybackId } from '../src/helpers.ts';
3
+
4
+ describe('helpers', () => {
5
+ describe('getSrcFromPlaybackId', () => {
6
+ it('with no token', () => {
7
+ assert.equal(getSrcFromPlaybackId('12345'), 'https://stream.mux.com/12345.m3u8?redundant_streams=true');
8
+ });
9
+
10
+ it('with a token', () => {
11
+ assert.equal(
12
+ getSrcFromPlaybackId('12345', { token: 't-1234' }),
13
+ 'https://stream.mux.com/12345.m3u8?token=t-1234'
14
+ );
15
+ });
16
+
17
+ it('with a custom domain', () => {
18
+ assert.equal(
19
+ getSrcFromPlaybackId('12345', { domain: 'fake.com' }),
20
+ 'https://stream.fake.com/12345.m3u8?redundant_streams=true'
21
+ );
22
+ });
23
+ });
24
+
25
+ describe('getPosterURLFromPlaybackId', () => {
26
+ it('with no token', () => {
27
+ assert.equal(getPosterURLFromPlaybackId('12345'), 'https://image.mux.com/12345/thumbnail.jpg');
28
+ });
29
+
30
+ it('with a token', () => {
31
+ assert.equal(
32
+ getPosterURLFromPlaybackId('12345', { token: 't-1234' }),
33
+ 'https://image.mux.com/12345/thumbnail.jpg?token=t-1234'
34
+ );
35
+ });
36
+
37
+ it('with a thumbnailTime', () => {
38
+ assert.equal(
39
+ getPosterURLFromPlaybackId('12345', { thumbnailTime: 20 }),
40
+ 'https://image.mux.com/12345/thumbnail.jpg?time=20'
41
+ );
42
+ });
43
+
44
+ it('with a thumbnailTime and token', () => {
45
+ assert.equal(
46
+ getPosterURLFromPlaybackId('12345', { token: 't-1234', thumbnailTime: 20 }),
47
+ 'https://image.mux.com/12345/thumbnail.jpg?token=t-1234'
48
+ );
49
+ });
50
+
51
+ it('with a custom domain', () => {
52
+ assert.equal(
53
+ getPosterURLFromPlaybackId('12345', { domain: 'fake.com' }),
54
+ 'https://image.fake.com/12345/thumbnail.jpg'
55
+ );
56
+ });
57
+ });
58
+
59
+ describe('getStoryboardURLFromPlaybackId', () => {
60
+ it('with no token', () => {
61
+ assert.equal(getStoryboardURLFromPlaybackId('12345'), 'https://image.mux.com/12345/storyboard.vtt');
62
+ });
63
+
64
+ it('with a token', () => {
65
+ assert.equal(
66
+ getStoryboardURLFromPlaybackId('12345', { token: 't-1234' }),
67
+ 'https://image.mux.com/12345/storyboard.vtt?token=t-1234'
68
+ );
69
+ });
70
+
71
+ it('with a custom domain', () => {
72
+ assert.equal(
73
+ getStoryboardURLFromPlaybackId('12345', { domain: 'fake.com' }),
74
+ 'https://image.fake.com/12345/storyboard.vtt'
75
+ );
76
+ });
77
+ });
78
+ });