Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28027 lines
814 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /**
  2. * @license
  3. * Video.js 7.6.5 <http://videojs.com/>
  4. * Copyright Brightcove, Inc. <https://www.brightcove.com/>
  5. * Available under Apache License Version 2.0
  6. * <https://github.com/videojs/video.js/blob/master/LICENSE>
  7. *
  8. * Includes vtt.js <https://github.com/mozilla/vtt.js>
  9. * Available under Apache License Version 2.0
  10. * <https://github.com/mozilla/vtt.js/blob/master/LICENSE>
  11. */
  12. (function (global, factory) {
  13. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('global/window'), require('global/document')) :
  14. typeof define === 'function' && define.amd ? define(['global/window', 'global/document'], factory) :
  15. (global = global || self, global.videojs = factory(global.window, global.document));
  16. }(this, function (window$1, document) {
  17. window$1 = window$1 && window$1.hasOwnProperty('default') ? window$1['default'] : window$1;
  18. document = document && document.hasOwnProperty('default') ? document['default'] : document;
  19. var version = "7.6.5";
  20. /**
  21. * @file create-logger.js
  22. * @module create-logger
  23. */
  24. var history = [];
  25. /**
  26. * Log messages to the console and history based on the type of message
  27. *
  28. * @private
  29. * @param {string} type
  30. * The name of the console method to use.
  31. *
  32. * @param {Array} args
  33. * The arguments to be passed to the matching console method.
  34. */
  35. var LogByTypeFactory = function LogByTypeFactory(name, log) {
  36. return function (type, level, args) {
  37. var lvl = log.levels[level];
  38. var lvlRegExp = new RegExp("^(" + lvl + ")$");
  39. if (type !== 'log') {
  40. // Add the type to the front of the message when it's not "log".
  41. args.unshift(type.toUpperCase() + ':');
  42. } // Add console prefix after adding to history.
  43. args.unshift(name + ':'); // Add a clone of the args at this point to history.
  44. if (history) {
  45. history.push([].concat(args));
  46. } // If there's no console then don't try to output messages, but they will
  47. // still be stored in history.
  48. if (!window$1.console) {
  49. return;
  50. } // Was setting these once outside of this function, but containing them
  51. // in the function makes it easier to test cases where console doesn't exist
  52. // when the module is executed.
  53. var fn = window$1.console[type];
  54. if (!fn && type === 'debug') {
  55. // Certain browsers don't have support for console.debug. For those, we
  56. // should default to the closest comparable log.
  57. fn = window$1.console.info || window$1.console.log;
  58. } // Bail out if there's no console or if this type is not allowed by the
  59. // current logging level.
  60. if (!fn || !lvl || !lvlRegExp.test(type)) {
  61. return;
  62. }
  63. fn[Array.isArray(args) ? 'apply' : 'call'](window$1.console, args);
  64. };
  65. };
  66. function createLogger(name) {
  67. // This is the private tracking variable for logging level.
  68. var level = 'info'; // the curried logByType bound to the specific log and history
  69. var logByType;
  70. /**
  71. * Logs plain debug messages. Similar to `console.log`.
  72. *
  73. * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149)
  74. * of our JSDoc template, we cannot properly document this as both a function
  75. * and a namespace, so its function signature is documented here.
  76. *
  77. * #### Arguments
  78. * ##### *args
  79. * Mixed[]
  80. *
  81. * Any combination of values that could be passed to `console.log()`.
  82. *
  83. * #### Return Value
  84. *
  85. * `undefined`
  86. *
  87. * @namespace
  88. * @param {Mixed[]} args
  89. * One or more messages or objects that should be logged.
  90. */
  91. var log = function log() {
  92. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  93. args[_key] = arguments[_key];
  94. }
  95. logByType('log', level, args);
  96. }; // This is the logByType helper that the logging methods below use
  97. logByType = LogByTypeFactory(name, log);
  98. /**
  99. * Create a new sublogger which chains the old name to the new name.
  100. *
  101. * For example, doing `videojs.log.createLogger('player')` and then using that logger will log the following:
  102. * ```js
  103. * mylogger('foo');
  104. * // > VIDEOJS: player: foo
  105. * ```
  106. *
  107. * @param {string} name
  108. * The name to add call the new logger
  109. * @return {Object}
  110. */
  111. log.createLogger = function (subname) {
  112. return createLogger(name + ': ' + subname);
  113. };
  114. /**
  115. * Enumeration of available logging levels, where the keys are the level names
  116. * and the values are `|`-separated strings containing logging methods allowed
  117. * in that logging level. These strings are used to create a regular expression
  118. * matching the function name being called.
  119. *
  120. * Levels provided by Video.js are:
  121. *
  122. * - `off`: Matches no calls. Any value that can be cast to `false` will have
  123. * this effect. The most restrictive.
  124. * - `all`: Matches only Video.js-provided functions (`debug`, `log`,
  125. * `log.warn`, and `log.error`).
  126. * - `debug`: Matches `log.debug`, `log`, `log.warn`, and `log.error` calls.
  127. * - `info` (default): Matches `log`, `log.warn`, and `log.error` calls.
  128. * - `warn`: Matches `log.warn` and `log.error` calls.
  129. * - `error`: Matches only `log.error` calls.
  130. *
  131. * @type {Object}
  132. */
  133. log.levels = {
  134. all: 'debug|log|warn|error',
  135. off: '',
  136. debug: 'debug|log|warn|error',
  137. info: 'log|warn|error',
  138. warn: 'warn|error',
  139. error: 'error',
  140. DEFAULT: level
  141. };
  142. /**
  143. * Get or set the current logging level.
  144. *
  145. * If a string matching a key from {@link module:log.levels} is provided, acts
  146. * as a setter.
  147. *
  148. * @param {string} [lvl]
  149. * Pass a valid level to set a new logging level.
  150. *
  151. * @return {string}
  152. * The current logging level.
  153. */
  154. log.level = function (lvl) {
  155. if (typeof lvl === 'string') {
  156. if (!log.levels.hasOwnProperty(lvl)) {
  157. throw new Error("\"" + lvl + "\" in not a valid log level");
  158. }
  159. level = lvl;
  160. }
  161. return level;
  162. };
  163. /**
  164. * Returns an array containing everything that has been logged to the history.
  165. *
  166. * This array is a shallow clone of the internal history record. However, its
  167. * contents are _not_ cloned; so, mutating objects inside this array will
  168. * mutate them in history.
  169. *
  170. * @return {Array}
  171. */
  172. log.history = function () {
  173. return history ? [].concat(history) : [];
  174. };
  175. /**
  176. * Allows you to filter the history by the given logger name
  177. *
  178. * @param {string} fname
  179. * The name to filter by
  180. *
  181. * @return {Array}
  182. * The filtered list to return
  183. */
  184. log.history.filter = function (fname) {
  185. return (history || []).filter(function (historyItem) {
  186. // if the first item in each historyItem includes `fname`, then it's a match
  187. return new RegExp(".*" + fname + ".*").test(historyItem[0]);
  188. });
  189. };
  190. /**
  191. * Clears the internal history tracking, but does not prevent further history
  192. * tracking.
  193. */
  194. log.history.clear = function () {
  195. if (history) {
  196. history.length = 0;
  197. }
  198. };
  199. /**
  200. * Disable history tracking if it is currently enabled.
  201. */
  202. log.history.disable = function () {
  203. if (history !== null) {
  204. history.length = 0;
  205. history = null;
  206. }
  207. };
  208. /**
  209. * Enable history tracking if it is currently disabled.
  210. */
  211. log.history.enable = function () {
  212. if (history === null) {
  213. history = [];
  214. }
  215. };
  216. /**
  217. * Logs error messages. Similar to `console.error`.
  218. *
  219. * @param {Mixed[]} args
  220. * One or more messages or objects that should be logged as an error
  221. */
  222. log.error = function () {
  223. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  224. args[_key2] = arguments[_key2];
  225. }
  226. return logByType('error', level, args);
  227. };
  228. /**
  229. * Logs warning messages. Similar to `console.warn`.
  230. *
  231. * @param {Mixed[]} args
  232. * One or more messages or objects that should be logged as a warning.
  233. */
  234. log.warn = function () {
  235. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  236. args[_key3] = arguments[_key3];
  237. }
  238. return logByType('warn', level, args);
  239. };
  240. /**
  241. * Logs debug messages. Similar to `console.debug`, but may also act as a comparable
  242. * log if `console.debug` is not available
  243. *
  244. * @param {Mixed[]} args
  245. * One or more messages or objects that should be logged as debug.
  246. */
  247. log.debug = function () {
  248. for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  249. args[_key4] = arguments[_key4];
  250. }
  251. return logByType('debug', level, args);
  252. };
  253. return log;
  254. }
  255. /**
  256. * @file log.js
  257. * @module log
  258. */
  259. var log = createLogger('VIDEOJS');
  260. var createLogger$1 = log.createLogger;
  261. /**
  262. * @file obj.js
  263. * @module obj
  264. */
  265. /**
  266. * @callback obj:EachCallback
  267. *
  268. * @param {Mixed} value
  269. * The current key for the object that is being iterated over.
  270. *
  271. * @param {string} key
  272. * The current key-value for object that is being iterated over
  273. */
  274. /**
  275. * @callback obj:ReduceCallback
  276. *
  277. * @param {Mixed} accum
  278. * The value that is accumulating over the reduce loop.
  279. *
  280. * @param {Mixed} value
  281. * The current key for the object that is being iterated over.
  282. *
  283. * @param {string} key
  284. * The current key-value for object that is being iterated over
  285. *
  286. * @return {Mixed}
  287. * The new accumulated value.
  288. */
  289. var toString = Object.prototype.toString;
  290. /**
  291. * Get the keys of an Object
  292. *
  293. * @param {Object}
  294. * The Object to get the keys from
  295. *
  296. * @return {string[]}
  297. * An array of the keys from the object. Returns an empty array if the
  298. * object passed in was invalid or had no keys.
  299. *
  300. * @private
  301. */
  302. var keys = function keys(object) {
  303. return isObject(object) ? Object.keys(object) : [];
  304. };
  305. /**
  306. * Array-like iteration for objects.
  307. *
  308. * @param {Object} object
  309. * The object to iterate over
  310. *
  311. * @param {obj:EachCallback} fn
  312. * The callback function which is called for each key in the object.
  313. */
  314. function each(object, fn) {
  315. keys(object).forEach(function (key) {
  316. return fn(object[key], key);
  317. });
  318. }
  319. /**
  320. * Array-like reduce for objects.
  321. *
  322. * @param {Object} object
  323. * The Object that you want to reduce.
  324. *
  325. * @param {Function} fn
  326. * A callback function which is called for each key in the object. It
  327. * receives the accumulated value and the per-iteration value and key
  328. * as arguments.
  329. *
  330. * @param {Mixed} [initial = 0]
  331. * Starting value
  332. *
  333. * @return {Mixed}
  334. * The final accumulated value.
  335. */
  336. function reduce(object, fn, initial) {
  337. if (initial === void 0) {
  338. initial = 0;
  339. }
  340. return keys(object).reduce(function (accum, key) {
  341. return fn(accum, object[key], key);
  342. }, initial);
  343. }
  344. /**
  345. * Object.assign-style object shallow merge/extend.
  346. *
  347. * @param {Object} target
  348. * @param {Object} ...sources
  349. * @return {Object}
  350. */
  351. function assign(target) {
  352. for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  353. sources[_key - 1] = arguments[_key];
  354. }
  355. if (Object.assign) {
  356. return Object.assign.apply(Object, [target].concat(sources));
  357. }
  358. sources.forEach(function (source) {
  359. if (!source) {
  360. return;
  361. }
  362. each(source, function (value, key) {
  363. target[key] = value;
  364. });
  365. });
  366. return target;
  367. }
  368. /**
  369. * Returns whether a value is an object of any kind - including DOM nodes,
  370. * arrays, regular expressions, etc. Not functions, though.
  371. *
  372. * This avoids the gotcha where using `typeof` on a `null` value
  373. * results in `'object'`.
  374. *
  375. * @param {Object} value
  376. * @return {boolean}
  377. */
  378. function isObject(value) {
  379. return !!value && typeof value === 'object';
  380. }
  381. /**
  382. * Returns whether an object appears to be a "plain" object - that is, a
  383. * direct instance of `Object`.
  384. *
  385. * @param {Object} value
  386. * @return {boolean}
  387. */
  388. function isPlain(value) {
  389. return isObject(value) && toString.call(value) === '[object Object]' && value.constructor === Object;
  390. }
  391. /**
  392. * @file computed-style.js
  393. * @module computed-style
  394. */
  395. /**
  396. * A safe getComputedStyle.
  397. *
  398. * This is needed because in Firefox, if the player is loaded in an iframe with
  399. * `display:none`, then `getComputedStyle` returns `null`, so, we do a
  400. * null-check to make sure that the player doesn't break in these cases.
  401. *
  402. * @function
  403. * @param {Element} el
  404. * The element you want the computed style of
  405. *
  406. * @param {string} prop
  407. * The property name you want
  408. *
  409. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=548397
  410. */
  411. function computedStyle(el, prop) {
  412. if (!el || !prop) {
  413. return '';
  414. }
  415. if (typeof window$1.getComputedStyle === 'function') {
  416. var computedStyleValue = window$1.getComputedStyle(el);
  417. return computedStyleValue ? computedStyleValue.getPropertyValue(prop) || computedStyleValue[prop] : '';
  418. }
  419. return '';
  420. }
  421. /**
  422. * @file dom.js
  423. * @module dom
  424. */
  425. /**
  426. * Detect if a value is a string with any non-whitespace characters.
  427. *
  428. * @private
  429. * @param {string} str
  430. * The string to check
  431. *
  432. * @return {boolean}
  433. * Will be `true` if the string is non-blank, `false` otherwise.
  434. *
  435. */
  436. function isNonBlankString(str) {
  437. return typeof str === 'string' && /\S/.test(str);
  438. }
  439. /**
  440. * Throws an error if the passed string has whitespace. This is used by
  441. * class methods to be relatively consistent with the classList API.
  442. *
  443. * @private
  444. * @param {string} str
  445. * The string to check for whitespace.
  446. *
  447. * @throws {Error}
  448. * Throws an error if there is whitespace in the string.
  449. */
  450. function throwIfWhitespace(str) {
  451. if (/\s/.test(str)) {
  452. throw new Error('class has illegal whitespace characters');
  453. }
  454. }
  455. /**
  456. * Produce a regular expression for matching a className within an elements className.
  457. *
  458. * @private
  459. * @param {string} className
  460. * The className to generate the RegExp for.
  461. *
  462. * @return {RegExp}
  463. * The RegExp that will check for a specific `className` in an elements
  464. * className.
  465. */
  466. function classRegExp(className) {
  467. return new RegExp('(^|\\s)' + className + '($|\\s)');
  468. }
  469. /**
  470. * Whether the current DOM interface appears to be real (i.e. not simulated).
  471. *
  472. * @return {boolean}
  473. * Will be `true` if the DOM appears to be real, `false` otherwise.
  474. */
  475. function isReal() {
  476. // Both document and window will never be undefined thanks to `global`.
  477. return document === window$1.document;
  478. }
  479. /**
  480. * Determines, via duck typing, whether or not a value is a DOM element.
  481. *
  482. * @param {Mixed} value
  483. * The value to check.
  484. *
  485. * @return {boolean}
  486. * Will be `true` if the value is a DOM element, `false` otherwise.
  487. */
  488. function isEl(value) {
  489. return isObject(value) && value.nodeType === 1;
  490. }
  491. /**
  492. * Determines if the current DOM is embedded in an iframe.
  493. *
  494. * @return {boolean}
  495. * Will be `true` if the DOM is embedded in an iframe, `false`
  496. * otherwise.
  497. */
  498. function isInFrame() {
  499. // We need a try/catch here because Safari will throw errors when attempting
  500. // to get either `parent` or `self`
  501. try {
  502. return window$1.parent !== window$1.self;
  503. } catch (x) {
  504. return true;
  505. }
  506. }
  507. /**
  508. * Creates functions to query the DOM using a given method.
  509. *
  510. * @private
  511. * @param {string} method
  512. * The method to create the query with.
  513. *
  514. * @return {Function}
  515. * The query method
  516. */
  517. function createQuerier(method) {
  518. return function (selector, context) {
  519. if (!isNonBlankString(selector)) {
  520. return document[method](null);
  521. }
  522. if (isNonBlankString(context)) {
  523. context = document.querySelector(context);
  524. }
  525. var ctx = isEl(context) ? context : document;
  526. return ctx[method] && ctx[method](selector);
  527. };
  528. }
  529. /**
  530. * Creates an element and applies properties, attributes, and inserts content.
  531. *
  532. * @param {string} [tagName='div']
  533. * Name of tag to be created.
  534. *
  535. * @param {Object} [properties={}]
  536. * Element properties to be applied.
  537. *
  538. * @param {Object} [attributes={}]
  539. * Element attributes to be applied.
  540. *
  541. * @param {module:dom~ContentDescriptor} content
  542. * A content descriptor object.
  543. *
  544. * @return {Element}
  545. * The element that was created.
  546. */
  547. function createEl(tagName, properties, attributes, content) {
  548. if (tagName === void 0) {
  549. tagName = 'div';
  550. }
  551. if (properties === void 0) {
  552. properties = {};
  553. }
  554. if (attributes === void 0) {
  555. attributes = {};
  556. }
  557. var el = document.createElement(tagName);
  558. Object.getOwnPropertyNames(properties).forEach(function (propName) {
  559. var val = properties[propName]; // See #2176
  560. // We originally were accepting both properties and attributes in the
  561. // same object, but that doesn't work so well.
  562. if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') {
  563. log.warn('Setting attributes in the second argument of createEl()\n' + 'has been deprecated. Use the third argument instead.\n' + ("createEl(type, properties, attributes). Attempting to set " + propName + " to " + val + "."));
  564. el.setAttribute(propName, val); // Handle textContent since it's not supported everywhere and we have a
  565. // method for it.
  566. } else if (propName === 'textContent') {
  567. textContent(el, val);
  568. } else {
  569. el[propName] = val;
  570. }
  571. });
  572. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  573. el.setAttribute(attrName, attributes[attrName]);
  574. });
  575. if (content) {
  576. appendContent(el, content);
  577. }
  578. return el;
  579. }
  580. /**
  581. * Injects text into an element, replacing any existing contents entirely.
  582. *
  583. * @param {Element} el
  584. * The element to add text content into
  585. *
  586. * @param {string} text
  587. * The text content to add.
  588. *
  589. * @return {Element}
  590. * The element with added text content.
  591. */
  592. function textContent(el, text) {
  593. if (typeof el.textContent === 'undefined') {
  594. el.innerText = text;
  595. } else {
  596. el.textContent = text;
  597. }
  598. return el;
  599. }
  600. /**
  601. * Insert an element as the first child node of another
  602. *
  603. * @param {Element} child
  604. * Element to insert
  605. *
  606. * @param {Element} parent
  607. * Element to insert child into
  608. */
  609. function prependTo(child, parent) {
  610. if (parent.firstChild) {
  611. parent.insertBefore(child, parent.firstChild);
  612. } else {
  613. parent.appendChild(child);
  614. }
  615. }
  616. /**
  617. * Check if an element has a class name.
  618. *
  619. * @param {Element} element
  620. * Element to check
  621. *
  622. * @param {string} classToCheck
  623. * Class name to check for
  624. *
  625. * @return {boolean}
  626. * Will be `true` if the element has a class, `false` otherwise.
  627. *
  628. * @throws {Error}
  629. * Throws an error if `classToCheck` has white space.
  630. */
  631. function hasClass(element, classToCheck) {
  632. throwIfWhitespace(classToCheck);
  633. if (element.classList) {
  634. return element.classList.contains(classToCheck);
  635. }
  636. return classRegExp(classToCheck).test(element.className);
  637. }
  638. /**
  639. * Add a class name to an element.
  640. *
  641. * @param {Element} element
  642. * Element to add class name to.
  643. *
  644. * @param {string} classToAdd
  645. * Class name to add.
  646. *
  647. * @return {Element}
  648. * The DOM element with the added class name.
  649. */
  650. function addClass(element, classToAdd) {
  651. if (element.classList) {
  652. element.classList.add(classToAdd); // Don't need to `throwIfWhitespace` here because `hasElClass` will do it
  653. // in the case of classList not being supported.
  654. } else if (!hasClass(element, classToAdd)) {
  655. element.className = (element.className + ' ' + classToAdd).trim();
  656. }
  657. return element;
  658. }
  659. /**
  660. * Remove a class name from an element.
  661. *
  662. * @param {Element} element
  663. * Element to remove a class name from.
  664. *
  665. * @param {string} classToRemove
  666. * Class name to remove
  667. *
  668. * @return {Element}
  669. * The DOM element with class name removed.
  670. */
  671. function removeClass(element, classToRemove) {
  672. if (element.classList) {
  673. element.classList.remove(classToRemove);
  674. } else {
  675. throwIfWhitespace(classToRemove);
  676. element.className = element.className.split(/\s+/).filter(function (c) {
  677. return c !== classToRemove;
  678. }).join(' ');
  679. }
  680. return element;
  681. }
  682. /**
  683. * The callback definition for toggleClass.
  684. *
  685. * @callback module:dom~PredicateCallback
  686. * @param {Element} element
  687. * The DOM element of the Component.
  688. *
  689. * @param {string} classToToggle
  690. * The `className` that wants to be toggled
  691. *
  692. * @return {boolean|undefined}
  693. * If `true` is returned, the `classToToggle` will be added to the
  694. * `element`. If `false`, the `classToToggle` will be removed from
  695. * the `element`. If `undefined`, the callback will be ignored.
  696. */
  697. /**
  698. * Adds or removes a class name to/from an element depending on an optional
  699. * condition or the presence/absence of the class name.
  700. *
  701. * @param {Element} element
  702. * The element to toggle a class name on.
  703. *
  704. * @param {string} classToToggle
  705. * The class that should be toggled.
  706. *
  707. * @param {boolean|module:dom~PredicateCallback} [predicate]
  708. * See the return value for {@link module:dom~PredicateCallback}
  709. *
  710. * @return {Element}
  711. * The element with a class that has been toggled.
  712. */
  713. function toggleClass(element, classToToggle, predicate) {
  714. // This CANNOT use `classList` internally because IE11 does not support the
  715. // second parameter to the `classList.toggle()` method! Which is fine because
  716. // `classList` will be used by the add/remove functions.
  717. var has = hasClass(element, classToToggle);
  718. if (typeof predicate === 'function') {
  719. predicate = predicate(element, classToToggle);
  720. }
  721. if (typeof predicate !== 'boolean') {
  722. predicate = !has;
  723. } // If the necessary class operation matches the current state of the
  724. // element, no action is required.
  725. if (predicate === has) {
  726. return;
  727. }
  728. if (predicate) {
  729. addClass(element, classToToggle);
  730. } else {
  731. removeClass(element, classToToggle);
  732. }
  733. return element;
  734. }
  735. /**
  736. * Apply attributes to an HTML element.
  737. *
  738. * @param {Element} el
  739. * Element to add attributes to.
  740. *
  741. * @param {Object} [attributes]
  742. * Attributes to be applied.
  743. */
  744. function setAttributes(el, attributes) {
  745. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  746. var attrValue = attributes[attrName];
  747. if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) {
  748. el.removeAttribute(attrName);
  749. } else {
  750. el.setAttribute(attrName, attrValue === true ? '' : attrValue);
  751. }
  752. });
  753. }
  754. /**
  755. * Get an element's attribute values, as defined on the HTML tag.
  756. *
  757. * Attributes are not the same as properties. They're defined on the tag
  758. * or with setAttribute.
  759. *
  760. * @param {Element} tag
  761. * Element from which to get tag attributes.
  762. *
  763. * @return {Object}
  764. * All attributes of the element. Boolean attributes will be `true` or
  765. * `false`, others will be strings.
  766. */
  767. function getAttributes(tag) {
  768. var obj = {}; // known boolean attributes
  769. // we can check for matching boolean properties, but not all browsers
  770. // and not all tags know about these attributes, so, we still want to check them manually
  771. var knownBooleans = ',' + 'autoplay,controls,playsinline,loop,muted,default,defaultMuted' + ',';
  772. if (tag && tag.attributes && tag.attributes.length > 0) {
  773. var attrs = tag.attributes;
  774. for (var i = attrs.length - 1; i >= 0; i--) {
  775. var attrName = attrs[i].name;
  776. var attrVal = attrs[i].value; // check for known booleans
  777. // the matching element property will return a value for typeof
  778. if (typeof tag[attrName] === 'boolean' || knownBooleans.indexOf(',' + attrName + ',') !== -1) {
  779. // the value of an included boolean attribute is typically an empty
  780. // string ('') which would equal false if we just check for a false value.
  781. // we also don't want support bad code like autoplay='false'
  782. attrVal = attrVal !== null ? true : false;
  783. }
  784. obj[attrName] = attrVal;
  785. }
  786. }
  787. return obj;
  788. }
  789. /**
  790. * Get the value of an element's attribute.
  791. *
  792. * @param {Element} el
  793. * A DOM element.
  794. *
  795. * @param {string} attribute
  796. * Attribute to get the value of.
  797. *
  798. * @return {string}
  799. * The value of the attribute.
  800. */
  801. function getAttribute(el, attribute) {
  802. return el.getAttribute(attribute);
  803. }
  804. /**
  805. * Set the value of an element's attribute.
  806. *
  807. * @param {Element} el
  808. * A DOM element.
  809. *
  810. * @param {string} attribute
  811. * Attribute to set.
  812. *
  813. * @param {string} value
  814. * Value to set the attribute to.
  815. */
  816. function setAttribute(el, attribute, value) {
  817. el.setAttribute(attribute, value);
  818. }
  819. /**
  820. * Remove an element's attribute.
  821. *
  822. * @param {Element} el
  823. * A DOM element.
  824. *
  825. * @param {string} attribute
  826. * Attribute to remove.
  827. */
  828. function removeAttribute(el, attribute) {
  829. el.removeAttribute(attribute);
  830. }
  831. /**
  832. * Attempt to block the ability to select text.
  833. */
  834. function blockTextSelection() {
  835. document.body.focus();
  836. document.onselectstart = function () {
  837. return false;
  838. };
  839. }
  840. /**
  841. * Turn off text selection blocking.
  842. */
  843. function unblockTextSelection() {
  844. document.onselectstart = function () {
  845. return true;
  846. };
  847. }
  848. /**
  849. * Identical to the native `getBoundingClientRect` function, but ensures that
  850. * the method is supported at all (it is in all browsers we claim to support)
  851. * and that the element is in the DOM before continuing.
  852. *
  853. * This wrapper function also shims properties which are not provided by some
  854. * older browsers (namely, IE8).
  855. *
  856. * Additionally, some browsers do not support adding properties to a
  857. * `ClientRect`/`DOMRect` object; so, we shallow-copy it with the standard
  858. * properties (except `x` and `y` which are not widely supported). This helps
  859. * avoid implementations where keys are non-enumerable.
  860. *
  861. * @param {Element} el
  862. * Element whose `ClientRect` we want to calculate.
  863. *
  864. * @return {Object|undefined}
  865. * Always returns a plain object - or `undefined` if it cannot.
  866. */
  867. function getBoundingClientRect(el) {
  868. if (el && el.getBoundingClientRect && el.parentNode) {
  869. var rect = el.getBoundingClientRect();
  870. var result = {};
  871. ['bottom', 'height', 'left', 'right', 'top', 'width'].forEach(function (k) {
  872. if (rect[k] !== undefined) {
  873. result[k] = rect[k];
  874. }
  875. });
  876. if (!result.height) {
  877. result.height = parseFloat(computedStyle(el, 'height'));
  878. }
  879. if (!result.width) {
  880. result.width = parseFloat(computedStyle(el, 'width'));
  881. }
  882. return result;
  883. }
  884. }
  885. /**
  886. * Represents the position of a DOM element on the page.
  887. *
  888. * @typedef {Object} module:dom~Position
  889. *
  890. * @property {number} left
  891. * Pixels to the left.
  892. *
  893. * @property {number} top
  894. * Pixels from the top.
  895. */
  896. /**
  897. * Get the position of an element in the DOM.
  898. *
  899. * Uses `getBoundingClientRect` technique from John Resig.
  900. *
  901. * @see http://ejohn.org/blog/getboundingclientrect-is-awesome/
  902. *
  903. * @param {Element} el
  904. * Element from which to get offset.
  905. *
  906. * @return {module:dom~Position}
  907. * The position of the element that was passed in.
  908. */
  909. function findPosition(el) {
  910. var box;
  911. if (el.getBoundingClientRect && el.parentNode) {
  912. box = el.getBoundingClientRect();
  913. }
  914. if (!box) {
  915. return {
  916. left: 0,
  917. top: 0
  918. };
  919. }
  920. var docEl = document.documentElement;
  921. var body = document.body;
  922. var clientLeft = docEl.clientLeft || body.clientLeft || 0;
  923. var scrollLeft = window$1.pageXOffset || body.scrollLeft;
  924. var left = box.left + scrollLeft - clientLeft;
  925. var clientTop = docEl.clientTop || body.clientTop || 0;
  926. var scrollTop = window$1.pageYOffset || body.scrollTop;
  927. var top = box.top + scrollTop - clientTop; // Android sometimes returns slightly off decimal values, so need to round
  928. return {
  929. left: Math.round(left),
  930. top: Math.round(top)
  931. };
  932. }
  933. /**
  934. * Represents x and y coordinates for a DOM element or mouse pointer.
  935. *
  936. * @typedef {Object} module:dom~Coordinates
  937. *
  938. * @property {number} x
  939. * x coordinate in pixels
  940. *
  941. * @property {number} y
  942. * y coordinate in pixels
  943. */
  944. /**
  945. * Get the pointer position within an element.
  946. *
  947. * The base on the coordinates are the bottom left of the element.
  948. *
  949. * @param {Element} el
  950. * Element on which to get the pointer position on.
  951. *
  952. * @param {EventTarget~Event} event
  953. * Event object.
  954. *
  955. * @return {module:dom~Coordinates}
  956. * A coordinates object corresponding to the mouse position.
  957. *
  958. */
  959. function getPointerPosition(el, event) {
  960. var position = {};
  961. var box = findPosition(el);
  962. var boxW = el.offsetWidth;
  963. var boxH = el.offsetHeight;
  964. var boxY = box.top;
  965. var boxX = box.left;
  966. var pageY = event.pageY;
  967. var pageX = event.pageX;
  968. if (event.changedTouches) {
  969. pageX = event.changedTouches[0].pageX;
  970. pageY = event.changedTouches[0].pageY;
  971. }
  972. position.y = Math.max(0, Math.min(1, (boxY - pageY + boxH) / boxH));
  973. position.x = Math.max(0, Math.min(1, (pageX - boxX) / boxW));
  974. return position;
  975. }
  976. /**
  977. * Determines, via duck typing, whether or not a value is a text node.
  978. *
  979. * @param {Mixed} value
  980. * Check if this value is a text node.
  981. *
  982. * @return {boolean}
  983. * Will be `true` if the value is a text node, `false` otherwise.
  984. */
  985. function isTextNode(value) {
  986. return isObject(value) && value.nodeType === 3;
  987. }
  988. /**
  989. * Empties the contents of an element.
  990. *
  991. * @param {Element} el
  992. * The element to empty children from
  993. *
  994. * @return {Element}
  995. * The element with no children
  996. */
  997. function emptyEl(el) {
  998. while (el.firstChild) {
  999. el.removeChild(el.firstChild);
  1000. }
  1001. return el;
  1002. }
  1003. /**
  1004. * This is a mixed value that describes content to be injected into the DOM
  1005. * via some method. It can be of the following types:
  1006. *
  1007. * Type | Description
  1008. * -----------|-------------
  1009. * `string` | The value will be normalized into a text node.
  1010. * `Element` | The value will be accepted as-is.
  1011. * `TextNode` | The value will be accepted as-is.
  1012. * `Array` | A one-dimensional array of strings, elements, text nodes, or functions. These functions should return a string, element, or text node (any other return value, like an array, will be ignored).
  1013. * `Function` | A function, which is expected to return a string, element, text node, or array - any of the other possible values described above. This means that a content descriptor could be a function that returns an array of functions, but those second-level functions must return strings, elements, or text nodes.
  1014. *
  1015. * @typedef {string|Element|TextNode|Array|Function} module:dom~ContentDescriptor
  1016. */
  1017. /**
  1018. * Normalizes content for eventual insertion into the DOM.
  1019. *
  1020. * This allows a wide range of content definition methods, but helps protect
  1021. * from falling into the trap of simply writing to `innerHTML`, which could
  1022. * be an XSS concern.
  1023. *
  1024. * The content for an element can be passed in multiple types and
  1025. * combinations, whose behavior is as follows:
  1026. *
  1027. * @param {module:dom~ContentDescriptor} content
  1028. * A content descriptor value.
  1029. *
  1030. * @return {Array}
  1031. * All of the content that was passed in, normalized to an array of
  1032. * elements or text nodes.
  1033. */
  1034. function normalizeContent(content) {
  1035. // First, invoke content if it is a function. If it produces an array,
  1036. // that needs to happen before normalization.
  1037. if (typeof content === 'function') {
  1038. content = content();
  1039. } // Next up, normalize to an array, so one or many items can be normalized,
  1040. // filtered, and returned.
  1041. return (Array.isArray(content) ? content : [content]).map(function (value) {
  1042. // First, invoke value if it is a function to produce a new value,
  1043. // which will be subsequently normalized to a Node of some kind.
  1044. if (typeof value === 'function') {
  1045. value = value();
  1046. }
  1047. if (isEl(value) || isTextNode(value)) {
  1048. return value;
  1049. }
  1050. if (typeof value === 'string' && /\S/.test(value)) {
  1051. return document.createTextNode(value);
  1052. }
  1053. }).filter(function (value) {
  1054. return value;
  1055. });
  1056. }
  1057. /**
  1058. * Normalizes and appends content to an element.
  1059. *
  1060. * @param {Element} el
  1061. * Element to append normalized content to.
  1062. *
  1063. * @param {module:dom~ContentDescriptor} content
  1064. * A content descriptor value.
  1065. *
  1066. * @return {Element}
  1067. * The element with appended normalized content.
  1068. */
  1069. function appendContent(el, content) {
  1070. normalizeContent(content).forEach(function (node) {
  1071. return el.appendChild(node);
  1072. });
  1073. return el;
  1074. }
  1075. /**
  1076. * Normalizes and inserts content into an element; this is identical to
  1077. * `appendContent()`, except it empties the element first.
  1078. *
  1079. * @param {Element} el
  1080. * Element to insert normalized content into.
  1081. *
  1082. * @param {module:dom~ContentDescriptor} content
  1083. * A content descriptor value.
  1084. *
  1085. * @return {Element}
  1086. * The element with inserted normalized content.
  1087. */
  1088. function insertContent(el, content) {
  1089. return appendContent(emptyEl(el), content);
  1090. }
  1091. /**
  1092. * Check if an event was a single left click.
  1093. *
  1094. * @param {EventTarget~Event} event
  1095. * Event object.
  1096. *
  1097. * @return {boolean}
  1098. * Will be `true` if a single left click, `false` otherwise.
  1099. */
  1100. function isSingleLeftClick(event) {
  1101. // Note: if you create something draggable, be sure to
  1102. // call it on both `mousedown` and `mousemove` event,
  1103. // otherwise `mousedown` should be enough for a button
  1104. if (event.button === undefined && event.buttons === undefined) {
  1105. // Why do we need `buttons` ?
  1106. // Because, middle mouse sometimes have this:
  1107. // e.button === 0 and e.buttons === 4
  1108. // Furthermore, we want to prevent combination click, something like
  1109. // HOLD middlemouse then left click, that would be
  1110. // e.button === 0, e.buttons === 5
  1111. // just `button` is not gonna work
  1112. // Alright, then what this block does ?
  1113. // this is for chrome `simulate mobile devices`
  1114. // I want to support this as well
  1115. return true;
  1116. }
  1117. if (event.button === 0 && event.buttons === undefined) {
  1118. // Touch screen, sometimes on some specific device, `buttons`
  1119. // doesn't have anything (safari on ios, blackberry...)
  1120. return true;
  1121. } // `mouseup` event on a single left click has
  1122. // `button` and `buttons` equal to 0
  1123. if (event.type === 'mouseup' && event.button === 0 && event.buttons === 0) {
  1124. return true;
  1125. }
  1126. if (event.button !== 0 || event.buttons !== 1) {
  1127. // This is the reason we have those if else block above
  1128. // if any special case we can catch and let it slide
  1129. // we do it above, when get to here, this definitely
  1130. // is-not-left-click
  1131. return false;
  1132. }
  1133. return true;
  1134. }
  1135. /**
  1136. * Finds a single DOM element matching `selector` within the optional
  1137. * `context` of another DOM element (defaulting to `document`).
  1138. *
  1139. * @param {string} selector
  1140. * A valid CSS selector, which will be passed to `querySelector`.
  1141. *
  1142. * @param {Element|String} [context=document]
  1143. * A DOM element within which to query. Can also be a selector
  1144. * string in which case the first matching element will be used
  1145. * as context. If missing (or no element matches selector), falls
  1146. * back to `document`.
  1147. *
  1148. * @return {Element|null}
  1149. * The element that was found or null.
  1150. */
  1151. var $ = createQuerier('querySelector');
  1152. /**
  1153. * Finds a all DOM elements matching `selector` within the optional
  1154. * `context` of another DOM element (defaulting to `document`).
  1155. *
  1156. * @param {string} selector
  1157. * A valid CSS selector, which will be passed to `querySelectorAll`.
  1158. *
  1159. * @param {Element|String} [context=document]
  1160. * A DOM element within which to query. Can also be a selector
  1161. * string in which case the first matching element will be used
  1162. * as context. If missing (or no element matches selector), falls
  1163. * back to `document`.
  1164. *
  1165. * @return {NodeList}
  1166. * A element list of elements that were found. Will be empty if none
  1167. * were found.
  1168. *
  1169. */
  1170. var $$ = createQuerier('querySelectorAll');
  1171. var Dom = /*#__PURE__*/Object.freeze({
  1172. isReal: isReal,
  1173. isEl: isEl,
  1174. isInFrame: isInFrame,
  1175. createEl: createEl,
  1176. textContent: textContent,
  1177. prependTo: prependTo,
  1178. hasClass: hasClass,
  1179. addClass: addClass,
  1180. removeClass: removeClass,
  1181. toggleClass: toggleClass,
  1182. setAttributes: setAttributes,
  1183. getAttributes: getAttributes,
  1184. getAttribute: getAttribute,
  1185. setAttribute: setAttribute,
  1186. removeAttribute: removeAttribute,
  1187. blockTextSelection: blockTextSelection,
  1188. unblockTextSelection: unblockTextSelection,
  1189. getBoundingClientRect: getBoundingClientRect,
  1190. findPosition: findPosition,
  1191. getPointerPosition: getPointerPosition,
  1192. isTextNode: isTextNode,
  1193. emptyEl: emptyEl,
  1194. normalizeContent: normalizeContent,
  1195. appendContent: appendContent,
  1196. insertContent: insertContent,
  1197. isSingleLeftClick: isSingleLeftClick,
  1198. $: $,
  1199. $$: $$
  1200. });
  1201. /**
  1202. * @file setup.js - Functions for setting up a player without
  1203. * user interaction based on the data-setup `attribute` of the video tag.
  1204. *
  1205. * @module setup
  1206. */
  1207. var _windowLoaded = false;
  1208. var videojs;
  1209. /**
  1210. * Set up any tags that have a data-setup `attribute` when the player is started.
  1211. */
  1212. var autoSetup = function autoSetup() {
  1213. // Protect against breakage in non-browser environments and check global autoSetup option.
  1214. if (!isReal() || videojs.options.autoSetup === false) {
  1215. return;
  1216. }
  1217. var vids = Array.prototype.slice.call(document.getElementsByTagName('video'));
  1218. var audios = Array.prototype.slice.call(document.getElementsByTagName('audio'));
  1219. var divs = Array.prototype.slice.call(document.getElementsByTagName('video-js'));
  1220. var mediaEls = vids.concat(audios, divs); // Check if any media elements exist
  1221. if (mediaEls && mediaEls.length > 0) {
  1222. for (var i = 0, e = mediaEls.length; i < e; i++) {
  1223. var mediaEl = mediaEls[i]; // Check if element exists, has getAttribute func.
  1224. if (mediaEl && mediaEl.getAttribute) {
  1225. // Make sure this player hasn't already been set up.
  1226. if (mediaEl.player === undefined) {
  1227. var options = mediaEl.getAttribute('data-setup'); // Check if data-setup attr exists.
  1228. // We only auto-setup if they've added the data-setup attr.
  1229. if (options !== null) {
  1230. // Create new video.js instance.
  1231. videojs(mediaEl);
  1232. }
  1233. } // If getAttribute isn't defined, we need to wait for the DOM.
  1234. } else {
  1235. autoSetupTimeout(1);
  1236. break;
  1237. }
  1238. } // No videos were found, so keep looping unless page is finished loading.
  1239. } else if (!_windowLoaded) {
  1240. autoSetupTimeout(1);
  1241. }
  1242. };
  1243. /**
  1244. * Wait until the page is loaded before running autoSetup. This will be called in
  1245. * autoSetup if `hasLoaded` returns false.
  1246. *
  1247. * @param {number} wait
  1248. * How long to wait in ms
  1249. *
  1250. * @param {module:videojs} [vjs]
  1251. * The videojs library function
  1252. */
  1253. function autoSetupTimeout(wait, vjs) {
  1254. if (vjs) {
  1255. videojs = vjs;
  1256. }
  1257. window$1.setTimeout(autoSetup, wait);
  1258. }
  1259. /**
  1260. * Used to set the internal tracking of window loaded state to true.
  1261. *
  1262. * @private
  1263. */
  1264. function setWindowLoaded() {
  1265. _windowLoaded = true;
  1266. window$1.removeEventListener('load', setWindowLoaded);
  1267. }
  1268. if (isReal()) {
  1269. if (document.readyState === 'complete') {
  1270. setWindowLoaded();
  1271. } else {
  1272. /**
  1273. * Listen for the load event on window, and set _windowLoaded to true.
  1274. *
  1275. * We use a standard event listener here to avoid incrementing the GUID
  1276. * before any players are created.
  1277. *
  1278. * @listens load
  1279. */
  1280. window$1.addEventListener('load', setWindowLoaded);
  1281. }
  1282. }
  1283. /**
  1284. * @file stylesheet.js
  1285. * @module stylesheet
  1286. */
  1287. /**
  1288. * Create a DOM syle element given a className for it.
  1289. *
  1290. * @param {string} className
  1291. * The className to add to the created style element.
  1292. *
  1293. * @return {Element}
  1294. * The element that was created.
  1295. */
  1296. var createStyleElement = function createStyleElement(className) {
  1297. var style = document.createElement('style');
  1298. style.className = className;
  1299. return style;
  1300. };
  1301. /**
  1302. * Add text to a DOM element.
  1303. *
  1304. * @param {Element} el
  1305. * The Element to add text content to.
  1306. *
  1307. * @param {string} content
  1308. * The text to add to the element.
  1309. */
  1310. var setTextContent = function setTextContent(el, content) {
  1311. if (el.styleSheet) {
  1312. el.styleSheet.cssText = content;
  1313. } else {
  1314. el.textContent = content;
  1315. }
  1316. };
  1317. /**
  1318. * @file dom-data.js
  1319. * @module dom-data
  1320. */
  1321. /**
  1322. * Element Data Store.
  1323. *
  1324. * Allows for binding data to an element without putting it directly on the
  1325. * element. Ex. Event listeners are stored here.
  1326. * (also from jsninja.com, slightly modified and updated for closure compiler)
  1327. *
  1328. * @type {Object}
  1329. * @private
  1330. */
  1331. var DomData = new WeakMap();
  1332. /**
  1333. * @file guid.js
  1334. * @module guid
  1335. */
  1336. // Default value for GUIDs. This allows us to reset the GUID counter in tests.
  1337. //
  1338. // The initial GUID is 3 because some users have come to rely on the first
  1339. // default player ID ending up as `vjs_video_3`.
  1340. //
  1341. // See: https://github.com/videojs/video.js/pull/6216
  1342. var _initialGuid = 3;
  1343. /**
  1344. * Unique ID for an element or function
  1345. *
  1346. * @type {Number}
  1347. */
  1348. var _guid = _initialGuid;
  1349. /**
  1350. * Get a unique auto-incrementing ID by number that has not been returned before.
  1351. *
  1352. * @return {number}
  1353. * A new unique ID.
  1354. */
  1355. function newGUID() {
  1356. return _guid++;
  1357. }
  1358. /**
  1359. * @file events.js. An Event System (John Resig - Secrets of a JS Ninja http://jsninja.com/)
  1360. * (Original book version wasn't completely usable, so fixed some things and made Closure Compiler compatible)
  1361. * This should work very similarly to jQuery's events, however it's based off the book version which isn't as
  1362. * robust as jquery's, so there's probably some differences.
  1363. *
  1364. * @file events.js
  1365. * @module events
  1366. */
  1367. /**
  1368. * Clean up the listener cache and dispatchers
  1369. *
  1370. * @param {Element|Object} elem
  1371. * Element to clean up
  1372. *
  1373. * @param {string} type
  1374. * Type of event to clean up
  1375. */
  1376. function _cleanUpEvents(elem, type) {
  1377. if (!DomData.has(elem)) {
  1378. return;
  1379. }
  1380. var data = DomData.get(elem); // Remove the events of a particular type if there are none left
  1381. if (data.handlers[type].length === 0) {
  1382. delete data.handlers[type]; // data.handlers[type] = null;
  1383. // Setting to null was causing an error with data.handlers
  1384. // Remove the meta-handler from the element
  1385. if (elem.removeEventListener) {
  1386. elem.removeEventListener(type, data.dispatcher, false);
  1387. } else if (elem.detachEvent) {
  1388. elem.detachEvent('on' + type, data.dispatcher);
  1389. }
  1390. } // Remove the events object if there are no types left
  1391. if (Object.getOwnPropertyNames(data.handlers).length <= 0) {
  1392. delete data.handlers;
  1393. delete data.dispatcher;
  1394. delete data.disabled;
  1395. } // Finally remove the element data if there is no data left
  1396. if (Object.getOwnPropertyNames(data).length === 0) {
  1397. DomData["delete"](elem);
  1398. }
  1399. }
  1400. /**
  1401. * Loops through an array of event types and calls the requested method for each type.
  1402. *
  1403. * @param {Function} fn
  1404. * The event method we want to use.
  1405. *
  1406. * @param {Element|Object} elem
  1407. * Element or object to bind listeners to
  1408. *
  1409. * @param {string} type
  1410. * Type of event to bind to.
  1411. *
  1412. * @param {EventTarget~EventListener} callback
  1413. * Event listener.
  1414. */
  1415. function _handleMultipleEvents(fn, elem, types, callback) {
  1416. types.forEach(function (type) {
  1417. // Call the event method for each one of the types
  1418. fn(elem, type, callback);
  1419. });
  1420. }
  1421. /**
  1422. * Fix a native event to have standard property values
  1423. *
  1424. * @param {Object} event
  1425. * Event object to fix.
  1426. *
  1427. * @return {Object}
  1428. * Fixed event object.
  1429. */
  1430. function fixEvent(event) {
  1431. function returnTrue() {
  1432. return true;
  1433. }
  1434. function returnFalse() {
  1435. return false;
  1436. } // Test if fixing up is needed
  1437. // Used to check if !event.stopPropagation instead of isPropagationStopped
  1438. // But native events return true for stopPropagation, but don't have
  1439. // other expected methods like isPropagationStopped. Seems to be a problem
  1440. // with the Javascript Ninja code. So we're just overriding all events now.
  1441. if (!event || !event.isPropagationStopped) {
  1442. var old = event || window$1.event;
  1443. event = {}; // Clone the old object so that we can modify the values event = {};
  1444. // IE8 Doesn't like when you mess with native event properties
  1445. // Firefox returns false for event.hasOwnProperty('type') and other props
  1446. // which makes copying more difficult.
  1447. // TODO: Probably best to create a whitelist of event props
  1448. for (var key in old) {
  1449. // Safari 6.0.3 warns you if you try to copy deprecated layerX/Y
  1450. // Chrome warns you if you try to copy deprecated keyboardEvent.keyLocation
  1451. // and webkitMovementX/Y
  1452. if (key !== 'layerX' && key !== 'layerY' && key !== 'keyLocation' && key !== 'webkitMovementX' && key !== 'webkitMovementY') {
  1453. // Chrome 32+ warns if you try to copy deprecated returnValue, but
  1454. // we still want to if preventDefault isn't supported (IE8).
  1455. if (!(key === 'returnValue' && old.preventDefault)) {
  1456. event[key] = old[key];
  1457. }
  1458. }
  1459. } // The event occurred on this element
  1460. if (!event.target) {
  1461. event.target = event.srcElement || document;
  1462. } // Handle which other element the event is related to
  1463. if (!event.relatedTarget) {
  1464. event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
  1465. } // Stop the default browser action
  1466. event.preventDefault = function () {
  1467. if (old.preventDefault) {
  1468. old.preventDefault();
  1469. }
  1470. event.returnValue = false;
  1471. old.returnValue = false;
  1472. event.defaultPrevented = true;
  1473. };
  1474. event.defaultPrevented = false; // Stop the event from bubbling
  1475. event.stopPropagation = function () {
  1476. if (old.stopPropagation) {
  1477. old.stopPropagation();
  1478. }
  1479. event.cancelBubble = true;
  1480. old.cancelBubble = true;
  1481. event.isPropagationStopped = returnTrue;
  1482. };
  1483. event.isPropagationStopped = returnFalse; // Stop the event from bubbling and executing other handlers
  1484. event.stopImmediatePropagation = function () {
  1485. if (old.stopImmediatePropagation) {
  1486. old.stopImmediatePropagation();
  1487. }
  1488. event.isImmediatePropagationStopped = returnTrue;
  1489. event.stopPropagation();
  1490. };
  1491. event.isImmediatePropagationStopped = returnFalse; // Handle mouse position
  1492. if (event.clientX !== null && event.clientX !== undefined) {
  1493. var doc = document.documentElement;
  1494. var body = document.body;
  1495. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
  1496. event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
  1497. } // Handle key presses
  1498. event.which = event.charCode || event.keyCode; // Fix button for mouse clicks:
  1499. // 0 == left; 1 == middle; 2 == right
  1500. if (event.button !== null && event.button !== undefined) {
  1501. // The following is disabled because it does not pass videojs-standard
  1502. // and... yikes.
  1503. /* eslint-disable */
  1504. event.button = event.button & 1 ? 0 : event.button & 4 ? 1 : event.button & 2 ? 2 : 0;
  1505. /* eslint-enable */
  1506. }
  1507. } // Returns fixed-up instance
  1508. return event;
  1509. }
  1510. /**
  1511. * Whether passive event listeners are supported
  1512. */
  1513. var _supportsPassive = false;
  1514. (function () {
  1515. try {
  1516. var opts = Object.defineProperty({}, 'passive', {
  1517. get: function get() {
  1518. _supportsPassive = true;
  1519. }
  1520. });
  1521. window$1.addEventListener('test', null, opts);
  1522. window$1.removeEventListener('test', null, opts);
  1523. } catch (e) {// disregard
  1524. }
  1525. })();
  1526. /**
  1527. * Touch events Chrome expects to be passive
  1528. */
  1529. var passiveEvents = ['touchstart', 'touchmove'];
  1530. /**
  1531. * Add an event listener to element
  1532. * It stores the handler function in a separate cache object
  1533. * and adds a generic handler to the element's event,
  1534. * along with a unique id (guid) to the element.
  1535. *
  1536. * @param {Element|Object} elem
  1537. * Element or object to bind listeners to
  1538. *
  1539. * @param {string|string[]} type
  1540. * Type of event to bind to.
  1541. *
  1542. * @param {EventTarget~EventListener} fn
  1543. * Event listener.
  1544. */
  1545. function on(elem, type, fn) {
  1546. if (Array.isArray(type)) {
  1547. return _handleMultipleEvents(on, elem, type, fn);
  1548. }
  1549. if (!DomData.has(elem)) {
  1550. DomData.set(elem, {});
  1551. }
  1552. var data = DomData.get(elem); // We need a place to store all our handler data
  1553. if (!data.handlers) {
  1554. data.handlers = {};
  1555. }
  1556. if (!data.handlers[type]) {
  1557. data.handlers[type] = [];
  1558. }
  1559. if (!fn.guid) {
  1560. fn.guid = newGUID();
  1561. }
  1562. data.handlers[type].push(fn);
  1563. if (!data.dispatcher) {
  1564. data.disabled = false;
  1565. data.dispatcher = function (event, hash) {
  1566. if (data.disabled) {
  1567. return;
  1568. }
  1569. event = fixEvent(event);
  1570. var handlers = data.handlers[event.type];
  1571. if (handlers) {
  1572. // Copy handlers so if handlers are added/removed during the process it doesn't throw everything off.
  1573. var handlersCopy = handlers.slice(0);
  1574. for (var m = 0, n = handlersCopy.length; m < n; m++) {
  1575. if (event.isImmediatePropagationStopped()) {
  1576. break;
  1577. } else {
  1578. try {
  1579. handlersCopy[m].call(elem, event, hash);
  1580. } catch (e) {
  1581. log.error(e);
  1582. }
  1583. }
  1584. }
  1585. }
  1586. };
  1587. }
  1588. if (data.handlers[type].length === 1) {
  1589. if (elem.addEventListener) {
  1590. var options = false;
  1591. if (_supportsPassive && passiveEvents.indexOf(type) > -1) {
  1592. options = {
  1593. passive: true
  1594. };
  1595. }
  1596. elem.addEventListener(type, data.dispatcher, options);
  1597. } else if (elem.attachEvent) {
  1598. elem.attachEvent('on' + type, data.dispatcher);
  1599. }
  1600. }
  1601. }
  1602. /**
  1603. * Removes event listeners from an element
  1604. *
  1605. * @param {Element|Object} elem
  1606. * Object to remove listeners from.
  1607. *
  1608. * @param {string|string[]} [type]
  1609. * Type of listener to remove. Don't include to remove all events from element.
  1610. *
  1611. * @param {EventTarget~EventListener} [fn]
  1612. * Specific listener to remove. Don't include to remove listeners for an event
  1613. * type.
  1614. */
  1615. function off(elem, type, fn) {
  1616. // Don't want to add a cache object through getElData if not needed
  1617. if (!DomData.has(elem)) {
  1618. return;
  1619. }
  1620. var data = DomData.get(elem); // If no events exist, nothing to unbind
  1621. if (!data.handlers) {
  1622. return;
  1623. }
  1624. if (Array.isArray(type)) {
  1625. return _handleMultipleEvents(off, elem, type, fn);
  1626. } // Utility function
  1627. var removeType = function removeType(el, t) {
  1628. data.handlers[t] = [];
  1629. _cleanUpEvents(el, t);
  1630. }; // Are we removing all bound events?
  1631. if (type === undefined) {
  1632. for (var t in data.handlers) {
  1633. if (Object.prototype.hasOwnProperty.call(data.handlers || {}, t)) {
  1634. removeType(elem, t);
  1635. }
  1636. }
  1637. return;
  1638. }
  1639. var handlers = data.handlers[type]; // If no handlers exist, nothing to unbind
  1640. if (!handlers) {
  1641. return;
  1642. } // If no listener was provided, remove all listeners for type
  1643. if (!fn) {
  1644. removeType(elem, type);
  1645. return;
  1646. } // We're only removing a single handler
  1647. if (fn.guid) {
  1648. for (var n = 0; n < handlers.length; n++) {
  1649. if (handlers[n].guid === fn.guid) {
  1650. handlers.splice(n--, 1);
  1651. }
  1652. }
  1653. }
  1654. _cleanUpEvents(elem, type);
  1655. }
  1656. /**
  1657. * Trigger an event for an element
  1658. *
  1659. * @param {Element|Object} elem
  1660. * Element to trigger an event on
  1661. *
  1662. * @param {EventTarget~Event|string} event
  1663. * A string (the type) or an event object with a type attribute
  1664. *
  1665. * @param {Object} [hash]
  1666. * data hash to pass along with the event
  1667. *
  1668. * @return {boolean|undefined}
  1669. * Returns the opposite of `defaultPrevented` if default was
  1670. * prevented. Otherwise, returns `undefined`
  1671. */
  1672. function trigger(elem, event, hash) {
  1673. // Fetches element data and a reference to the parent (for bubbling).
  1674. // Don't want to add a data object to cache for every parent,
  1675. // so checking hasElData first.
  1676. var elemData = DomData.has(elem) ? DomData.get(elem) : {};
  1677. var parent = elem.parentNode || elem.ownerDocument; // type = event.type || event,
  1678. // handler;
  1679. // If an event name was passed as a string, creates an event out of it
  1680. if (typeof event === 'string') {
  1681. event = {
  1682. type: event,
  1683. target: elem
  1684. };
  1685. } else if (!event.target) {
  1686. event.target = elem;
  1687. } // Normalizes the event properties.
  1688. event = fixEvent(event); // If the passed element has a dispatcher, executes the established handlers.
  1689. if (elemData.dispatcher) {
  1690. elemData.dispatcher.call(elem, event, hash);
  1691. } // Unless explicitly stopped or the event does not bubble (e.g. media events)
  1692. // recursively calls this function to bubble the event up the DOM.
  1693. if (parent && !event.isPropagationStopped() && event.bubbles === true) {
  1694. trigger.call(null, parent, event, hash); // If at the top of the DOM, triggers the default action unless disabled.
  1695. } else if (!parent && !event.defaultPrevented && event.target && event.target[event.type]) {
  1696. if (!DomData.has(event.target)) {
  1697. DomData.set(event.target, {});
  1698. }
  1699. var targetData = DomData.get(event.target); // Checks if the target has a default action for this event.
  1700. if (event.target[event.type]) {
  1701. // Temporarily disables event dispatching on the target as we have already executed the handler.
  1702. targetData.disabled = true; // Executes the default action.
  1703. if (typeof event.target[event.type] === 'function') {
  1704. event.target[event.type]();
  1705. } // Re-enables event dispatching.
  1706. targetData.disabled = false;
  1707. }
  1708. } // Inform the triggerer if the default was prevented by returning false
  1709. return !event.defaultPrevented;
  1710. }
  1711. /**
  1712. * Trigger a listener only once for an event.
  1713. *
  1714. * @param {Element|Object} elem
  1715. * Element or object to bind to.
  1716. *
  1717. * @param {string|string[]} type
  1718. * Name/type of event
  1719. *
  1720. * @param {Event~EventListener} fn
  1721. * Event listener function
  1722. */
  1723. function one(elem, type, fn) {
  1724. if (Array.isArray(type)) {
  1725. return _handleMultipleEvents(one, elem, type, fn);
  1726. }
  1727. var func = function func() {
  1728. off(elem, type, func);
  1729. fn.apply(this, arguments);
  1730. }; // copy the guid to the new function so it can removed using the original function's ID
  1731. func.guid = fn.guid = fn.guid || newGUID();
  1732. on(elem, type, func);
  1733. }
  1734. /**
  1735. * Trigger a listener only once and then turn if off for all
  1736. * configured events
  1737. *
  1738. * @param {Element|Object} elem
  1739. * Element or object to bind to.
  1740. *
  1741. * @param {string|string[]} type
  1742. * Name/type of event
  1743. *
  1744. * @param {Event~EventListener} fn
  1745. * Event listener function
  1746. */
  1747. function any(elem, type, fn) {
  1748. var func = function func() {
  1749. off(elem, type, func);
  1750. fn.apply(this, arguments);
  1751. }; // copy the guid to the new function so it can removed using the original function's ID
  1752. func.guid = fn.guid = fn.guid || newGUID(); // multiple ons, but one off for everything
  1753. on(elem, type, func);
  1754. }
  1755. var Events = /*#__PURE__*/Object.freeze({
  1756. fixEvent: fixEvent,
  1757. on: on,
  1758. off: off,
  1759. trigger: trigger,
  1760. one: one,
  1761. any: any
  1762. });
  1763. /**
  1764. * @file fn.js
  1765. * @module fn
  1766. */
  1767. var UPDATE_REFRESH_INTERVAL = 30;
  1768. /**
  1769. * Bind (a.k.a proxy or context). A simple method for changing the context of
  1770. * a function.
  1771. *
  1772. * It also stores a unique id on the function so it can be easily removed from
  1773. * events.
  1774. *
  1775. * @function
  1776. * @param {Mixed} context
  1777. * The object to bind as scope.
  1778. *
  1779. * @param {Function} fn
  1780. * The function to be bound to a scope.
  1781. *
  1782. * @param {number} [uid]
  1783. * An optional unique ID for the function to be set
  1784. *
  1785. * @return {Function}
  1786. * The new function that will be bound into the context given
  1787. */
  1788. var bind = function bind(context, fn, uid) {
  1789. // Make sure the function has a unique ID
  1790. if (!fn.guid) {
  1791. fn.guid = newGUID();
  1792. } // Create the new function that changes the context
  1793. var bound = fn.bind(context); // Allow for the ability to individualize this function
  1794. // Needed in the case where multiple objects might share the same prototype
  1795. // IF both items add an event listener with the same function, then you try to remove just one
  1796. // it will remove both because they both have the same guid.
  1797. // when using this, you need to use the bind method when you remove the listener as well.
  1798. // currently used in text tracks
  1799. bound.guid = uid ? uid + '_' + fn.guid : fn.guid;
  1800. return bound;
  1801. };
  1802. /**
  1803. * Wraps the given function, `fn`, with a new function that only invokes `fn`
  1804. * at most once per every `wait` milliseconds.
  1805. *
  1806. * @function
  1807. * @param {Function} fn
  1808. * The function to be throttled.
  1809. *
  1810. * @param {number} wait
  1811. * The number of milliseconds by which to throttle.
  1812. *
  1813. * @return {Function}
  1814. */
  1815. var throttle = function throttle(fn, wait) {
  1816. var last = window$1.performance.now();
  1817. var throttled = function throttled() {
  1818. var now = window$1.performance.now();
  1819. if (now - last >= wait) {
  1820. fn.apply(void 0, arguments);
  1821. last = now;
  1822. }
  1823. };
  1824. return throttled;
  1825. };
  1826. /**
  1827. * Creates a debounced function that delays invoking `func` until after `wait`
  1828. * milliseconds have elapsed since the last time the debounced function was
  1829. * invoked.
  1830. *
  1831. * Inspired by lodash and underscore implementations.
  1832. *
  1833. * @function
  1834. * @param {Function} func
  1835. * The function to wrap with debounce behavior.
  1836. *
  1837. * @param {number} wait
  1838. * The number of milliseconds to wait after the last invocation.
  1839. *
  1840. * @param {boolean} [immediate]
  1841. * Whether or not to invoke the function immediately upon creation.
  1842. *
  1843. * @param {Object} [context=window]
  1844. * The "context" in which the debounced function should debounce. For
  1845. * example, if this function should be tied to a Video.js player,
  1846. * the player can be passed here. Alternatively, defaults to the
  1847. * global `window` object.
  1848. *
  1849. * @return {Function}
  1850. * A debounced function.
  1851. */
  1852. var debounce = function debounce(func, wait, immediate, context) {
  1853. if (context === void 0) {
  1854. context = window$1;
  1855. }
  1856. var timeout;
  1857. var cancel = function cancel() {
  1858. context.clearTimeout(timeout);
  1859. timeout = null;
  1860. };
  1861. /* eslint-disable consistent-this */
  1862. var debounced = function debounced() {
  1863. var self = this;
  1864. var args = arguments;
  1865. var _later = function later() {
  1866. timeout = null;
  1867. _later = null;
  1868. if (!immediate) {
  1869. func.apply(self, args);
  1870. }
  1871. };
  1872. if (!timeout && immediate) {
  1873. func.apply(self, args);
  1874. }
  1875. context.clearTimeout(timeout);
  1876. timeout = context.setTimeout(_later, wait);
  1877. };
  1878. /* eslint-enable consistent-this */
  1879. debounced.cancel = cancel;
  1880. return debounced;
  1881. };
  1882. /**
  1883. * @file src/js/event-target.js
  1884. */
  1885. /**
  1886. * `EventTarget` is a class that can have the same API as the DOM `EventTarget`. It
  1887. * adds shorthand functions that wrap around lengthy functions. For example:
  1888. * the `on` function is a wrapper around `addEventListener`.
  1889. *
  1890. * @see [EventTarget Spec]{@link https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget}
  1891. * @class EventTarget
  1892. */
  1893. var EventTarget = function EventTarget() {};
  1894. /**
  1895. * A Custom DOM event.
  1896. *
  1897. * @typedef {Object} EventTarget~Event
  1898. * @see [Properties]{@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent}
  1899. */
  1900. /**
  1901. * All event listeners should follow the following format.
  1902. *
  1903. * @callback EventTarget~EventListener
  1904. * @this {EventTarget}
  1905. *
  1906. * @param {EventTarget~Event} event
  1907. * the event that triggered this function
  1908. *
  1909. * @param {Object} [hash]
  1910. * hash of data sent during the event
  1911. */
  1912. /**
  1913. * An object containing event names as keys and booleans as values.
  1914. *
  1915. * > NOTE: If an event name is set to a true value here {@link EventTarget#trigger}
  1916. * will have extra functionality. See that function for more information.
  1917. *
  1918. * @property EventTarget.prototype.allowedEvents_
  1919. * @private
  1920. */
  1921. EventTarget.prototype.allowedEvents_ = {};
  1922. /**
  1923. * Adds an `event listener` to an instance of an `EventTarget`. An `event listener` is a
  1924. * function that will get called when an event with a certain name gets triggered.
  1925. *
  1926. * @param {string|string[]} type
  1927. * An event name or an array of event names.
  1928. *
  1929. * @param {EventTarget~EventListener} fn
  1930. * The function to call with `EventTarget`s
  1931. */
  1932. EventTarget.prototype.on = function (type, fn) {
  1933. // Remove the addEventListener alias before calling Events.on
  1934. // so we don't get into an infinite type loop
  1935. var ael = this.addEventListener;
  1936. this.addEventListener = function () {};
  1937. on(this, type, fn);
  1938. this.addEventListener = ael;
  1939. };
  1940. /**
  1941. * An alias of {@link EventTarget#on}. Allows `EventTarget` to mimic
  1942. * the standard DOM API.
  1943. *
  1944. * @function
  1945. * @see {@link EventTarget#on}
  1946. */
  1947. EventTarget.prototype.addEventListener = EventTarget.prototype.on;
  1948. /**
  1949. * Removes an `event listener` for a specific event from an instance of `EventTarget`.
  1950. * This makes it so that the `event listener` will no longer get called when the
  1951. * named event happens.
  1952. *
  1953. * @param {string|string[]} type
  1954. * An event name or an array of event names.
  1955. *
  1956. * @param {EventTarget~EventListener} fn
  1957. * The function to remove.
  1958. */
  1959. EventTarget.prototype.off = function (type, fn) {
  1960. off(this, type, fn);
  1961. };
  1962. /**
  1963. * An alias of {@link EventTarget#off}. Allows `EventTarget` to mimic
  1964. * the standard DOM API.
  1965. *
  1966. * @function
  1967. * @see {@link EventTarget#off}
  1968. */
  1969. EventTarget.prototype.removeEventListener = EventTarget.prototype.off;
  1970. /**
  1971. * This function will add an `event listener` that gets triggered only once. After the
  1972. * first trigger it will get removed. This is like adding an `event listener`
  1973. * with {@link EventTarget#on} that calls {@link EventTarget#off} on itself.
  1974. *
  1975. * @param {string|string[]} type
  1976. * An event name or an array of event names.
  1977. *
  1978. * @param {EventTarget~EventListener} fn
  1979. * The function to be called once for each event name.
  1980. */
  1981. EventTarget.prototype.one = function (type, fn) {
  1982. // Remove the addEventListener aliasing Events.on
  1983. // so we don't get into an infinite type loop
  1984. var ael = this.addEventListener;
  1985. this.addEventListener = function () {};
  1986. one(this, type, fn);
  1987. this.addEventListener = ael;
  1988. };
  1989. EventTarget.prototype.any = function (type, fn) {
  1990. // Remove the addEventListener aliasing Events.on
  1991. // so we don't get into an infinite type loop
  1992. var ael = this.addEventListener;
  1993. this.addEventListener = function () {};
  1994. any(this, type, fn);
  1995. this.addEventListener = ael;
  1996. };
  1997. /**
  1998. * This function causes an event to happen. This will then cause any `event listeners`
  1999. * that are waiting for that event, to get called. If there are no `event listeners`
  2000. * for an event then nothing will happen.
  2001. *
  2002. * If the name of the `Event` that is being triggered is in `EventTarget.allowedEvents_`.
  2003. * Trigger will also call the `on` + `uppercaseEventName` function.
  2004. *
  2005. * Example:
  2006. * 'click' is in `EventTarget.allowedEvents_`, so, trigger will attempt to call
  2007. * `onClick` if it exists.
  2008. *
  2009. * @param {string|EventTarget~Event|Object} event
  2010. * The name of the event, an `Event`, or an object with a key of type set to
  2011. * an event name.
  2012. */
  2013. EventTarget.prototype.trigger = function (event) {
  2014. var type = event.type || event; // deprecation
  2015. // In a future version we should default target to `this`
  2016. // similar to how we default the target to `elem` in
  2017. // `Events.trigger`. Right now the default `target` will be
  2018. // `document` due to the `Event.fixEvent` call.
  2019. if (typeof event === 'string') {
  2020. event = {
  2021. type: type
  2022. };
  2023. }
  2024. event = fixEvent(event);
  2025. if (this.allowedEvents_[type] && this['on' + type]) {
  2026. this['on' + type](event);
  2027. }
  2028. trigger(this, event);
  2029. };
  2030. /**
  2031. * An alias of {@link EventTarget#trigger}. Allows `EventTarget` to mimic
  2032. * the standard DOM API.
  2033. *
  2034. * @function
  2035. * @see {@link EventTarget#trigger}
  2036. */
  2037. EventTarget.prototype.dispatchEvent = EventTarget.prototype.trigger;
  2038. var EVENT_MAP;
  2039. EventTarget.prototype.queueTrigger = function (event) {
  2040. var _this = this;
  2041. // only set up EVENT_MAP if it'll be used
  2042. if (!EVENT_MAP) {
  2043. EVENT_MAP = new Map();
  2044. }
  2045. var type = event.type || event;
  2046. var map = EVENT_MAP.get(this);
  2047. if (!map) {
  2048. map = new Map();
  2049. EVENT_MAP.set(this, map);
  2050. }
  2051. var oldTimeout = map.get(type);
  2052. map["delete"](type);
  2053. window$1.clearTimeout(oldTimeout);
  2054. var timeout = window$1.setTimeout(function () {
  2055. // if we cleared out all timeouts for the current target, delete its map
  2056. if (map.size === 0) {
  2057. map = null;
  2058. EVENT_MAP["delete"](_this);
  2059. }
  2060. _this.trigger(event);
  2061. }, 0);
  2062. map.set(type, timeout);
  2063. };
  2064. /**
  2065. * @file mixins/evented.js
  2066. * @module evented
  2067. */
  2068. /**
  2069. * Returns whether or not an object has had the evented mixin applied.
  2070. *
  2071. * @param {Object} object
  2072. * An object to test.
  2073. *
  2074. * @return {boolean}
  2075. * Whether or not the object appears to be evented.
  2076. */
  2077. var isEvented = function isEvented(object) {
  2078. return object instanceof EventTarget || !!object.eventBusEl_ && ['on', 'one', 'off', 'trigger'].every(function (k) {
  2079. return typeof object[k] === 'function';
  2080. });
  2081. };
  2082. /**
  2083. * Adds a callback to run after the evented mixin applied.
  2084. *
  2085. * @param {Object} object
  2086. * An object to Add
  2087. * @param {Function} callback
  2088. * The callback to run.
  2089. */
  2090. var addEventedCallback = function addEventedCallback(target, callback) {
  2091. if (isEvented(target)) {
  2092. callback();
  2093. } else {
  2094. if (!target.eventedCallbacks) {
  2095. target.eventedCallbacks = [];
  2096. }
  2097. target.eventedCallbacks.push(callback);
  2098. }
  2099. };
  2100. /**
  2101. * Whether a value is a valid event type - non-empty string or array.
  2102. *
  2103. * @private
  2104. * @param {string|Array} type
  2105. * The type value to test.
  2106. *
  2107. * @return {boolean}
  2108. * Whether or not the type is a valid event type.
  2109. */
  2110. var isValidEventType = function isValidEventType(type) {
  2111. return (// The regex here verifies that the `type` contains at least one non-
  2112. // whitespace character.
  2113. typeof type === 'string' && /\S/.test(type) || Array.isArray(type) && !!type.length
  2114. );
  2115. };
  2116. /**
  2117. * Validates a value to determine if it is a valid event target. Throws if not.
  2118. *
  2119. * @private
  2120. * @throws {Error}
  2121. * If the target does not appear to be a valid event target.
  2122. *
  2123. * @param {Object} target
  2124. * The object to test.
  2125. */
  2126. var validateTarget = function validateTarget(target) {
  2127. if (!target.nodeName && !isEvented(target)) {
  2128. throw new Error('Invalid target; must be a DOM node or evented object.');
  2129. }
  2130. };
  2131. /**
  2132. * Validates a value to determine if it is a valid event target. Throws if not.
  2133. *
  2134. * @private
  2135. * @throws {Error}
  2136. * If the type does not appear to be a valid event type.
  2137. *
  2138. * @param {string|Array} type
  2139. * The type to test.
  2140. */
  2141. var validateEventType = function validateEventType(type) {
  2142. if (!isValidEventType(type)) {
  2143. throw new Error('Invalid event type; must be a non-empty string or array.');
  2144. }
  2145. };
  2146. /**
  2147. * Validates a value to determine if it is a valid listener. Throws if not.
  2148. *
  2149. * @private
  2150. * @throws {Error}
  2151. * If the listener is not a function.
  2152. *
  2153. * @param {Function} listener
  2154. * The listener to test.
  2155. */
  2156. var validateListener = function validateListener(listener) {
  2157. if (typeof listener !== 'function') {
  2158. throw new Error('Invalid listener; must be a function.');
  2159. }
  2160. };
  2161. /**
  2162. * Takes an array of arguments given to `on()` or `one()`, validates them, and
  2163. * normalizes them into an object.
  2164. *
  2165. * @private
  2166. * @param {Object} self
  2167. * The evented object on which `on()` or `one()` was called. This
  2168. * object will be bound as the `this` value for the listener.
  2169. *
  2170. * @param {Array} args
  2171. * An array of arguments passed to `on()` or `one()`.
  2172. *
  2173. * @return {Object}
  2174. * An object containing useful values for `on()` or `one()` calls.
  2175. */
  2176. var normalizeListenArgs = function normalizeListenArgs(self, args) {
  2177. // If the number of arguments is less than 3, the target is always the
  2178. // evented object itself.
  2179. var isTargetingSelf = args.length < 3 || args[0] === self || args[0] === self.eventBusEl_;
  2180. var target;
  2181. var type;
  2182. var listener;
  2183. if (isTargetingSelf) {
  2184. target = self.eventBusEl_; // Deal with cases where we got 3 arguments, but we are still listening to
  2185. // the evented object itself.
  2186. if (args.length >= 3) {
  2187. args.shift();
  2188. }
  2189. type = args[0];
  2190. listener = args[1];
  2191. } else {
  2192. target = args[0];
  2193. type = args[1];
  2194. listener = args[2];
  2195. }
  2196. validateTarget(target);
  2197. validateEventType(type);
  2198. validateListener(listener);
  2199. listener = bind(self, listener);
  2200. return {
  2201. isTargetingSelf: isTargetingSelf,
  2202. target: target,
  2203. type: type,
  2204. listener: listener
  2205. };
  2206. };
  2207. /**
  2208. * Adds the listener to the event type(s) on the target, normalizing for
  2209. * the type of target.
  2210. *
  2211. * @private
  2212. * @param {Element|Object} target
  2213. * A DOM node or evented object.
  2214. *
  2215. * @param {string} method
  2216. * The event binding method to use ("on" or "one").
  2217. *
  2218. * @param {string|Array} type
  2219. * One or more event type(s).
  2220. *
  2221. * @param {Function} listener
  2222. * A listener function.
  2223. */
  2224. var listen = function listen(target, method, type, listener) {
  2225. validateTarget(target);
  2226. if (target.nodeName) {
  2227. Events[method](target, type, listener);
  2228. } else {
  2229. target[method](type, listener);
  2230. }
  2231. };
  2232. /**
  2233. * Contains methods that provide event capabilities to an object which is passed
  2234. * to {@link module:evented|evented}.
  2235. *
  2236. * @mixin EventedMixin
  2237. */
  2238. var EventedMixin = {
  2239. /**
  2240. * Add a listener to an event (or events) on this object or another evented
  2241. * object.
  2242. *
  2243. * @param {string|Array|Element|Object} targetOrType
  2244. * If this is a string or array, it represents the event type(s)
  2245. * that will trigger the listener.
  2246. *
  2247. * Another evented object can be passed here instead, which will
  2248. * cause the listener to listen for events on _that_ object.
  2249. *
  2250. * In either case, the listener's `this` value will be bound to
  2251. * this object.
  2252. *
  2253. * @param {string|Array|Function} typeOrListener
  2254. * If the first argument was a string or array, this should be the
  2255. * listener function. Otherwise, this is a string or array of event
  2256. * type(s).
  2257. *
  2258. * @param {Function} [listener]
  2259. * If the first argument was another evented object, this will be
  2260. * the listener function.
  2261. */
  2262. on: function on() {
  2263. var _this = this;
  2264. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2265. args[_key] = arguments[_key];
  2266. }
  2267. var _normalizeListenArgs = normalizeListenArgs(this, args),
  2268. isTargetingSelf = _normalizeListenArgs.isTargetingSelf,
  2269. target = _normalizeListenArgs.target,
  2270. type = _normalizeListenArgs.type,
  2271. listener = _normalizeListenArgs.listener;
  2272. listen(target, 'on', type, listener); // If this object is listening to another evented object.
  2273. if (!isTargetingSelf) {
  2274. // If this object is disposed, remove the listener.
  2275. var removeListenerOnDispose = function removeListenerOnDispose() {
  2276. return _this.off(target, type, listener);
  2277. }; // Use the same function ID as the listener so we can remove it later it
  2278. // using the ID of the original listener.
  2279. removeListenerOnDispose.guid = listener.guid; // Add a listener to the target's dispose event as well. This ensures
  2280. // that if the target is disposed BEFORE this object, we remove the
  2281. // removal listener that was just added. Otherwise, we create a memory leak.
  2282. var removeRemoverOnTargetDispose = function removeRemoverOnTargetDispose() {
  2283. return _this.off('dispose', removeListenerOnDispose);
  2284. }; // Use the same function ID as the listener so we can remove it later
  2285. // it using the ID of the original listener.
  2286. removeRemoverOnTargetDispose.guid = listener.guid;
  2287. listen(this, 'on', 'dispose', removeListenerOnDispose);
  2288. listen(target, 'on', 'dispose', removeRemoverOnTargetDispose);
  2289. }
  2290. },
  2291. /**
  2292. * Add a listener to an event (or events) on this object or another evented
  2293. * object. The listener will be called once per event and then removed.
  2294. *
  2295. * @param {string|Array|Element|Object} targetOrType
  2296. * If this is a string or array, it represents the event type(s)
  2297. * that will trigger the listener.
  2298. *
  2299. * Another evented object can be passed here instead, which will
  2300. * cause the listener to listen for events on _that_ object.
  2301. *
  2302. * In either case, the listener's `this` value will be bound to
  2303. * this object.
  2304. *
  2305. * @param {string|Array|Function} typeOrListener
  2306. * If the first argument was a string or array, this should be the
  2307. * listener function. Otherwise, this is a string or array of event
  2308. * type(s).
  2309. *
  2310. * @param {Function} [listener]
  2311. * If the first argument was another evented object, this will be
  2312. * the listener function.
  2313. */
  2314. one: function one() {
  2315. var _this2 = this;
  2316. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  2317. args[_key2] = arguments[_key2];
  2318. }
  2319. var _normalizeListenArgs2 = normalizeListenArgs(this, args),
  2320. isTargetingSelf = _normalizeListenArgs2.isTargetingSelf,
  2321. target = _normalizeListenArgs2.target,
  2322. type = _normalizeListenArgs2.type,
  2323. listener = _normalizeListenArgs2.listener; // Targeting this evented object.
  2324. if (isTargetingSelf) {
  2325. listen(target, 'one', type, listener); // Targeting another evented object.
  2326. } else {
  2327. // TODO: This wrapper is incorrect! It should only
  2328. // remove the wrapper for the event type that called it.
  2329. // Instead all listners are removed on the first trigger!
  2330. // see https://github.com/videojs/video.js/issues/5962
  2331. var wrapper = function wrapper() {
  2332. _this2.off(target, type, wrapper);
  2333. for (var _len3 = arguments.length, largs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  2334. largs[_key3] = arguments[_key3];
  2335. }
  2336. listener.apply(null, largs);
  2337. }; // Use the same function ID as the listener so we can remove it later
  2338. // it using the ID of the original listener.
  2339. wrapper.guid = listener.guid;
  2340. listen(target, 'one', type, wrapper);
  2341. }
  2342. },
  2343. /**
  2344. * Add a listener to an event (or events) on this object or another evented
  2345. * object. The listener will only be called once for the first event that is triggered
  2346. * then removed.
  2347. *
  2348. * @param {string|Array|Element|Object} targetOrType
  2349. * If this is a string or array, it represents the event type(s)
  2350. * that will trigger the listener.
  2351. *
  2352. * Another evented object can be passed here instead, which will
  2353. * cause the listener to listen for events on _that_ object.
  2354. *
  2355. * In either case, the listener's `this` value will be bound to
  2356. * this object.
  2357. *
  2358. * @param {string|Array|Function} typeOrListener
  2359. * If the first argument was a string or array, this should be the
  2360. * listener function. Otherwise, this is a string or array of event
  2361. * type(s).
  2362. *
  2363. * @param {Function} [listener]
  2364. * If the first argument was another evented object, this will be
  2365. * the listener function.
  2366. */
  2367. any: function any() {
  2368. var _this3 = this;
  2369. for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  2370. args[_key4] = arguments[_key4];
  2371. }
  2372. var _normalizeListenArgs3 = normalizeListenArgs(this, args),
  2373. isTargetingSelf = _normalizeListenArgs3.isTargetingSelf,
  2374. target = _normalizeListenArgs3.target,
  2375. type = _normalizeListenArgs3.type,
  2376. listener = _normalizeListenArgs3.listener; // Targeting this evented object.
  2377. if (isTargetingSelf) {
  2378. listen(target, 'any', type, listener); // Targeting another evented object.
  2379. } else {
  2380. var wrapper = function wrapper() {
  2381. _this3.off(target, type, wrapper);
  2382. for (var _len5 = arguments.length, largs = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  2383. largs[_key5] = arguments[_key5];
  2384. }
  2385. listener.apply(null, largs);
  2386. }; // Use the same function ID as the listener so we can remove it later
  2387. // it using the ID of the original listener.
  2388. wrapper.guid = listener.guid;
  2389. listen(target, 'any', type, wrapper);
  2390. }
  2391. },
  2392. /**
  2393. * Removes listener(s) from event(s) on an evented object.
  2394. *
  2395. * @param {string|Array|Element|Object} [targetOrType]
  2396. * If this is a string or array, it represents the event type(s).
  2397. *
  2398. * Another evented object can be passed here instead, in which case
  2399. * ALL 3 arguments are _required_.
  2400. *
  2401. * @param {string|Array|Function} [typeOrListener]
  2402. * If the first argument was a string or array, this may be the
  2403. * listener function. Otherwise, this is a string or array of event
  2404. * type(s).
  2405. *
  2406. * @param {Function} [listener]
  2407. * If the first argument was another evented object, this will be
  2408. * the listener function; otherwise, _all_ listeners bound to the
  2409. * event type(s) will be removed.
  2410. */
  2411. off: function off$1(targetOrType, typeOrListener, listener) {
  2412. // Targeting this evented object.
  2413. if (!targetOrType || isValidEventType(targetOrType)) {
  2414. off(this.eventBusEl_, targetOrType, typeOrListener); // Targeting another evented object.
  2415. } else {
  2416. var target = targetOrType;
  2417. var type = typeOrListener; // Fail fast and in a meaningful way!
  2418. validateTarget(target);
  2419. validateEventType(type);
  2420. validateListener(listener); // Ensure there's at least a guid, even if the function hasn't been used
  2421. listener = bind(this, listener); // Remove the dispose listener on this evented object, which was given
  2422. // the same guid as the event listener in on().
  2423. this.off('dispose', listener);
  2424. if (target.nodeName) {
  2425. off(target, type, listener);
  2426. off(target, 'dispose', listener);
  2427. } else if (isEvented(target)) {
  2428. target.off(type, listener);
  2429. target.off('dispose', listener);
  2430. }
  2431. }
  2432. },
  2433. /**
  2434. * Fire an event on this evented object, causing its listeners to be called.
  2435. *
  2436. * @param {string|Object} event
  2437. * An event type or an object with a type property.
  2438. *
  2439. * @param {Object} [hash]
  2440. * An additional object to pass along to listeners.
  2441. *
  2442. * @return {boolean}
  2443. * Whether or not the default behavior was prevented.
  2444. */
  2445. trigger: function trigger$1(event, hash) {
  2446. return trigger(this.eventBusEl_, event, hash);
  2447. }
  2448. };
  2449. /**
  2450. * Applies {@link module:evented~EventedMixin|EventedMixin} to a target object.
  2451. *
  2452. * @param {Object} target
  2453. * The object to which to add event methods.
  2454. *
  2455. * @param {Object} [options={}]
  2456. * Options for customizing the mixin behavior.
  2457. *
  2458. * @param {string} [options.eventBusKey]
  2459. * By default, adds a `eventBusEl_` DOM element to the target object,
  2460. * which is used as an event bus. If the target object already has a
  2461. * DOM element that should be used, pass its key here.
  2462. *
  2463. * @return {Object}
  2464. * The target object.
  2465. */
  2466. function evented(target, options) {
  2467. if (options === void 0) {
  2468. options = {};
  2469. }
  2470. var _options = options,
  2471. eventBusKey = _options.eventBusKey; // Set or create the eventBusEl_.
  2472. if (eventBusKey) {
  2473. if (!target[eventBusKey].nodeName) {
  2474. throw new Error("The eventBusKey \"" + eventBusKey + "\" does not refer to an element.");
  2475. }
  2476. target.eventBusEl_ = target[eventBusKey];
  2477. } else {
  2478. target.eventBusEl_ = createEl('span', {
  2479. className: 'vjs-event-bus'
  2480. });
  2481. }
  2482. assign(target, EventedMixin);
  2483. if (target.eventedCallbacks) {
  2484. target.eventedCallbacks.forEach(function (callback) {
  2485. callback();
  2486. });
  2487. } // When any evented object is disposed, it removes all its listeners.
  2488. target.on('dispose', function () {
  2489. target.off();
  2490. window$1.setTimeout(function () {
  2491. target.eventBusEl_ = null;
  2492. }, 0);
  2493. });
  2494. return target;
  2495. }
  2496. /**
  2497. * @file mixins/stateful.js
  2498. * @module stateful
  2499. */
  2500. /**
  2501. * Contains methods that provide statefulness to an object which is passed
  2502. * to {@link module:stateful}.
  2503. *
  2504. * @mixin StatefulMixin
  2505. */
  2506. var StatefulMixin = {
  2507. /**
  2508. * A hash containing arbitrary keys and values representing the state of
  2509. * the object.
  2510. *
  2511. * @type {Object}
  2512. */
  2513. state: {},
  2514. /**
  2515. * Set the state of an object by mutating its
  2516. * {@link module:stateful~StatefulMixin.state|state} object in place.
  2517. *
  2518. * @fires module:stateful~StatefulMixin#statechanged
  2519. * @param {Object|Function} stateUpdates
  2520. * A new set of properties to shallow-merge into the plugin state.
  2521. * Can be a plain object or a function returning a plain object.
  2522. *
  2523. * @return {Object|undefined}
  2524. * An object containing changes that occurred. If no changes
  2525. * occurred, returns `undefined`.
  2526. */
  2527. setState: function setState(stateUpdates) {
  2528. var _this = this;
  2529. // Support providing the `stateUpdates` state as a function.
  2530. if (typeof stateUpdates === 'function') {
  2531. stateUpdates = stateUpdates();
  2532. }
  2533. var changes;
  2534. each(stateUpdates, function (value, key) {
  2535. // Record the change if the value is different from what's in the
  2536. // current state.
  2537. if (_this.state[key] !== value) {
  2538. changes = changes || {};
  2539. changes[key] = {
  2540. from: _this.state[key],
  2541. to: value
  2542. };
  2543. }
  2544. _this.state[key] = value;
  2545. }); // Only trigger "statechange" if there were changes AND we have a trigger
  2546. // function. This allows us to not require that the target object be an
  2547. // evented object.
  2548. if (changes && isEvented(this)) {
  2549. /**
  2550. * An event triggered on an object that is both
  2551. * {@link module:stateful|stateful} and {@link module:evented|evented}
  2552. * indicating that its state has changed.
  2553. *
  2554. * @event module:stateful~StatefulMixin#statechanged
  2555. * @type {Object}
  2556. * @property {Object} changes
  2557. * A hash containing the properties that were changed and
  2558. * the values they were changed `from` and `to`.
  2559. */
  2560. this.trigger({
  2561. changes: changes,
  2562. type: 'statechanged'
  2563. });
  2564. }
  2565. return changes;
  2566. }
  2567. };
  2568. /**
  2569. * Applies {@link module:stateful~StatefulMixin|StatefulMixin} to a target
  2570. * object.
  2571. *
  2572. * If the target object is {@link module:evented|evented} and has a
  2573. * `handleStateChanged` method, that method will be automatically bound to the
  2574. * `statechanged` event on itself.
  2575. *
  2576. * @param {Object} target
  2577. * The object to be made stateful.
  2578. *
  2579. * @param {Object} [defaultState]
  2580. * A default set of properties to populate the newly-stateful object's
  2581. * `state` property.
  2582. *
  2583. * @return {Object}
  2584. * Returns the `target`.
  2585. */
  2586. function stateful(target, defaultState) {
  2587. assign(target, StatefulMixin); // This happens after the mixing-in because we need to replace the `state`
  2588. // added in that step.
  2589. target.state = assign({}, target.state, defaultState); // Auto-bind the `handleStateChanged` method of the target object if it exists.
  2590. if (typeof target.handleStateChanged === 'function' && isEvented(target)) {
  2591. target.on('statechanged', target.handleStateChanged);
  2592. }
  2593. return target;
  2594. }
  2595. /**
  2596. * @file string-cases.js
  2597. * @module to-lower-case
  2598. */
  2599. /**
  2600. * Lowercase the first letter of a string.
  2601. *
  2602. * @param {string} string
  2603. * String to be lowercased
  2604. *
  2605. * @return {string}
  2606. * The string with a lowercased first letter
  2607. */
  2608. var toLowerCase = function toLowerCase(string) {
  2609. if (typeof string !== 'string') {
  2610. return string;
  2611. }
  2612. return string.replace(/./, function (w) {
  2613. return w.toLowerCase();
  2614. });
  2615. };
  2616. /**
  2617. * Uppercase the first letter of a string.
  2618. *
  2619. * @param {string} string
  2620. * String to be uppercased
  2621. *
  2622. * @return {string}
  2623. * The string with an uppercased first letter
  2624. */
  2625. var toTitleCase = function toTitleCase(string) {
  2626. if (typeof string !== 'string') {
  2627. return string;
  2628. }
  2629. return string.replace(/./, function (w) {
  2630. return w.toUpperCase();
  2631. });
  2632. };
  2633. /**
  2634. * Compares the TitleCase versions of the two strings for equality.
  2635. *
  2636. * @param {string} str1
  2637. * The first string to compare
  2638. *
  2639. * @param {string} str2
  2640. * The second string to compare
  2641. *
  2642. * @return {boolean}
  2643. * Whether the TitleCase versions of the strings are equal
  2644. */
  2645. var titleCaseEquals = function titleCaseEquals(str1, str2) {
  2646. return toTitleCase(str1) === toTitleCase(str2);
  2647. };
  2648. /**
  2649. * @file merge-options.js
  2650. * @module merge-options
  2651. */
  2652. /**
  2653. * Merge two objects recursively.
  2654. *
  2655. * Performs a deep merge like
  2656. * {@link https://lodash.com/docs/4.17.10#merge|lodash.merge}, but only merges
  2657. * plain objects (not arrays, elements, or anything else).
  2658. *
  2659. * Non-plain object values will be copied directly from the right-most
  2660. * argument.
  2661. *
  2662. * @static
  2663. * @param {Object[]} sources
  2664. * One or more objects to merge into a new object.
  2665. *
  2666. * @return {Object}
  2667. * A new object that is the merged result of all sources.
  2668. */
  2669. function mergeOptions() {
  2670. var result = {};
  2671. for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
  2672. sources[_key] = arguments[_key];
  2673. }
  2674. sources.forEach(function (source) {
  2675. if (!source) {
  2676. return;
  2677. }
  2678. each(source, function (value, key) {
  2679. if (!isPlain(value)) {
  2680. result[key] = value;
  2681. return;
  2682. }
  2683. if (!isPlain(result[key])) {
  2684. result[key] = {};
  2685. }
  2686. result[key] = mergeOptions(result[key], value);
  2687. });
  2688. });
  2689. return result;
  2690. }
  2691. /**
  2692. * Player Component - Base class for all UI objects
  2693. *
  2694. * @file component.js
  2695. */
  2696. /**
  2697. * Base class for all UI Components.
  2698. * Components are UI objects which represent both a javascript object and an element
  2699. * in the DOM. They can be children of other components, and can have
  2700. * children themselves.
  2701. *
  2702. * Components can also use methods from {@link EventTarget}
  2703. */
  2704. var Component =
  2705. /*#__PURE__*/
  2706. function () {
  2707. /**
  2708. * A callback that is called when a component is ready. Does not have any
  2709. * paramters and any callback value will be ignored.
  2710. *
  2711. * @callback Component~ReadyCallback
  2712. * @this Component
  2713. */
  2714. /**
  2715. * Creates an instance of this class.
  2716. *
  2717. * @param {Player} player
  2718. * The `Player` that this class should be attached to.
  2719. *
  2720. * @param {Object} [options]
  2721. * The key/value store of player options.
  2722. *
  2723. * @param {Object[]} [options.children]
  2724. * An array of children objects to intialize this component with. Children objects have
  2725. * a name property that will be used if more than one component of the same type needs to be
  2726. * added.
  2727. *
  2728. * @param {Component~ReadyCallback} [ready]
  2729. * Function that gets called when the `Component` is ready.
  2730. */
  2731. function Component(player, options, ready) {
  2732. // The component might be the player itself and we can't pass `this` to super
  2733. if (!player && this.play) {
  2734. this.player_ = player = this; // eslint-disable-line
  2735. } else {
  2736. this.player_ = player;
  2737. } // Hold the reference to the parent component via `addChild` method
  2738. this.parentComponent_ = null; // Make a copy of prototype.options_ to protect against overriding defaults
  2739. this.options_ = mergeOptions({}, this.options_); // Updated options with supplied options
  2740. options = this.options_ = mergeOptions(this.options_, options); // Get ID from options or options element if one is supplied
  2741. this.id_ = options.id || options.el && options.el.id; // If there was no ID from the options, generate one
  2742. if (!this.id_) {
  2743. // Don't require the player ID function in the case of mock players
  2744. var id = player && player.id && player.id() || 'no_player';
  2745. this.id_ = id + "_component_" + newGUID();
  2746. }
  2747. this.name_ = options.name || null; // Create element if one wasn't provided in options
  2748. if (options.el) {
  2749. this.el_ = options.el;
  2750. } else if (options.createEl !== false) {
  2751. this.el_ = this.createEl();
  2752. } // if evented is anything except false, we want to mixin in evented
  2753. if (options.evented !== false) {
  2754. // Make this an evented object and use `el_`, if available, as its event bus
  2755. evented(this, {
  2756. eventBusKey: this.el_ ? 'el_' : null
  2757. });
  2758. }
  2759. stateful(this, this.constructor.defaultState);
  2760. this.children_ = [];
  2761. this.childIndex_ = {};
  2762. this.childNameIndex_ = {};
  2763. this.setTimeoutIds_ = new Set();
  2764. this.setIntervalIds_ = new Set();
  2765. this.rafIds_ = new Set();
  2766. this.clearingTimersOnDispose_ = false; // Add any child components in options
  2767. if (options.initChildren !== false) {
  2768. this.initChildren();
  2769. }
  2770. this.ready(ready); // Don't want to trigger ready here or it will before init is actually
  2771. // finished for all children that run this constructor
  2772. if (options.reportTouchActivity !== false) {
  2773. this.enableTouchActivity();
  2774. }
  2775. }
  2776. /**
  2777. * Dispose of the `Component` and all child components.
  2778. *
  2779. * @fires Component#dispose
  2780. */
  2781. var _proto = Component.prototype;
  2782. _proto.dispose = function dispose() {
  2783. /**
  2784. * Triggered when a `Component` is disposed.
  2785. *
  2786. * @event Component#dispose
  2787. * @type {EventTarget~Event}
  2788. *
  2789. * @property {boolean} [bubbles=false]
  2790. * set to false so that the close event does not
  2791. * bubble up
  2792. */
  2793. this.trigger({
  2794. type: 'dispose',
  2795. bubbles: false
  2796. }); // Dispose all children.
  2797. if (this.children_) {
  2798. for (var i = this.children_.length - 1; i >= 0; i--) {
  2799. if (this.children_[i].dispose) {
  2800. this.children_[i].dispose();
  2801. }
  2802. }
  2803. } // Delete child references
  2804. this.children_ = null;
  2805. this.childIndex_ = null;
  2806. this.childNameIndex_ = null;
  2807. this.parentComponent_ = null;
  2808. if (this.el_) {
  2809. // Remove element from DOM
  2810. if (this.el_.parentNode) {
  2811. this.el_.parentNode.removeChild(this.el_);
  2812. }
  2813. if (DomData.has(this.el_)) {
  2814. DomData["delete"](this.el_);
  2815. }
  2816. this.el_ = null;
  2817. } // remove reference to the player after disposing of the element
  2818. this.player_ = null;
  2819. }
  2820. /**
  2821. * Return the {@link Player} that the `Component` has attached to.
  2822. *
  2823. * @return {Player}
  2824. * The player that this `Component` has attached to.
  2825. */
  2826. ;
  2827. _proto.player = function player() {
  2828. return this.player_;
  2829. }
  2830. /**
  2831. * Deep merge of options objects with new options.
  2832. * > Note: When both `obj` and `options` contain properties whose values are objects.
  2833. * The two properties get merged using {@link module:mergeOptions}
  2834. *
  2835. * @param {Object} obj
  2836. * The object that contains new options.
  2837. *
  2838. * @return {Object}
  2839. * A new object of `this.options_` and `obj` merged together.
  2840. */
  2841. ;
  2842. _proto.options = function options(obj) {
  2843. if (!obj) {
  2844. return this.options_;
  2845. }
  2846. this.options_ = mergeOptions(this.options_, obj);
  2847. return this.options_;
  2848. }
  2849. /**
  2850. * Get the `Component`s DOM element
  2851. *
  2852. * @return {Element}
  2853. * The DOM element for this `Component`.
  2854. */
  2855. ;
  2856. _proto.el = function el() {
  2857. return this.el_;
  2858. }
  2859. /**
  2860. * Create the `Component`s DOM element.
  2861. *
  2862. * @param {string} [tagName]
  2863. * Element's DOM node type. e.g. 'div'
  2864. *
  2865. * @param {Object} [properties]
  2866. * An object of properties that should be set.
  2867. *
  2868. * @param {Object} [attributes]
  2869. * An object of attributes that should be set.
  2870. *
  2871. * @return {Element}
  2872. * The element that gets created.
  2873. */
  2874. ;
  2875. _proto.createEl = function createEl$1(tagName, properties, attributes) {
  2876. return createEl(tagName, properties, attributes);
  2877. }
  2878. /**
  2879. * Localize a string given the string in english.
  2880. *
  2881. * If tokens are provided, it'll try and run a simple token replacement on the provided string.
  2882. * The tokens it looks for look like `{1}` with the index being 1-indexed into the tokens array.
  2883. *
  2884. * If a `defaultValue` is provided, it'll use that over `string`,
  2885. * if a value isn't found in provided language files.
  2886. * This is useful if you want to have a descriptive key for token replacement
  2887. * but have a succinct localized string and not require `en.json` to be included.
  2888. *
  2889. * Currently, it is used for the progress bar timing.
  2890. * ```js
  2891. * {
  2892. * "progress bar timing: currentTime={1} duration={2}": "{1} of {2}"
  2893. * }
  2894. * ```
  2895. * It is then used like so:
  2896. * ```js
  2897. * this.localize('progress bar timing: currentTime={1} duration{2}',
  2898. * [this.player_.currentTime(), this.player_.duration()],
  2899. * '{1} of {2}');
  2900. * ```
  2901. *
  2902. * Which outputs something like: `01:23 of 24:56`.
  2903. *
  2904. *
  2905. * @param {string} string
  2906. * The string to localize and the key to lookup in the language files.
  2907. * @param {string[]} [tokens]
  2908. * If the current item has token replacements, provide the tokens here.
  2909. * @param {string} [defaultValue]
  2910. * Defaults to `string`. Can be a default value to use for token replacement
  2911. * if the lookup key is needed to be separate.
  2912. *
  2913. * @return {string}
  2914. * The localized string or if no localization exists the english string.
  2915. */
  2916. ;
  2917. _proto.localize = function localize(string, tokens, defaultValue) {
  2918. if (defaultValue === void 0) {
  2919. defaultValue = string;
  2920. }
  2921. var code = this.player_.language && this.player_.language();
  2922. var languages = this.player_.languages && this.player_.languages();
  2923. var language = languages && languages[code];
  2924. var primaryCode = code && code.split('-')[0];
  2925. var primaryLang = languages && languages[primaryCode];
  2926. var localizedString = defaultValue;
  2927. if (language && language[string]) {
  2928. localizedString = language[string];
  2929. } else if (primaryLang && primaryLang[string]) {
  2930. localizedString = primaryLang[string];
  2931. }
  2932. if (tokens) {
  2933. localizedString = localizedString.replace(/\{(\d+)\}/g, function (match, index) {
  2934. var value = tokens[index - 1];
  2935. var ret = value;
  2936. if (typeof value === 'undefined') {
  2937. ret = match;
  2938. }
  2939. return ret;
  2940. });
  2941. }
  2942. return localizedString;
  2943. }
  2944. /**
  2945. * Return the `Component`s DOM element. This is where children get inserted.
  2946. * This will usually be the the same as the element returned in {@link Component#el}.
  2947. *
  2948. * @return {Element}
  2949. * The content element for this `Component`.
  2950. */
  2951. ;
  2952. _proto.contentEl = function contentEl() {
  2953. return this.contentEl_ || this.el_;
  2954. }
  2955. /**
  2956. * Get this `Component`s ID
  2957. *
  2958. * @return {string}
  2959. * The id of this `Component`
  2960. */
  2961. ;
  2962. _proto.id = function id() {
  2963. return this.id_;
  2964. }
  2965. /**
  2966. * Get the `Component`s name. The name gets used to reference the `Component`
  2967. * and is set during registration.
  2968. *
  2969. * @return {string}
  2970. * The name of this `Component`.
  2971. */
  2972. ;
  2973. _proto.name = function name() {
  2974. return this.name_;
  2975. }
  2976. /**
  2977. * Get an array of all child components
  2978. *
  2979. * @return {Array}
  2980. * The children
  2981. */
  2982. ;
  2983. _proto.children = function children() {
  2984. return this.children_;
  2985. }
  2986. /**
  2987. * Returns the child `Component` with the given `id`.
  2988. *
  2989. * @param {string} id
  2990. * The id of the child `Component` to get.
  2991. *
  2992. * @return {Component|undefined}
  2993. * The child `Component` with the given `id` or undefined.
  2994. */
  2995. ;
  2996. _proto.getChildById = function getChildById(id) {
  2997. return this.childIndex_[id];
  2998. }
  2999. /**
  3000. * Returns the child `Component` with the given `name`.
  3001. *
  3002. * @param {string} name
  3003. * The name of the child `Component` to get.
  3004. *
  3005. * @return {Component|undefined}
  3006. * The child `Component` with the given `name` or undefined.
  3007. */
  3008. ;
  3009. _proto.getChild = function getChild(name) {
  3010. if (!name) {
  3011. return;
  3012. }
  3013. return this.childNameIndex_[name];
  3014. }
  3015. /**
  3016. * Add a child `Component` inside the current `Component`.
  3017. *
  3018. *
  3019. * @param {string|Component} child
  3020. * The name or instance of a child to add.
  3021. *
  3022. * @param {Object} [options={}]
  3023. * The key/value store of options that will get passed to children of
  3024. * the child.
  3025. *
  3026. * @param {number} [index=this.children_.length]
  3027. * The index to attempt to add a child into.
  3028. *
  3029. * @return {Component}
  3030. * The `Component` that gets added as a child. When using a string the
  3031. * `Component` will get created by this process.
  3032. */
  3033. ;
  3034. _proto.addChild = function addChild(child, options, index) {
  3035. if (options === void 0) {
  3036. options = {};
  3037. }
  3038. if (index === void 0) {
  3039. index = this.children_.length;
  3040. }
  3041. var component;
  3042. var componentName; // If child is a string, create component with options
  3043. if (typeof child === 'string') {
  3044. componentName = toTitleCase(child);
  3045. var componentClassName = options.componentClass || componentName; // Set name through options
  3046. options.name = componentName; // Create a new object & element for this controls set
  3047. // If there's no .player_, this is a player
  3048. var ComponentClass = Component.getComponent(componentClassName);
  3049. if (!ComponentClass) {
  3050. throw new Error("Component " + componentClassName + " does not exist");
  3051. } // data stored directly on the videojs object may be
  3052. // misidentified as a component to retain
  3053. // backwards-compatibility with 4.x. check to make sure the
  3054. // component class can be instantiated.
  3055. if (typeof ComponentClass !== 'function') {
  3056. return null;
  3057. }
  3058. component = new ComponentClass(this.player_ || this, options); // child is a component instance
  3059. } else {
  3060. component = child;
  3061. }
  3062. if (component.parentComponent_) {
  3063. component.parentComponent_.removeChild(component);
  3064. }
  3065. this.children_.splice(index, 0, component);
  3066. component.parentComponent_ = this;
  3067. if (typeof component.id === 'function') {
  3068. this.childIndex_[component.id()] = component;
  3069. } // If a name wasn't used to create the component, check if we can use the
  3070. // name function of the component
  3071. componentName = componentName || component.name && toTitleCase(component.name());
  3072. if (componentName) {
  3073. this.childNameIndex_[componentName] = component;
  3074. this.childNameIndex_[toLowerCase(componentName)] = component;
  3075. } // Add the UI object's element to the container div (box)
  3076. // Having an element is not required
  3077. if (typeof component.el === 'function' && component.el()) {
  3078. var childNodes = this.contentEl().children;
  3079. var refNode = childNodes[index] || null;
  3080. this.contentEl().insertBefore(component.el(), refNode);
  3081. } // Return so it can stored on parent object if desired.
  3082. return component;
  3083. }
  3084. /**
  3085. * Remove a child `Component` from this `Component`s list of children. Also removes
  3086. * the child `Component`s element from this `Component`s element.
  3087. *
  3088. * @param {Component} component
  3089. * The child `Component` to remove.
  3090. */
  3091. ;
  3092. _proto.removeChild = function removeChild(component) {
  3093. if (typeof component === 'string') {
  3094. component = this.getChild(component);
  3095. }
  3096. if (!component || !this.children_) {
  3097. return;
  3098. }
  3099. var childFound = false;
  3100. for (var i = this.children_.length - 1; i >= 0; i--) {
  3101. if (this.children_[i] === component) {
  3102. childFound = true;
  3103. this.children_.splice(i, 1);
  3104. break;
  3105. }
  3106. }
  3107. if (!childFound) {
  3108. return;
  3109. }
  3110. component.parentComponent_ = null;
  3111. this.childIndex_[component.id()] = null;
  3112. this.childNameIndex_[toTitleCase(component.name())] = null;
  3113. this.childNameIndex_[toLowerCase(component.name())] = null;
  3114. var compEl = component.el();
  3115. if (compEl && compEl.parentNode === this.contentEl()) {
  3116. this.contentEl().removeChild(component.el());
  3117. }
  3118. }
  3119. /**
  3120. * Add and initialize default child `Component`s based upon options.
  3121. */
  3122. ;
  3123. _proto.initChildren = function initChildren() {
  3124. var _this = this;
  3125. var children = this.options_.children;
  3126. if (children) {
  3127. // `this` is `parent`
  3128. var parentOptions = this.options_;
  3129. var handleAdd = function handleAdd(child) {
  3130. var name = child.name;
  3131. var opts = child.opts; // Allow options for children to be set at the parent options
  3132. // e.g. videojs(id, { controlBar: false });
  3133. // instead of videojs(id, { children: { controlBar: false });
  3134. if (parentOptions[name] !== undefined) {
  3135. opts = parentOptions[name];
  3136. } // Allow for disabling default components
  3137. // e.g. options['children']['posterImage'] = false
  3138. if (opts === false) {
  3139. return;
  3140. } // Allow options to be passed as a simple boolean if no configuration
  3141. // is necessary.
  3142. if (opts === true) {
  3143. opts = {};
  3144. } // We also want to pass the original player options
  3145. // to each component as well so they don't need to
  3146. // reach back into the player for options later.
  3147. opts.playerOptions = _this.options_.playerOptions; // Create and add the child component.
  3148. // Add a direct reference to the child by name on the parent instance.
  3149. // If two of the same component are used, different names should be supplied
  3150. // for each
  3151. var newChild = _this.addChild(name, opts);
  3152. if (newChild) {
  3153. _this[name] = newChild;
  3154. }
  3155. }; // Allow for an array of children details to passed in the options
  3156. var workingChildren;
  3157. var Tech = Component.getComponent('Tech');
  3158. if (Array.isArray(children)) {
  3159. workingChildren = children;
  3160. } else {
  3161. workingChildren = Object.keys(children);
  3162. }
  3163. workingChildren // children that are in this.options_ but also in workingChildren would
  3164. // give us extra children we do not want. So, we want to filter them out.
  3165. .concat(Object.keys(this.options_).filter(function (child) {
  3166. return !workingChildren.some(function (wchild) {
  3167. if (typeof wchild === 'string') {
  3168. return child === wchild;
  3169. }
  3170. return child === wchild.name;
  3171. });
  3172. })).map(function (child) {
  3173. var name;
  3174. var opts;
  3175. if (typeof child === 'string') {
  3176. name = child;
  3177. opts = children[name] || _this.options_[name] || {};
  3178. } else {
  3179. name = child.name;
  3180. opts = child;
  3181. }
  3182. return {
  3183. name: name,
  3184. opts: opts
  3185. };
  3186. }).filter(function (child) {
  3187. // we have to make sure that child.name isn't in the techOrder since
  3188. // techs are registerd as Components but can't aren't compatible
  3189. // See https://github.com/videojs/video.js/issues/2772
  3190. var c = Component.getComponent(child.opts.componentClass || toTitleCase(child.name));
  3191. return c && !Tech.isTech(c);
  3192. }).forEach(handleAdd);
  3193. }
  3194. }
  3195. /**
  3196. * Builds the default DOM class name. Should be overriden by sub-components.
  3197. *
  3198. * @return {string}
  3199. * The DOM class name for this object.
  3200. *
  3201. * @abstract
  3202. */
  3203. ;
  3204. _proto.buildCSSClass = function buildCSSClass() {
  3205. // Child classes can include a function that does:
  3206. // return 'CLASS NAME' + this._super();
  3207. return '';
  3208. }
  3209. /**
  3210. * Bind a listener to the component's ready state.
  3211. * Different from event listeners in that if the ready event has already happened
  3212. * it will trigger the function immediately.
  3213. *
  3214. * @return {Component}
  3215. * Returns itself; method can be chained.
  3216. */
  3217. ;
  3218. _proto.ready = function ready(fn, sync) {
  3219. if (sync === void 0) {
  3220. sync = false;
  3221. }
  3222. if (!fn) {
  3223. return;
  3224. }
  3225. if (!this.isReady_) {
  3226. this.readyQueue_ = this.readyQueue_ || [];
  3227. this.readyQueue_.push(fn);
  3228. return;
  3229. }
  3230. if (sync) {
  3231. fn.call(this);
  3232. } else {
  3233. // Call the function asynchronously by default for consistency
  3234. this.setTimeout(fn, 1);
  3235. }
  3236. }
  3237. /**
  3238. * Trigger all the ready listeners for this `Component`.
  3239. *
  3240. * @fires Component#ready
  3241. */
  3242. ;
  3243. _proto.triggerReady = function triggerReady() {
  3244. this.isReady_ = true; // Ensure ready is triggered asynchronously
  3245. this.setTimeout(function () {
  3246. var readyQueue = this.readyQueue_; // Reset Ready Queue
  3247. this.readyQueue_ = [];
  3248. if (readyQueue && readyQueue.length > 0) {
  3249. readyQueue.forEach(function (fn) {
  3250. fn.call(this);
  3251. }, this);
  3252. } // Allow for using event listeners also
  3253. /**
  3254. * Triggered when a `Component` is ready.
  3255. *
  3256. * @event Component#ready
  3257. * @type {EventTarget~Event}
  3258. */
  3259. this.trigger('ready');
  3260. }, 1);
  3261. }
  3262. /**
  3263. * Find a single DOM element matching a `selector`. This can be within the `Component`s
  3264. * `contentEl()` or another custom context.
  3265. *
  3266. * @param {string} selector
  3267. * A valid CSS selector, which will be passed to `querySelector`.
  3268. *
  3269. * @param {Element|string} [context=this.contentEl()]
  3270. * A DOM element within which to query. Can also be a selector string in
  3271. * which case the first matching element will get used as context. If
  3272. * missing `this.contentEl()` gets used. If `this.contentEl()` returns
  3273. * nothing it falls back to `document`.
  3274. *
  3275. * @return {Element|null}
  3276. * the dom element that was found, or null
  3277. *
  3278. * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors)
  3279. */
  3280. ;
  3281. _proto.$ = function $$1(selector, context) {
  3282. return $(selector, context || this.contentEl());
  3283. }
  3284. /**
  3285. * Finds all DOM element matching a `selector`. This can be within the `Component`s
  3286. * `contentEl()` or another custom context.
  3287. *
  3288. * @param {string} selector
  3289. * A valid CSS selector, which will be passed to `querySelectorAll`.
  3290. *
  3291. * @param {Element|string} [context=this.contentEl()]
  3292. * A DOM element within which to query. Can also be a selector string in
  3293. * which case the first matching element will get used as context. If
  3294. * missing `this.contentEl()` gets used. If `this.contentEl()` returns
  3295. * nothing it falls back to `document`.
  3296. *
  3297. * @return {NodeList}
  3298. * a list of dom elements that were found
  3299. *
  3300. * @see [Information on CSS Selectors](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors)
  3301. */
  3302. ;
  3303. _proto.$$ = function $$$1(selector, context) {
  3304. return $$(selector, context || this.contentEl());
  3305. }
  3306. /**
  3307. * Check if a component's element has a CSS class name.
  3308. *
  3309. * @param {string} classToCheck
  3310. * CSS class name to check.
  3311. *
  3312. * @return {boolean}
  3313. * - True if the `Component` has the class.
  3314. * - False if the `Component` does not have the class`
  3315. */
  3316. ;
  3317. _proto.hasClass = function hasClass$1(classToCheck) {
  3318. return hasClass(this.el_, classToCheck);
  3319. }
  3320. /**
  3321. * Add a CSS class name to the `Component`s element.
  3322. *
  3323. * @param {string} classToAdd
  3324. * CSS class name to add
  3325. */
  3326. ;
  3327. _proto.addClass = function addClass$1(classToAdd) {
  3328. addClass(this.el_, classToAdd);
  3329. }
  3330. /**
  3331. * Remove a CSS class name from the `Component`s element.
  3332. *
  3333. * @param {string} classToRemove
  3334. * CSS class name to remove
  3335. */
  3336. ;
  3337. _proto.removeClass = function removeClass$1(classToRemove) {
  3338. removeClass(this.el_, classToRemove);
  3339. }
  3340. /**
  3341. * Add or remove a CSS class name from the component's element.
  3342. * - `classToToggle` gets added when {@link Component#hasClass} would return false.
  3343. * - `classToToggle` gets removed when {@link Component#hasClass} would return true.
  3344. *
  3345. * @param {string} classToToggle
  3346. * The class to add or remove based on (@link Component#hasClass}
  3347. *
  3348. * @param {boolean|Dom~predicate} [predicate]
  3349. * An {@link Dom~predicate} function or a boolean
  3350. */
  3351. ;
  3352. _proto.toggleClass = function toggleClass$1(classToToggle, predicate) {
  3353. toggleClass(this.el_, classToToggle, predicate);
  3354. }
  3355. /**
  3356. * Show the `Component`s element if it is hidden by removing the
  3357. * 'vjs-hidden' class name from it.
  3358. */
  3359. ;
  3360. _proto.show = function show() {
  3361. this.removeClass('vjs-hidden');
  3362. }
  3363. /**
  3364. * Hide the `Component`s element if it is currently showing by adding the
  3365. * 'vjs-hidden` class name to it.
  3366. */
  3367. ;
  3368. _proto.hide = function hide() {
  3369. this.addClass('vjs-hidden');
  3370. }
  3371. /**
  3372. * Lock a `Component`s element in its visible state by adding the 'vjs-lock-showing'
  3373. * class name to it. Used during fadeIn/fadeOut.
  3374. *
  3375. * @private
  3376. */
  3377. ;
  3378. _proto.lockShowing = function lockShowing() {
  3379. this.addClass('vjs-lock-showing');
  3380. }
  3381. /**
  3382. * Unlock a `Component`s element from its visible state by removing the 'vjs-lock-showing'
  3383. * class name from it. Used during fadeIn/fadeOut.
  3384. *
  3385. * @private
  3386. */
  3387. ;
  3388. _proto.unlockShowing = function unlockShowing() {
  3389. this.removeClass('vjs-lock-showing');
  3390. }
  3391. /**
  3392. * Get the value of an attribute on the `Component`s element.
  3393. *
  3394. * @param {string} attribute
  3395. * Name of the attribute to get the value from.
  3396. *
  3397. * @return {string|null}
  3398. * - The value of the attribute that was asked for.
  3399. * - Can be an empty string on some browsers if the attribute does not exist
  3400. * or has no value
  3401. * - Most browsers will return null if the attibute does not exist or has
  3402. * no value.
  3403. *
  3404. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttribute}
  3405. */
  3406. ;
  3407. _proto.getAttribute = function getAttribute$1(attribute) {
  3408. return getAttribute(this.el_, attribute);
  3409. }
  3410. /**
  3411. * Set the value of an attribute on the `Component`'s element
  3412. *
  3413. * @param {string} attribute
  3414. * Name of the attribute to set.
  3415. *
  3416. * @param {string} value
  3417. * Value to set the attribute to.
  3418. *
  3419. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute}
  3420. */
  3421. ;
  3422. _proto.setAttribute = function setAttribute$1(attribute, value) {
  3423. setAttribute(this.el_, attribute, value);
  3424. }
  3425. /**
  3426. * Remove an attribute from the `Component`s element.
  3427. *
  3428. * @param {string} attribute
  3429. * Name of the attribute to remove.
  3430. *
  3431. * @see [DOM API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute}
  3432. */
  3433. ;
  3434. _proto.removeAttribute = function removeAttribute$1(attribute) {
  3435. removeAttribute(this.el_, attribute);
  3436. }
  3437. /**
  3438. * Get or set the width of the component based upon the CSS styles.
  3439. * See {@link Component#dimension} for more detailed information.
  3440. *
  3441. * @param {number|string} [num]
  3442. * The width that you want to set postfixed with '%', 'px' or nothing.
  3443. *
  3444. * @param {boolean} [skipListeners]
  3445. * Skip the componentresize event trigger
  3446. *
  3447. * @return {number|string}
  3448. * The width when getting, zero if there is no width. Can be a string
  3449. * postpixed with '%' or 'px'.
  3450. */
  3451. ;
  3452. _proto.width = function width(num, skipListeners) {
  3453. return this.dimension('width', num, skipListeners);
  3454. }
  3455. /**
  3456. * Get or set the height of the component based upon the CSS styles.
  3457. * See {@link Component#dimension} for more detailed information.
  3458. *
  3459. * @param {number|string} [num]
  3460. * The height that you want to set postfixed with '%', 'px' or nothing.
  3461. *
  3462. * @param {boolean} [skipListeners]
  3463. * Skip the componentresize event trigger
  3464. *
  3465. * @return {number|string}
  3466. * The width when getting, zero if there is no width. Can be a string
  3467. * postpixed with '%' or 'px'.
  3468. */
  3469. ;
  3470. _proto.height = function height(num, skipListeners) {
  3471. return this.dimension('height', num, skipListeners);
  3472. }
  3473. /**
  3474. * Set both the width and height of the `Component` element at the same time.
  3475. *
  3476. * @param {number|string} width
  3477. * Width to set the `Component`s element to.
  3478. *
  3479. * @param {number|string} height
  3480. * Height to set the `Component`s element to.
  3481. */
  3482. ;
  3483. _proto.dimensions = function dimensions(width, height) {
  3484. // Skip componentresize listeners on width for optimization
  3485. this.width(width, true);
  3486. this.height(height);
  3487. }
  3488. /**
  3489. * Get or set width or height of the `Component` element. This is the shared code
  3490. * for the {@link Component#width} and {@link Component#height}.
  3491. *
  3492. * Things to know:
  3493. * - If the width or height in an number this will return the number postfixed with 'px'.
  3494. * - If the width/height is a percent this will return the percent postfixed with '%'
  3495. * - Hidden elements have a width of 0 with `window.getComputedStyle`. This function
  3496. * defaults to the `Component`s `style.width` and falls back to `window.getComputedStyle`.
  3497. * See [this]{@link http://www.foliotek.com/devblog/getting-the-width-of-a-hidden-element-with-jquery-using-width/}
  3498. * for more information
  3499. * - If you want the computed style of the component, use {@link Component#currentWidth}
  3500. * and {@link {Component#currentHeight}
  3501. *
  3502. * @fires Component#componentresize
  3503. *
  3504. * @param {string} widthOrHeight
  3505. 8 'width' or 'height'
  3506. *
  3507. * @param {number|string} [num]
  3508. 8 New dimension
  3509. *
  3510. * @param {boolean} [skipListeners]
  3511. * Skip componentresize event trigger
  3512. *
  3513. * @return {number}
  3514. * The dimension when getting or 0 if unset
  3515. */
  3516. ;
  3517. _proto.dimension = function dimension(widthOrHeight, num, skipListeners) {
  3518. if (num !== undefined) {
  3519. // Set to zero if null or literally NaN (NaN !== NaN)
  3520. if (num === null || num !== num) {
  3521. num = 0;
  3522. } // Check if using css width/height (% or px) and adjust
  3523. if (('' + num).indexOf('%') !== -1 || ('' + num).indexOf('px') !== -1) {
  3524. this.el_.style[widthOrHeight] = num;
  3525. } else if (num === 'auto') {
  3526. this.el_.style[widthOrHeight] = '';
  3527. } else {
  3528. this.el_.style[widthOrHeight] = num + 'px';
  3529. } // skipListeners allows us to avoid triggering the resize event when setting both width and height
  3530. if (!skipListeners) {
  3531. /**
  3532. * Triggered when a component is resized.
  3533. *
  3534. * @event Component#componentresize
  3535. * @type {EventTarget~Event}
  3536. */
  3537. this.trigger('componentresize');
  3538. }
  3539. return;
  3540. } // Not setting a value, so getting it
  3541. // Make sure element exists
  3542. if (!this.el_) {
  3543. return 0;
  3544. } // Get dimension value from style
  3545. var val = this.el_.style[widthOrHeight];
  3546. var pxIndex = val.indexOf('px');
  3547. if (pxIndex !== -1) {
  3548. // Return the pixel value with no 'px'
  3549. return parseInt(val.slice(0, pxIndex), 10);
  3550. } // No px so using % or no style was set, so falling back to offsetWidth/height
  3551. // If component has display:none, offset will return 0
  3552. // TODO: handle display:none and no dimension style using px
  3553. return parseInt(this.el_['offset' + toTitleCase(widthOrHeight)], 10);
  3554. }
  3555. /**
  3556. * Get the computed width or the height of the component's element.
  3557. *
  3558. * Uses `window.getComputedStyle`.
  3559. *
  3560. * @param {string} widthOrHeight
  3561. * A string containing 'width' or 'height'. Whichever one you want to get.
  3562. *
  3563. * @return {number}
  3564. * The dimension that gets asked for or 0 if nothing was set
  3565. * for that dimension.
  3566. */
  3567. ;
  3568. _proto.currentDimension = function currentDimension(widthOrHeight) {
  3569. var computedWidthOrHeight = 0;
  3570. if (widthOrHeight !== 'width' && widthOrHeight !== 'height') {
  3571. throw new Error('currentDimension only accepts width or height value');
  3572. }
  3573. computedWidthOrHeight = computedStyle(this.el_, widthOrHeight); // remove 'px' from variable and parse as integer
  3574. computedWidthOrHeight = parseFloat(computedWidthOrHeight); // if the computed value is still 0, it's possible that the browser is lying
  3575. // and we want to check the offset values.
  3576. // This code also runs wherever getComputedStyle doesn't exist.
  3577. if (computedWidthOrHeight === 0 || isNaN(computedWidthOrHeight)) {
  3578. var rule = "offset" + toTitleCase(widthOrHeight);
  3579. computedWidthOrHeight = this.el_[rule];
  3580. }
  3581. return computedWidthOrHeight;
  3582. }
  3583. /**
  3584. * An object that contains width and height values of the `Component`s
  3585. * computed style. Uses `window.getComputedStyle`.
  3586. *
  3587. * @typedef {Object} Component~DimensionObject
  3588. *
  3589. * @property {number} width
  3590. * The width of the `Component`s computed style.
  3591. *
  3592. * @property {number} height
  3593. * The height of the `Component`s computed style.
  3594. */
  3595. /**
  3596. * Get an object that contains computed width and height values of the
  3597. * component's element.
  3598. *
  3599. * Uses `window.getComputedStyle`.
  3600. *
  3601. * @return {Component~DimensionObject}
  3602. * The computed dimensions of the component's element.
  3603. */
  3604. ;
  3605. _proto.currentDimensions = function currentDimensions() {
  3606. return {
  3607. width: this.currentDimension('width'),
  3608. height: this.currentDimension('height')
  3609. };
  3610. }
  3611. /**
  3612. * Get the computed width of the component's element.
  3613. *
  3614. * Uses `window.getComputedStyle`.
  3615. *
  3616. * @return {number}
  3617. * The computed width of the component's element.
  3618. */
  3619. ;
  3620. _proto.currentWidth = function currentWidth() {
  3621. return this.currentDimension('width');
  3622. }
  3623. /**
  3624. * Get the computed height of the component's element.
  3625. *
  3626. * Uses `window.getComputedStyle`.
  3627. *
  3628. * @return {number}
  3629. * The computed height of the component's element.
  3630. */
  3631. ;
  3632. _proto.currentHeight = function currentHeight() {
  3633. return this.currentDimension('height');
  3634. }
  3635. /**
  3636. * Set the focus to this component
  3637. */
  3638. ;
  3639. _proto.focus = function focus() {
  3640. this.el_.focus();
  3641. }
  3642. /**
  3643. * Remove the focus from this component
  3644. */
  3645. ;
  3646. _proto.blur = function blur() {
  3647. this.el_.blur();
  3648. }
  3649. /**
  3650. * When this Component receives a `keydown` event which it does not process,
  3651. * it passes the event to the Player for handling.
  3652. *
  3653. * @param {EventTarget~Event} event
  3654. * The `keydown` event that caused this function to be called.
  3655. */
  3656. ;
  3657. _proto.handleKeyDown = function handleKeyDown(event) {
  3658. if (this.player_) {
  3659. // We only stop propagation here because we want unhandled events to fall
  3660. // back to the browser.
  3661. event.stopPropagation();
  3662. this.player_.handleKeyDown(event);
  3663. }
  3664. }
  3665. /**
  3666. * Many components used to have a `handleKeyPress` method, which was poorly
  3667. * named because it listened to a `keydown` event. This method name now
  3668. * delegates to `handleKeyDown`. This means anyone calling `handleKeyPress`
  3669. * will not see their method calls stop working.
  3670. *
  3671. * @param {EventTarget~Event} event
  3672. * The event that caused this function to be called.
  3673. */
  3674. ;
  3675. _proto.handleKeyPress = function handleKeyPress(event) {
  3676. this.handleKeyDown(event);
  3677. }
  3678. /**
  3679. * Emit a 'tap' events when touch event support gets detected. This gets used to
  3680. * support toggling the controls through a tap on the video. They get enabled
  3681. * because every sub-component would have extra overhead otherwise.
  3682. *
  3683. * @private
  3684. * @fires Component#tap
  3685. * @listens Component#touchstart
  3686. * @listens Component#touchmove
  3687. * @listens Component#touchleave
  3688. * @listens Component#touchcancel
  3689. * @listens Component#touchend
  3690. */
  3691. ;
  3692. _proto.emitTapEvents = function emitTapEvents() {
  3693. // Track the start time so we can determine how long the touch lasted
  3694. var touchStart = 0;
  3695. var firstTouch = null; // Maximum movement allowed during a touch event to still be considered a tap
  3696. // Other popular libs use anywhere from 2 (hammer.js) to 15,
  3697. // so 10 seems like a nice, round number.
  3698. var tapMovementThreshold = 10; // The maximum length a touch can be while still being considered a tap
  3699. var touchTimeThreshold = 200;
  3700. var couldBeTap;
  3701. this.on('touchstart', function (event) {
  3702. // If more than one finger, don't consider treating this as a click
  3703. if (event.touches.length === 1) {
  3704. // Copy pageX/pageY from the object
  3705. firstTouch = {
  3706. pageX: event.touches[0].pageX,
  3707. pageY: event.touches[0].pageY
  3708. }; // Record start time so we can detect a tap vs. "touch and hold"
  3709. touchStart = window$1.performance.now(); // Reset couldBeTap tracking
  3710. couldBeTap = true;
  3711. }
  3712. });
  3713. this.on('touchmove', function (event) {
  3714. // If more than one finger, don't consider treating this as a click
  3715. if (event.touches.length > 1) {
  3716. couldBeTap = false;
  3717. } else if (firstTouch) {
  3718. // Some devices will throw touchmoves for all but the slightest of taps.
  3719. // So, if we moved only a small distance, this could still be a tap
  3720. var xdiff = event.touches[0].pageX - firstTouch.pageX;
  3721. var ydiff = event.touches[0].pageY - firstTouch.pageY;
  3722. var touchDistance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
  3723. if (touchDistance > tapMovementThreshold) {
  3724. couldBeTap = false;
  3725. }
  3726. }
  3727. });
  3728. var noTap = function noTap() {
  3729. couldBeTap = false;
  3730. }; // TODO: Listen to the original target. http://youtu.be/DujfpXOKUp8?t=13m8s
  3731. this.on('touchleave', noTap);
  3732. this.on('touchcancel', noTap); // When the touch ends, measure how long it took and trigger the appropriate
  3733. // event
  3734. this.on('touchend', function (event) {
  3735. firstTouch = null; // Proceed only if the touchmove/leave/cancel event didn't happen
  3736. if (couldBeTap === true) {
  3737. // Measure how long the touch lasted
  3738. var touchTime = window$1.performance.now() - touchStart; // Make sure the touch was less than the threshold to be considered a tap
  3739. if (touchTime < touchTimeThreshold) {
  3740. // Don't let browser turn this into a click
  3741. event.preventDefault();
  3742. /**
  3743. * Triggered when a `Component` is tapped.
  3744. *
  3745. * @event Component#tap
  3746. * @type {EventTarget~Event}
  3747. */
  3748. this.trigger('tap'); // It may be good to copy the touchend event object and change the
  3749. // type to tap, if the other event properties aren't exact after
  3750. // Events.fixEvent runs (e.g. event.target)
  3751. }
  3752. }
  3753. });
  3754. }
  3755. /**
  3756. * This function reports user activity whenever touch events happen. This can get
  3757. * turned off by any sub-components that wants touch events to act another way.
  3758. *
  3759. * Report user touch activity when touch events occur. User activity gets used to
  3760. * determine when controls should show/hide. It is simple when it comes to mouse
  3761. * events, because any mouse event should show the controls. So we capture mouse
  3762. * events that bubble up to the player and report activity when that happens.
  3763. * With touch events it isn't as easy as `touchstart` and `touchend` toggle player
  3764. * controls. So touch events can't help us at the player level either.
  3765. *
  3766. * User activity gets checked asynchronously. So what could happen is a tap event
  3767. * on the video turns the controls off. Then the `touchend` event bubbles up to
  3768. * the player. Which, if it reported user activity, would turn the controls right
  3769. * back on. We also don't want to completely block touch events from bubbling up.
  3770. * Furthermore a `touchmove` event and anything other than a tap, should not turn
  3771. * controls back on.
  3772. *
  3773. * @listens Component#touchstart
  3774. * @listens Component#touchmove
  3775. * @listens Component#touchend
  3776. * @listens Component#touchcancel
  3777. */
  3778. ;
  3779. _proto.enableTouchActivity = function enableTouchActivity() {
  3780. // Don't continue if the root player doesn't support reporting user activity
  3781. if (!this.player() || !this.player().reportUserActivity) {
  3782. return;
  3783. } // listener for reporting that the user is active
  3784. var report = bind(this.player(), this.player().reportUserActivity);
  3785. var touchHolding;
  3786. this.on('touchstart', function () {
  3787. report(); // For as long as the they are touching the device or have their mouse down,
  3788. // we consider them active even if they're not moving their finger or mouse.
  3789. // So we want to continue to update that they are active
  3790. this.clearInterval(touchHolding); // report at the same interval as activityCheck
  3791. touchHolding = this.setInterval(report, 250);
  3792. });
  3793. var touchEnd = function touchEnd(event) {
  3794. report(); // stop the interval that maintains activity if the touch is holding
  3795. this.clearInterval(touchHolding);
  3796. };
  3797. this.on('touchmove', report);
  3798. this.on('touchend', touchEnd);
  3799. this.on('touchcancel', touchEnd);
  3800. }
  3801. /**
  3802. * A callback that has no parameters and is bound into `Component`s context.
  3803. *
  3804. * @callback Component~GenericCallback
  3805. * @this Component
  3806. */
  3807. /**
  3808. * Creates a function that runs after an `x` millisecond timeout. This function is a
  3809. * wrapper around `window.setTimeout`. There are a few reasons to use this one
  3810. * instead though:
  3811. * 1. It gets cleared via {@link Component#clearTimeout} when
  3812. * {@link Component#dispose} gets called.
  3813. * 2. The function callback will gets turned into a {@link Component~GenericCallback}
  3814. *
  3815. * > Note: You can't use `window.clearTimeout` on the id returned by this function. This
  3816. * will cause its dispose listener not to get cleaned up! Please use
  3817. * {@link Component#clearTimeout} or {@link Component#dispose} instead.
  3818. *
  3819. * @param {Component~GenericCallback} fn
  3820. * The function that will be run after `timeout`.
  3821. *
  3822. * @param {number} timeout
  3823. * Timeout in milliseconds to delay before executing the specified function.
  3824. *
  3825. * @return {number}
  3826. * Returns a timeout ID that gets used to identify the timeout. It can also
  3827. * get used in {@link Component#clearTimeout} to clear the timeout that
  3828. * was set.
  3829. *
  3830. * @listens Component#dispose
  3831. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout}
  3832. */
  3833. ;
  3834. _proto.setTimeout = function setTimeout(fn, timeout) {
  3835. var _this2 = this;
  3836. // declare as variables so they are properly available in timeout function
  3837. // eslint-disable-next-line
  3838. var timeoutId;
  3839. fn = bind(this, fn);
  3840. this.clearTimersOnDispose_();
  3841. timeoutId = window$1.setTimeout(function () {
  3842. if (_this2.setTimeoutIds_.has(timeoutId)) {
  3843. _this2.setTimeoutIds_["delete"](timeoutId);
  3844. }
  3845. fn();
  3846. }, timeout);
  3847. this.setTimeoutIds_.add(timeoutId);
  3848. return timeoutId;
  3849. }
  3850. /**
  3851. * Clears a timeout that gets created via `window.setTimeout` or
  3852. * {@link Component#setTimeout}. If you set a timeout via {@link Component#setTimeout}
  3853. * use this function instead of `window.clearTimout`. If you don't your dispose
  3854. * listener will not get cleaned up until {@link Component#dispose}!
  3855. *
  3856. * @param {number} timeoutId
  3857. * The id of the timeout to clear. The return value of
  3858. * {@link Component#setTimeout} or `window.setTimeout`.
  3859. *
  3860. * @return {number}
  3861. * Returns the timeout id that was cleared.
  3862. *
  3863. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearTimeout}
  3864. */
  3865. ;
  3866. _proto.clearTimeout = function clearTimeout(timeoutId) {
  3867. if (this.setTimeoutIds_.has(timeoutId)) {
  3868. this.setTimeoutIds_["delete"](timeoutId);
  3869. window$1.clearTimeout(timeoutId);
  3870. }
  3871. return timeoutId;
  3872. }
  3873. /**
  3874. * Creates a function that gets run every `x` milliseconds. This function is a wrapper
  3875. * around `window.setInterval`. There are a few reasons to use this one instead though.
  3876. * 1. It gets cleared via {@link Component#clearInterval} when
  3877. * {@link Component#dispose} gets called.
  3878. * 2. The function callback will be a {@link Component~GenericCallback}
  3879. *
  3880. * @param {Component~GenericCallback} fn
  3881. * The function to run every `x` seconds.
  3882. *
  3883. * @param {number} interval
  3884. * Execute the specified function every `x` milliseconds.
  3885. *
  3886. * @return {number}
  3887. * Returns an id that can be used to identify the interval. It can also be be used in
  3888. * {@link Component#clearInterval} to clear the interval.
  3889. *
  3890. * @listens Component#dispose
  3891. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval}
  3892. */
  3893. ;
  3894. _proto.setInterval = function setInterval(fn, interval) {
  3895. fn = bind(this, fn);
  3896. this.clearTimersOnDispose_();
  3897. var intervalId = window$1.setInterval(fn, interval);
  3898. this.setIntervalIds_.add(intervalId);
  3899. return intervalId;
  3900. }
  3901. /**
  3902. * Clears an interval that gets created via `window.setInterval` or
  3903. * {@link Component#setInterval}. If you set an inteval via {@link Component#setInterval}
  3904. * use this function instead of `window.clearInterval`. If you don't your dispose
  3905. * listener will not get cleaned up until {@link Component#dispose}!
  3906. *
  3907. * @param {number} intervalId
  3908. * The id of the interval to clear. The return value of
  3909. * {@link Component#setInterval} or `window.setInterval`.
  3910. *
  3911. * @return {number}
  3912. * Returns the interval id that was cleared.
  3913. *
  3914. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval}
  3915. */
  3916. ;
  3917. _proto.clearInterval = function clearInterval(intervalId) {
  3918. if (this.setIntervalIds_.has(intervalId)) {
  3919. this.setIntervalIds_["delete"](intervalId);
  3920. window$1.clearInterval(intervalId);
  3921. }
  3922. return intervalId;
  3923. }
  3924. /**
  3925. * Queues up a callback to be passed to requestAnimationFrame (rAF), but
  3926. * with a few extra bonuses:
  3927. *
  3928. * - Supports browsers that do not support rAF by falling back to
  3929. * {@link Component#setTimeout}.
  3930. *
  3931. * - The callback is turned into a {@link Component~GenericCallback} (i.e.
  3932. * bound to the component).
  3933. *
  3934. * - Automatic cancellation of the rAF callback is handled if the component
  3935. * is disposed before it is called.
  3936. *
  3937. * @param {Component~GenericCallback} fn
  3938. * A function that will be bound to this component and executed just
  3939. * before the browser's next repaint.
  3940. *
  3941. * @return {number}
  3942. * Returns an rAF ID that gets used to identify the timeout. It can
  3943. * also be used in {@link Component#cancelAnimationFrame} to cancel
  3944. * the animation frame callback.
  3945. *
  3946. * @listens Component#dispose
  3947. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame}
  3948. */
  3949. ;
  3950. _proto.requestAnimationFrame = function requestAnimationFrame(fn) {
  3951. var _this3 = this;
  3952. // Fall back to using a timer.
  3953. if (!this.supportsRaf_) {
  3954. return this.setTimeout(fn, 1000 / 60);
  3955. }
  3956. this.clearTimersOnDispose_(); // declare as variables so they are properly available in rAF function
  3957. // eslint-disable-next-line
  3958. var id;
  3959. fn = bind(this, fn);
  3960. id = window$1.requestAnimationFrame(function () {
  3961. if (_this3.rafIds_.has(id)) {
  3962. _this3.rafIds_["delete"](id);
  3963. }
  3964. fn();
  3965. });
  3966. this.rafIds_.add(id);
  3967. return id;
  3968. }
  3969. /**
  3970. * Cancels a queued callback passed to {@link Component#requestAnimationFrame}
  3971. * (rAF).
  3972. *
  3973. * If you queue an rAF callback via {@link Component#requestAnimationFrame},
  3974. * use this function instead of `window.cancelAnimationFrame`. If you don't,
  3975. * your dispose listener will not get cleaned up until {@link Component#dispose}!
  3976. *
  3977. * @param {number} id
  3978. * The rAF ID to clear. The return value of {@link Component#requestAnimationFrame}.
  3979. *
  3980. * @return {number}
  3981. * Returns the rAF ID that was cleared.
  3982. *
  3983. * @see [Similar to]{@link https://developer.mozilla.org/en-US/docs/Web/API/window/cancelAnimationFrame}
  3984. */
  3985. ;
  3986. _proto.cancelAnimationFrame = function cancelAnimationFrame(id) {
  3987. // Fall back to using a timer.
  3988. if (!this.supportsRaf_) {
  3989. return this.clearTimeout(id);
  3990. }
  3991. if (this.rafIds_.has(id)) {
  3992. this.rafIds_["delete"](id);
  3993. window$1.cancelAnimationFrame(id);
  3994. }
  3995. return id;
  3996. }
  3997. /**
  3998. * A function to setup `requestAnimationFrame`, `setTimeout`,
  3999. * and `setInterval`, clearing on dispose.
  4000. *
  4001. * > Previously each timer added and removed dispose listeners on it's own.
  4002. * For better performance it was decided to batch them all, and use `Set`s
  4003. * to track outstanding timer ids.
  4004. *
  4005. * @private
  4006. */
  4007. ;
  4008. _proto.clearTimersOnDispose_ = function clearTimersOnDispose_() {
  4009. var _this4 = this;
  4010. if (this.clearingTimersOnDispose_) {
  4011. return;
  4012. }
  4013. this.clearingTimersOnDispose_ = true;
  4014. this.one('dispose', function () {
  4015. [['rafIds_', 'cancelAnimationFrame'], ['setTimeoutIds_', 'clearTimeout'], ['setIntervalIds_', 'clearInterval']].forEach(function (_ref) {
  4016. var idName = _ref[0],
  4017. cancelName = _ref[1];
  4018. _this4[idName].forEach(_this4[cancelName], _this4);
  4019. });
  4020. _this4.clearingTimersOnDispose_ = false;
  4021. });
  4022. }
  4023. /**
  4024. * Register a `Component` with `videojs` given the name and the component.
  4025. *
  4026. * > NOTE: {@link Tech}s should not be registered as a `Component`. {@link Tech}s
  4027. * should be registered using {@link Tech.registerTech} or
  4028. * {@link videojs:videojs.registerTech}.
  4029. *
  4030. * > NOTE: This function can also be seen on videojs as
  4031. * {@link videojs:videojs.registerComponent}.
  4032. *
  4033. * @param {string} name
  4034. * The name of the `Component` to register.
  4035. *
  4036. * @param {Component} ComponentToRegister
  4037. * The `Component` class to register.
  4038. *
  4039. * @return {Component}
  4040. * The `Component` that was registered.
  4041. */
  4042. ;
  4043. Component.registerComponent = function registerComponent(name, ComponentToRegister) {
  4044. if (typeof name !== 'string' || !name) {
  4045. throw new Error("Illegal component name, \"" + name + "\"; must be a non-empty string.");
  4046. }
  4047. var Tech = Component.getComponent('Tech'); // We need to make sure this check is only done if Tech has been registered.
  4048. var isTech = Tech && Tech.isTech(ComponentToRegister);
  4049. var isComp = Component === ComponentToRegister || Component.prototype.isPrototypeOf(ComponentToRegister.prototype);
  4050. if (isTech || !isComp) {
  4051. var reason;
  4052. if (isTech) {
  4053. reason = 'techs must be registered using Tech.registerTech()';
  4054. } else {
  4055. reason = 'must be a Component subclass';
  4056. }
  4057. throw new Error("Illegal component, \"" + name + "\"; " + reason + ".");
  4058. }
  4059. name = toTitleCase(name);
  4060. if (!Component.components_) {
  4061. Component.components_ = {};
  4062. }
  4063. var Player = Component.getComponent('Player');
  4064. if (name === 'Player' && Player && Player.players) {
  4065. var players = Player.players;
  4066. var playerNames = Object.keys(players); // If we have players that were disposed, then their name will still be
  4067. // in Players.players. So, we must loop through and verify that the value
  4068. // for each item is not null. This allows registration of the Player component
  4069. // after all players have been disposed or before any were created.
  4070. if (players && playerNames.length > 0 && playerNames.map(function (pname) {
  4071. return players[pname];
  4072. }).every(Boolean)) {
  4073. throw new Error('Can not register Player component after player has been created.');
  4074. }
  4075. }
  4076. Component.components_[name] = ComponentToRegister;
  4077. Component.components_[toLowerCase(name)] = ComponentToRegister;
  4078. return ComponentToRegister;
  4079. }
  4080. /**
  4081. * Get a `Component` based on the name it was registered with.
  4082. *
  4083. * @param {string} name
  4084. * The Name of the component to get.
  4085. *
  4086. * @return {Component}
  4087. * The `Component` that got registered under the given name.
  4088. *
  4089. * @deprecated In `videojs` 6 this will not return `Component`s that were not
  4090. * registered using {@link Component.registerComponent}. Currently we
  4091. * check the global `videojs` object for a `Component` name and
  4092. * return that if it exists.
  4093. */
  4094. ;
  4095. Component.getComponent = function getComponent(name) {
  4096. if (!name || !Component.components_) {
  4097. return;
  4098. }
  4099. return Component.components_[name];
  4100. };
  4101. return Component;
  4102. }();
  4103. /**
  4104. * Whether or not this component supports `requestAnimationFrame`.
  4105. *
  4106. * This is exposed primarily for testing purposes.
  4107. *
  4108. * @private
  4109. * @type {Boolean}
  4110. */
  4111. Component.prototype.supportsRaf_ = typeof window$1.requestAnimationFrame === 'function' && typeof window$1.cancelAnimationFrame === 'function';
  4112. Component.registerComponent('Component', Component);
  4113. function _inheritsLoose(subClass, superClass) {
  4114. subClass.prototype = Object.create(superClass.prototype);
  4115. subClass.prototype.constructor = subClass;
  4116. subClass.__proto__ = superClass;
  4117. }
  4118. function _setPrototypeOf(o, p) {
  4119. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  4120. o.__proto__ = p;
  4121. return o;
  4122. };
  4123. return _setPrototypeOf(o, p);
  4124. }
  4125. function isNativeReflectConstruct() {
  4126. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  4127. if (Reflect.construct.sham) return false;
  4128. if (typeof Proxy === "function") return true;
  4129. try {
  4130. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  4131. return true;
  4132. } catch (e) {
  4133. return false;
  4134. }
  4135. }
  4136. function _construct(Parent, args, Class) {
  4137. if (isNativeReflectConstruct()) {
  4138. _construct = Reflect.construct;
  4139. } else {
  4140. _construct = function _construct(Parent, args, Class) {
  4141. var a = [null];
  4142. a.push.apply(a, args);
  4143. var Constructor = Function.bind.apply(Parent, a);
  4144. var instance = new Constructor();
  4145. if (Class) _setPrototypeOf(instance, Class.prototype);
  4146. return instance;
  4147. };
  4148. }
  4149. return _construct.apply(null, arguments);
  4150. }
  4151. function _assertThisInitialized(self) {
  4152. if (self === void 0) {
  4153. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  4154. }
  4155. return self;
  4156. }
  4157. /**
  4158. * @file browser.js
  4159. * @module browser
  4160. */
  4161. var USER_AGENT = window$1.navigator && window$1.navigator.userAgent || '';
  4162. var webkitVersionMap = /AppleWebKit\/([\d.]+)/i.exec(USER_AGENT);
  4163. var appleWebkitVersion = webkitVersionMap ? parseFloat(webkitVersionMap.pop()) : null;
  4164. /**
  4165. * Whether or not this device is an iPad.
  4166. *
  4167. * @static
  4168. * @const
  4169. * @type {Boolean}
  4170. */
  4171. var IS_IPAD = /iPad/i.test(USER_AGENT);
  4172. /**
  4173. * Whether or not this device is an iPhone.
  4174. *
  4175. * @static
  4176. * @const
  4177. * @type {Boolean}
  4178. */
  4179. // The Facebook app's UIWebView identifies as both an iPhone and iPad, so
  4180. // to identify iPhones, we need to exclude iPads.
  4181. // http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/
  4182. var IS_IPHONE = /iPhone/i.test(USER_AGENT) && !IS_IPAD;
  4183. /**
  4184. * Whether or not this device is an iPod.
  4185. *
  4186. * @static
  4187. * @const
  4188. * @type {Boolean}
  4189. */
  4190. var IS_IPOD = /iPod/i.test(USER_AGENT);
  4191. /**
  4192. * Whether or not this is an iOS device.
  4193. *
  4194. * @static
  4195. * @const
  4196. * @type {Boolean}
  4197. */
  4198. var IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD;
  4199. /**
  4200. * The detected iOS version - or `null`.
  4201. *
  4202. * @static
  4203. * @const
  4204. * @type {string|null}
  4205. */
  4206. var IOS_VERSION = function () {
  4207. var match = USER_AGENT.match(/OS (\d+)_/i);
  4208. if (match && match[1]) {
  4209. return match[1];
  4210. }
  4211. return null;
  4212. }();
  4213. /**
  4214. * Whether or not this is an Android device.
  4215. *
  4216. * @static
  4217. * @const
  4218. * @type {Boolean}
  4219. */
  4220. var IS_ANDROID = /Android/i.test(USER_AGENT);
  4221. /**
  4222. * The detected Android version - or `null`.
  4223. *
  4224. * @static
  4225. * @const
  4226. * @type {number|string|null}
  4227. */
  4228. var ANDROID_VERSION = function () {
  4229. // This matches Android Major.Minor.Patch versions
  4230. // ANDROID_VERSION is Major.Minor as a Number, if Minor isn't available, then only Major is returned
  4231. var match = USER_AGENT.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);
  4232. if (!match) {
  4233. return null;
  4234. }
  4235. var major = match[1] && parseFloat(match[1]);
  4236. var minor = match[2] && parseFloat(match[2]);
  4237. if (major && minor) {
  4238. return parseFloat(match[1] + '.' + match[2]);
  4239. } else if (major) {
  4240. return major;
  4241. }
  4242. return null;
  4243. }();
  4244. /**
  4245. * Whether or not this is a native Android browser.
  4246. *
  4247. * @static
  4248. * @const
  4249. * @type {Boolean}
  4250. */
  4251. var IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537;
  4252. /**
  4253. * Whether or not this is Mozilla Firefox.
  4254. *
  4255. * @static
  4256. * @const
  4257. * @type {Boolean}
  4258. */
  4259. var IS_FIREFOX = /Firefox/i.test(USER_AGENT);
  4260. /**
  4261. * Whether or not this is Microsoft Edge.
  4262. *
  4263. * @static
  4264. * @const
  4265. * @type {Boolean}
  4266. */
  4267. var IS_EDGE = /Edge/i.test(USER_AGENT);
  4268. /**
  4269. * Whether or not this is Google Chrome.
  4270. *
  4271. * This will also be `true` for Chrome on iOS, which will have different support
  4272. * as it is actually Safari under the hood.
  4273. *
  4274. * @static
  4275. * @const
  4276. * @type {Boolean}
  4277. */
  4278. var IS_CHROME = !IS_EDGE && (/Chrome/i.test(USER_AGENT) || /CriOS/i.test(USER_AGENT));
  4279. /**
  4280. * The detected Google Chrome version - or `null`.
  4281. *
  4282. * @static
  4283. * @const
  4284. * @type {number|null}
  4285. */
  4286. var CHROME_VERSION = function () {
  4287. var match = USER_AGENT.match(/(Chrome|CriOS)\/(\d+)/);
  4288. if (match && match[2]) {
  4289. return parseFloat(match[2]);
  4290. }
  4291. return null;
  4292. }();
  4293. /**
  4294. * The detected Internet Explorer version - or `null`.
  4295. *
  4296. * @static
  4297. * @const
  4298. * @type {number|null}
  4299. */
  4300. var IE_VERSION = function () {
  4301. var result = /MSIE\s(\d+)\.\d/.exec(USER_AGENT);
  4302. var version = result && parseFloat(result[1]);
  4303. if (!version && /Trident\/7.0/i.test(USER_AGENT) && /rv:11.0/.test(USER_AGENT)) {
  4304. // IE 11 has a different user agent string than other IE versions
  4305. version = 11.0;
  4306. }
  4307. return version;
  4308. }();
  4309. /**
  4310. * Whether or not this is desktop Safari.
  4311. *
  4312. * @static
  4313. * @const
  4314. * @type {Boolean}
  4315. */
  4316. var IS_SAFARI = /Safari/i.test(USER_AGENT) && !IS_CHROME && !IS_ANDROID && !IS_EDGE;
  4317. /**
  4318. * Whether or not this is any flavor of Safari - including iOS.
  4319. *
  4320. * @static
  4321. * @const
  4322. * @type {Boolean}
  4323. */
  4324. var IS_ANY_SAFARI = (IS_SAFARI || IS_IOS) && !IS_CHROME;
  4325. /**
  4326. * Whether or not this is a Windows machine.
  4327. *
  4328. * @static
  4329. * @const
  4330. * @type {Boolean}
  4331. */
  4332. var IS_WINDOWS = /Windows/i.test(USER_AGENT);
  4333. /**
  4334. * Whether or not this device is touch-enabled.
  4335. *
  4336. * @static
  4337. * @const
  4338. * @type {Boolean}
  4339. */
  4340. var TOUCH_ENABLED = isReal() && ('ontouchstart' in window$1 || window$1.navigator.maxTouchPoints || window$1.DocumentTouch && window$1.document instanceof window$1.DocumentTouch);
  4341. var browser = /*#__PURE__*/Object.freeze({
  4342. IS_IPAD: IS_IPAD,
  4343. IS_IPHONE: IS_IPHONE,
  4344. IS_IPOD: IS_IPOD,
  4345. IS_IOS: IS_IOS,
  4346. IOS_VERSION: IOS_VERSION,
  4347. IS_ANDROID: IS_ANDROID,
  4348. ANDROID_VERSION: ANDROID_VERSION,
  4349. IS_NATIVE_ANDROID: IS_NATIVE_ANDROID,
  4350. IS_FIREFOX: IS_FIREFOX,
  4351. IS_EDGE: IS_EDGE,
  4352. IS_CHROME: IS_CHROME,
  4353. CHROME_VERSION: CHROME_VERSION,
  4354. IE_VERSION: IE_VERSION,
  4355. IS_SAFARI: IS_SAFARI,
  4356. IS_ANY_SAFARI: IS_ANY_SAFARI,
  4357. IS_WINDOWS: IS_WINDOWS,
  4358. TOUCH_ENABLED: TOUCH_ENABLED
  4359. });
  4360. /**
  4361. * @file time-ranges.js
  4362. * @module time-ranges
  4363. */
  4364. /**
  4365. * Returns the time for the specified index at the start or end
  4366. * of a TimeRange object.
  4367. *
  4368. * @typedef {Function} TimeRangeIndex
  4369. *
  4370. * @param {number} [index=0]
  4371. * The range number to return the time for.
  4372. *
  4373. * @return {number}
  4374. * The time offset at the specified index.
  4375. *
  4376. * @deprecated The index argument must be provided.
  4377. * In the future, leaving it out will throw an error.
  4378. */
  4379. /**
  4380. * An object that contains ranges of time.
  4381. *
  4382. * @typedef {Object} TimeRange
  4383. *
  4384. * @property {number} length
  4385. * The number of time ranges represented by this object.
  4386. *
  4387. * @property {module:time-ranges~TimeRangeIndex} start
  4388. * Returns the time offset at which a specified time range begins.
  4389. *
  4390. * @property {module:time-ranges~TimeRangeIndex} end
  4391. * Returns the time offset at which a specified time range ends.
  4392. *
  4393. * @see https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges
  4394. */
  4395. /**
  4396. * Check if any of the time ranges are over the maximum index.
  4397. *
  4398. * @private
  4399. * @param {string} fnName
  4400. * The function name to use for logging
  4401. *
  4402. * @param {number} index
  4403. * The index to check
  4404. *
  4405. * @param {number} maxIndex
  4406. * The maximum possible index
  4407. *
  4408. * @throws {Error} if the timeRanges provided are over the maxIndex
  4409. */
  4410. function rangeCheck(fnName, index, maxIndex) {
  4411. if (typeof index !== 'number' || index < 0 || index > maxIndex) {
  4412. throw new Error("Failed to execute '" + fnName + "' on 'TimeRanges': The index provided (" + index + ") is non-numeric or out of bounds (0-" + maxIndex + ").");
  4413. }
  4414. }
  4415. /**
  4416. * Get the time for the specified index at the start or end
  4417. * of a TimeRange object.
  4418. *
  4419. * @private
  4420. * @param {string} fnName
  4421. * The function name to use for logging
  4422. *
  4423. * @param {string} valueIndex
  4424. * The property that should be used to get the time. should be
  4425. * 'start' or 'end'
  4426. *
  4427. * @param {Array} ranges
  4428. * An array of time ranges
  4429. *
  4430. * @param {Array} [rangeIndex=0]
  4431. * The index to start the search at
  4432. *
  4433. * @return {number}
  4434. * The time that offset at the specified index.
  4435. *
  4436. * @deprecated rangeIndex must be set to a value, in the future this will throw an error.
  4437. * @throws {Error} if rangeIndex is more than the length of ranges
  4438. */
  4439. function getRange(fnName, valueIndex, ranges, rangeIndex) {
  4440. rangeCheck(fnName, rangeIndex, ranges.length - 1);
  4441. return ranges[rangeIndex][valueIndex];
  4442. }
  4443. /**
  4444. * Create a time range object given ranges of time.
  4445. *
  4446. * @private
  4447. * @param {Array} [ranges]
  4448. * An array of time ranges.
  4449. */
  4450. function createTimeRangesObj(ranges) {
  4451. if (ranges === undefined || ranges.length === 0) {
  4452. return {
  4453. length: 0,
  4454. start: function start() {
  4455. throw new Error('This TimeRanges object is empty');
  4456. },
  4457. end: function end() {
  4458. throw new Error('This TimeRanges object is empty');
  4459. }
  4460. };
  4461. }
  4462. return {
  4463. length: ranges.length,
  4464. start: getRange.bind(null, 'start', 0, ranges),
  4465. end: getRange.bind(null, 'end', 1, ranges)
  4466. };
  4467. }
  4468. /**
  4469. * Create a `TimeRange` object which mimics an
  4470. * {@link https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges|HTML5 TimeRanges instance}.
  4471. *
  4472. * @param {number|Array[]} start
  4473. * The start of a single range (a number) or an array of ranges (an
  4474. * array of arrays of two numbers each).
  4475. *
  4476. * @param {number} end
  4477. * The end of a single range. Cannot be used with the array form of
  4478. * the `start` argument.
  4479. */
  4480. function createTimeRanges(start, end) {
  4481. if (Array.isArray(start)) {
  4482. return createTimeRangesObj(start);
  4483. } else if (start === undefined || end === undefined) {
  4484. return createTimeRangesObj();
  4485. }
  4486. return createTimeRangesObj([[start, end]]);
  4487. }
  4488. /**
  4489. * @file buffer.js
  4490. * @module buffer
  4491. */
  4492. /**
  4493. * Compute the percentage of the media that has been buffered.
  4494. *
  4495. * @param {TimeRange} buffered
  4496. * The current `TimeRange` object representing buffered time ranges
  4497. *
  4498. * @param {number} duration
  4499. * Total duration of the media
  4500. *
  4501. * @return {number}
  4502. * Percent buffered of the total duration in decimal form.
  4503. */
  4504. function bufferedPercent(buffered, duration) {
  4505. var bufferedDuration = 0;
  4506. var start;
  4507. var end;
  4508. if (!duration) {
  4509. return 0;
  4510. }
  4511. if (!buffered || !buffered.length) {
  4512. buffered = createTimeRanges(0, 0);
  4513. }
  4514. for (var i = 0; i < buffered.length; i++) {
  4515. start = buffered.start(i);
  4516. end = buffered.end(i); // buffered end can be bigger than duration by a very small fraction
  4517. if (end > duration) {
  4518. end = duration;
  4519. }
  4520. bufferedDuration += end - start;
  4521. }
  4522. return bufferedDuration / duration;
  4523. }
  4524. /**
  4525. * @file fullscreen-api.js
  4526. * @module fullscreen-api
  4527. * @private
  4528. */
  4529. /**
  4530. * Store the browser-specific methods for the fullscreen API.
  4531. *
  4532. * @type {Object}
  4533. * @see [Specification]{@link https://fullscreen.spec.whatwg.org}
  4534. * @see [Map Approach From Screenfull.js]{@link https://github.com/sindresorhus/screenfull.js}
  4535. */
  4536. var FullscreenApi = {
  4537. prefixed: true
  4538. }; // browser API methods
  4539. var apiMap = [['requestFullscreen', 'exitFullscreen', 'fullscreenElement', 'fullscreenEnabled', 'fullscreenchange', 'fullscreenerror', 'fullscreen'], // WebKit
  4540. ['webkitRequestFullscreen', 'webkitExitFullscreen', 'webkitFullscreenElement', 'webkitFullscreenEnabled', 'webkitfullscreenchange', 'webkitfullscreenerror', '-webkit-full-screen'], // Mozilla
  4541. ['mozRequestFullScreen', 'mozCancelFullScreen', 'mozFullScreenElement', 'mozFullScreenEnabled', 'mozfullscreenchange', 'mozfullscreenerror', '-moz-full-screen'], // Microsoft
  4542. ['msRequestFullscreen', 'msExitFullscreen', 'msFullscreenElement', 'msFullscreenEnabled', 'MSFullscreenChange', 'MSFullscreenError', '-ms-fullscreen']];
  4543. var specApi = apiMap[0];
  4544. var browserApi; // determine the supported set of functions
  4545. for (var i = 0; i < apiMap.length; i++) {
  4546. // check for exitFullscreen function
  4547. if (apiMap[i][1] in document) {
  4548. browserApi = apiMap[i];
  4549. break;
  4550. }
  4551. } // map the browser API names to the spec API names
  4552. if (browserApi) {
  4553. for (var _i = 0; _i < browserApi.length; _i++) {
  4554. FullscreenApi[specApi[_i]] = browserApi[_i];
  4555. }
  4556. FullscreenApi.prefixed = browserApi[0] !== specApi[0];
  4557. }
  4558. /**
  4559. * @file media-error.js
  4560. */
  4561. /**
  4562. * A Custom `MediaError` class which mimics the standard HTML5 `MediaError` class.
  4563. *
  4564. * @param {number|string|Object|MediaError} value
  4565. * This can be of multiple types:
  4566. * - number: should be a standard error code
  4567. * - string: an error message (the code will be 0)
  4568. * - Object: arbitrary properties
  4569. * - `MediaError` (native): used to populate a video.js `MediaError` object
  4570. * - `MediaError` (video.js): will return itself if it's already a
  4571. * video.js `MediaError` object.
  4572. *
  4573. * @see [MediaError Spec]{@link https://dev.w3.org/html5/spec-author-view/video.html#mediaerror}
  4574. * @see [Encrypted MediaError Spec]{@link https://www.w3.org/TR/2013/WD-encrypted-media-20130510/#error-codes}
  4575. *
  4576. * @class MediaError
  4577. */
  4578. function MediaError(value) {
  4579. // Allow redundant calls to this constructor to avoid having `instanceof`
  4580. // checks peppered around the code.
  4581. if (value instanceof MediaError) {
  4582. return value;
  4583. }
  4584. if (typeof value === 'number') {
  4585. this.code = value;
  4586. } else if (typeof value === 'string') {
  4587. // default code is zero, so this is a custom error
  4588. this.message = value;
  4589. } else if (isObject(value)) {
  4590. // We assign the `code` property manually because native `MediaError` objects
  4591. // do not expose it as an own/enumerable property of the object.
  4592. if (typeof value.code === 'number') {
  4593. this.code = value.code;
  4594. }
  4595. assign(this, value);
  4596. }
  4597. if (!this.message) {
  4598. this.message = MediaError.defaultMessages[this.code] || '';
  4599. }
  4600. }
  4601. /**
  4602. * The error code that refers two one of the defined `MediaError` types
  4603. *
  4604. * @type {Number}
  4605. */
  4606. MediaError.prototype.code = 0;
  4607. /**
  4608. * An optional message that to show with the error. Message is not part of the HTML5
  4609. * video spec but allows for more informative custom errors.
  4610. *
  4611. * @type {String}
  4612. */
  4613. MediaError.prototype.message = '';
  4614. /**
  4615. * An optional status code that can be set by plugins to allow even more detail about
  4616. * the error. For example a plugin might provide a specific HTTP status code and an
  4617. * error message for that code. Then when the plugin gets that error this class will
  4618. * know how to display an error message for it. This allows a custom message to show
  4619. * up on the `Player` error overlay.
  4620. *
  4621. * @type {Array}
  4622. */
  4623. MediaError.prototype.status = null;
  4624. /**
  4625. * Errors indexed by the W3C standard. The order **CANNOT CHANGE**! See the
  4626. * specification listed under {@link MediaError} for more information.
  4627. *
  4628. * @enum {array}
  4629. * @readonly
  4630. * @property {string} 0 - MEDIA_ERR_CUSTOM
  4631. * @property {string} 1 - MEDIA_ERR_ABORTED
  4632. * @property {string} 2 - MEDIA_ERR_NETWORK
  4633. * @property {string} 3 - MEDIA_ERR_DECODE
  4634. * @property {string} 4 - MEDIA_ERR_SRC_NOT_SUPPORTED
  4635. * @property {string} 5 - MEDIA_ERR_ENCRYPTED
  4636. */
  4637. MediaError.errorTypes = ['MEDIA_ERR_CUSTOM', 'MEDIA_ERR_ABORTED', 'MEDIA_ERR_NETWORK', 'MEDIA_ERR_DECODE', 'MEDIA_ERR_SRC_NOT_SUPPORTED', 'MEDIA_ERR_ENCRYPTED'];
  4638. /**
  4639. * The default `MediaError` messages based on the {@link MediaError.errorTypes}.
  4640. *
  4641. * @type {Array}
  4642. * @constant
  4643. */
  4644. MediaError.defaultMessages = {
  4645. 1: 'You aborted the media playback',
  4646. 2: 'A network error caused the media download to fail part-way.',
  4647. 3: 'The media playback was aborted due to a corruption problem or because the media used features your browser did not support.',
  4648. 4: 'The media could not be loaded, either because the server or network failed or because the format is not supported.',
  4649. 5: 'The media is encrypted and we do not have the keys to decrypt it.'
  4650. }; // Add types as properties on MediaError
  4651. // e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
  4652. for (var errNum = 0; errNum < MediaError.errorTypes.length; errNum++) {
  4653. MediaError[MediaError.errorTypes[errNum]] = errNum; // values should be accessible on both the class and instance
  4654. MediaError.prototype[MediaError.errorTypes[errNum]] = errNum;
  4655. } // jsdocs for instance/static members added above
  4656. var tuple = SafeParseTuple;
  4657. function SafeParseTuple(obj, reviver) {
  4658. var json;
  4659. var error = null;
  4660. try {
  4661. json = JSON.parse(obj, reviver);
  4662. } catch (err) {
  4663. error = err;
  4664. }
  4665. return [error, json];
  4666. }
  4667. /**
  4668. * Returns whether an object is `Promise`-like (i.e. has a `then` method).
  4669. *
  4670. * @param {Object} value
  4671. * An object that may or may not be `Promise`-like.
  4672. *
  4673. * @return {boolean}
  4674. * Whether or not the object is `Promise`-like.
  4675. */
  4676. function isPromise(value) {
  4677. return value !== undefined && value !== null && typeof value.then === 'function';
  4678. }
  4679. /**
  4680. * Silence a Promise-like object.
  4681. *
  4682. * This is useful for avoiding non-harmful, but potentially confusing "uncaught
  4683. * play promise" rejection error messages.
  4684. *
  4685. * @param {Object} value
  4686. * An object that may or may not be `Promise`-like.
  4687. */
  4688. function silencePromise(value) {
  4689. if (isPromise(value)) {
  4690. value.then(null, function (e) {});
  4691. }
  4692. }
  4693. /**
  4694. * @file text-track-list-converter.js Utilities for capturing text track state and
  4695. * re-creating tracks based on a capture.
  4696. *
  4697. * @module text-track-list-converter
  4698. */
  4699. /**
  4700. * Examine a single {@link TextTrack} and return a JSON-compatible javascript object that
  4701. * represents the {@link TextTrack}'s state.
  4702. *
  4703. * @param {TextTrack} track
  4704. * The text track to query.
  4705. *
  4706. * @return {Object}
  4707. * A serializable javascript representation of the TextTrack.
  4708. * @private
  4709. */
  4710. var trackToJson_ = function trackToJson_(track) {
  4711. var ret = ['kind', 'label', 'language', 'id', 'inBandMetadataTrackDispatchType', 'mode', 'src'].reduce(function (acc, prop, i) {
  4712. if (track[prop]) {
  4713. acc[prop] = track[prop];
  4714. }
  4715. return acc;
  4716. }, {
  4717. cues: track.cues && Array.prototype.map.call(track.cues, function (cue) {
  4718. return {
  4719. startTime: cue.startTime,
  4720. endTime: cue.endTime,
  4721. text: cue.text,
  4722. id: cue.id
  4723. };
  4724. })
  4725. });
  4726. return ret;
  4727. };
  4728. /**
  4729. * Examine a {@link Tech} and return a JSON-compatible javascript array that represents the
  4730. * state of all {@link TextTrack}s currently configured. The return array is compatible with
  4731. * {@link text-track-list-converter:jsonToTextTracks}.
  4732. *
  4733. * @param {Tech} tech
  4734. * The tech object to query
  4735. *
  4736. * @return {Array}
  4737. * A serializable javascript representation of the {@link Tech}s
  4738. * {@link TextTrackList}.
  4739. */
  4740. var textTracksToJson = function textTracksToJson(tech) {
  4741. var trackEls = tech.$$('track');
  4742. var trackObjs = Array.prototype.map.call(trackEls, function (t) {
  4743. return t.track;
  4744. });
  4745. var tracks = Array.prototype.map.call(trackEls, function (trackEl) {
  4746. var json = trackToJson_(trackEl.track);
  4747. if (trackEl.src) {
  4748. json.src = trackEl.src;
  4749. }
  4750. return json;
  4751. });
  4752. return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function (track) {
  4753. return trackObjs.indexOf(track) === -1;
  4754. }).map(trackToJson_));
  4755. };
  4756. /**
  4757. * Create a set of remote {@link TextTrack}s on a {@link Tech} based on an array of javascript
  4758. * object {@link TextTrack} representations.
  4759. *
  4760. * @param {Array} json
  4761. * An array of `TextTrack` representation objects, like those that would be
  4762. * produced by `textTracksToJson`.
  4763. *
  4764. * @param {Tech} tech
  4765. * The `Tech` to create the `TextTrack`s on.
  4766. */
  4767. var jsonToTextTracks = function jsonToTextTracks(json, tech) {
  4768. json.forEach(function (track) {
  4769. var addedTrack = tech.addRemoteTextTrack(track).track;
  4770. if (!track.src && track.cues) {
  4771. track.cues.forEach(function (cue) {
  4772. return addedTrack.addCue(cue);
  4773. });
  4774. }
  4775. });
  4776. return tech.textTracks();
  4777. };
  4778. var textTrackConverter = {
  4779. textTracksToJson: textTracksToJson,
  4780. jsonToTextTracks: jsonToTextTracks,
  4781. trackToJson_: trackToJson_
  4782. };
  4783. function createCommonjsModule(fn, module) {
  4784. return module = { exports: {} }, fn(module, module.exports), module.exports;
  4785. }
  4786. var keycode = createCommonjsModule(function (module, exports) {
  4787. // Source: http://jsfiddle.net/vWx8V/
  4788. // http://stackoverflow.com/questions/5603195/full-list-of-javascript-keycodes
  4789. /**
  4790. * Conenience method returns corresponding value for given keyName or keyCode.
  4791. *
  4792. * @param {Mixed} keyCode {Number} or keyName {String}
  4793. * @return {Mixed}
  4794. * @api public
  4795. */
  4796. function keyCode(searchInput) {
  4797. // Keyboard Events
  4798. if (searchInput && 'object' === typeof searchInput) {
  4799. var hasKeyCode = searchInput.which || searchInput.keyCode || searchInput.charCode;
  4800. if (hasKeyCode) searchInput = hasKeyCode;
  4801. } // Numbers
  4802. if ('number' === typeof searchInput) return names[searchInput]; // Everything else (cast to string)
  4803. var search = String(searchInput); // check codes
  4804. var foundNamedKey = codes[search.toLowerCase()];
  4805. if (foundNamedKey) return foundNamedKey; // check aliases
  4806. var foundNamedKey = aliases[search.toLowerCase()];
  4807. if (foundNamedKey) return foundNamedKey; // weird character?
  4808. if (search.length === 1) return search.charCodeAt(0);
  4809. return undefined;
  4810. }
  4811. /**
  4812. * Compares a keyboard event with a given keyCode or keyName.
  4813. *
  4814. * @param {Event} event Keyboard event that should be tested
  4815. * @param {Mixed} keyCode {Number} or keyName {String}
  4816. * @return {Boolean}
  4817. * @api public
  4818. */
  4819. keyCode.isEventKey = function isEventKey(event, nameOrCode) {
  4820. if (event && 'object' === typeof event) {
  4821. var keyCode = event.which || event.keyCode || event.charCode;
  4822. if (keyCode === null || keyCode === undefined) {
  4823. return false;
  4824. }
  4825. if (typeof nameOrCode === 'string') {
  4826. // check codes
  4827. var foundNamedKey = codes[nameOrCode.toLowerCase()];
  4828. if (foundNamedKey) {
  4829. return foundNamedKey === keyCode;
  4830. } // check aliases
  4831. var foundNamedKey = aliases[nameOrCode.toLowerCase()];
  4832. if (foundNamedKey) {
  4833. return foundNamedKey === keyCode;
  4834. }
  4835. } else if (typeof nameOrCode === 'number') {
  4836. return nameOrCode === keyCode;
  4837. }
  4838. return false;
  4839. }
  4840. };
  4841. exports = module.exports = keyCode;
  4842. /**
  4843. * Get by name
  4844. *
  4845. * exports.code['enter'] // => 13
  4846. */
  4847. var codes = exports.code = exports.codes = {
  4848. 'backspace': 8,
  4849. 'tab': 9,
  4850. 'enter': 13,
  4851. 'shift': 16,
  4852. 'ctrl': 17,
  4853. 'alt': 18,
  4854. 'pause/break': 19,
  4855. 'caps lock': 20,
  4856. 'esc': 27,
  4857. 'space': 32,
  4858. 'page up': 33,
  4859. 'page down': 34,
  4860. 'end': 35,
  4861. 'home': 36,
  4862. 'left': 37,
  4863. 'up': 38,
  4864. 'right': 39,
  4865. 'down': 40,
  4866. 'insert': 45,
  4867. 'delete': 46,
  4868. 'command': 91,
  4869. 'left command': 91,
  4870. 'right command': 93,
  4871. 'numpad *': 106,
  4872. 'numpad +': 107,
  4873. 'numpad -': 109,
  4874. 'numpad .': 110,
  4875. 'numpad /': 111,
  4876. 'num lock': 144,
  4877. 'scroll lock': 145,
  4878. 'my computer': 182,
  4879. 'my calculator': 183,
  4880. ';': 186,
  4881. '=': 187,
  4882. ',': 188,
  4883. '-': 189,
  4884. '.': 190,
  4885. '/': 191,
  4886. '`': 192,
  4887. '[': 219,
  4888. '\\': 220,
  4889. ']': 221,
  4890. "'": 222 // Helper aliases
  4891. };
  4892. var aliases = exports.aliases = {
  4893. 'windows': 91,
  4894. '⇧': 16,
  4895. '⌥': 18,
  4896. '⌃': 17,
  4897. '⌘': 91,
  4898. 'ctl': 17,
  4899. 'control': 17,
  4900. 'option': 18,
  4901. 'pause': 19,
  4902. 'break': 19,
  4903. 'caps': 20,
  4904. 'return': 13,
  4905. 'escape': 27,
  4906. 'spc': 32,
  4907. 'spacebar': 32,
  4908. 'pgup': 33,
  4909. 'pgdn': 34,
  4910. 'ins': 45,
  4911. 'del': 46,
  4912. 'cmd': 91
  4913. /*!
  4914. * Programatically add the following
  4915. */
  4916. // lower case chars
  4917. };
  4918. for (i = 97; i < 123; i++) {
  4919. codes[String.fromCharCode(i)] = i - 32;
  4920. } // numbers
  4921. for (var i = 48; i < 58; i++) {
  4922. codes[i - 48] = i;
  4923. } // function keys
  4924. for (i = 1; i < 13; i++) {
  4925. codes['f' + i] = i + 111;
  4926. } // numpad keys
  4927. for (i = 0; i < 10; i++) {
  4928. codes['numpad ' + i] = i + 96;
  4929. }
  4930. /**
  4931. * Get by code
  4932. *
  4933. * exports.name[13] // => 'Enter'
  4934. */
  4935. var names = exports.names = exports.title = {}; // title for backward compat
  4936. // Create reverse mapping
  4937. for (i in codes) {
  4938. names[codes[i]] = i;
  4939. } // Add aliases
  4940. for (var alias in aliases) {
  4941. codes[alias] = aliases[alias];
  4942. }
  4943. });
  4944. var keycode_1 = keycode.code;
  4945. var keycode_2 = keycode.codes;
  4946. var keycode_3 = keycode.aliases;
  4947. var keycode_4 = keycode.names;
  4948. var keycode_5 = keycode.title;
  4949. var MODAL_CLASS_NAME = 'vjs-modal-dialog';
  4950. /**
  4951. * The `ModalDialog` displays over the video and its controls, which blocks
  4952. * interaction with the player until it is closed.
  4953. *
  4954. * Modal dialogs include a "Close" button and will close when that button
  4955. * is activated - or when ESC is pressed anywhere.
  4956. *
  4957. * @extends Component
  4958. */
  4959. var ModalDialog =
  4960. /*#__PURE__*/
  4961. function (_Component) {
  4962. _inheritsLoose(ModalDialog, _Component);
  4963. /**
  4964. * Create an instance of this class.
  4965. *
  4966. * @param {Player} player
  4967. * The `Player` that this class should be attached to.
  4968. *
  4969. * @param {Object} [options]
  4970. * The key/value store of player options.
  4971. *
  4972. * @param {Mixed} [options.content=undefined]
  4973. * Provide customized content for this modal.
  4974. *
  4975. * @param {string} [options.description]
  4976. * A text description for the modal, primarily for accessibility.
  4977. *
  4978. * @param {boolean} [options.fillAlways=false]
  4979. * Normally, modals are automatically filled only the first time
  4980. * they open. This tells the modal to refresh its content
  4981. * every time it opens.
  4982. *
  4983. * @param {string} [options.label]
  4984. * A text label for the modal, primarily for accessibility.
  4985. *
  4986. * @param {boolean} [options.pauseOnOpen=true]
  4987. * If `true`, playback will will be paused if playing when
  4988. * the modal opens, and resumed when it closes.
  4989. *
  4990. * @param {boolean} [options.temporary=true]
  4991. * If `true`, the modal can only be opened once; it will be
  4992. * disposed as soon as it's closed.
  4993. *
  4994. * @param {boolean} [options.uncloseable=false]
  4995. * If `true`, the user will not be able to close the modal
  4996. * through the UI in the normal ways. Programmatic closing is
  4997. * still possible.
  4998. */
  4999. function ModalDialog(player, options) {
  5000. var _this;
  5001. _this = _Component.call(this, player, options) || this;
  5002. _this.opened_ = _this.hasBeenOpened_ = _this.hasBeenFilled_ = false;
  5003. _this.closeable(!_this.options_.uncloseable);
  5004. _this.content(_this.options_.content); // Make sure the contentEl is defined AFTER any children are initialized
  5005. // because we only want the contents of the modal in the contentEl
  5006. // (not the UI elements like the close button).
  5007. _this.contentEl_ = createEl('div', {
  5008. className: MODAL_CLASS_NAME + "-content"
  5009. }, {
  5010. role: 'document'
  5011. });
  5012. _this.descEl_ = createEl('p', {
  5013. className: MODAL_CLASS_NAME + "-description vjs-control-text",
  5014. id: _this.el().getAttribute('aria-describedby')
  5015. });
  5016. textContent(_this.descEl_, _this.description());
  5017. _this.el_.appendChild(_this.descEl_);
  5018. _this.el_.appendChild(_this.contentEl_);
  5019. return _this;
  5020. }
  5021. /**
  5022. * Create the `ModalDialog`'s DOM element
  5023. *
  5024. * @return {Element}
  5025. * The DOM element that gets created.
  5026. */
  5027. var _proto = ModalDialog.prototype;
  5028. _proto.createEl = function createEl() {
  5029. return _Component.prototype.createEl.call(this, 'div', {
  5030. className: this.buildCSSClass(),
  5031. tabIndex: -1
  5032. }, {
  5033. 'aria-describedby': this.id() + "_description",
  5034. 'aria-hidden': 'true',
  5035. 'aria-label': this.label(),
  5036. 'role': 'dialog'
  5037. });
  5038. };
  5039. _proto.dispose = function dispose() {
  5040. this.contentEl_ = null;
  5041. this.descEl_ = null;
  5042. this.previouslyActiveEl_ = null;
  5043. _Component.prototype.dispose.call(this);
  5044. }
  5045. /**
  5046. * Builds the default DOM `className`.
  5047. *
  5048. * @return {string}
  5049. * The DOM `className` for this object.
  5050. */
  5051. ;
  5052. _proto.buildCSSClass = function buildCSSClass() {
  5053. return MODAL_CLASS_NAME + " vjs-hidden " + _Component.prototype.buildCSSClass.call(this);
  5054. }
  5055. /**
  5056. * Returns the label string for this modal. Primarily used for accessibility.
  5057. *
  5058. * @return {string}
  5059. * the localized or raw label of this modal.
  5060. */
  5061. ;
  5062. _proto.label = function label() {
  5063. return this.localize(this.options_.label || 'Modal Window');
  5064. }
  5065. /**
  5066. * Returns the description string for this modal. Primarily used for
  5067. * accessibility.
  5068. *
  5069. * @return {string}
  5070. * The localized or raw description of this modal.
  5071. */
  5072. ;
  5073. _proto.description = function description() {
  5074. var desc = this.options_.description || this.localize('This is a modal window.'); // Append a universal closeability message if the modal is closeable.
  5075. if (this.closeable()) {
  5076. desc += ' ' + this.localize('This modal can be closed by pressing the Escape key or activating the close button.');
  5077. }
  5078. return desc;
  5079. }
  5080. /**
  5081. * Opens the modal.
  5082. *
  5083. * @fires ModalDialog#beforemodalopen
  5084. * @fires ModalDialog#modalopen
  5085. */
  5086. ;
  5087. _proto.open = function open() {
  5088. if (!this.opened_) {
  5089. var player = this.player();
  5090. /**
  5091. * Fired just before a `ModalDialog` is opened.
  5092. *
  5093. * @event ModalDialog#beforemodalopen
  5094. * @type {EventTarget~Event}
  5095. */
  5096. this.trigger('beforemodalopen');
  5097. this.opened_ = true; // Fill content if the modal has never opened before and
  5098. // never been filled.
  5099. if (this.options_.fillAlways || !this.hasBeenOpened_ && !this.hasBeenFilled_) {
  5100. this.fill();
  5101. } // If the player was playing, pause it and take note of its previously
  5102. // playing state.
  5103. this.wasPlaying_ = !player.paused();
  5104. if (this.options_.pauseOnOpen && this.wasPlaying_) {
  5105. player.pause();
  5106. }
  5107. this.on('keydown', this.handleKeyDown); // Hide controls and note if they were enabled.
  5108. this.hadControls_ = player.controls();
  5109. player.controls(false);
  5110. this.show();
  5111. this.conditionalFocus_();
  5112. this.el().setAttribute('aria-hidden', 'false');
  5113. /**
  5114. * Fired just after a `ModalDialog` is opened.
  5115. *
  5116. * @event ModalDialog#modalopen
  5117. * @type {EventTarget~Event}
  5118. */
  5119. this.trigger('modalopen');
  5120. this.hasBeenOpened_ = true;
  5121. }
  5122. }
  5123. /**
  5124. * If the `ModalDialog` is currently open or closed.
  5125. *
  5126. * @param {boolean} [value]
  5127. * If given, it will open (`true`) or close (`false`) the modal.
  5128. *
  5129. * @return {boolean}
  5130. * the current open state of the modaldialog
  5131. */
  5132. ;
  5133. _proto.opened = function opened(value) {
  5134. if (typeof value === 'boolean') {
  5135. this[value ? 'open' : 'close']();
  5136. }
  5137. return this.opened_;
  5138. }
  5139. /**
  5140. * Closes the modal, does nothing if the `ModalDialog` is
  5141. * not open.
  5142. *
  5143. * @fires ModalDialog#beforemodalclose
  5144. * @fires ModalDialog#modalclose
  5145. */
  5146. ;
  5147. _proto.close = function close() {
  5148. if (!this.opened_) {
  5149. return;
  5150. }
  5151. var player = this.player();
  5152. /**
  5153. * Fired just before a `ModalDialog` is closed.
  5154. *
  5155. * @event ModalDialog#beforemodalclose
  5156. * @type {EventTarget~Event}
  5157. */
  5158. this.trigger('beforemodalclose');
  5159. this.opened_ = false;
  5160. if (this.wasPlaying_ && this.options_.pauseOnOpen) {
  5161. player.play();
  5162. }
  5163. this.off('keydown', this.handleKeyDown);
  5164. if (this.hadControls_) {
  5165. player.controls(true);
  5166. }
  5167. this.hide();
  5168. this.el().setAttribute('aria-hidden', 'true');
  5169. /**
  5170. * Fired just after a `ModalDialog` is closed.
  5171. *
  5172. * @event ModalDialog#modalclose
  5173. * @type {EventTarget~Event}
  5174. */
  5175. this.trigger('modalclose');
  5176. this.conditionalBlur_();
  5177. if (this.options_.temporary) {
  5178. this.dispose();
  5179. }
  5180. }
  5181. /**
  5182. * Check to see if the `ModalDialog` is closeable via the UI.
  5183. *
  5184. * @param {boolean} [value]
  5185. * If given as a boolean, it will set the `closeable` option.
  5186. *
  5187. * @return {boolean}
  5188. * Returns the final value of the closable option.
  5189. */
  5190. ;
  5191. _proto.closeable = function closeable(value) {
  5192. if (typeof value === 'boolean') {
  5193. var closeable = this.closeable_ = !!value;
  5194. var close = this.getChild('closeButton'); // If this is being made closeable and has no close button, add one.
  5195. if (closeable && !close) {
  5196. // The close button should be a child of the modal - not its
  5197. // content element, so temporarily change the content element.
  5198. var temp = this.contentEl_;
  5199. this.contentEl_ = this.el_;
  5200. close = this.addChild('closeButton', {
  5201. controlText: 'Close Modal Dialog'
  5202. });
  5203. this.contentEl_ = temp;
  5204. this.on(close, 'close', this.close);
  5205. } // If this is being made uncloseable and has a close button, remove it.
  5206. if (!closeable && close) {
  5207. this.off(close, 'close', this.close);
  5208. this.removeChild(close);
  5209. close.dispose();
  5210. }
  5211. }
  5212. return this.closeable_;
  5213. }
  5214. /**
  5215. * Fill the modal's content element with the modal's "content" option.
  5216. * The content element will be emptied before this change takes place.
  5217. */
  5218. ;
  5219. _proto.fill = function fill() {
  5220. this.fillWith(this.content());
  5221. }
  5222. /**
  5223. * Fill the modal's content element with arbitrary content.
  5224. * The content element will be emptied before this change takes place.
  5225. *
  5226. * @fires ModalDialog#beforemodalfill
  5227. * @fires ModalDialog#modalfill
  5228. *
  5229. * @param {Mixed} [content]
  5230. * The same rules apply to this as apply to the `content` option.
  5231. */
  5232. ;
  5233. _proto.fillWith = function fillWith(content) {
  5234. var contentEl = this.contentEl();
  5235. var parentEl = contentEl.parentNode;
  5236. var nextSiblingEl = contentEl.nextSibling;
  5237. /**
  5238. * Fired just before a `ModalDialog` is filled with content.
  5239. *
  5240. * @event ModalDialog#beforemodalfill
  5241. * @type {EventTarget~Event}
  5242. */
  5243. this.trigger('beforemodalfill');
  5244. this.hasBeenFilled_ = true; // Detach the content element from the DOM before performing
  5245. // manipulation to avoid modifying the live DOM multiple times.
  5246. parentEl.removeChild(contentEl);
  5247. this.empty();
  5248. insertContent(contentEl, content);
  5249. /**
  5250. * Fired just after a `ModalDialog` is filled with content.
  5251. *
  5252. * @event ModalDialog#modalfill
  5253. * @type {EventTarget~Event}
  5254. */
  5255. this.trigger('modalfill'); // Re-inject the re-filled content element.
  5256. if (nextSiblingEl) {
  5257. parentEl.insertBefore(contentEl, nextSiblingEl);
  5258. } else {
  5259. parentEl.appendChild(contentEl);
  5260. } // make sure that the close button is last in the dialog DOM
  5261. var closeButton = this.getChild('closeButton');
  5262. if (closeButton) {
  5263. parentEl.appendChild(closeButton.el_);
  5264. }
  5265. }
  5266. /**
  5267. * Empties the content element. This happens anytime the modal is filled.
  5268. *
  5269. * @fires ModalDialog#beforemodalempty
  5270. * @fires ModalDialog#modalempty
  5271. */
  5272. ;
  5273. _proto.empty = function empty() {
  5274. /**
  5275. * Fired just before a `ModalDialog` is emptied.
  5276. *
  5277. * @event ModalDialog#beforemodalempty
  5278. * @type {EventTarget~Event}
  5279. */
  5280. this.trigger('beforemodalempty');
  5281. emptyEl(this.contentEl());
  5282. /**
  5283. * Fired just after a `ModalDialog` is emptied.
  5284. *
  5285. * @event ModalDialog#modalempty
  5286. * @type {EventTarget~Event}
  5287. */
  5288. this.trigger('modalempty');
  5289. }
  5290. /**
  5291. * Gets or sets the modal content, which gets normalized before being
  5292. * rendered into the DOM.
  5293. *
  5294. * This does not update the DOM or fill the modal, but it is called during
  5295. * that process.
  5296. *
  5297. * @param {Mixed} [value]
  5298. * If defined, sets the internal content value to be used on the
  5299. * next call(s) to `fill`. This value is normalized before being
  5300. * inserted. To "clear" the internal content value, pass `null`.
  5301. *
  5302. * @return {Mixed}
  5303. * The current content of the modal dialog
  5304. */
  5305. ;
  5306. _proto.content = function content(value) {
  5307. if (typeof value !== 'undefined') {
  5308. this.content_ = value;
  5309. }
  5310. return this.content_;
  5311. }
  5312. /**
  5313. * conditionally focus the modal dialog if focus was previously on the player.
  5314. *
  5315. * @private
  5316. */
  5317. ;
  5318. _proto.conditionalFocus_ = function conditionalFocus_() {
  5319. var activeEl = document.activeElement;
  5320. var playerEl = this.player_.el_;
  5321. this.previouslyActiveEl_ = null;
  5322. if (playerEl.contains(activeEl) || playerEl === activeEl) {
  5323. this.previouslyActiveEl_ = activeEl;
  5324. this.focus();
  5325. }
  5326. }
  5327. /**
  5328. * conditionally blur the element and refocus the last focused element
  5329. *
  5330. * @private
  5331. */
  5332. ;
  5333. _proto.conditionalBlur_ = function conditionalBlur_() {
  5334. if (this.previouslyActiveEl_) {
  5335. this.previouslyActiveEl_.focus();
  5336. this.previouslyActiveEl_ = null;
  5337. }
  5338. }
  5339. /**
  5340. * Keydown handler. Attached when modal is focused.
  5341. *
  5342. * @listens keydown
  5343. */
  5344. ;
  5345. _proto.handleKeyDown = function handleKeyDown(event) {
  5346. // Do not allow keydowns to reach out of the modal dialog.
  5347. event.stopPropagation();
  5348. if (keycode.isEventKey(event, 'Escape') && this.closeable()) {
  5349. event.preventDefault();
  5350. this.close();
  5351. return;
  5352. } // exit early if it isn't a tab key
  5353. if (!keycode.isEventKey(event, 'Tab')) {
  5354. return;
  5355. }
  5356. var focusableEls = this.focusableEls_();
  5357. var activeEl = this.el_.querySelector(':focus');
  5358. var focusIndex;
  5359. for (var i = 0; i < focusableEls.length; i++) {
  5360. if (activeEl === focusableEls[i]) {
  5361. focusIndex = i;
  5362. break;
  5363. }
  5364. }
  5365. if (document.activeElement === this.el_) {
  5366. focusIndex = 0;
  5367. }
  5368. if (event.shiftKey && focusIndex === 0) {
  5369. focusableEls[focusableEls.length - 1].focus();
  5370. event.preventDefault();
  5371. } else if (!event.shiftKey && focusIndex === focusableEls.length - 1) {
  5372. focusableEls[0].focus();
  5373. event.preventDefault();
  5374. }
  5375. }
  5376. /**
  5377. * get all focusable elements
  5378. *
  5379. * @private
  5380. */
  5381. ;
  5382. _proto.focusableEls_ = function focusableEls_() {
  5383. var allChildren = this.el_.querySelectorAll('*');
  5384. return Array.prototype.filter.call(allChildren, function (child) {
  5385. return (child instanceof window$1.HTMLAnchorElement || child instanceof window$1.HTMLAreaElement) && child.hasAttribute('href') || (child instanceof window$1.HTMLInputElement || child instanceof window$1.HTMLSelectElement || child instanceof window$1.HTMLTextAreaElement || child instanceof window$1.HTMLButtonElement) && !child.hasAttribute('disabled') || child instanceof window$1.HTMLIFrameElement || child instanceof window$1.HTMLObjectElement || child instanceof window$1.HTMLEmbedElement || child.hasAttribute('tabindex') && child.getAttribute('tabindex') !== -1 || child.hasAttribute('contenteditable');
  5386. });
  5387. };
  5388. return ModalDialog;
  5389. }(Component);
  5390. /**
  5391. * Default options for `ModalDialog` default options.
  5392. *
  5393. * @type {Object}
  5394. * @private
  5395. */
  5396. ModalDialog.prototype.options_ = {
  5397. pauseOnOpen: true,
  5398. temporary: true
  5399. };
  5400. Component.registerComponent('ModalDialog', ModalDialog);
  5401. /**
  5402. * Common functionaliy between {@link TextTrackList}, {@link AudioTrackList}, and
  5403. * {@link VideoTrackList}
  5404. *
  5405. * @extends EventTarget
  5406. */
  5407. var TrackList =
  5408. /*#__PURE__*/
  5409. function (_EventTarget) {
  5410. _inheritsLoose(TrackList, _EventTarget);
  5411. /**
  5412. * Create an instance of this class
  5413. *
  5414. * @param {Track[]} tracks
  5415. * A list of tracks to initialize the list with.
  5416. *
  5417. * @abstract
  5418. */
  5419. function TrackList(tracks) {
  5420. var _this;
  5421. if (tracks === void 0) {
  5422. tracks = [];
  5423. }
  5424. _this = _EventTarget.call(this) || this;
  5425. _this.tracks_ = [];
  5426. /**
  5427. * @memberof TrackList
  5428. * @member {number} length
  5429. * The current number of `Track`s in the this Trackist.
  5430. * @instance
  5431. */
  5432. Object.defineProperty(_assertThisInitialized(_this), 'length', {
  5433. get: function get() {
  5434. return this.tracks_.length;
  5435. }
  5436. });
  5437. for (var i = 0; i < tracks.length; i++) {
  5438. _this.addTrack(tracks[i]);
  5439. }
  5440. return _this;
  5441. }
  5442. /**
  5443. * Add a {@link Track} to the `TrackList`
  5444. *
  5445. * @param {Track} track
  5446. * The audio, video, or text track to add to the list.
  5447. *
  5448. * @fires TrackList#addtrack
  5449. */
  5450. var _proto = TrackList.prototype;
  5451. _proto.addTrack = function addTrack(track) {
  5452. var index = this.tracks_.length;
  5453. if (!('' + index in this)) {
  5454. Object.defineProperty(this, index, {
  5455. get: function get() {
  5456. return this.tracks_[index];
  5457. }
  5458. });
  5459. } // Do not add duplicate tracks
  5460. if (this.tracks_.indexOf(track) === -1) {
  5461. this.tracks_.push(track);
  5462. /**
  5463. * Triggered when a track is added to a track list.
  5464. *
  5465. * @event TrackList#addtrack
  5466. * @type {EventTarget~Event}
  5467. * @property {Track} track
  5468. * A reference to track that was added.
  5469. */
  5470. this.trigger({
  5471. track: track,
  5472. type: 'addtrack',
  5473. target: this
  5474. });
  5475. }
  5476. }
  5477. /**
  5478. * Remove a {@link Track} from the `TrackList`
  5479. *
  5480. * @param {Track} rtrack
  5481. * The audio, video, or text track to remove from the list.
  5482. *
  5483. * @fires TrackList#removetrack
  5484. */
  5485. ;
  5486. _proto.removeTrack = function removeTrack(rtrack) {
  5487. var track;
  5488. for (var i = 0, l = this.length; i < l; i++) {
  5489. if (this[i] === rtrack) {
  5490. track = this[i];
  5491. if (track.off) {
  5492. track.off();
  5493. }
  5494. this.tracks_.splice(i, 1);
  5495. break;
  5496. }
  5497. }
  5498. if (!track) {
  5499. return;
  5500. }
  5501. /**
  5502. * Triggered when a track is removed from track list.
  5503. *
  5504. * @event TrackList#removetrack
  5505. * @type {EventTarget~Event}
  5506. * @property {Track} track
  5507. * A reference to track that was removed.
  5508. */
  5509. this.trigger({
  5510. track: track,
  5511. type: 'removetrack',
  5512. target: this
  5513. });
  5514. }
  5515. /**
  5516. * Get a Track from the TrackList by a tracks id
  5517. *
  5518. * @param {string} id - the id of the track to get
  5519. * @method getTrackById
  5520. * @return {Track}
  5521. * @private
  5522. */
  5523. ;
  5524. _proto.getTrackById = function getTrackById(id) {
  5525. var result = null;
  5526. for (var i = 0, l = this.length; i < l; i++) {
  5527. var track = this[i];
  5528. if (track.id === id) {
  5529. result = track;
  5530. break;
  5531. }
  5532. }
  5533. return result;
  5534. };
  5535. return TrackList;
  5536. }(EventTarget);
  5537. /**
  5538. * Triggered when a different track is selected/enabled.
  5539. *
  5540. * @event TrackList#change
  5541. * @type {EventTarget~Event}
  5542. */
  5543. /**
  5544. * Events that can be called with on + eventName. See {@link EventHandler}.
  5545. *
  5546. * @property {Object} TrackList#allowedEvents_
  5547. * @private
  5548. */
  5549. TrackList.prototype.allowedEvents_ = {
  5550. change: 'change',
  5551. addtrack: 'addtrack',
  5552. removetrack: 'removetrack'
  5553. }; // emulate attribute EventHandler support to allow for feature detection
  5554. for (var event in TrackList.prototype.allowedEvents_) {
  5555. TrackList.prototype['on' + event] = null;
  5556. }
  5557. /**
  5558. * Anywhere we call this function we diverge from the spec
  5559. * as we only support one enabled audiotrack at a time
  5560. *
  5561. * @param {AudioTrackList} list
  5562. * list to work on
  5563. *
  5564. * @param {AudioTrack} track
  5565. * The track to skip
  5566. *
  5567. * @private
  5568. */
  5569. var disableOthers = function disableOthers(list, track) {
  5570. for (var i = 0; i < list.length; i++) {
  5571. if (!Object.keys(list[i]).length || track.id === list[i].id) {
  5572. continue;
  5573. } // another audio track is enabled, disable it
  5574. list[i].enabled = false;
  5575. }
  5576. };
  5577. /**
  5578. * The current list of {@link AudioTrack} for a media file.
  5579. *
  5580. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist}
  5581. * @extends TrackList
  5582. */
  5583. var AudioTrackList =
  5584. /*#__PURE__*/
  5585. function (_TrackList) {
  5586. _inheritsLoose(AudioTrackList, _TrackList);
  5587. /**
  5588. * Create an instance of this class.
  5589. *
  5590. * @param {AudioTrack[]} [tracks=[]]
  5591. * A list of `AudioTrack` to instantiate the list with.
  5592. */
  5593. function AudioTrackList(tracks) {
  5594. var _this;
  5595. if (tracks === void 0) {
  5596. tracks = [];
  5597. }
  5598. // make sure only 1 track is enabled
  5599. // sorted from last index to first index
  5600. for (var i = tracks.length - 1; i >= 0; i--) {
  5601. if (tracks[i].enabled) {
  5602. disableOthers(tracks, tracks[i]);
  5603. break;
  5604. }
  5605. }
  5606. _this = _TrackList.call(this, tracks) || this;
  5607. _this.changing_ = false;
  5608. return _this;
  5609. }
  5610. /**
  5611. * Add an {@link AudioTrack} to the `AudioTrackList`.
  5612. *
  5613. * @param {AudioTrack} track
  5614. * The AudioTrack to add to the list
  5615. *
  5616. * @fires TrackList#addtrack
  5617. */
  5618. var _proto = AudioTrackList.prototype;
  5619. _proto.addTrack = function addTrack(track) {
  5620. var _this2 = this;
  5621. if (track.enabled) {
  5622. disableOthers(this, track);
  5623. }
  5624. _TrackList.prototype.addTrack.call(this, track); // native tracks don't have this
  5625. if (!track.addEventListener) {
  5626. return;
  5627. }
  5628. track.enabledChange_ = function () {
  5629. // when we are disabling other tracks (since we don't support
  5630. // more than one track at a time) we will set changing_
  5631. // to true so that we don't trigger additional change events
  5632. if (_this2.changing_) {
  5633. return;
  5634. }
  5635. _this2.changing_ = true;
  5636. disableOthers(_this2, track);
  5637. _this2.changing_ = false;
  5638. _this2.trigger('change');
  5639. };
  5640. /**
  5641. * @listens AudioTrack#enabledchange
  5642. * @fires TrackList#change
  5643. */
  5644. track.addEventListener('enabledchange', track.enabledChange_);
  5645. };
  5646. _proto.removeTrack = function removeTrack(rtrack) {
  5647. _TrackList.prototype.removeTrack.call(this, rtrack);
  5648. if (rtrack.removeEventListener && rtrack.enabledChange_) {
  5649. rtrack.removeEventListener('enabledchange', rtrack.enabledChange_);
  5650. rtrack.enabledChange_ = null;
  5651. }
  5652. };
  5653. return AudioTrackList;
  5654. }(TrackList);
  5655. /**
  5656. * Un-select all other {@link VideoTrack}s that are selected.
  5657. *
  5658. * @param {VideoTrackList} list
  5659. * list to work on
  5660. *
  5661. * @param {VideoTrack} track
  5662. * The track to skip
  5663. *
  5664. * @private
  5665. */
  5666. var disableOthers$1 = function disableOthers(list, track) {
  5667. for (var i = 0; i < list.length; i++) {
  5668. if (!Object.keys(list[i]).length || track.id === list[i].id) {
  5669. continue;
  5670. } // another video track is enabled, disable it
  5671. list[i].selected = false;
  5672. }
  5673. };
  5674. /**
  5675. * The current list of {@link VideoTrack} for a video.
  5676. *
  5677. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist}
  5678. * @extends TrackList
  5679. */
  5680. var VideoTrackList =
  5681. /*#__PURE__*/
  5682. function (_TrackList) {
  5683. _inheritsLoose(VideoTrackList, _TrackList);
  5684. /**
  5685. * Create an instance of this class.
  5686. *
  5687. * @param {VideoTrack[]} [tracks=[]]
  5688. * A list of `VideoTrack` to instantiate the list with.
  5689. */
  5690. function VideoTrackList(tracks) {
  5691. var _this;
  5692. if (tracks === void 0) {
  5693. tracks = [];
  5694. }
  5695. // make sure only 1 track is enabled
  5696. // sorted from last index to first index
  5697. for (var i = tracks.length - 1; i >= 0; i--) {
  5698. if (tracks[i].selected) {
  5699. disableOthers$1(tracks, tracks[i]);
  5700. break;
  5701. }
  5702. }
  5703. _this = _TrackList.call(this, tracks) || this;
  5704. _this.changing_ = false;
  5705. /**
  5706. * @member {number} VideoTrackList#selectedIndex
  5707. * The current index of the selected {@link VideoTrack`}.
  5708. */
  5709. Object.defineProperty(_assertThisInitialized(_this), 'selectedIndex', {
  5710. get: function get() {
  5711. for (var _i = 0; _i < this.length; _i++) {
  5712. if (this[_i].selected) {
  5713. return _i;
  5714. }
  5715. }
  5716. return -1;
  5717. },
  5718. set: function set() {}
  5719. });
  5720. return _this;
  5721. }
  5722. /**
  5723. * Add a {@link VideoTrack} to the `VideoTrackList`.
  5724. *
  5725. * @param {VideoTrack} track
  5726. * The VideoTrack to add to the list
  5727. *
  5728. * @fires TrackList#addtrack
  5729. */
  5730. var _proto = VideoTrackList.prototype;
  5731. _proto.addTrack = function addTrack(track) {
  5732. var _this2 = this;
  5733. if (track.selected) {
  5734. disableOthers$1(this, track);
  5735. }
  5736. _TrackList.prototype.addTrack.call(this, track); // native tracks don't have this
  5737. if (!track.addEventListener) {
  5738. return;
  5739. }
  5740. track.selectedChange_ = function () {
  5741. if (_this2.changing_) {
  5742. return;
  5743. }
  5744. _this2.changing_ = true;
  5745. disableOthers$1(_this2, track);
  5746. _this2.changing_ = false;
  5747. _this2.trigger('change');
  5748. };
  5749. /**
  5750. * @listens VideoTrack#selectedchange
  5751. * @fires TrackList#change
  5752. */
  5753. track.addEventListener('selectedchange', track.selectedChange_);
  5754. };
  5755. _proto.removeTrack = function removeTrack(rtrack) {
  5756. _TrackList.prototype.removeTrack.call(this, rtrack);
  5757. if (rtrack.removeEventListener && rtrack.selectedChange_) {
  5758. rtrack.removeEventListener('selectedchange', rtrack.selectedChange_);
  5759. rtrack.selectedChange_ = null;
  5760. }
  5761. };
  5762. return VideoTrackList;
  5763. }(TrackList);
  5764. /**
  5765. * The current list of {@link TextTrack} for a media file.
  5766. *
  5767. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttracklist}
  5768. * @extends TrackList
  5769. */
  5770. var TextTrackList =
  5771. /*#__PURE__*/
  5772. function (_TrackList) {
  5773. _inheritsLoose(TextTrackList, _TrackList);
  5774. function TextTrackList() {
  5775. return _TrackList.apply(this, arguments) || this;
  5776. }
  5777. var _proto = TextTrackList.prototype;
  5778. /**
  5779. * Add a {@link TextTrack} to the `TextTrackList`
  5780. *
  5781. * @param {TextTrack} track
  5782. * The text track to add to the list.
  5783. *
  5784. * @fires TrackList#addtrack
  5785. */
  5786. _proto.addTrack = function addTrack(track) {
  5787. var _this = this;
  5788. _TrackList.prototype.addTrack.call(this, track);
  5789. if (!this.queueChange_) {
  5790. this.queueChange_ = function () {
  5791. return _this.queueTrigger('change');
  5792. };
  5793. }
  5794. if (!this.triggerSelectedlanguagechange) {
  5795. this.triggerSelectedlanguagechange_ = function () {
  5796. return _this.trigger('selectedlanguagechange');
  5797. };
  5798. }
  5799. /**
  5800. * @listens TextTrack#modechange
  5801. * @fires TrackList#change
  5802. */
  5803. track.addEventListener('modechange', this.queueChange_);
  5804. var nonLanguageTextTrackKind = ['metadata', 'chapters'];
  5805. if (nonLanguageTextTrackKind.indexOf(track.kind) === -1) {
  5806. track.addEventListener('modechange', this.triggerSelectedlanguagechange_);
  5807. }
  5808. };
  5809. _proto.removeTrack = function removeTrack(rtrack) {
  5810. _TrackList.prototype.removeTrack.call(this, rtrack); // manually remove the event handlers we added
  5811. if (rtrack.removeEventListener) {
  5812. if (this.queueChange_) {
  5813. rtrack.removeEventListener('modechange', this.queueChange_);
  5814. }
  5815. if (this.selectedlanguagechange_) {
  5816. rtrack.removeEventListener('modechange', this.triggerSelectedlanguagechange_);
  5817. }
  5818. }
  5819. };
  5820. return TextTrackList;
  5821. }(TrackList);
  5822. /**
  5823. * @file html-track-element-list.js
  5824. */
  5825. /**
  5826. * The current list of {@link HtmlTrackElement}s.
  5827. */
  5828. var HtmlTrackElementList =
  5829. /*#__PURE__*/
  5830. function () {
  5831. /**
  5832. * Create an instance of this class.
  5833. *
  5834. * @param {HtmlTrackElement[]} [tracks=[]]
  5835. * A list of `HtmlTrackElement` to instantiate the list with.
  5836. */
  5837. function HtmlTrackElementList(trackElements) {
  5838. if (trackElements === void 0) {
  5839. trackElements = [];
  5840. }
  5841. this.trackElements_ = [];
  5842. /**
  5843. * @memberof HtmlTrackElementList
  5844. * @member {number} length
  5845. * The current number of `Track`s in the this Trackist.
  5846. * @instance
  5847. */
  5848. Object.defineProperty(this, 'length', {
  5849. get: function get() {
  5850. return this.trackElements_.length;
  5851. }
  5852. });
  5853. for (var i = 0, length = trackElements.length; i < length; i++) {
  5854. this.addTrackElement_(trackElements[i]);
  5855. }
  5856. }
  5857. /**
  5858. * Add an {@link HtmlTrackElement} to the `HtmlTrackElementList`
  5859. *
  5860. * @param {HtmlTrackElement} trackElement
  5861. * The track element to add to the list.
  5862. *
  5863. * @private
  5864. */
  5865. var _proto = HtmlTrackElementList.prototype;
  5866. _proto.addTrackElement_ = function addTrackElement_(trackElement) {
  5867. var index = this.trackElements_.length;
  5868. if (!('' + index in this)) {
  5869. Object.defineProperty(this, index, {
  5870. get: function get() {
  5871. return this.trackElements_[index];
  5872. }
  5873. });
  5874. } // Do not add duplicate elements
  5875. if (this.trackElements_.indexOf(trackElement) === -1) {
  5876. this.trackElements_.push(trackElement);
  5877. }
  5878. }
  5879. /**
  5880. * Get an {@link HtmlTrackElement} from the `HtmlTrackElementList` given an
  5881. * {@link TextTrack}.
  5882. *
  5883. * @param {TextTrack} track
  5884. * The track associated with a track element.
  5885. *
  5886. * @return {HtmlTrackElement|undefined}
  5887. * The track element that was found or undefined.
  5888. *
  5889. * @private
  5890. */
  5891. ;
  5892. _proto.getTrackElementByTrack_ = function getTrackElementByTrack_(track) {
  5893. var trackElement_;
  5894. for (var i = 0, length = this.trackElements_.length; i < length; i++) {
  5895. if (track === this.trackElements_[i].track) {
  5896. trackElement_ = this.trackElements_[i];
  5897. break;
  5898. }
  5899. }
  5900. return trackElement_;
  5901. }
  5902. /**
  5903. * Remove a {@link HtmlTrackElement} from the `HtmlTrackElementList`
  5904. *
  5905. * @param {HtmlTrackElement} trackElement
  5906. * The track element to remove from the list.
  5907. *
  5908. * @private
  5909. */
  5910. ;
  5911. _proto.removeTrackElement_ = function removeTrackElement_(trackElement) {
  5912. for (var i = 0, length = this.trackElements_.length; i < length; i++) {
  5913. if (trackElement === this.trackElements_[i]) {
  5914. if (this.trackElements_[i].track && typeof this.trackElements_[i].track.off === 'function') {
  5915. this.trackElements_[i].track.off();
  5916. }
  5917. if (typeof this.trackElements_[i].off === 'function') {
  5918. this.trackElements_[i].off();
  5919. }
  5920. this.trackElements_.splice(i, 1);
  5921. break;
  5922. }
  5923. }
  5924. };
  5925. return HtmlTrackElementList;
  5926. }();
  5927. /**
  5928. * @file text-track-cue-list.js
  5929. */
  5930. /**
  5931. * @typedef {Object} TextTrackCueList~TextTrackCue
  5932. *
  5933. * @property {string} id
  5934. * The unique id for this text track cue
  5935. *
  5936. * @property {number} startTime
  5937. * The start time for this text track cue
  5938. *
  5939. * @property {number} endTime
  5940. * The end time for this text track cue
  5941. *
  5942. * @property {boolean} pauseOnExit
  5943. * Pause when the end time is reached if true.
  5944. *
  5945. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcue}
  5946. */
  5947. /**
  5948. * A List of TextTrackCues.
  5949. *
  5950. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcuelist}
  5951. */
  5952. var TextTrackCueList =
  5953. /*#__PURE__*/
  5954. function () {
  5955. /**
  5956. * Create an instance of this class..
  5957. *
  5958. * @param {Array} cues
  5959. * A list of cues to be initialized with
  5960. */
  5961. function TextTrackCueList(cues) {
  5962. TextTrackCueList.prototype.setCues_.call(this, cues);
  5963. /**
  5964. * @memberof TextTrackCueList
  5965. * @member {number} length
  5966. * The current number of `TextTrackCue`s in the TextTrackCueList.
  5967. * @instance
  5968. */
  5969. Object.defineProperty(this, 'length', {
  5970. get: function get() {
  5971. return this.length_;
  5972. }
  5973. });
  5974. }
  5975. /**
  5976. * A setter for cues in this list. Creates getters
  5977. * an an index for the cues.
  5978. *
  5979. * @param {Array} cues
  5980. * An array of cues to set
  5981. *
  5982. * @private
  5983. */
  5984. var _proto = TextTrackCueList.prototype;
  5985. _proto.setCues_ = function setCues_(cues) {
  5986. var oldLength = this.length || 0;
  5987. var i = 0;
  5988. var l = cues.length;
  5989. this.cues_ = cues;
  5990. this.length_ = cues.length;
  5991. var defineProp = function defineProp(index) {
  5992. if (!('' + index in this)) {
  5993. Object.defineProperty(this, '' + index, {
  5994. get: function get() {
  5995. return this.cues_[index];
  5996. }
  5997. });
  5998. }
  5999. };
  6000. if (oldLength < l) {
  6001. i = oldLength;
  6002. for (; i < l; i++) {
  6003. defineProp.call(this, i);
  6004. }
  6005. }
  6006. }
  6007. /**
  6008. * Get a `TextTrackCue` that is currently in the `TextTrackCueList` by id.
  6009. *
  6010. * @param {string} id
  6011. * The id of the cue that should be searched for.
  6012. *
  6013. * @return {TextTrackCueList~TextTrackCue|null}
  6014. * A single cue or null if none was found.
  6015. */
  6016. ;
  6017. _proto.getCueById = function getCueById(id) {
  6018. var result = null;
  6019. for (var i = 0, l = this.length; i < l; i++) {
  6020. var cue = this[i];
  6021. if (cue.id === id) {
  6022. result = cue;
  6023. break;
  6024. }
  6025. }
  6026. return result;
  6027. };
  6028. return TextTrackCueList;
  6029. }();
  6030. /**
  6031. * @file track-kinds.js
  6032. */
  6033. /**
  6034. * All possible `VideoTrackKind`s
  6035. *
  6036. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-videotrack-kind
  6037. * @typedef VideoTrack~Kind
  6038. * @enum
  6039. */
  6040. var VideoTrackKind = {
  6041. alternative: 'alternative',
  6042. captions: 'captions',
  6043. main: 'main',
  6044. sign: 'sign',
  6045. subtitles: 'subtitles',
  6046. commentary: 'commentary'
  6047. };
  6048. /**
  6049. * All possible `AudioTrackKind`s
  6050. *
  6051. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-audiotrack-kind
  6052. * @typedef AudioTrack~Kind
  6053. * @enum
  6054. */
  6055. var AudioTrackKind = {
  6056. 'alternative': 'alternative',
  6057. 'descriptions': 'descriptions',
  6058. 'main': 'main',
  6059. 'main-desc': 'main-desc',
  6060. 'translation': 'translation',
  6061. 'commentary': 'commentary'
  6062. };
  6063. /**
  6064. * All possible `TextTrackKind`s
  6065. *
  6066. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-kind
  6067. * @typedef TextTrack~Kind
  6068. * @enum
  6069. */
  6070. var TextTrackKind = {
  6071. subtitles: 'subtitles',
  6072. captions: 'captions',
  6073. descriptions: 'descriptions',
  6074. chapters: 'chapters',
  6075. metadata: 'metadata'
  6076. };
  6077. /**
  6078. * All possible `TextTrackMode`s
  6079. *
  6080. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackmode
  6081. * @typedef TextTrack~Mode
  6082. * @enum
  6083. */
  6084. var TextTrackMode = {
  6085. disabled: 'disabled',
  6086. hidden: 'hidden',
  6087. showing: 'showing'
  6088. };
  6089. /**
  6090. * A Track class that contains all of the common functionality for {@link AudioTrack},
  6091. * {@link VideoTrack}, and {@link TextTrack}.
  6092. *
  6093. * > Note: This class should not be used directly
  6094. *
  6095. * @see {@link https://html.spec.whatwg.org/multipage/embedded-content.html}
  6096. * @extends EventTarget
  6097. * @abstract
  6098. */
  6099. var Track =
  6100. /*#__PURE__*/
  6101. function (_EventTarget) {
  6102. _inheritsLoose(Track, _EventTarget);
  6103. /**
  6104. * Create an instance of this class.
  6105. *
  6106. * @param {Object} [options={}]
  6107. * Object of option names and values
  6108. *
  6109. * @param {string} [options.kind='']
  6110. * A valid kind for the track type you are creating.
  6111. *
  6112. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  6113. * A unique id for this AudioTrack.
  6114. *
  6115. * @param {string} [options.label='']
  6116. * The menu label for this track.
  6117. *
  6118. * @param {string} [options.language='']
  6119. * A valid two character language code.
  6120. *
  6121. * @abstract
  6122. */
  6123. function Track(options) {
  6124. var _this;
  6125. if (options === void 0) {
  6126. options = {};
  6127. }
  6128. _this = _EventTarget.call(this) || this;
  6129. var trackProps = {
  6130. id: options.id || 'vjs_track_' + newGUID(),
  6131. kind: options.kind || '',
  6132. label: options.label || '',
  6133. language: options.language || ''
  6134. };
  6135. /**
  6136. * @memberof Track
  6137. * @member {string} id
  6138. * The id of this track. Cannot be changed after creation.
  6139. * @instance
  6140. *
  6141. * @readonly
  6142. */
  6143. /**
  6144. * @memberof Track
  6145. * @member {string} kind
  6146. * The kind of track that this is. Cannot be changed after creation.
  6147. * @instance
  6148. *
  6149. * @readonly
  6150. */
  6151. /**
  6152. * @memberof Track
  6153. * @member {string} label
  6154. * The label of this track. Cannot be changed after creation.
  6155. * @instance
  6156. *
  6157. * @readonly
  6158. */
  6159. /**
  6160. * @memberof Track
  6161. * @member {string} language
  6162. * The two letter language code for this track. Cannot be changed after
  6163. * creation.
  6164. * @instance
  6165. *
  6166. * @readonly
  6167. */
  6168. var _loop = function _loop(key) {
  6169. Object.defineProperty(_assertThisInitialized(_this), key, {
  6170. get: function get() {
  6171. return trackProps[key];
  6172. },
  6173. set: function set() {}
  6174. });
  6175. };
  6176. for (var key in trackProps) {
  6177. _loop(key);
  6178. }
  6179. return _this;
  6180. }
  6181. return Track;
  6182. }(EventTarget);
  6183. /**
  6184. * @file url.js
  6185. * @module url
  6186. */
  6187. /**
  6188. * @typedef {Object} url:URLObject
  6189. *
  6190. * @property {string} protocol
  6191. * The protocol of the url that was parsed.
  6192. *
  6193. * @property {string} hostname
  6194. * The hostname of the url that was parsed.
  6195. *
  6196. * @property {string} port
  6197. * The port of the url that was parsed.
  6198. *
  6199. * @property {string} pathname
  6200. * The pathname of the url that was parsed.
  6201. *
  6202. * @property {string} search
  6203. * The search query of the url that was parsed.
  6204. *
  6205. * @property {string} hash
  6206. * The hash of the url that was parsed.
  6207. *
  6208. * @property {string} host
  6209. * The host of the url that was parsed.
  6210. */
  6211. /**
  6212. * Resolve and parse the elements of a URL.
  6213. *
  6214. * @function
  6215. * @param {String} url
  6216. * The url to parse
  6217. *
  6218. * @return {url:URLObject}
  6219. * An object of url details
  6220. */
  6221. var parseUrl = function parseUrl(url) {
  6222. var props = ['protocol', 'hostname', 'port', 'pathname', 'search', 'hash', 'host']; // add the url to an anchor and let the browser parse the URL
  6223. var a = document.createElement('a');
  6224. a.href = url; // IE8 (and 9?) Fix
  6225. // ie8 doesn't parse the URL correctly until the anchor is actually
  6226. // added to the body, and an innerHTML is needed to trigger the parsing
  6227. var addToBody = a.host === '' && a.protocol !== 'file:';
  6228. var div;
  6229. if (addToBody) {
  6230. div = document.createElement('div');
  6231. div.innerHTML = "<a href=\"" + url + "\"></a>";
  6232. a = div.firstChild; // prevent the div from affecting layout
  6233. div.setAttribute('style', 'display:none; position:absolute;');
  6234. document.body.appendChild(div);
  6235. } // Copy the specific URL properties to a new object
  6236. // This is also needed for IE8 because the anchor loses its
  6237. // properties when it's removed from the dom
  6238. var details = {};
  6239. for (var i = 0; i < props.length; i++) {
  6240. details[props[i]] = a[props[i]];
  6241. } // IE9 adds the port to the host property unlike everyone else. If
  6242. // a port identifier is added for standard ports, strip it.
  6243. if (details.protocol === 'http:') {
  6244. details.host = details.host.replace(/:80$/, '');
  6245. }
  6246. if (details.protocol === 'https:') {
  6247. details.host = details.host.replace(/:443$/, '');
  6248. }
  6249. if (!details.protocol) {
  6250. details.protocol = window$1.location.protocol;
  6251. }
  6252. if (addToBody) {
  6253. document.body.removeChild(div);
  6254. }
  6255. return details;
  6256. };
  6257. /**
  6258. * Get absolute version of relative URL. Used to tell Flash the correct URL.
  6259. *
  6260. * @function
  6261. * @param {string} url
  6262. * URL to make absolute
  6263. *
  6264. * @return {string}
  6265. * Absolute URL
  6266. *
  6267. * @see http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
  6268. */
  6269. var getAbsoluteURL = function getAbsoluteURL(url) {
  6270. // Check if absolute URL
  6271. if (!url.match(/^https?:\/\//)) {
  6272. // Convert to absolute URL. Flash hosted off-site needs an absolute URL.
  6273. var div = document.createElement('div');
  6274. div.innerHTML = "<a href=\"" + url + "\">x</a>";
  6275. url = div.firstChild.href;
  6276. }
  6277. return url;
  6278. };
  6279. /**
  6280. * Returns the extension of the passed file name. It will return an empty string
  6281. * if passed an invalid path.
  6282. *
  6283. * @function
  6284. * @param {string} path
  6285. * The fileName path like '/path/to/file.mp4'
  6286. *
  6287. * @return {string}
  6288. * The extension in lower case or an empty string if no
  6289. * extension could be found.
  6290. */
  6291. var getFileExtension = function getFileExtension(path) {
  6292. if (typeof path === 'string') {
  6293. var splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$/;
  6294. var pathParts = splitPathRe.exec(path);
  6295. if (pathParts) {
  6296. return pathParts.pop().toLowerCase();
  6297. }
  6298. }
  6299. return '';
  6300. };
  6301. /**
  6302. * Returns whether the url passed is a cross domain request or not.
  6303. *
  6304. * @function
  6305. * @param {string} url
  6306. * The url to check.
  6307. *
  6308. * @return {boolean}
  6309. * Whether it is a cross domain request or not.
  6310. */
  6311. var isCrossOrigin = function isCrossOrigin(url) {
  6312. var winLoc = window$1.location;
  6313. var urlInfo = parseUrl(url); // IE8 protocol relative urls will return ':' for protocol
  6314. var srcProtocol = urlInfo.protocol === ':' ? winLoc.protocol : urlInfo.protocol; // Check if url is for another domain/origin
  6315. // IE8 doesn't know location.origin, so we won't rely on it here
  6316. var crossOrigin = srcProtocol + urlInfo.host !== winLoc.protocol + winLoc.host;
  6317. return crossOrigin;
  6318. };
  6319. var Url = /*#__PURE__*/Object.freeze({
  6320. parseUrl: parseUrl,
  6321. getAbsoluteURL: getAbsoluteURL,
  6322. getFileExtension: getFileExtension,
  6323. isCrossOrigin: isCrossOrigin
  6324. });
  6325. var isFunction_1 = isFunction;
  6326. var toString$1 = Object.prototype.toString;
  6327. function isFunction(fn) {
  6328. var string = toString$1.call(fn);
  6329. return string === '[object Function]' || typeof fn === 'function' && string !== '[object RegExp]' || typeof window !== 'undefined' && ( // IE8 and below
  6330. fn === window.setTimeout || fn === window.alert || fn === window.confirm || fn === window.prompt);
  6331. }
  6332. /* eslint no-invalid-this: 1 */
  6333. var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
  6334. var slice = Array.prototype.slice;
  6335. var toStr = Object.prototype.toString;
  6336. var funcType = '[object Function]';
  6337. var implementation = function bind(that) {
  6338. var target = this;
  6339. if (typeof target !== 'function' || toStr.call(target) !== funcType) {
  6340. throw new TypeError(ERROR_MESSAGE + target);
  6341. }
  6342. var args = slice.call(arguments, 1);
  6343. var bound;
  6344. var binder = function binder() {
  6345. if (this instanceof bound) {
  6346. var result = target.apply(this, args.concat(slice.call(arguments)));
  6347. if (Object(result) === result) {
  6348. return result;
  6349. }
  6350. return this;
  6351. } else {
  6352. return target.apply(that, args.concat(slice.call(arguments)));
  6353. }
  6354. };
  6355. var boundLength = Math.max(0, target.length - args.length);
  6356. var boundArgs = [];
  6357. for (var i = 0; i < boundLength; i++) {
  6358. boundArgs.push('$' + i);
  6359. }
  6360. bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
  6361. if (target.prototype) {
  6362. var Empty = function Empty() {};
  6363. Empty.prototype = target.prototype;
  6364. bound.prototype = new Empty();
  6365. Empty.prototype = null;
  6366. }
  6367. return bound;
  6368. };
  6369. var functionBind = Function.prototype.bind || implementation;
  6370. var toStr$1 = Object.prototype.toString;
  6371. var isArguments = function isArguments(value) {
  6372. var str = toStr$1.call(value);
  6373. var isArgs = str === '[object Arguments]';
  6374. if (!isArgs) {
  6375. isArgs = str !== '[object Array]' && value !== null && typeof value === 'object' && typeof value.length === 'number' && value.length >= 0 && toStr$1.call(value.callee) === '[object Function]';
  6376. }
  6377. return isArgs;
  6378. };
  6379. var keysShim;
  6380. if (!Object.keys) {
  6381. // modified from https://github.com/es-shims/es5-shim
  6382. var has = Object.prototype.hasOwnProperty;
  6383. var toStr$2 = Object.prototype.toString;
  6384. var isArgs = isArguments; // eslint-disable-line global-require
  6385. var isEnumerable = Object.prototype.propertyIsEnumerable;
  6386. var hasDontEnumBug = !isEnumerable.call({
  6387. toString: null
  6388. }, 'toString');
  6389. var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
  6390. var dontEnums = ['toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor'];
  6391. var equalsConstructorPrototype = function equalsConstructorPrototype(o) {
  6392. var ctor = o.constructor;
  6393. return ctor && ctor.prototype === o;
  6394. };
  6395. var excludedKeys = {
  6396. $applicationCache: true,
  6397. $console: true,
  6398. $external: true,
  6399. $frame: true,
  6400. $frameElement: true,
  6401. $frames: true,
  6402. $innerHeight: true,
  6403. $innerWidth: true,
  6404. $onmozfullscreenchange: true,
  6405. $onmozfullscreenerror: true,
  6406. $outerHeight: true,
  6407. $outerWidth: true,
  6408. $pageXOffset: true,
  6409. $pageYOffset: true,
  6410. $parent: true,
  6411. $scrollLeft: true,
  6412. $scrollTop: true,
  6413. $scrollX: true,
  6414. $scrollY: true,
  6415. $self: true,
  6416. $webkitIndexedDB: true,
  6417. $webkitStorageInfo: true,
  6418. $window: true
  6419. };
  6420. var hasAutomationEqualityBug = function () {
  6421. /* global window */
  6422. if (typeof window === 'undefined') {
  6423. return false;
  6424. }
  6425. for (var k in window) {
  6426. try {
  6427. if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
  6428. try {
  6429. equalsConstructorPrototype(window[k]);
  6430. } catch (e) {
  6431. return true;
  6432. }
  6433. }
  6434. } catch (e) {
  6435. return true;
  6436. }
  6437. }
  6438. return false;
  6439. }();
  6440. var equalsConstructorPrototypeIfNotBuggy = function equalsConstructorPrototypeIfNotBuggy(o) {
  6441. /* global window */
  6442. if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
  6443. return equalsConstructorPrototype(o);
  6444. }
  6445. try {
  6446. return equalsConstructorPrototype(o);
  6447. } catch (e) {
  6448. return false;
  6449. }
  6450. };
  6451. keysShim = function keys(object) {
  6452. var isObject = object !== null && typeof object === 'object';
  6453. var isFunction = toStr$2.call(object) === '[object Function]';
  6454. var isArguments = isArgs(object);
  6455. var isString = isObject && toStr$2.call(object) === '[object String]';
  6456. var theKeys = [];
  6457. if (!isObject && !isFunction && !isArguments) {
  6458. throw new TypeError('Object.keys called on a non-object');
  6459. }
  6460. var skipProto = hasProtoEnumBug && isFunction;
  6461. if (isString && object.length > 0 && !has.call(object, 0)) {
  6462. for (var i = 0; i < object.length; ++i) {
  6463. theKeys.push(String(i));
  6464. }
  6465. }
  6466. if (isArguments && object.length > 0) {
  6467. for (var j = 0; j < object.length; ++j) {
  6468. theKeys.push(String(j));
  6469. }
  6470. } else {
  6471. for (var name in object) {
  6472. if (!(skipProto && name === 'prototype') && has.call(object, name)) {
  6473. theKeys.push(String(name));
  6474. }
  6475. }
  6476. }
  6477. if (hasDontEnumBug) {
  6478. var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
  6479. for (var k = 0; k < dontEnums.length; ++k) {
  6480. if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
  6481. theKeys.push(dontEnums[k]);
  6482. }
  6483. }
  6484. }
  6485. return theKeys;
  6486. };
  6487. }
  6488. var implementation$1 = keysShim;
  6489. var slice$1 = Array.prototype.slice;
  6490. var origKeys = Object.keys;
  6491. var keysShim$1 = origKeys ? function keys(o) {
  6492. return origKeys(o);
  6493. } : implementation$1;
  6494. var originalKeys = Object.keys;
  6495. keysShim$1.shim = function shimObjectKeys() {
  6496. if (Object.keys) {
  6497. var keysWorksWithArguments = function () {
  6498. // Safari 5.0 bug
  6499. var args = Object.keys(arguments);
  6500. return args && args.length === arguments.length;
  6501. }(1, 2);
  6502. if (!keysWorksWithArguments) {
  6503. Object.keys = function keys(object) {
  6504. // eslint-disable-line func-name-matching
  6505. if (isArguments(object)) {
  6506. return originalKeys(slice$1.call(object));
  6507. }
  6508. return originalKeys(object);
  6509. };
  6510. }
  6511. } else {
  6512. Object.keys = keysShim$1;
  6513. }
  6514. return Object.keys || keysShim$1;
  6515. };
  6516. var objectKeys = keysShim$1;
  6517. var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
  6518. var toStr$3 = Object.prototype.toString;
  6519. var concat = Array.prototype.concat;
  6520. var origDefineProperty = Object.defineProperty;
  6521. var isFunction$1 = function isFunction(fn) {
  6522. return typeof fn === 'function' && toStr$3.call(fn) === '[object Function]';
  6523. };
  6524. var arePropertyDescriptorsSupported = function arePropertyDescriptorsSupported() {
  6525. var obj = {};
  6526. try {
  6527. origDefineProperty(obj, 'x', {
  6528. enumerable: false,
  6529. value: obj
  6530. }); // eslint-disable-next-line no-unused-vars, no-restricted-syntax
  6531. for (var _ in obj) {
  6532. // jscs:ignore disallowUnusedVariables
  6533. return false;
  6534. }
  6535. return obj.x === obj;
  6536. } catch (e) {
  6537. /* this is IE 8. */
  6538. return false;
  6539. }
  6540. };
  6541. var supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();
  6542. var defineProperty = function defineProperty(object, name, value, predicate) {
  6543. if (name in object && (!isFunction$1(predicate) || !predicate())) {
  6544. return;
  6545. }
  6546. if (supportsDescriptors) {
  6547. origDefineProperty(object, name, {
  6548. configurable: true,
  6549. enumerable: false,
  6550. value: value,
  6551. writable: true
  6552. });
  6553. } else {
  6554. object[name] = value;
  6555. }
  6556. };
  6557. var defineProperties = function defineProperties(object, map) {
  6558. var predicates = arguments.length > 2 ? arguments[2] : {};
  6559. var props = objectKeys(map);
  6560. if (hasSymbols) {
  6561. props = concat.call(props, Object.getOwnPropertySymbols(map));
  6562. }
  6563. for (var i = 0; i < props.length; i += 1) {
  6564. defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
  6565. }
  6566. };
  6567. defineProperties.supportsDescriptors = !!supportsDescriptors;
  6568. var defineProperties_1 = defineProperties;
  6569. /* globals
  6570. Set,
  6571. Map,
  6572. WeakSet,
  6573. WeakMap,
  6574. Promise,
  6575. Symbol,
  6576. Proxy,
  6577. Atomics,
  6578. SharedArrayBuffer,
  6579. ArrayBuffer,
  6580. DataView,
  6581. Uint8Array,
  6582. Float32Array,
  6583. Float64Array,
  6584. Int8Array,
  6585. Int16Array,
  6586. Int32Array,
  6587. Uint8ClampedArray,
  6588. Uint16Array,
  6589. Uint32Array,
  6590. */
  6591. var undefined$1; // eslint-disable-line no-shadow-restricted-names
  6592. var ThrowTypeError = Object.getOwnPropertyDescriptor ? function () {
  6593. return Object.getOwnPropertyDescriptor(arguments, 'callee').get;
  6594. }() : function () {
  6595. throw new TypeError();
  6596. };
  6597. var hasSymbols$1 = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
  6598. var getProto = Object.getPrototypeOf || function (x) {
  6599. return x.__proto__;
  6600. }; // eslint-disable-line no-proto
  6601. var generatorFunction = undefined$1;
  6602. var asyncFunction = undefined$1;
  6603. var asyncGenFunction = undefined$1;
  6604. var TypedArray = typeof Uint8Array === 'undefined' ? undefined$1 : getProto(Uint8Array);
  6605. var INTRINSICS = {
  6606. '$ %Array%': Array,
  6607. '$ %ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
  6608. '$ %ArrayBufferPrototype%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer.prototype,
  6609. '$ %ArrayIteratorPrototype%': hasSymbols$1 ? getProto([][Symbol.iterator]()) : undefined$1,
  6610. '$ %ArrayPrototype%': Array.prototype,
  6611. '$ %ArrayProto_entries%': Array.prototype.entries,
  6612. '$ %ArrayProto_forEach%': Array.prototype.forEach,
  6613. '$ %ArrayProto_keys%': Array.prototype.keys,
  6614. '$ %ArrayProto_values%': Array.prototype.values,
  6615. '$ %AsyncFromSyncIteratorPrototype%': undefined$1,
  6616. '$ %AsyncFunction%': asyncFunction,
  6617. '$ %AsyncFunctionPrototype%': undefined$1,
  6618. '$ %AsyncGenerator%': undefined$1,
  6619. '$ %AsyncGeneratorFunction%': asyncGenFunction,
  6620. '$ %AsyncGeneratorPrototype%': undefined$1,
  6621. '$ %AsyncIteratorPrototype%': undefined$1,
  6622. '$ %Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
  6623. '$ %Boolean%': Boolean,
  6624. '$ %BooleanPrototype%': Boolean.prototype,
  6625. '$ %DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
  6626. '$ %DataViewPrototype%': typeof DataView === 'undefined' ? undefined$1 : DataView.prototype,
  6627. '$ %Date%': Date,
  6628. '$ %DatePrototype%': Date.prototype,
  6629. '$ %decodeURI%': decodeURI,
  6630. '$ %decodeURIComponent%': decodeURIComponent,
  6631. '$ %encodeURI%': encodeURI,
  6632. '$ %encodeURIComponent%': encodeURIComponent,
  6633. '$ %Error%': Error,
  6634. '$ %ErrorPrototype%': Error.prototype,
  6635. '$ %eval%': eval,
  6636. // eslint-disable-line no-eval
  6637. '$ %EvalError%': EvalError,
  6638. '$ %EvalErrorPrototype%': EvalError.prototype,
  6639. '$ %Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
  6640. '$ %Float32ArrayPrototype%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array.prototype,
  6641. '$ %Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
  6642. '$ %Float64ArrayPrototype%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array.prototype,
  6643. '$ %Function%': Function,
  6644. '$ %FunctionPrototype%': Function.prototype,
  6645. '$ %Generator%': undefined$1,
  6646. '$ %GeneratorFunction%': generatorFunction,
  6647. '$ %GeneratorPrototype%': undefined$1,
  6648. '$ %Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
  6649. '$ %Int8ArrayPrototype%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array.prototype,
  6650. '$ %Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
  6651. '$ %Int16ArrayPrototype%': typeof Int16Array === 'undefined' ? undefined$1 : Int8Array.prototype,
  6652. '$ %Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
  6653. '$ %Int32ArrayPrototype%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array.prototype,
  6654. '$ %isFinite%': isFinite,
  6655. '$ %isNaN%': isNaN,
  6656. '$ %IteratorPrototype%': hasSymbols$1 ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
  6657. '$ %JSON%': JSON,
  6658. '$ %JSONParse%': JSON.parse,
  6659. '$ %Map%': typeof Map === 'undefined' ? undefined$1 : Map,
  6660. '$ %MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$1 ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
  6661. '$ %MapPrototype%': typeof Map === 'undefined' ? undefined$1 : Map.prototype,
  6662. '$ %Math%': Math,
  6663. '$ %Number%': Number,
  6664. '$ %NumberPrototype%': Number.prototype,
  6665. '$ %Object%': Object,
  6666. '$ %ObjectPrototype%': Object.prototype,
  6667. '$ %ObjProto_toString%': Object.prototype.toString,
  6668. '$ %ObjProto_valueOf%': Object.prototype.valueOf,
  6669. '$ %parseFloat%': parseFloat,
  6670. '$ %parseInt%': parseInt,
  6671. '$ %Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
  6672. '$ %PromisePrototype%': typeof Promise === 'undefined' ? undefined$1 : Promise.prototype,
  6673. '$ %PromiseProto_then%': typeof Promise === 'undefined' ? undefined$1 : Promise.prototype.then,
  6674. '$ %Promise_all%': typeof Promise === 'undefined' ? undefined$1 : Promise.all,
  6675. '$ %Promise_reject%': typeof Promise === 'undefined' ? undefined$1 : Promise.reject,
  6676. '$ %Promise_resolve%': typeof Promise === 'undefined' ? undefined$1 : Promise.resolve,
  6677. '$ %Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
  6678. '$ %RangeError%': RangeError,
  6679. '$ %RangeErrorPrototype%': RangeError.prototype,
  6680. '$ %ReferenceError%': ReferenceError,
  6681. '$ %ReferenceErrorPrototype%': ReferenceError.prototype,
  6682. '$ %Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
  6683. '$ %RegExp%': RegExp,
  6684. '$ %RegExpPrototype%': RegExp.prototype,
  6685. '$ %Set%': typeof Set === 'undefined' ? undefined$1 : Set,
  6686. '$ %SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$1 ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
  6687. '$ %SetPrototype%': typeof Set === 'undefined' ? undefined$1 : Set.prototype,
  6688. '$ %SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
  6689. '$ %SharedArrayBufferPrototype%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer.prototype,
  6690. '$ %String%': String,
  6691. '$ %StringIteratorPrototype%': hasSymbols$1 ? getProto(''[Symbol.iterator]()) : undefined$1,
  6692. '$ %StringPrototype%': String.prototype,
  6693. '$ %Symbol%': hasSymbols$1 ? Symbol : undefined$1,
  6694. '$ %SymbolPrototype%': hasSymbols$1 ? Symbol.prototype : undefined$1,
  6695. '$ %SyntaxError%': SyntaxError,
  6696. '$ %SyntaxErrorPrototype%': SyntaxError.prototype,
  6697. '$ %ThrowTypeError%': ThrowTypeError,
  6698. '$ %TypedArray%': TypedArray,
  6699. '$ %TypedArrayPrototype%': TypedArray ? TypedArray.prototype : undefined$1,
  6700. '$ %TypeError%': TypeError,
  6701. '$ %TypeErrorPrototype%': TypeError.prototype,
  6702. '$ %Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
  6703. '$ %Uint8ArrayPrototype%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array.prototype,
  6704. '$ %Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
  6705. '$ %Uint8ClampedArrayPrototype%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray.prototype,
  6706. '$ %Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
  6707. '$ %Uint16ArrayPrototype%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array.prototype,
  6708. '$ %Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
  6709. '$ %Uint32ArrayPrototype%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array.prototype,
  6710. '$ %URIError%': URIError,
  6711. '$ %URIErrorPrototype%': URIError.prototype,
  6712. '$ %WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
  6713. '$ %WeakMapPrototype%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap.prototype,
  6714. '$ %WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet,
  6715. '$ %WeakSetPrototype%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet.prototype
  6716. };
  6717. var GetIntrinsic = function GetIntrinsic(name, allowMissing) {
  6718. if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
  6719. throw new TypeError('"allowMissing" argument must be a boolean');
  6720. }
  6721. var key = '$ ' + name;
  6722. if (!(key in INTRINSICS)) {
  6723. throw new SyntaxError('intrinsic ' + name + ' does not exist!');
  6724. } // istanbul ignore if // hopefully this is impossible to test :-)
  6725. if (typeof INTRINSICS[key] === 'undefined' && !allowMissing) {
  6726. throw new TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
  6727. }
  6728. return INTRINSICS[key];
  6729. };
  6730. var src = functionBind.call(Function.call, Object.prototype.hasOwnProperty);
  6731. var $TypeError = GetIntrinsic('%TypeError%');
  6732. var $SyntaxError = GetIntrinsic('%SyntaxError%');
  6733. var predicates = {
  6734. // https://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type
  6735. 'Property Descriptor': function isPropertyDescriptor(ES, Desc) {
  6736. if (ES.Type(Desc) !== 'Object') {
  6737. return false;
  6738. }
  6739. var allowed = {
  6740. '[[Configurable]]': true,
  6741. '[[Enumerable]]': true,
  6742. '[[Get]]': true,
  6743. '[[Set]]': true,
  6744. '[[Value]]': true,
  6745. '[[Writable]]': true
  6746. };
  6747. for (var key in Desc) {
  6748. // eslint-disable-line
  6749. if (src(Desc, key) && !allowed[key]) {
  6750. return false;
  6751. }
  6752. }
  6753. var isData = src(Desc, '[[Value]]');
  6754. var IsAccessor = src(Desc, '[[Get]]') || src(Desc, '[[Set]]');
  6755. if (isData && IsAccessor) {
  6756. throw new $TypeError('Property Descriptors may not be both accessor and data descriptors');
  6757. }
  6758. return true;
  6759. }
  6760. };
  6761. var assertRecord = function assertRecord(ES, recordType, argumentName, value) {
  6762. var predicate = predicates[recordType];
  6763. if (typeof predicate !== 'function') {
  6764. throw new $SyntaxError('unknown record type: ' + recordType);
  6765. }
  6766. if (!predicate(ES, value)) {
  6767. throw new $TypeError(argumentName + ' must be a ' + recordType);
  6768. }
  6769. console.log(predicate(ES, value), value);
  6770. };
  6771. var _isNaN = Number.isNaN || function isNaN(a) {
  6772. return a !== a;
  6773. };
  6774. var $isNaN = Number.isNaN || function (a) {
  6775. return a !== a;
  6776. };
  6777. var _isFinite = Number.isFinite || function (x) {
  6778. return typeof x === 'number' && !$isNaN(x) && x !== Infinity && x !== -Infinity;
  6779. };
  6780. var sign = function sign(number) {
  6781. return number >= 0 ? 1 : -1;
  6782. };
  6783. var mod = function mod(number, modulo) {
  6784. var remain = number % modulo;
  6785. return Math.floor(remain >= 0 ? remain : remain + modulo);
  6786. };
  6787. var fnToStr = Function.prototype.toString;
  6788. var constructorRegex = /^\s*class\b/;
  6789. var isES6ClassFn = function isES6ClassFunction(value) {
  6790. try {
  6791. var fnStr = fnToStr.call(value);
  6792. return constructorRegex.test(fnStr);
  6793. } catch (e) {
  6794. return false; // not a function
  6795. }
  6796. };
  6797. var tryFunctionObject = function tryFunctionToStr(value) {
  6798. try {
  6799. if (isES6ClassFn(value)) {
  6800. return false;
  6801. }
  6802. fnToStr.call(value);
  6803. return true;
  6804. } catch (e) {
  6805. return false;
  6806. }
  6807. };
  6808. var toStr$4 = Object.prototype.toString;
  6809. var fnClass = '[object Function]';
  6810. var genClass = '[object GeneratorFunction]';
  6811. var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
  6812. var isCallable = function isCallable(value) {
  6813. if (!value) {
  6814. return false;
  6815. }
  6816. if (typeof value !== 'function' && typeof value !== 'object') {
  6817. return false;
  6818. }
  6819. if (typeof value === 'function' && !value.prototype) {
  6820. return true;
  6821. }
  6822. if (hasToStringTag) {
  6823. return tryFunctionObject(value);
  6824. }
  6825. if (isES6ClassFn(value)) {
  6826. return false;
  6827. }
  6828. var strClass = toStr$4.call(value);
  6829. return strClass === fnClass || strClass === genClass;
  6830. };
  6831. var isPrimitive = function isPrimitive(value) {
  6832. return value === null || typeof value !== 'function' && typeof value !== 'object';
  6833. };
  6834. var toStr$5 = Object.prototype.toString; // http://ecma-international.org/ecma-262/5.1/#sec-8.12.8
  6835. var ES5internalSlots = {
  6836. '[[DefaultValue]]': function DefaultValue(O) {
  6837. var actualHint;
  6838. if (arguments.length > 1) {
  6839. actualHint = arguments[1];
  6840. } else {
  6841. actualHint = toStr$5.call(O) === '[object Date]' ? String : Number;
  6842. }
  6843. if (actualHint === String || actualHint === Number) {
  6844. var methods = actualHint === String ? ['toString', 'valueOf'] : ['valueOf', 'toString'];
  6845. var value, i;
  6846. for (i = 0; i < methods.length; ++i) {
  6847. if (isCallable(O[methods[i]])) {
  6848. value = O[methods[i]]();
  6849. if (isPrimitive(value)) {
  6850. return value;
  6851. }
  6852. }
  6853. }
  6854. throw new TypeError('No default value');
  6855. }
  6856. throw new TypeError('invalid [[DefaultValue]] hint supplied');
  6857. }
  6858. }; // http://ecma-international.org/ecma-262/5.1/#sec-9.1
  6859. var es5 = function ToPrimitive(input) {
  6860. if (isPrimitive(input)) {
  6861. return input;
  6862. }
  6863. if (arguments.length > 1) {
  6864. return ES5internalSlots['[[DefaultValue]]'](input, arguments[1]);
  6865. }
  6866. return ES5internalSlots['[[DefaultValue]]'](input);
  6867. };
  6868. var $Object = GetIntrinsic('%Object%');
  6869. var $TypeError$1 = GetIntrinsic('%TypeError%');
  6870. var $String = GetIntrinsic('%String%'); // https://es5.github.io/#x9
  6871. var ES5 = {
  6872. ToPrimitive: es5,
  6873. ToBoolean: function ToBoolean(value) {
  6874. return !!value;
  6875. },
  6876. ToNumber: function ToNumber(value) {
  6877. return +value; // eslint-disable-line no-implicit-coercion
  6878. },
  6879. ToInteger: function ToInteger(value) {
  6880. var number = this.ToNumber(value);
  6881. if (_isNaN(number)) {
  6882. return 0;
  6883. }
  6884. if (number === 0 || !_isFinite(number)) {
  6885. return number;
  6886. }
  6887. return sign(number) * Math.floor(Math.abs(number));
  6888. },
  6889. ToInt32: function ToInt32(x) {
  6890. return this.ToNumber(x) >> 0;
  6891. },
  6892. ToUint32: function ToUint32(x) {
  6893. return this.ToNumber(x) >>> 0;
  6894. },
  6895. ToUint16: function ToUint16(value) {
  6896. var number = this.ToNumber(value);
  6897. if (_isNaN(number) || number === 0 || !_isFinite(number)) {
  6898. return 0;
  6899. }
  6900. var posInt = sign(number) * Math.floor(Math.abs(number));
  6901. return mod(posInt, 0x10000);
  6902. },
  6903. ToString: function ToString(value) {
  6904. return $String(value);
  6905. },
  6906. ToObject: function ToObject(value) {
  6907. this.CheckObjectCoercible(value);
  6908. return $Object(value);
  6909. },
  6910. CheckObjectCoercible: function CheckObjectCoercible(value, optMessage) {
  6911. /* jshint eqnull:true */
  6912. if (value == null) {
  6913. throw new $TypeError$1(optMessage || 'Cannot call method on ' + value);
  6914. }
  6915. return value;
  6916. },
  6917. IsCallable: isCallable,
  6918. SameValue: function SameValue(x, y) {
  6919. if (x === y) {
  6920. // 0 === -0, but they are not identical.
  6921. if (x === 0) {
  6922. return 1 / x === 1 / y;
  6923. }
  6924. return true;
  6925. }
  6926. return _isNaN(x) && _isNaN(y);
  6927. },
  6928. // https://www.ecma-international.org/ecma-262/5.1/#sec-8
  6929. Type: function Type(x) {
  6930. if (x === null) {
  6931. return 'Null';
  6932. }
  6933. if (typeof x === 'undefined') {
  6934. return 'Undefined';
  6935. }
  6936. if (typeof x === 'function' || typeof x === 'object') {
  6937. return 'Object';
  6938. }
  6939. if (typeof x === 'number') {
  6940. return 'Number';
  6941. }
  6942. if (typeof x === 'boolean') {
  6943. return 'Boolean';
  6944. }
  6945. if (typeof x === 'string') {
  6946. return 'String';
  6947. }
  6948. },
  6949. // https://ecma-international.org/ecma-262/6.0/#sec-property-descriptor-specification-type
  6950. IsPropertyDescriptor: function IsPropertyDescriptor(Desc) {
  6951. if (this.Type(Desc) !== 'Object') {
  6952. return false;
  6953. }
  6954. var allowed = {
  6955. '[[Configurable]]': true,
  6956. '[[Enumerable]]': true,
  6957. '[[Get]]': true,
  6958. '[[Set]]': true,
  6959. '[[Value]]': true,
  6960. '[[Writable]]': true
  6961. };
  6962. for (var key in Desc) {
  6963. // eslint-disable-line
  6964. if (src(Desc, key) && !allowed[key]) {
  6965. return false;
  6966. }
  6967. }
  6968. var isData = src(Desc, '[[Value]]');
  6969. var IsAccessor = src(Desc, '[[Get]]') || src(Desc, '[[Set]]');
  6970. if (isData && IsAccessor) {
  6971. throw new $TypeError$1('Property Descriptors may not be both accessor and data descriptors');
  6972. }
  6973. return true;
  6974. },
  6975. // https://ecma-international.org/ecma-262/5.1/#sec-8.10.1
  6976. IsAccessorDescriptor: function IsAccessorDescriptor(Desc) {
  6977. if (typeof Desc === 'undefined') {
  6978. return false;
  6979. }
  6980. assertRecord(this, 'Property Descriptor', 'Desc', Desc);
  6981. if (!src(Desc, '[[Get]]') && !src(Desc, '[[Set]]')) {
  6982. return false;
  6983. }
  6984. return true;
  6985. },
  6986. // https://ecma-international.org/ecma-262/5.1/#sec-8.10.2
  6987. IsDataDescriptor: function IsDataDescriptor(Desc) {
  6988. if (typeof Desc === 'undefined') {
  6989. return false;
  6990. }
  6991. assertRecord(this, 'Property Descriptor', 'Desc', Desc);
  6992. if (!src(Desc, '[[Value]]') && !src(Desc, '[[Writable]]')) {
  6993. return false;
  6994. }
  6995. return true;
  6996. },
  6997. // https://ecma-international.org/ecma-262/5.1/#sec-8.10.3
  6998. IsGenericDescriptor: function IsGenericDescriptor(Desc) {
  6999. if (typeof Desc === 'undefined') {
  7000. return false;
  7001. }
  7002. assertRecord(this, 'Property Descriptor', 'Desc', Desc);
  7003. if (!this.IsAccessorDescriptor(Desc) && !this.IsDataDescriptor(Desc)) {
  7004. return true;
  7005. }
  7006. return false;
  7007. },
  7008. // https://ecma-international.org/ecma-262/5.1/#sec-8.10.4
  7009. FromPropertyDescriptor: function FromPropertyDescriptor(Desc) {
  7010. if (typeof Desc === 'undefined') {
  7011. return Desc;
  7012. }
  7013. assertRecord(this, 'Property Descriptor', 'Desc', Desc);
  7014. if (this.IsDataDescriptor(Desc)) {
  7015. return {
  7016. value: Desc['[[Value]]'],
  7017. writable: !!Desc['[[Writable]]'],
  7018. enumerable: !!Desc['[[Enumerable]]'],
  7019. configurable: !!Desc['[[Configurable]]']
  7020. };
  7021. } else if (this.IsAccessorDescriptor(Desc)) {
  7022. return {
  7023. get: Desc['[[Get]]'],
  7024. set: Desc['[[Set]]'],
  7025. enumerable: !!Desc['[[Enumerable]]'],
  7026. configurable: !!Desc['[[Configurable]]']
  7027. };
  7028. } else {
  7029. throw new $TypeError$1('FromPropertyDescriptor must be called with a fully populated Property Descriptor');
  7030. }
  7031. },
  7032. // https://ecma-international.org/ecma-262/5.1/#sec-8.10.5
  7033. ToPropertyDescriptor: function ToPropertyDescriptor(Obj) {
  7034. if (this.Type(Obj) !== 'Object') {
  7035. throw new $TypeError$1('ToPropertyDescriptor requires an object');
  7036. }
  7037. var desc = {};
  7038. if (src(Obj, 'enumerable')) {
  7039. desc['[[Enumerable]]'] = this.ToBoolean(Obj.enumerable);
  7040. }
  7041. if (src(Obj, 'configurable')) {
  7042. desc['[[Configurable]]'] = this.ToBoolean(Obj.configurable);
  7043. }
  7044. if (src(Obj, 'value')) {
  7045. desc['[[Value]]'] = Obj.value;
  7046. }
  7047. if (src(Obj, 'writable')) {
  7048. desc['[[Writable]]'] = this.ToBoolean(Obj.writable);
  7049. }
  7050. if (src(Obj, 'get')) {
  7051. var getter = Obj.get;
  7052. if (typeof getter !== 'undefined' && !this.IsCallable(getter)) {
  7053. throw new TypeError('getter must be a function');
  7054. }
  7055. desc['[[Get]]'] = getter;
  7056. }
  7057. if (src(Obj, 'set')) {
  7058. var setter = Obj.set;
  7059. if (typeof setter !== 'undefined' && !this.IsCallable(setter)) {
  7060. throw new $TypeError$1('setter must be a function');
  7061. }
  7062. desc['[[Set]]'] = setter;
  7063. }
  7064. if ((src(desc, '[[Get]]') || src(desc, '[[Set]]')) && (src(desc, '[[Value]]') || src(desc, '[[Writable]]'))) {
  7065. throw new $TypeError$1('Invalid property descriptor. Cannot both specify accessors and a value or writable attribute');
  7066. }
  7067. return desc;
  7068. }
  7069. };
  7070. var es5$1 = ES5;
  7071. var replace = functionBind.call(Function.call, String.prototype.replace);
  7072. /* eslint-disable no-control-regex */
  7073. var leftWhitespace = /^[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+/;
  7074. var rightWhitespace = /[\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF]+$/;
  7075. /* eslint-enable no-control-regex */
  7076. var implementation$2 = function trim() {
  7077. var S = es5$1.ToString(es5$1.CheckObjectCoercible(this));
  7078. return replace(replace(S, leftWhitespace, ''), rightWhitespace, '');
  7079. };
  7080. var zeroWidthSpace = "\u200B";
  7081. var polyfill = function getPolyfill() {
  7082. if (String.prototype.trim && zeroWidthSpace.trim() === zeroWidthSpace) {
  7083. return String.prototype.trim;
  7084. }
  7085. return implementation$2;
  7086. };
  7087. var shim = function shimStringTrim() {
  7088. var polyfill$1 = polyfill();
  7089. defineProperties_1(String.prototype, {
  7090. trim: polyfill$1
  7091. }, {
  7092. trim: function testTrim() {
  7093. return String.prototype.trim !== polyfill$1;
  7094. }
  7095. });
  7096. return polyfill$1;
  7097. };
  7098. var boundTrim = functionBind.call(Function.call, polyfill());
  7099. defineProperties_1(boundTrim, {
  7100. getPolyfill: polyfill,
  7101. implementation: implementation$2,
  7102. shim: shim
  7103. });
  7104. var string_prototype_trim = boundTrim;
  7105. var toStr$6 = Object.prototype.toString;
  7106. var hasOwnProperty = Object.prototype.hasOwnProperty;
  7107. var forEachArray = function forEachArray(array, iterator, receiver) {
  7108. for (var i = 0, len = array.length; i < len; i++) {
  7109. if (hasOwnProperty.call(array, i)) {
  7110. if (receiver == null) {
  7111. iterator(array[i], i, array);
  7112. } else {
  7113. iterator.call(receiver, array[i], i, array);
  7114. }
  7115. }
  7116. }
  7117. };
  7118. var forEachString = function forEachString(string, iterator, receiver) {
  7119. for (var i = 0, len = string.length; i < len; i++) {
  7120. // no such thing as a sparse string.
  7121. if (receiver == null) {
  7122. iterator(string.charAt(i), i, string);
  7123. } else {
  7124. iterator.call(receiver, string.charAt(i), i, string);
  7125. }
  7126. }
  7127. };
  7128. var forEachObject = function forEachObject(object, iterator, receiver) {
  7129. for (var k in object) {
  7130. if (hasOwnProperty.call(object, k)) {
  7131. if (receiver == null) {
  7132. iterator(object[k], k, object);
  7133. } else {
  7134. iterator.call(receiver, object[k], k, object);
  7135. }
  7136. }
  7137. }
  7138. };
  7139. var forEach = function forEach(list, iterator, thisArg) {
  7140. if (!isCallable(iterator)) {
  7141. throw new TypeError('iterator must be a function');
  7142. }
  7143. var receiver;
  7144. if (arguments.length >= 3) {
  7145. receiver = thisArg;
  7146. }
  7147. if (toStr$6.call(list) === '[object Array]') {
  7148. forEachArray(list, iterator, receiver);
  7149. } else if (typeof list === 'string') {
  7150. forEachString(list, iterator, receiver);
  7151. } else {
  7152. forEachObject(list, iterator, receiver);
  7153. }
  7154. };
  7155. var forEach_1 = forEach;
  7156. var isArray = function isArray(arg) {
  7157. return Object.prototype.toString.call(arg) === '[object Array]';
  7158. };
  7159. var parseHeaders = function parseHeaders(headers) {
  7160. if (!headers) return {};
  7161. var result = {};
  7162. forEach_1(string_prototype_trim(headers).split('\n'), function (row) {
  7163. var index = row.indexOf(':'),
  7164. key = string_prototype_trim(row.slice(0, index)).toLowerCase(),
  7165. value = string_prototype_trim(row.slice(index + 1));
  7166. if (typeof result[key] === 'undefined') {
  7167. result[key] = value;
  7168. } else if (isArray(result[key])) {
  7169. result[key].push(value);
  7170. } else {
  7171. result[key] = [result[key], value];
  7172. }
  7173. });
  7174. return result;
  7175. };
  7176. var immutable = extend;
  7177. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  7178. function extend() {
  7179. var target = {};
  7180. for (var i = 0; i < arguments.length; i++) {
  7181. var source = arguments[i];
  7182. for (var key in source) {
  7183. if (hasOwnProperty$1.call(source, key)) {
  7184. target[key] = source[key];
  7185. }
  7186. }
  7187. }
  7188. return target;
  7189. }
  7190. var xhr = createXHR;
  7191. createXHR.XMLHttpRequest = window$1.XMLHttpRequest || noop;
  7192. createXHR.XDomainRequest = "withCredentials" in new createXHR.XMLHttpRequest() ? createXHR.XMLHttpRequest : window$1.XDomainRequest;
  7193. forEachArray$1(["get", "put", "post", "patch", "head", "delete"], function (method) {
  7194. createXHR[method === "delete" ? "del" : method] = function (uri, options, callback) {
  7195. options = initParams(uri, options, callback);
  7196. options.method = method.toUpperCase();
  7197. return _createXHR(options);
  7198. };
  7199. });
  7200. function forEachArray$1(array, iterator) {
  7201. for (var i = 0; i < array.length; i++) {
  7202. iterator(array[i]);
  7203. }
  7204. }
  7205. function isEmpty(obj) {
  7206. for (var i in obj) {
  7207. if (obj.hasOwnProperty(i)) return false;
  7208. }
  7209. return true;
  7210. }
  7211. function initParams(uri, options, callback) {
  7212. var params = uri;
  7213. if (isFunction_1(options)) {
  7214. callback = options;
  7215. if (typeof uri === "string") {
  7216. params = {
  7217. uri: uri
  7218. };
  7219. }
  7220. } else {
  7221. params = immutable(options, {
  7222. uri: uri
  7223. });
  7224. }
  7225. params.callback = callback;
  7226. return params;
  7227. }
  7228. function createXHR(uri, options, callback) {
  7229. options = initParams(uri, options, callback);
  7230. return _createXHR(options);
  7231. }
  7232. function _createXHR(options) {
  7233. if (typeof options.callback === "undefined") {
  7234. throw new Error("callback argument missing");
  7235. }
  7236. var called = false;
  7237. var callback = function cbOnce(err, response, body) {
  7238. if (!called) {
  7239. called = true;
  7240. options.callback(err, response, body);
  7241. }
  7242. };
  7243. function readystatechange() {
  7244. if (xhr.readyState === 4) {
  7245. setTimeout(loadFunc, 0);
  7246. }
  7247. }
  7248. function getBody() {
  7249. // Chrome with requestType=blob throws errors arround when even testing access to responseText
  7250. var body = undefined;
  7251. if (xhr.response) {
  7252. body = xhr.response;
  7253. } else {
  7254. body = xhr.responseText || getXml(xhr);
  7255. }
  7256. if (isJson) {
  7257. try {
  7258. body = JSON.parse(body);
  7259. } catch (e) {}
  7260. }
  7261. return body;
  7262. }
  7263. function errorFunc(evt) {
  7264. clearTimeout(timeoutTimer);
  7265. if (!(evt instanceof Error)) {
  7266. evt = new Error("" + (evt || "Unknown XMLHttpRequest Error"));
  7267. }
  7268. evt.statusCode = 0;
  7269. return callback(evt, failureResponse);
  7270. } // will load the data & process the response in a special response object
  7271. function loadFunc() {
  7272. if (aborted) return;
  7273. var status;
  7274. clearTimeout(timeoutTimer);
  7275. if (options.useXDR && xhr.status === undefined) {
  7276. //IE8 CORS GET successful response doesn't have a status field, but body is fine
  7277. status = 200;
  7278. } else {
  7279. status = xhr.status === 1223 ? 204 : xhr.status;
  7280. }
  7281. var response = failureResponse;
  7282. var err = null;
  7283. if (status !== 0) {
  7284. response = {
  7285. body: getBody(),
  7286. statusCode: status,
  7287. method: method,
  7288. headers: {},
  7289. url: uri,
  7290. rawRequest: xhr
  7291. };
  7292. if (xhr.getAllResponseHeaders) {
  7293. //remember xhr can in fact be XDR for CORS in IE
  7294. response.headers = parseHeaders(xhr.getAllResponseHeaders());
  7295. }
  7296. } else {
  7297. err = new Error("Internal XMLHttpRequest Error");
  7298. }
  7299. return callback(err, response, response.body);
  7300. }
  7301. var xhr = options.xhr || null;
  7302. if (!xhr) {
  7303. if (options.cors || options.useXDR) {
  7304. xhr = new createXHR.XDomainRequest();
  7305. } else {
  7306. xhr = new createXHR.XMLHttpRequest();
  7307. }
  7308. }
  7309. var key;
  7310. var aborted;
  7311. var uri = xhr.url = options.uri || options.url;
  7312. var method = xhr.method = options.method || "GET";
  7313. var body = options.body || options.data;
  7314. var headers = xhr.headers = options.headers || {};
  7315. var sync = !!options.sync;
  7316. var isJson = false;
  7317. var timeoutTimer;
  7318. var failureResponse = {
  7319. body: undefined,
  7320. headers: {},
  7321. statusCode: 0,
  7322. method: method,
  7323. url: uri,
  7324. rawRequest: xhr
  7325. };
  7326. if ("json" in options && options.json !== false) {
  7327. isJson = true;
  7328. headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json"); //Don't override existing accept header declared by user
  7329. if (method !== "GET" && method !== "HEAD") {
  7330. headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json"); //Don't override existing accept header declared by user
  7331. body = JSON.stringify(options.json === true ? body : options.json);
  7332. }
  7333. }
  7334. xhr.onreadystatechange = readystatechange;
  7335. xhr.onload = loadFunc;
  7336. xhr.onerror = errorFunc; // IE9 must have onprogress be set to a unique function.
  7337. xhr.onprogress = function () {// IE must die
  7338. };
  7339. xhr.onabort = function () {
  7340. aborted = true;
  7341. };
  7342. xhr.ontimeout = errorFunc;
  7343. xhr.open(method, uri, !sync, options.username, options.password); //has to be after open
  7344. if (!sync) {
  7345. xhr.withCredentials = !!options.withCredentials;
  7346. } // Cannot set timeout with sync request
  7347. // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly
  7348. // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent
  7349. if (!sync && options.timeout > 0) {
  7350. timeoutTimer = setTimeout(function () {
  7351. if (aborted) return;
  7352. aborted = true; //IE9 may still call readystatechange
  7353. xhr.abort("timeout");
  7354. var e = new Error("XMLHttpRequest timeout");
  7355. e.code = "ETIMEDOUT";
  7356. errorFunc(e);
  7357. }, options.timeout);
  7358. }
  7359. if (xhr.setRequestHeader) {
  7360. for (key in headers) {
  7361. if (headers.hasOwnProperty(key)) {
  7362. xhr.setRequestHeader(key, headers[key]);
  7363. }
  7364. }
  7365. } else if (options.headers && !isEmpty(options.headers)) {
  7366. throw new Error("Headers cannot be set on an XDomainRequest object");
  7367. }
  7368. if ("responseType" in options) {
  7369. xhr.responseType = options.responseType;
  7370. }
  7371. if ("beforeSend" in options && typeof options.beforeSend === "function") {
  7372. options.beforeSend(xhr);
  7373. } // Microsoft Edge browser sends "undefined" when send is called with undefined value.
  7374. // XMLHttpRequest spec says to pass null as body to indicate no body
  7375. // See https://github.com/naugtur/xhr/issues/100.
  7376. xhr.send(body || null);
  7377. return xhr;
  7378. }
  7379. function getXml(xhr) {
  7380. if (xhr.responseType === "document") {
  7381. return xhr.responseXML;
  7382. }
  7383. var firefoxBugTakenEffect = xhr.responseXML && xhr.responseXML.documentElement.nodeName === "parsererror";
  7384. if (xhr.responseType === "" && !firefoxBugTakenEffect) {
  7385. return xhr.responseXML;
  7386. }
  7387. return null;
  7388. }
  7389. function noop() {}
  7390. /**
  7391. * Takes a webvtt file contents and parses it into cues
  7392. *
  7393. * @param {string} srcContent
  7394. * webVTT file contents
  7395. *
  7396. * @param {TextTrack} track
  7397. * TextTrack to add cues to. Cues come from the srcContent.
  7398. *
  7399. * @private
  7400. */
  7401. var parseCues = function parseCues(srcContent, track) {
  7402. var parser = new window$1.WebVTT.Parser(window$1, window$1.vttjs, window$1.WebVTT.StringDecoder());
  7403. var errors = [];
  7404. parser.oncue = function (cue) {
  7405. track.addCue(cue);
  7406. };
  7407. parser.onparsingerror = function (error) {
  7408. errors.push(error);
  7409. };
  7410. parser.onflush = function () {
  7411. track.trigger({
  7412. type: 'loadeddata',
  7413. target: track
  7414. });
  7415. };
  7416. parser.parse(srcContent);
  7417. if (errors.length > 0) {
  7418. if (window$1.console && window$1.console.groupCollapsed) {
  7419. window$1.console.groupCollapsed("Text Track parsing errors for " + track.src);
  7420. }
  7421. errors.forEach(function (error) {
  7422. return log.error(error);
  7423. });
  7424. if (window$1.console && window$1.console.groupEnd) {
  7425. window$1.console.groupEnd();
  7426. }
  7427. }
  7428. parser.flush();
  7429. };
  7430. /**
  7431. * Load a `TextTrack` from a specified url.
  7432. *
  7433. * @param {string} src
  7434. * Url to load track from.
  7435. *
  7436. * @param {TextTrack} track
  7437. * Track to add cues to. Comes from the content at the end of `url`.
  7438. *
  7439. * @private
  7440. */
  7441. var loadTrack = function loadTrack(src, track) {
  7442. var opts = {
  7443. uri: src
  7444. };
  7445. var crossOrigin = isCrossOrigin(src);
  7446. if (crossOrigin) {
  7447. opts.cors = crossOrigin;
  7448. }
  7449. xhr(opts, bind(this, function (err, response, responseBody) {
  7450. if (err) {
  7451. return log.error(err, response);
  7452. }
  7453. track.loaded_ = true; // Make sure that vttjs has loaded, otherwise, wait till it finished loading
  7454. // NOTE: this is only used for the alt/video.novtt.js build
  7455. if (typeof window$1.WebVTT !== 'function') {
  7456. if (track.tech_) {
  7457. // to prevent use before define eslint error, we define loadHandler
  7458. // as a let here
  7459. track.tech_.any(['vttjsloaded', 'vttjserror'], function (event) {
  7460. if (event.type === 'vttjserror') {
  7461. log.error("vttjs failed to load, stopping trying to process " + track.src);
  7462. return;
  7463. }
  7464. return parseCues(responseBody, track);
  7465. });
  7466. }
  7467. } else {
  7468. parseCues(responseBody, track);
  7469. }
  7470. }));
  7471. };
  7472. /**
  7473. * A representation of a single `TextTrack`.
  7474. *
  7475. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#texttrack}
  7476. * @extends Track
  7477. */
  7478. var TextTrack =
  7479. /*#__PURE__*/
  7480. function (_Track) {
  7481. _inheritsLoose(TextTrack, _Track);
  7482. /**
  7483. * Create an instance of this class.
  7484. *
  7485. * @param {Object} options={}
  7486. * Object of option names and values
  7487. *
  7488. * @param {Tech} options.tech
  7489. * A reference to the tech that owns this TextTrack.
  7490. *
  7491. * @param {TextTrack~Kind} [options.kind='subtitles']
  7492. * A valid text track kind.
  7493. *
  7494. * @param {TextTrack~Mode} [options.mode='disabled']
  7495. * A valid text track mode.
  7496. *
  7497. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7498. * A unique id for this TextTrack.
  7499. *
  7500. * @param {string} [options.label='']
  7501. * The menu label for this track.
  7502. *
  7503. * @param {string} [options.language='']
  7504. * A valid two character language code.
  7505. *
  7506. * @param {string} [options.srclang='']
  7507. * A valid two character language code. An alternative, but deprioritized
  7508. * version of `options.language`
  7509. *
  7510. * @param {string} [options.src]
  7511. * A url to TextTrack cues.
  7512. *
  7513. * @param {boolean} [options.default]
  7514. * If this track should default to on or off.
  7515. */
  7516. function TextTrack(options) {
  7517. var _this;
  7518. if (options === void 0) {
  7519. options = {};
  7520. }
  7521. if (!options.tech) {
  7522. throw new Error('A tech was not provided.');
  7523. }
  7524. var settings = mergeOptions(options, {
  7525. kind: TextTrackKind[options.kind] || 'subtitles',
  7526. language: options.language || options.srclang || ''
  7527. });
  7528. var mode = TextTrackMode[settings.mode] || 'disabled';
  7529. var default_ = settings["default"];
  7530. if (settings.kind === 'metadata' || settings.kind === 'chapters') {
  7531. mode = 'hidden';
  7532. }
  7533. _this = _Track.call(this, settings) || this;
  7534. _this.tech_ = settings.tech;
  7535. _this.cues_ = [];
  7536. _this.activeCues_ = [];
  7537. var cues = new TextTrackCueList(_this.cues_);
  7538. var activeCues = new TextTrackCueList(_this.activeCues_);
  7539. var changed = false;
  7540. var timeupdateHandler = bind(_assertThisInitialized(_this), function () {
  7541. // Accessing this.activeCues for the side-effects of updating itself
  7542. // due to its nature as a getter function. Do not remove or cues will
  7543. // stop updating!
  7544. // Use the setter to prevent deletion from uglify (pure_getters rule)
  7545. this.activeCues = this.activeCues;
  7546. if (changed) {
  7547. this.trigger('cuechange');
  7548. changed = false;
  7549. }
  7550. });
  7551. if (mode !== 'disabled') {
  7552. _this.tech_.ready(function () {
  7553. _this.tech_.on('timeupdate', timeupdateHandler);
  7554. }, true);
  7555. }
  7556. Object.defineProperties(_assertThisInitialized(_this), {
  7557. /**
  7558. * @memberof TextTrack
  7559. * @member {boolean} default
  7560. * If this track was set to be on or off by default. Cannot be changed after
  7561. * creation.
  7562. * @instance
  7563. *
  7564. * @readonly
  7565. */
  7566. "default": {
  7567. get: function get() {
  7568. return default_;
  7569. },
  7570. set: function set() {}
  7571. },
  7572. /**
  7573. * @memberof TextTrack
  7574. * @member {string} mode
  7575. * Set the mode of this TextTrack to a valid {@link TextTrack~Mode}. Will
  7576. * not be set if setting to an invalid mode.
  7577. * @instance
  7578. *
  7579. * @fires TextTrack#modechange
  7580. */
  7581. mode: {
  7582. get: function get() {
  7583. return mode;
  7584. },
  7585. set: function set(newMode) {
  7586. var _this2 = this;
  7587. if (!TextTrackMode[newMode]) {
  7588. return;
  7589. }
  7590. mode = newMode;
  7591. if (mode !== 'disabled') {
  7592. this.tech_.ready(function () {
  7593. _this2.tech_.on('timeupdate', timeupdateHandler);
  7594. }, true);
  7595. } else {
  7596. this.tech_.off('timeupdate', timeupdateHandler);
  7597. }
  7598. /**
  7599. * An event that fires when mode changes on this track. This allows
  7600. * the TextTrackList that holds this track to act accordingly.
  7601. *
  7602. * > Note: This is not part of the spec!
  7603. *
  7604. * @event TextTrack#modechange
  7605. * @type {EventTarget~Event}
  7606. */
  7607. this.trigger('modechange');
  7608. }
  7609. },
  7610. /**
  7611. * @memberof TextTrack
  7612. * @member {TextTrackCueList} cues
  7613. * The text track cue list for this TextTrack.
  7614. * @instance
  7615. */
  7616. cues: {
  7617. get: function get() {
  7618. if (!this.loaded_) {
  7619. return null;
  7620. }
  7621. return cues;
  7622. },
  7623. set: function set() {}
  7624. },
  7625. /**
  7626. * @memberof TextTrack
  7627. * @member {TextTrackCueList} activeCues
  7628. * The list text track cues that are currently active for this TextTrack.
  7629. * @instance
  7630. */
  7631. activeCues: {
  7632. get: function get() {
  7633. if (!this.loaded_) {
  7634. return null;
  7635. } // nothing to do
  7636. if (this.cues.length === 0) {
  7637. return activeCues;
  7638. }
  7639. var ct = this.tech_.currentTime();
  7640. var active = [];
  7641. for (var i = 0, l = this.cues.length; i < l; i++) {
  7642. var cue = this.cues[i];
  7643. if (cue.startTime <= ct && cue.endTime >= ct) {
  7644. active.push(cue);
  7645. } else if (cue.startTime === cue.endTime && cue.startTime <= ct && cue.startTime + 0.5 >= ct) {
  7646. active.push(cue);
  7647. }
  7648. }
  7649. changed = false;
  7650. if (active.length !== this.activeCues_.length) {
  7651. changed = true;
  7652. } else {
  7653. for (var _i = 0; _i < active.length; _i++) {
  7654. if (this.activeCues_.indexOf(active[_i]) === -1) {
  7655. changed = true;
  7656. }
  7657. }
  7658. }
  7659. this.activeCues_ = active;
  7660. activeCues.setCues_(this.activeCues_);
  7661. return activeCues;
  7662. },
  7663. // /!\ Keep this setter empty (see the timeupdate handler above)
  7664. set: function set() {}
  7665. }
  7666. });
  7667. if (settings.src) {
  7668. _this.src = settings.src;
  7669. loadTrack(settings.src, _assertThisInitialized(_this));
  7670. } else {
  7671. _this.loaded_ = true;
  7672. }
  7673. return _this;
  7674. }
  7675. /**
  7676. * Add a cue to the internal list of cues.
  7677. *
  7678. * @param {TextTrack~Cue} cue
  7679. * The cue to add to our internal list
  7680. */
  7681. var _proto = TextTrack.prototype;
  7682. _proto.addCue = function addCue(originalCue) {
  7683. var cue = originalCue;
  7684. if (window$1.vttjs && !(originalCue instanceof window$1.vttjs.VTTCue)) {
  7685. cue = new window$1.vttjs.VTTCue(originalCue.startTime, originalCue.endTime, originalCue.text);
  7686. for (var prop in originalCue) {
  7687. if (!(prop in cue)) {
  7688. cue[prop] = originalCue[prop];
  7689. }
  7690. } // make sure that `id` is copied over
  7691. cue.id = originalCue.id;
  7692. cue.originalCue_ = originalCue;
  7693. }
  7694. var tracks = this.tech_.textTracks();
  7695. for (var i = 0; i < tracks.length; i++) {
  7696. if (tracks[i] !== this) {
  7697. tracks[i].removeCue(cue);
  7698. }
  7699. }
  7700. this.cues_.push(cue);
  7701. this.cues.setCues_(this.cues_);
  7702. }
  7703. /**
  7704. * Remove a cue from our internal list
  7705. *
  7706. * @param {TextTrack~Cue} removeCue
  7707. * The cue to remove from our internal list
  7708. */
  7709. ;
  7710. _proto.removeCue = function removeCue(_removeCue) {
  7711. var i = this.cues_.length;
  7712. while (i--) {
  7713. var cue = this.cues_[i];
  7714. if (cue === _removeCue || cue.originalCue_ && cue.originalCue_ === _removeCue) {
  7715. this.cues_.splice(i, 1);
  7716. this.cues.setCues_(this.cues_);
  7717. break;
  7718. }
  7719. }
  7720. };
  7721. return TextTrack;
  7722. }(Track);
  7723. /**
  7724. * cuechange - One or more cues in the track have become active or stopped being active.
  7725. */
  7726. TextTrack.prototype.allowedEvents_ = {
  7727. cuechange: 'cuechange'
  7728. };
  7729. /**
  7730. * A representation of a single `AudioTrack`. If it is part of an {@link AudioTrackList}
  7731. * only one `AudioTrack` in the list will be enabled at a time.
  7732. *
  7733. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotrack}
  7734. * @extends Track
  7735. */
  7736. var AudioTrack =
  7737. /*#__PURE__*/
  7738. function (_Track) {
  7739. _inheritsLoose(AudioTrack, _Track);
  7740. /**
  7741. * Create an instance of this class.
  7742. *
  7743. * @param {Object} [options={}]
  7744. * Object of option names and values
  7745. *
  7746. * @param {AudioTrack~Kind} [options.kind='']
  7747. * A valid audio track kind
  7748. *
  7749. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7750. * A unique id for this AudioTrack.
  7751. *
  7752. * @param {string} [options.label='']
  7753. * The menu label for this track.
  7754. *
  7755. * @param {string} [options.language='']
  7756. * A valid two character language code.
  7757. *
  7758. * @param {boolean} [options.enabled]
  7759. * If this track is the one that is currently playing. If this track is part of
  7760. * an {@link AudioTrackList}, only one {@link AudioTrack} will be enabled.
  7761. */
  7762. function AudioTrack(options) {
  7763. var _this;
  7764. if (options === void 0) {
  7765. options = {};
  7766. }
  7767. var settings = mergeOptions(options, {
  7768. kind: AudioTrackKind[options.kind] || ''
  7769. });
  7770. _this = _Track.call(this, settings) || this;
  7771. var enabled = false;
  7772. /**
  7773. * @memberof AudioTrack
  7774. * @member {boolean} enabled
  7775. * If this `AudioTrack` is enabled or not. When setting this will
  7776. * fire {@link AudioTrack#enabledchange} if the state of enabled is changed.
  7777. * @instance
  7778. *
  7779. * @fires VideoTrack#selectedchange
  7780. */
  7781. Object.defineProperty(_assertThisInitialized(_this), 'enabled', {
  7782. get: function get() {
  7783. return enabled;
  7784. },
  7785. set: function set(newEnabled) {
  7786. // an invalid or unchanged value
  7787. if (typeof newEnabled !== 'boolean' || newEnabled === enabled) {
  7788. return;
  7789. }
  7790. enabled = newEnabled;
  7791. /**
  7792. * An event that fires when enabled changes on this track. This allows
  7793. * the AudioTrackList that holds this track to act accordingly.
  7794. *
  7795. * > Note: This is not part of the spec! Native tracks will do
  7796. * this internally without an event.
  7797. *
  7798. * @event AudioTrack#enabledchange
  7799. * @type {EventTarget~Event}
  7800. */
  7801. this.trigger('enabledchange');
  7802. }
  7803. }); // if the user sets this track to selected then
  7804. // set selected to that true value otherwise
  7805. // we keep it false
  7806. if (settings.enabled) {
  7807. _this.enabled = settings.enabled;
  7808. }
  7809. _this.loaded_ = true;
  7810. return _this;
  7811. }
  7812. return AudioTrack;
  7813. }(Track);
  7814. /**
  7815. * A representation of a single `VideoTrack`.
  7816. *
  7817. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotrack}
  7818. * @extends Track
  7819. */
  7820. var VideoTrack =
  7821. /*#__PURE__*/
  7822. function (_Track) {
  7823. _inheritsLoose(VideoTrack, _Track);
  7824. /**
  7825. * Create an instance of this class.
  7826. *
  7827. * @param {Object} [options={}]
  7828. * Object of option names and values
  7829. *
  7830. * @param {string} [options.kind='']
  7831. * A valid {@link VideoTrack~Kind}
  7832. *
  7833. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7834. * A unique id for this AudioTrack.
  7835. *
  7836. * @param {string} [options.label='']
  7837. * The menu label for this track.
  7838. *
  7839. * @param {string} [options.language='']
  7840. * A valid two character language code.
  7841. *
  7842. * @param {boolean} [options.selected]
  7843. * If this track is the one that is currently playing.
  7844. */
  7845. function VideoTrack(options) {
  7846. var _this;
  7847. if (options === void 0) {
  7848. options = {};
  7849. }
  7850. var settings = mergeOptions(options, {
  7851. kind: VideoTrackKind[options.kind] || ''
  7852. });
  7853. _this = _Track.call(this, settings) || this;
  7854. var selected = false;
  7855. /**
  7856. * @memberof VideoTrack
  7857. * @member {boolean} selected
  7858. * If this `VideoTrack` is selected or not. When setting this will
  7859. * fire {@link VideoTrack#selectedchange} if the state of selected changed.
  7860. * @instance
  7861. *
  7862. * @fires VideoTrack#selectedchange
  7863. */
  7864. Object.defineProperty(_assertThisInitialized(_this), 'selected', {
  7865. get: function get() {
  7866. return selected;
  7867. },
  7868. set: function set(newSelected) {
  7869. // an invalid or unchanged value
  7870. if (typeof newSelected !== 'boolean' || newSelected === selected) {
  7871. return;
  7872. }
  7873. selected = newSelected;
  7874. /**
  7875. * An event that fires when selected changes on this track. This allows
  7876. * the VideoTrackList that holds this track to act accordingly.
  7877. *
  7878. * > Note: This is not part of the spec! Native tracks will do
  7879. * this internally without an event.
  7880. *
  7881. * @event VideoTrack#selectedchange
  7882. * @type {EventTarget~Event}
  7883. */
  7884. this.trigger('selectedchange');
  7885. }
  7886. }); // if the user sets this track to selected then
  7887. // set selected to that true value otherwise
  7888. // we keep it false
  7889. if (settings.selected) {
  7890. _this.selected = settings.selected;
  7891. }
  7892. return _this;
  7893. }
  7894. return VideoTrack;
  7895. }(Track);
  7896. /**
  7897. * @memberof HTMLTrackElement
  7898. * @typedef {HTMLTrackElement~ReadyState}
  7899. * @enum {number}
  7900. */
  7901. var NONE = 0;
  7902. var LOADING = 1;
  7903. var LOADED = 2;
  7904. var ERROR = 3;
  7905. /**
  7906. * A single track represented in the DOM.
  7907. *
  7908. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#htmltrackelement}
  7909. * @extends EventTarget
  7910. */
  7911. var HTMLTrackElement =
  7912. /*#__PURE__*/
  7913. function (_EventTarget) {
  7914. _inheritsLoose(HTMLTrackElement, _EventTarget);
  7915. /**
  7916. * Create an instance of this class.
  7917. *
  7918. * @param {Object} options={}
  7919. * Object of option names and values
  7920. *
  7921. * @param {Tech} options.tech
  7922. * A reference to the tech that owns this HTMLTrackElement.
  7923. *
  7924. * @param {TextTrack~Kind} [options.kind='subtitles']
  7925. * A valid text track kind.
  7926. *
  7927. * @param {TextTrack~Mode} [options.mode='disabled']
  7928. * A valid text track mode.
  7929. *
  7930. * @param {string} [options.id='vjs_track_' + Guid.newGUID()]
  7931. * A unique id for this TextTrack.
  7932. *
  7933. * @param {string} [options.label='']
  7934. * The menu label for this track.
  7935. *
  7936. * @param {string} [options.language='']
  7937. * A valid two character language code.
  7938. *
  7939. * @param {string} [options.srclang='']
  7940. * A valid two character language code. An alternative, but deprioritized
  7941. * vesion of `options.language`
  7942. *
  7943. * @param {string} [options.src]
  7944. * A url to TextTrack cues.
  7945. *
  7946. * @param {boolean} [options.default]
  7947. * If this track should default to on or off.
  7948. */
  7949. function HTMLTrackElement(options) {
  7950. var _this;
  7951. if (options === void 0) {
  7952. options = {};
  7953. }
  7954. _this = _EventTarget.call(this) || this;
  7955. var readyState;
  7956. var track = new TextTrack(options);
  7957. _this.kind = track.kind;
  7958. _this.src = track.src;
  7959. _this.srclang = track.language;
  7960. _this.label = track.label;
  7961. _this["default"] = track["default"];
  7962. Object.defineProperties(_assertThisInitialized(_this), {
  7963. /**
  7964. * @memberof HTMLTrackElement
  7965. * @member {HTMLTrackElement~ReadyState} readyState
  7966. * The current ready state of the track element.
  7967. * @instance
  7968. */
  7969. readyState: {
  7970. get: function get() {
  7971. return readyState;
  7972. }
  7973. },
  7974. /**
  7975. * @memberof HTMLTrackElement
  7976. * @member {TextTrack} track
  7977. * The underlying TextTrack object.
  7978. * @instance
  7979. *
  7980. */
  7981. track: {
  7982. get: function get() {
  7983. return track;
  7984. }
  7985. }
  7986. });
  7987. readyState = NONE;
  7988. /**
  7989. * @listens TextTrack#loadeddata
  7990. * @fires HTMLTrackElement#load
  7991. */
  7992. track.addEventListener('loadeddata', function () {
  7993. readyState = LOADED;
  7994. _this.trigger({
  7995. type: 'load',
  7996. target: _assertThisInitialized(_this)
  7997. });
  7998. });
  7999. return _this;
  8000. }
  8001. return HTMLTrackElement;
  8002. }(EventTarget);
  8003. HTMLTrackElement.prototype.allowedEvents_ = {
  8004. load: 'load'
  8005. };
  8006. HTMLTrackElement.NONE = NONE;
  8007. HTMLTrackElement.LOADING = LOADING;
  8008. HTMLTrackElement.LOADED = LOADED;
  8009. HTMLTrackElement.ERROR = ERROR;
  8010. /*
  8011. * This file contains all track properties that are used in
  8012. * player.js, tech.js, html5.js and possibly other techs in the future.
  8013. */
  8014. var NORMAL = {
  8015. audio: {
  8016. ListClass: AudioTrackList,
  8017. TrackClass: AudioTrack,
  8018. capitalName: 'Audio'
  8019. },
  8020. video: {
  8021. ListClass: VideoTrackList,
  8022. TrackClass: VideoTrack,
  8023. capitalName: 'Video'
  8024. },
  8025. text: {
  8026. ListClass: TextTrackList,
  8027. TrackClass: TextTrack,
  8028. capitalName: 'Text'
  8029. }
  8030. };
  8031. Object.keys(NORMAL).forEach(function (type) {
  8032. NORMAL[type].getterName = type + "Tracks";
  8033. NORMAL[type].privateName = type + "Tracks_";
  8034. });
  8035. var REMOTE = {
  8036. remoteText: {
  8037. ListClass: TextTrackList,
  8038. TrackClass: TextTrack,
  8039. capitalName: 'RemoteText',
  8040. getterName: 'remoteTextTracks',
  8041. privateName: 'remoteTextTracks_'
  8042. },
  8043. remoteTextEl: {
  8044. ListClass: HtmlTrackElementList,
  8045. TrackClass: HTMLTrackElement,
  8046. capitalName: 'RemoteTextTrackEls',
  8047. getterName: 'remoteTextTrackEls',
  8048. privateName: 'remoteTextTrackEls_'
  8049. }
  8050. };
  8051. var ALL = mergeOptions(NORMAL, REMOTE);
  8052. REMOTE.names = Object.keys(REMOTE);
  8053. NORMAL.names = Object.keys(NORMAL);
  8054. ALL.names = [].concat(REMOTE.names).concat(NORMAL.names);
  8055. var vtt = {};
  8056. /**
  8057. * An Object containing a structure like: `{src: 'url', type: 'mimetype'}` or string
  8058. * that just contains the src url alone.
  8059. * * `var SourceObject = {src: 'http://ex.com/video.mp4', type: 'video/mp4'};`
  8060. * `var SourceString = 'http://example.com/some-video.mp4';`
  8061. *
  8062. * @typedef {Object|string} Tech~SourceObject
  8063. *
  8064. * @property {string} src
  8065. * The url to the source
  8066. *
  8067. * @property {string} type
  8068. * The mime type of the source
  8069. */
  8070. /**
  8071. * A function used by {@link Tech} to create a new {@link TextTrack}.
  8072. *
  8073. * @private
  8074. *
  8075. * @param {Tech} self
  8076. * An instance of the Tech class.
  8077. *
  8078. * @param {string} kind
  8079. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  8080. *
  8081. * @param {string} [label]
  8082. * Label to identify the text track
  8083. *
  8084. * @param {string} [language]
  8085. * Two letter language abbreviation
  8086. *
  8087. * @param {Object} [options={}]
  8088. * An object with additional text track options
  8089. *
  8090. * @return {TextTrack}
  8091. * The text track that was created.
  8092. */
  8093. function createTrackHelper(self, kind, label, language, options) {
  8094. if (options === void 0) {
  8095. options = {};
  8096. }
  8097. var tracks = self.textTracks();
  8098. options.kind = kind;
  8099. if (label) {
  8100. options.label = label;
  8101. }
  8102. if (language) {
  8103. options.language = language;
  8104. }
  8105. options.tech = self;
  8106. var track = new ALL.text.TrackClass(options);
  8107. tracks.addTrack(track);
  8108. return track;
  8109. }
  8110. /**
  8111. * This is the base class for media playback technology controllers, such as
  8112. * {@link Flash} and {@link HTML5}
  8113. *
  8114. * @extends Component
  8115. */
  8116. var Tech =
  8117. /*#__PURE__*/
  8118. function (_Component) {
  8119. _inheritsLoose(Tech, _Component);
  8120. /**
  8121. * Create an instance of this Tech.
  8122. *
  8123. * @param {Object} [options]
  8124. * The key/value store of player options.
  8125. *
  8126. * @param {Component~ReadyCallback} ready
  8127. * Callback function to call when the `HTML5` Tech is ready.
  8128. */
  8129. function Tech(options, ready) {
  8130. var _this;
  8131. if (options === void 0) {
  8132. options = {};
  8133. }
  8134. if (ready === void 0) {
  8135. ready = function ready() {};
  8136. }
  8137. // we don't want the tech to report user activity automatically.
  8138. // This is done manually in addControlsListeners
  8139. options.reportTouchActivity = false;
  8140. _this = _Component.call(this, null, options, ready) || this; // keep track of whether the current source has played at all to
  8141. // implement a very limited played()
  8142. _this.hasStarted_ = false;
  8143. _this.on('playing', function () {
  8144. this.hasStarted_ = true;
  8145. });
  8146. _this.on('loadstart', function () {
  8147. this.hasStarted_ = false;
  8148. });
  8149. ALL.names.forEach(function (name) {
  8150. var props = ALL[name];
  8151. if (options && options[props.getterName]) {
  8152. _this[props.privateName] = options[props.getterName];
  8153. }
  8154. }); // Manually track progress in cases where the browser/flash player doesn't report it.
  8155. if (!_this.featuresProgressEvents) {
  8156. _this.manualProgressOn();
  8157. } // Manually track timeupdates in cases where the browser/flash player doesn't report it.
  8158. if (!_this.featuresTimeupdateEvents) {
  8159. _this.manualTimeUpdatesOn();
  8160. }
  8161. ['Text', 'Audio', 'Video'].forEach(function (track) {
  8162. if (options["native" + track + "Tracks"] === false) {
  8163. _this["featuresNative" + track + "Tracks"] = false;
  8164. }
  8165. });
  8166. if (options.nativeCaptions === false || options.nativeTextTracks === false) {
  8167. _this.featuresNativeTextTracks = false;
  8168. } else if (options.nativeCaptions === true || options.nativeTextTracks === true) {
  8169. _this.featuresNativeTextTracks = true;
  8170. }
  8171. if (!_this.featuresNativeTextTracks) {
  8172. _this.emulateTextTracks();
  8173. }
  8174. _this.autoRemoteTextTracks_ = new ALL.text.ListClass();
  8175. _this.initTrackListeners(); // Turn on component tap events only if not using native controls
  8176. if (!options.nativeControlsForTouch) {
  8177. _this.emitTapEvents();
  8178. }
  8179. if (_this.constructor) {
  8180. _this.name_ = _this.constructor.name || 'Unknown Tech';
  8181. }
  8182. return _this;
  8183. }
  8184. /**
  8185. * A special function to trigger source set in a way that will allow player
  8186. * to re-trigger if the player or tech are not ready yet.
  8187. *
  8188. * @fires Tech#sourceset
  8189. * @param {string} src The source string at the time of the source changing.
  8190. */
  8191. var _proto = Tech.prototype;
  8192. _proto.triggerSourceset = function triggerSourceset(src) {
  8193. var _this2 = this;
  8194. if (!this.isReady_) {
  8195. // on initial ready we have to trigger source set
  8196. // 1ms after ready so that player can watch for it.
  8197. this.one('ready', function () {
  8198. return _this2.setTimeout(function () {
  8199. return _this2.triggerSourceset(src);
  8200. }, 1);
  8201. });
  8202. }
  8203. /**
  8204. * Fired when the source is set on the tech causing the media element
  8205. * to reload.
  8206. *
  8207. * @see {@link Player#event:sourceset}
  8208. * @event Tech#sourceset
  8209. * @type {EventTarget~Event}
  8210. */
  8211. this.trigger({
  8212. src: src,
  8213. type: 'sourceset'
  8214. });
  8215. }
  8216. /* Fallbacks for unsupported event types
  8217. ================================================================================ */
  8218. /**
  8219. * Polyfill the `progress` event for browsers that don't support it natively.
  8220. *
  8221. * @see {@link Tech#trackProgress}
  8222. */
  8223. ;
  8224. _proto.manualProgressOn = function manualProgressOn() {
  8225. this.on('durationchange', this.onDurationChange);
  8226. this.manualProgress = true; // Trigger progress watching when a source begins loading
  8227. this.one('ready', this.trackProgress);
  8228. }
  8229. /**
  8230. * Turn off the polyfill for `progress` events that was created in
  8231. * {@link Tech#manualProgressOn}
  8232. */
  8233. ;
  8234. _proto.manualProgressOff = function manualProgressOff() {
  8235. this.manualProgress = false;
  8236. this.stopTrackingProgress();
  8237. this.off('durationchange', this.onDurationChange);
  8238. }
  8239. /**
  8240. * This is used to trigger a `progress` event when the buffered percent changes. It
  8241. * sets an interval function that will be called every 500 milliseconds to check if the
  8242. * buffer end percent has changed.
  8243. *
  8244. * > This function is called by {@link Tech#manualProgressOn}
  8245. *
  8246. * @param {EventTarget~Event} event
  8247. * The `ready` event that caused this to run.
  8248. *
  8249. * @listens Tech#ready
  8250. * @fires Tech#progress
  8251. */
  8252. ;
  8253. _proto.trackProgress = function trackProgress(event) {
  8254. this.stopTrackingProgress();
  8255. this.progressInterval = this.setInterval(bind(this, function () {
  8256. // Don't trigger unless buffered amount is greater than last time
  8257. var numBufferedPercent = this.bufferedPercent();
  8258. if (this.bufferedPercent_ !== numBufferedPercent) {
  8259. /**
  8260. * See {@link Player#progress}
  8261. *
  8262. * @event Tech#progress
  8263. * @type {EventTarget~Event}
  8264. */
  8265. this.trigger('progress');
  8266. }
  8267. this.bufferedPercent_ = numBufferedPercent;
  8268. if (numBufferedPercent === 1) {
  8269. this.stopTrackingProgress();
  8270. }
  8271. }), 500);
  8272. }
  8273. /**
  8274. * Update our internal duration on a `durationchange` event by calling
  8275. * {@link Tech#duration}.
  8276. *
  8277. * @param {EventTarget~Event} event
  8278. * The `durationchange` event that caused this to run.
  8279. *
  8280. * @listens Tech#durationchange
  8281. */
  8282. ;
  8283. _proto.onDurationChange = function onDurationChange(event) {
  8284. this.duration_ = this.duration();
  8285. }
  8286. /**
  8287. * Get and create a `TimeRange` object for buffering.
  8288. *
  8289. * @return {TimeRange}
  8290. * The time range object that was created.
  8291. */
  8292. ;
  8293. _proto.buffered = function buffered() {
  8294. return createTimeRanges(0, 0);
  8295. }
  8296. /**
  8297. * Get the percentage of the current video that is currently buffered.
  8298. *
  8299. * @return {number}
  8300. * A number from 0 to 1 that represents the decimal percentage of the
  8301. * video that is buffered.
  8302. *
  8303. */
  8304. ;
  8305. _proto.bufferedPercent = function bufferedPercent$1() {
  8306. return bufferedPercent(this.buffered(), this.duration_);
  8307. }
  8308. /**
  8309. * Turn off the polyfill for `progress` events that was created in
  8310. * {@link Tech#manualProgressOn}
  8311. * Stop manually tracking progress events by clearing the interval that was set in
  8312. * {@link Tech#trackProgress}.
  8313. */
  8314. ;
  8315. _proto.stopTrackingProgress = function stopTrackingProgress() {
  8316. this.clearInterval(this.progressInterval);
  8317. }
  8318. /**
  8319. * Polyfill the `timeupdate` event for browsers that don't support it.
  8320. *
  8321. * @see {@link Tech#trackCurrentTime}
  8322. */
  8323. ;
  8324. _proto.manualTimeUpdatesOn = function manualTimeUpdatesOn() {
  8325. this.manualTimeUpdates = true;
  8326. this.on('play', this.trackCurrentTime);
  8327. this.on('pause', this.stopTrackingCurrentTime);
  8328. }
  8329. /**
  8330. * Turn off the polyfill for `timeupdate` events that was created in
  8331. * {@link Tech#manualTimeUpdatesOn}
  8332. */
  8333. ;
  8334. _proto.manualTimeUpdatesOff = function manualTimeUpdatesOff() {
  8335. this.manualTimeUpdates = false;
  8336. this.stopTrackingCurrentTime();
  8337. this.off('play', this.trackCurrentTime);
  8338. this.off('pause', this.stopTrackingCurrentTime);
  8339. }
  8340. /**
  8341. * Sets up an interval function to track current time and trigger `timeupdate` every
  8342. * 250 milliseconds.
  8343. *
  8344. * @listens Tech#play
  8345. * @triggers Tech#timeupdate
  8346. */
  8347. ;
  8348. _proto.trackCurrentTime = function trackCurrentTime() {
  8349. if (this.currentTimeInterval) {
  8350. this.stopTrackingCurrentTime();
  8351. }
  8352. this.currentTimeInterval = this.setInterval(function () {
  8353. /**
  8354. * Triggered at an interval of 250ms to indicated that time is passing in the video.
  8355. *
  8356. * @event Tech#timeupdate
  8357. * @type {EventTarget~Event}
  8358. */
  8359. this.trigger({
  8360. type: 'timeupdate',
  8361. target: this,
  8362. manuallyTriggered: true
  8363. }); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
  8364. }, 250);
  8365. }
  8366. /**
  8367. * Stop the interval function created in {@link Tech#trackCurrentTime} so that the
  8368. * `timeupdate` event is no longer triggered.
  8369. *
  8370. * @listens {Tech#pause}
  8371. */
  8372. ;
  8373. _proto.stopTrackingCurrentTime = function stopTrackingCurrentTime() {
  8374. this.clearInterval(this.currentTimeInterval); // #1002 - if the video ends right before the next timeupdate would happen,
  8375. // the progress bar won't make it all the way to the end
  8376. this.trigger({
  8377. type: 'timeupdate',
  8378. target: this,
  8379. manuallyTriggered: true
  8380. });
  8381. }
  8382. /**
  8383. * Turn off all event polyfills, clear the `Tech`s {@link AudioTrackList},
  8384. * {@link VideoTrackList}, and {@link TextTrackList}, and dispose of this Tech.
  8385. *
  8386. * @fires Component#dispose
  8387. */
  8388. ;
  8389. _proto.dispose = function dispose() {
  8390. // clear out all tracks because we can't reuse them between techs
  8391. this.clearTracks(NORMAL.names); // Turn off any manual progress or timeupdate tracking
  8392. if (this.manualProgress) {
  8393. this.manualProgressOff();
  8394. }
  8395. if (this.manualTimeUpdates) {
  8396. this.manualTimeUpdatesOff();
  8397. }
  8398. _Component.prototype.dispose.call(this);
  8399. }
  8400. /**
  8401. * Clear out a single `TrackList` or an array of `TrackLists` given their names.
  8402. *
  8403. * > Note: Techs without source handlers should call this between sources for `video`
  8404. * & `audio` tracks. You don't want to use them between tracks!
  8405. *
  8406. * @param {string[]|string} types
  8407. * TrackList names to clear, valid names are `video`, `audio`, and
  8408. * `text`.
  8409. */
  8410. ;
  8411. _proto.clearTracks = function clearTracks(types) {
  8412. var _this3 = this;
  8413. types = [].concat(types); // clear out all tracks because we can't reuse them between techs
  8414. types.forEach(function (type) {
  8415. var list = _this3[type + "Tracks"]() || [];
  8416. var i = list.length;
  8417. while (i--) {
  8418. var track = list[i];
  8419. if (type === 'text') {
  8420. _this3.removeRemoteTextTrack(track);
  8421. }
  8422. list.removeTrack(track);
  8423. }
  8424. });
  8425. }
  8426. /**
  8427. * Remove any TextTracks added via addRemoteTextTrack that are
  8428. * flagged for automatic garbage collection
  8429. */
  8430. ;
  8431. _proto.cleanupAutoTextTracks = function cleanupAutoTextTracks() {
  8432. var list = this.autoRemoteTextTracks_ || [];
  8433. var i = list.length;
  8434. while (i--) {
  8435. var track = list[i];
  8436. this.removeRemoteTextTrack(track);
  8437. }
  8438. }
  8439. /**
  8440. * Reset the tech, which will removes all sources and reset the internal readyState.
  8441. *
  8442. * @abstract
  8443. */
  8444. ;
  8445. _proto.reset = function reset() {}
  8446. /**
  8447. * Get or set an error on the Tech.
  8448. *
  8449. * @param {MediaError} [err]
  8450. * Error to set on the Tech
  8451. *
  8452. * @return {MediaError|null}
  8453. * The current error object on the tech, or null if there isn't one.
  8454. */
  8455. ;
  8456. _proto.error = function error(err) {
  8457. if (err !== undefined) {
  8458. this.error_ = new MediaError(err);
  8459. this.trigger('error');
  8460. }
  8461. return this.error_;
  8462. }
  8463. /**
  8464. * Returns the `TimeRange`s that have been played through for the current source.
  8465. *
  8466. * > NOTE: This implementation is incomplete. It does not track the played `TimeRange`.
  8467. * It only checks whether the source has played at all or not.
  8468. *
  8469. * @return {TimeRange}
  8470. * - A single time range if this video has played
  8471. * - An empty set of ranges if not.
  8472. */
  8473. ;
  8474. _proto.played = function played() {
  8475. if (this.hasStarted_) {
  8476. return createTimeRanges(0, 0);
  8477. }
  8478. return createTimeRanges();
  8479. }
  8480. /**
  8481. * Causes a manual time update to occur if {@link Tech#manualTimeUpdatesOn} was
  8482. * previously called.
  8483. *
  8484. * @fires Tech#timeupdate
  8485. */
  8486. ;
  8487. _proto.setCurrentTime = function setCurrentTime() {
  8488. // improve the accuracy of manual timeupdates
  8489. if (this.manualTimeUpdates) {
  8490. /**
  8491. * A manual `timeupdate` event.
  8492. *
  8493. * @event Tech#timeupdate
  8494. * @type {EventTarget~Event}
  8495. */
  8496. this.trigger({
  8497. type: 'timeupdate',
  8498. target: this,
  8499. manuallyTriggered: true
  8500. });
  8501. }
  8502. }
  8503. /**
  8504. * Turn on listeners for {@link VideoTrackList}, {@link {AudioTrackList}, and
  8505. * {@link TextTrackList} events.
  8506. *
  8507. * This adds {@link EventTarget~EventListeners} for `addtrack`, and `removetrack`.
  8508. *
  8509. * @fires Tech#audiotrackchange
  8510. * @fires Tech#videotrackchange
  8511. * @fires Tech#texttrackchange
  8512. */
  8513. ;
  8514. _proto.initTrackListeners = function initTrackListeners() {
  8515. var _this4 = this;
  8516. /**
  8517. * Triggered when tracks are added or removed on the Tech {@link AudioTrackList}
  8518. *
  8519. * @event Tech#audiotrackchange
  8520. * @type {EventTarget~Event}
  8521. */
  8522. /**
  8523. * Triggered when tracks are added or removed on the Tech {@link VideoTrackList}
  8524. *
  8525. * @event Tech#videotrackchange
  8526. * @type {EventTarget~Event}
  8527. */
  8528. /**
  8529. * Triggered when tracks are added or removed on the Tech {@link TextTrackList}
  8530. *
  8531. * @event Tech#texttrackchange
  8532. * @type {EventTarget~Event}
  8533. */
  8534. NORMAL.names.forEach(function (name) {
  8535. var props = NORMAL[name];
  8536. var trackListChanges = function trackListChanges() {
  8537. _this4.trigger(name + "trackchange");
  8538. };
  8539. var tracks = _this4[props.getterName]();
  8540. tracks.addEventListener('removetrack', trackListChanges);
  8541. tracks.addEventListener('addtrack', trackListChanges);
  8542. _this4.on('dispose', function () {
  8543. tracks.removeEventListener('removetrack', trackListChanges);
  8544. tracks.removeEventListener('addtrack', trackListChanges);
  8545. });
  8546. });
  8547. }
  8548. /**
  8549. * Emulate TextTracks using vtt.js if necessary
  8550. *
  8551. * @fires Tech#vttjsloaded
  8552. * @fires Tech#vttjserror
  8553. */
  8554. ;
  8555. _proto.addWebVttScript_ = function addWebVttScript_() {
  8556. var _this5 = this;
  8557. if (window$1.WebVTT) {
  8558. return;
  8559. } // Initially, Tech.el_ is a child of a dummy-div wait until the Component system
  8560. // signals that the Tech is ready at which point Tech.el_ is part of the DOM
  8561. // before inserting the WebVTT script
  8562. if (document.body.contains(this.el())) {
  8563. // load via require if available and vtt.js script location was not passed in
  8564. // as an option. novtt builds will turn the above require call into an empty object
  8565. // which will cause this if check to always fail.
  8566. if (!this.options_['vtt.js'] && isPlain(vtt) && Object.keys(vtt).length > 0) {
  8567. this.trigger('vttjsloaded');
  8568. return;
  8569. } // load vtt.js via the script location option or the cdn of no location was
  8570. // passed in
  8571. var script = document.createElement('script');
  8572. script.src = this.options_['vtt.js'] || 'https://vjs.zencdn.net/vttjs/0.14.1/vtt.min.js';
  8573. script.onload = function () {
  8574. /**
  8575. * Fired when vtt.js is loaded.
  8576. *
  8577. * @event Tech#vttjsloaded
  8578. * @type {EventTarget~Event}
  8579. */
  8580. _this5.trigger('vttjsloaded');
  8581. };
  8582. script.onerror = function () {
  8583. /**
  8584. * Fired when vtt.js was not loaded due to an error
  8585. *
  8586. * @event Tech#vttjsloaded
  8587. * @type {EventTarget~Event}
  8588. */
  8589. _this5.trigger('vttjserror');
  8590. };
  8591. this.on('dispose', function () {
  8592. script.onload = null;
  8593. script.onerror = null;
  8594. }); // but have not loaded yet and we set it to true before the inject so that
  8595. // we don't overwrite the injected window.WebVTT if it loads right away
  8596. window$1.WebVTT = true;
  8597. this.el().parentNode.appendChild(script);
  8598. } else {
  8599. this.ready(this.addWebVttScript_);
  8600. }
  8601. }
  8602. /**
  8603. * Emulate texttracks
  8604. *
  8605. */
  8606. ;
  8607. _proto.emulateTextTracks = function emulateTextTracks() {
  8608. var _this6 = this;
  8609. var tracks = this.textTracks();
  8610. var remoteTracks = this.remoteTextTracks();
  8611. var handleAddTrack = function handleAddTrack(e) {
  8612. return tracks.addTrack(e.track);
  8613. };
  8614. var handleRemoveTrack = function handleRemoveTrack(e) {
  8615. return tracks.removeTrack(e.track);
  8616. };
  8617. remoteTracks.on('addtrack', handleAddTrack);
  8618. remoteTracks.on('removetrack', handleRemoveTrack);
  8619. this.addWebVttScript_();
  8620. var updateDisplay = function updateDisplay() {
  8621. return _this6.trigger('texttrackchange');
  8622. };
  8623. var textTracksChanges = function textTracksChanges() {
  8624. updateDisplay();
  8625. for (var i = 0; i < tracks.length; i++) {
  8626. var track = tracks[i];
  8627. track.removeEventListener('cuechange', updateDisplay);
  8628. if (track.mode === 'showing') {
  8629. track.addEventListener('cuechange', updateDisplay);
  8630. }
  8631. }
  8632. };
  8633. textTracksChanges();
  8634. tracks.addEventListener('change', textTracksChanges);
  8635. tracks.addEventListener('addtrack', textTracksChanges);
  8636. tracks.addEventListener('removetrack', textTracksChanges);
  8637. this.on('dispose', function () {
  8638. remoteTracks.off('addtrack', handleAddTrack);
  8639. remoteTracks.off('removetrack', handleRemoveTrack);
  8640. tracks.removeEventListener('change', textTracksChanges);
  8641. tracks.removeEventListener('addtrack', textTracksChanges);
  8642. tracks.removeEventListener('removetrack', textTracksChanges);
  8643. for (var i = 0; i < tracks.length; i++) {
  8644. var track = tracks[i];
  8645. track.removeEventListener('cuechange', updateDisplay);
  8646. }
  8647. });
  8648. }
  8649. /**
  8650. * Create and returns a remote {@link TextTrack} object.
  8651. *
  8652. * @param {string} kind
  8653. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  8654. *
  8655. * @param {string} [label]
  8656. * Label to identify the text track
  8657. *
  8658. * @param {string} [language]
  8659. * Two letter language abbreviation
  8660. *
  8661. * @return {TextTrack}
  8662. * The TextTrack that gets created.
  8663. */
  8664. ;
  8665. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  8666. if (!kind) {
  8667. throw new Error('TextTrack kind is required but was not provided');
  8668. }
  8669. return createTrackHelper(this, kind, label, language);
  8670. }
  8671. /**
  8672. * Create an emulated TextTrack for use by addRemoteTextTrack
  8673. *
  8674. * This is intended to be overridden by classes that inherit from
  8675. * Tech in order to create native or custom TextTracks.
  8676. *
  8677. * @param {Object} options
  8678. * The object should contain the options to initialize the TextTrack with.
  8679. *
  8680. * @param {string} [options.kind]
  8681. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  8682. *
  8683. * @param {string} [options.label].
  8684. * Label to identify the text track
  8685. *
  8686. * @param {string} [options.language]
  8687. * Two letter language abbreviation.
  8688. *
  8689. * @return {HTMLTrackElement}
  8690. * The track element that gets created.
  8691. */
  8692. ;
  8693. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  8694. var track = mergeOptions(options, {
  8695. tech: this
  8696. });
  8697. return new REMOTE.remoteTextEl.TrackClass(track);
  8698. }
  8699. /**
  8700. * Creates a remote text track object and returns an html track element.
  8701. *
  8702. * > Note: This can be an emulated {@link HTMLTrackElement} or a native one.
  8703. *
  8704. * @param {Object} options
  8705. * See {@link Tech#createRemoteTextTrack} for more detailed properties.
  8706. *
  8707. * @param {boolean} [manualCleanup=true]
  8708. * - When false: the TextTrack will be automatically removed from the video
  8709. * element whenever the source changes
  8710. * - When True: The TextTrack will have to be cleaned up manually
  8711. *
  8712. * @return {HTMLTrackElement}
  8713. * An Html Track Element.
  8714. *
  8715. * @deprecated The default functionality for this function will be equivalent
  8716. * to "manualCleanup=false" in the future. The manualCleanup parameter will
  8717. * also be removed.
  8718. */
  8719. ;
  8720. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  8721. var _this7 = this;
  8722. if (options === void 0) {
  8723. options = {};
  8724. }
  8725. var htmlTrackElement = this.createRemoteTextTrack(options);
  8726. if (manualCleanup !== true && manualCleanup !== false) {
  8727. // deprecation warning
  8728. log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js');
  8729. manualCleanup = true;
  8730. } // store HTMLTrackElement and TextTrack to remote list
  8731. this.remoteTextTrackEls().addTrackElement_(htmlTrackElement);
  8732. this.remoteTextTracks().addTrack(htmlTrackElement.track);
  8733. if (manualCleanup !== true) {
  8734. // create the TextTrackList if it doesn't exist
  8735. this.ready(function () {
  8736. return _this7.autoRemoteTextTracks_.addTrack(htmlTrackElement.track);
  8737. });
  8738. }
  8739. return htmlTrackElement;
  8740. }
  8741. /**
  8742. * Remove a remote text track from the remote `TextTrackList`.
  8743. *
  8744. * @param {TextTrack} track
  8745. * `TextTrack` to remove from the `TextTrackList`
  8746. */
  8747. ;
  8748. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  8749. var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track); // remove HTMLTrackElement and TextTrack from remote list
  8750. this.remoteTextTrackEls().removeTrackElement_(trackElement);
  8751. this.remoteTextTracks().removeTrack(track);
  8752. this.autoRemoteTextTracks_.removeTrack(track);
  8753. }
  8754. /**
  8755. * Gets available media playback quality metrics as specified by the W3C's Media
  8756. * Playback Quality API.
  8757. *
  8758. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  8759. *
  8760. * @return {Object}
  8761. * An object with supported media playback quality metrics
  8762. *
  8763. * @abstract
  8764. */
  8765. ;
  8766. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  8767. return {};
  8768. }
  8769. /**
  8770. * Attempt to create a floating video window always on top of other windows
  8771. * so that users may continue consuming media while they interact with other
  8772. * content sites, or applications on their device.
  8773. *
  8774. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  8775. *
  8776. * @return {Promise|undefined}
  8777. * A promise with a Picture-in-Picture window if the browser supports
  8778. * Promises (or one was passed in as an option). It returns undefined
  8779. * otherwise.
  8780. *
  8781. * @abstract
  8782. */
  8783. ;
  8784. _proto.requestPictureInPicture = function requestPictureInPicture() {
  8785. var PromiseClass = this.options_.Promise || window$1.Promise;
  8786. if (PromiseClass) {
  8787. return PromiseClass.reject();
  8788. }
  8789. }
  8790. /**
  8791. * A method to set a poster from a `Tech`.
  8792. *
  8793. * @abstract
  8794. */
  8795. ;
  8796. _proto.setPoster = function setPoster() {}
  8797. /**
  8798. * A method to check for the presence of the 'playsinline' <video> attribute.
  8799. *
  8800. * @abstract
  8801. */
  8802. ;
  8803. _proto.playsinline = function playsinline() {}
  8804. /**
  8805. * A method to set or unset the 'playsinline' <video> attribute.
  8806. *
  8807. * @abstract
  8808. */
  8809. ;
  8810. _proto.setPlaysinline = function setPlaysinline() {}
  8811. /**
  8812. * Attempt to force override of native audio tracks.
  8813. *
  8814. * @param {boolean} override - If set to true native audio will be overridden,
  8815. * otherwise native audio will potentially be used.
  8816. *
  8817. * @abstract
  8818. */
  8819. ;
  8820. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks() {}
  8821. /**
  8822. * Attempt to force override of native video tracks.
  8823. *
  8824. * @param {boolean} override - If set to true native video will be overridden,
  8825. * otherwise native video will potentially be used.
  8826. *
  8827. * @abstract
  8828. */
  8829. ;
  8830. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks() {}
  8831. /*
  8832. * Check if the tech can support the given mime-type.
  8833. *
  8834. * The base tech does not support any type, but source handlers might
  8835. * overwrite this.
  8836. *
  8837. * @param {string} type
  8838. * The mimetype to check for support
  8839. *
  8840. * @return {string}
  8841. * 'probably', 'maybe', or empty string
  8842. *
  8843. * @see [Spec]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType}
  8844. *
  8845. * @abstract
  8846. */
  8847. ;
  8848. _proto.canPlayType = function canPlayType() {
  8849. return '';
  8850. }
  8851. /**
  8852. * Check if the type is supported by this tech.
  8853. *
  8854. * The base tech does not support any type, but source handlers might
  8855. * overwrite this.
  8856. *
  8857. * @param {string} type
  8858. * The media type to check
  8859. * @return {string} Returns the native video element's response
  8860. */
  8861. ;
  8862. Tech.canPlayType = function canPlayType() {
  8863. return '';
  8864. }
  8865. /**
  8866. * Check if the tech can support the given source
  8867. *
  8868. * @param {Object} srcObj
  8869. * The source object
  8870. * @param {Object} options
  8871. * The options passed to the tech
  8872. * @return {string} 'probably', 'maybe', or '' (empty string)
  8873. */
  8874. ;
  8875. Tech.canPlaySource = function canPlaySource(srcObj, options) {
  8876. return Tech.canPlayType(srcObj.type);
  8877. }
  8878. /*
  8879. * Return whether the argument is a Tech or not.
  8880. * Can be passed either a Class like `Html5` or a instance like `player.tech_`
  8881. *
  8882. * @param {Object} component
  8883. * The item to check
  8884. *
  8885. * @return {boolean}
  8886. * Whether it is a tech or not
  8887. * - True if it is a tech
  8888. * - False if it is not
  8889. */
  8890. ;
  8891. Tech.isTech = function isTech(component) {
  8892. return component.prototype instanceof Tech || component instanceof Tech || component === Tech;
  8893. }
  8894. /**
  8895. * Registers a `Tech` into a shared list for videojs.
  8896. *
  8897. * @param {string} name
  8898. * Name of the `Tech` to register.
  8899. *
  8900. * @param {Object} tech
  8901. * The `Tech` class to register.
  8902. */
  8903. ;
  8904. Tech.registerTech = function registerTech(name, tech) {
  8905. if (!Tech.techs_) {
  8906. Tech.techs_ = {};
  8907. }
  8908. if (!Tech.isTech(tech)) {
  8909. throw new Error("Tech " + name + " must be a Tech");
  8910. }
  8911. if (!Tech.canPlayType) {
  8912. throw new Error('Techs must have a static canPlayType method on them');
  8913. }
  8914. if (!Tech.canPlaySource) {
  8915. throw new Error('Techs must have a static canPlaySource method on them');
  8916. }
  8917. name = toTitleCase(name);
  8918. Tech.techs_[name] = tech;
  8919. Tech.techs_[toLowerCase(name)] = tech;
  8920. if (name !== 'Tech') {
  8921. // camel case the techName for use in techOrder
  8922. Tech.defaultTechOrder_.push(name);
  8923. }
  8924. return tech;
  8925. }
  8926. /**
  8927. * Get a `Tech` from the shared list by name.
  8928. *
  8929. * @param {string} name
  8930. * `camelCase` or `TitleCase` name of the Tech to get
  8931. *
  8932. * @return {Tech|undefined}
  8933. * The `Tech` or undefined if there was no tech with the name requested.
  8934. */
  8935. ;
  8936. Tech.getTech = function getTech(name) {
  8937. if (!name) {
  8938. return;
  8939. }
  8940. if (Tech.techs_ && Tech.techs_[name]) {
  8941. return Tech.techs_[name];
  8942. }
  8943. name = toTitleCase(name);
  8944. if (window$1 && window$1.videojs && window$1.videojs[name]) {
  8945. log.warn("The " + name + " tech was added to the videojs object when it should be registered using videojs.registerTech(name, tech)");
  8946. return window$1.videojs[name];
  8947. }
  8948. };
  8949. return Tech;
  8950. }(Component);
  8951. /**
  8952. * Get the {@link VideoTrackList}
  8953. *
  8954. * @returns {VideoTrackList}
  8955. * @method Tech.prototype.videoTracks
  8956. */
  8957. /**
  8958. * Get the {@link AudioTrackList}
  8959. *
  8960. * @returns {AudioTrackList}
  8961. * @method Tech.prototype.audioTracks
  8962. */
  8963. /**
  8964. * Get the {@link TextTrackList}
  8965. *
  8966. * @returns {TextTrackList}
  8967. * @method Tech.prototype.textTracks
  8968. */
  8969. /**
  8970. * Get the remote element {@link TextTrackList}
  8971. *
  8972. * @returns {TextTrackList}
  8973. * @method Tech.prototype.remoteTextTracks
  8974. */
  8975. /**
  8976. * Get the remote element {@link HtmlTrackElementList}
  8977. *
  8978. * @returns {HtmlTrackElementList}
  8979. * @method Tech.prototype.remoteTextTrackEls
  8980. */
  8981. ALL.names.forEach(function (name) {
  8982. var props = ALL[name];
  8983. Tech.prototype[props.getterName] = function () {
  8984. this[props.privateName] = this[props.privateName] || new props.ListClass();
  8985. return this[props.privateName];
  8986. };
  8987. });
  8988. /**
  8989. * List of associated text tracks
  8990. *
  8991. * @type {TextTrackList}
  8992. * @private
  8993. * @property Tech#textTracks_
  8994. */
  8995. /**
  8996. * List of associated audio tracks.
  8997. *
  8998. * @type {AudioTrackList}
  8999. * @private
  9000. * @property Tech#audioTracks_
  9001. */
  9002. /**
  9003. * List of associated video tracks.
  9004. *
  9005. * @type {VideoTrackList}
  9006. * @private
  9007. * @property Tech#videoTracks_
  9008. */
  9009. /**
  9010. * Boolean indicating whether the `Tech` supports volume control.
  9011. *
  9012. * @type {boolean}
  9013. * @default
  9014. */
  9015. Tech.prototype.featuresVolumeControl = true;
  9016. /**
  9017. * Boolean indicating whether the `Tech` supports muting volume.
  9018. *
  9019. * @type {bolean}
  9020. * @default
  9021. */
  9022. Tech.prototype.featuresMuteControl = true;
  9023. /**
  9024. * Boolean indicating whether the `Tech` supports fullscreen resize control.
  9025. * Resizing plugins using request fullscreen reloads the plugin
  9026. *
  9027. * @type {boolean}
  9028. * @default
  9029. */
  9030. Tech.prototype.featuresFullscreenResize = false;
  9031. /**
  9032. * Boolean indicating whether the `Tech` supports changing the speed at which the video
  9033. * plays. Examples:
  9034. * - Set player to play 2x (twice) as fast
  9035. * - Set player to play 0.5x (half) as fast
  9036. *
  9037. * @type {boolean}
  9038. * @default
  9039. */
  9040. Tech.prototype.featuresPlaybackRate = false;
  9041. /**
  9042. * Boolean indicating whether the `Tech` supports the `progress` event. This is currently
  9043. * not triggered by video-js-swf. This will be used to determine if
  9044. * {@link Tech#manualProgressOn} should be called.
  9045. *
  9046. * @type {boolean}
  9047. * @default
  9048. */
  9049. Tech.prototype.featuresProgressEvents = false;
  9050. /**
  9051. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  9052. *
  9053. * A tech should set this to `true` and then use {@link Tech#triggerSourceset}
  9054. * to trigger a {@link Tech#event:sourceset} at the earliest time after getting
  9055. * a new source.
  9056. *
  9057. * @type {boolean}
  9058. * @default
  9059. */
  9060. Tech.prototype.featuresSourceset = false;
  9061. /**
  9062. * Boolean indicating whether the `Tech` supports the `timeupdate` event. This is currently
  9063. * not triggered by video-js-swf. This will be used to determine if
  9064. * {@link Tech#manualTimeUpdates} should be called.
  9065. *
  9066. * @type {boolean}
  9067. * @default
  9068. */
  9069. Tech.prototype.featuresTimeupdateEvents = false;
  9070. /**
  9071. * Boolean indicating whether the `Tech` supports the native `TextTrack`s.
  9072. * This will help us integrate with native `TextTrack`s if the browser supports them.
  9073. *
  9074. * @type {boolean}
  9075. * @default
  9076. */
  9077. Tech.prototype.featuresNativeTextTracks = false;
  9078. /**
  9079. * A functional mixin for techs that want to use the Source Handler pattern.
  9080. * Source handlers are scripts for handling specific formats.
  9081. * The source handler pattern is used for adaptive formats (HLS, DASH) that
  9082. * manually load video data and feed it into a Source Buffer (Media Source Extensions)
  9083. * Example: `Tech.withSourceHandlers.call(MyTech);`
  9084. *
  9085. * @param {Tech} _Tech
  9086. * The tech to add source handler functions to.
  9087. *
  9088. * @mixes Tech~SourceHandlerAdditions
  9089. */
  9090. Tech.withSourceHandlers = function (_Tech) {
  9091. /**
  9092. * Register a source handler
  9093. *
  9094. * @param {Function} handler
  9095. * The source handler class
  9096. *
  9097. * @param {number} [index]
  9098. * Register it at the following index
  9099. */
  9100. _Tech.registerSourceHandler = function (handler, index) {
  9101. var handlers = _Tech.sourceHandlers;
  9102. if (!handlers) {
  9103. handlers = _Tech.sourceHandlers = [];
  9104. }
  9105. if (index === undefined) {
  9106. // add to the end of the list
  9107. index = handlers.length;
  9108. }
  9109. handlers.splice(index, 0, handler);
  9110. };
  9111. /**
  9112. * Check if the tech can support the given type. Also checks the
  9113. * Techs sourceHandlers.
  9114. *
  9115. * @param {string} type
  9116. * The mimetype to check.
  9117. *
  9118. * @return {string}
  9119. * 'probably', 'maybe', or '' (empty string)
  9120. */
  9121. _Tech.canPlayType = function (type) {
  9122. var handlers = _Tech.sourceHandlers || [];
  9123. var can;
  9124. for (var i = 0; i < handlers.length; i++) {
  9125. can = handlers[i].canPlayType(type);
  9126. if (can) {
  9127. return can;
  9128. }
  9129. }
  9130. return '';
  9131. };
  9132. /**
  9133. * Returns the first source handler that supports the source.
  9134. *
  9135. * TODO: Answer question: should 'probably' be prioritized over 'maybe'
  9136. *
  9137. * @param {Tech~SourceObject} source
  9138. * The source object
  9139. *
  9140. * @param {Object} options
  9141. * The options passed to the tech
  9142. *
  9143. * @return {SourceHandler|null}
  9144. * The first source handler that supports the source or null if
  9145. * no SourceHandler supports the source
  9146. */
  9147. _Tech.selectSourceHandler = function (source, options) {
  9148. var handlers = _Tech.sourceHandlers || [];
  9149. var can;
  9150. for (var i = 0; i < handlers.length; i++) {
  9151. can = handlers[i].canHandleSource(source, options);
  9152. if (can) {
  9153. return handlers[i];
  9154. }
  9155. }
  9156. return null;
  9157. };
  9158. /**
  9159. * Check if the tech can support the given source.
  9160. *
  9161. * @param {Tech~SourceObject} srcObj
  9162. * The source object
  9163. *
  9164. * @param {Object} options
  9165. * The options passed to the tech
  9166. *
  9167. * @return {string}
  9168. * 'probably', 'maybe', or '' (empty string)
  9169. */
  9170. _Tech.canPlaySource = function (srcObj, options) {
  9171. var sh = _Tech.selectSourceHandler(srcObj, options);
  9172. if (sh) {
  9173. return sh.canHandleSource(srcObj, options);
  9174. }
  9175. return '';
  9176. };
  9177. /**
  9178. * When using a source handler, prefer its implementation of
  9179. * any function normally provided by the tech.
  9180. */
  9181. var deferrable = ['seekable', 'seeking', 'duration'];
  9182. /**
  9183. * A wrapper around {@link Tech#seekable} that will call a `SourceHandler`s seekable
  9184. * function if it exists, with a fallback to the Techs seekable function.
  9185. *
  9186. * @method _Tech.seekable
  9187. */
  9188. /**
  9189. * A wrapper around {@link Tech#duration} that will call a `SourceHandler`s duration
  9190. * function if it exists, otherwise it will fallback to the techs duration function.
  9191. *
  9192. * @method _Tech.duration
  9193. */
  9194. deferrable.forEach(function (fnName) {
  9195. var originalFn = this[fnName];
  9196. if (typeof originalFn !== 'function') {
  9197. return;
  9198. }
  9199. this[fnName] = function () {
  9200. if (this.sourceHandler_ && this.sourceHandler_[fnName]) {
  9201. return this.sourceHandler_[fnName].apply(this.sourceHandler_, arguments);
  9202. }
  9203. return originalFn.apply(this, arguments);
  9204. };
  9205. }, _Tech.prototype);
  9206. /**
  9207. * Create a function for setting the source using a source object
  9208. * and source handlers.
  9209. * Should never be called unless a source handler was found.
  9210. *
  9211. * @param {Tech~SourceObject} source
  9212. * A source object with src and type keys
  9213. */
  9214. _Tech.prototype.setSource = function (source) {
  9215. var sh = _Tech.selectSourceHandler(source, this.options_);
  9216. if (!sh) {
  9217. // Fall back to a native source hander when unsupported sources are
  9218. // deliberately set
  9219. if (_Tech.nativeSourceHandler) {
  9220. sh = _Tech.nativeSourceHandler;
  9221. } else {
  9222. log.error('No source handler found for the current source.');
  9223. }
  9224. } // Dispose any existing source handler
  9225. this.disposeSourceHandler();
  9226. this.off('dispose', this.disposeSourceHandler);
  9227. if (sh !== _Tech.nativeSourceHandler) {
  9228. this.currentSource_ = source;
  9229. }
  9230. this.sourceHandler_ = sh.handleSource(source, this, this.options_);
  9231. this.one('dispose', this.disposeSourceHandler);
  9232. };
  9233. /**
  9234. * Clean up any existing SourceHandlers and listeners when the Tech is disposed.
  9235. *
  9236. * @listens Tech#dispose
  9237. */
  9238. _Tech.prototype.disposeSourceHandler = function () {
  9239. // if we have a source and get another one
  9240. // then we are loading something new
  9241. // than clear all of our current tracks
  9242. if (this.currentSource_) {
  9243. this.clearTracks(['audio', 'video']);
  9244. this.currentSource_ = null;
  9245. } // always clean up auto-text tracks
  9246. this.cleanupAutoTextTracks();
  9247. if (this.sourceHandler_) {
  9248. if (this.sourceHandler_.dispose) {
  9249. this.sourceHandler_.dispose();
  9250. }
  9251. this.sourceHandler_ = null;
  9252. }
  9253. };
  9254. }; // The base Tech class needs to be registered as a Component. It is the only
  9255. // Tech that can be registered as a Component.
  9256. Component.registerComponent('Tech', Tech);
  9257. Tech.registerTech('Tech', Tech);
  9258. /**
  9259. * A list of techs that should be added to techOrder on Players
  9260. *
  9261. * @private
  9262. */
  9263. Tech.defaultTechOrder_ = [];
  9264. /**
  9265. * @file middleware.js
  9266. * @module middleware
  9267. */
  9268. var middlewares = {};
  9269. var middlewareInstances = {};
  9270. var TERMINATOR = {};
  9271. /**
  9272. * A middleware object is a plain JavaScript object that has methods that
  9273. * match the {@link Tech} methods found in the lists of allowed
  9274. * {@link module:middleware.allowedGetters|getters},
  9275. * {@link module:middleware.allowedSetters|setters}, and
  9276. * {@link module:middleware.allowedMediators|mediators}.
  9277. *
  9278. * @typedef {Object} MiddlewareObject
  9279. */
  9280. /**
  9281. * A middleware factory function that should return a
  9282. * {@link module:middleware~MiddlewareObject|MiddlewareObject}.
  9283. *
  9284. * This factory will be called for each player when needed, with the player
  9285. * passed in as an argument.
  9286. *
  9287. * @callback MiddlewareFactory
  9288. * @param {Player} player
  9289. * A Video.js player.
  9290. */
  9291. /**
  9292. * Define a middleware that the player should use by way of a factory function
  9293. * that returns a middleware object.
  9294. *
  9295. * @param {string} type
  9296. * The MIME type to match or `"*"` for all MIME types.
  9297. *
  9298. * @param {MiddlewareFactory} middleware
  9299. * A middleware factory function that will be executed for
  9300. * matching types.
  9301. */
  9302. function use(type, middleware) {
  9303. middlewares[type] = middlewares[type] || [];
  9304. middlewares[type].push(middleware);
  9305. }
  9306. /**
  9307. * Asynchronously sets a source using middleware by recursing through any
  9308. * matching middlewares and calling `setSource` on each, passing along the
  9309. * previous returned value each time.
  9310. *
  9311. * @param {Player} player
  9312. * A {@link Player} instance.
  9313. *
  9314. * @param {Tech~SourceObject} src
  9315. * A source object.
  9316. *
  9317. * @param {Function}
  9318. * The next middleware to run.
  9319. */
  9320. function setSource(player, src, next) {
  9321. player.setTimeout(function () {
  9322. return setSourceHelper(src, middlewares[src.type], next, player);
  9323. }, 1);
  9324. }
  9325. /**
  9326. * When the tech is set, passes the tech to each middleware's `setTech` method.
  9327. *
  9328. * @param {Object[]} middleware
  9329. * An array of middleware instances.
  9330. *
  9331. * @param {Tech} tech
  9332. * A Video.js tech.
  9333. */
  9334. function setTech(middleware, tech) {
  9335. middleware.forEach(function (mw) {
  9336. return mw.setTech && mw.setTech(tech);
  9337. });
  9338. }
  9339. /**
  9340. * Calls a getter on the tech first, through each middleware
  9341. * from right to left to the player.
  9342. *
  9343. * @param {Object[]} middleware
  9344. * An array of middleware instances.
  9345. *
  9346. * @param {Tech} tech
  9347. * The current tech.
  9348. *
  9349. * @param {string} method
  9350. * A method name.
  9351. *
  9352. * @return {Mixed}
  9353. * The final value from the tech after middleware has intercepted it.
  9354. */
  9355. function get(middleware, tech, method) {
  9356. return middleware.reduceRight(middlewareIterator(method), tech[method]());
  9357. }
  9358. /**
  9359. * Takes the argument given to the player and calls the setter method on each
  9360. * middleware from left to right to the tech.
  9361. *
  9362. * @param {Object[]} middleware
  9363. * An array of middleware instances.
  9364. *
  9365. * @param {Tech} tech
  9366. * The current tech.
  9367. *
  9368. * @param {string} method
  9369. * A method name.
  9370. *
  9371. * @param {Mixed} arg
  9372. * The value to set on the tech.
  9373. *
  9374. * @return {Mixed}
  9375. * The return value of the `method` of the `tech`.
  9376. */
  9377. function set(middleware, tech, method, arg) {
  9378. return tech[method](middleware.reduce(middlewareIterator(method), arg));
  9379. }
  9380. /**
  9381. * Takes the argument given to the player and calls the `call` version of the
  9382. * method on each middleware from left to right.
  9383. *
  9384. * Then, call the passed in method on the tech and return the result unchanged
  9385. * back to the player, through middleware, this time from right to left.
  9386. *
  9387. * @param {Object[]} middleware
  9388. * An array of middleware instances.
  9389. *
  9390. * @param {Tech} tech
  9391. * The current tech.
  9392. *
  9393. * @param {string} method
  9394. * A method name.
  9395. *
  9396. * @param {Mixed} arg
  9397. * The value to set on the tech.
  9398. *
  9399. * @return {Mixed}
  9400. * The return value of the `method` of the `tech`, regardless of the
  9401. * return values of middlewares.
  9402. */
  9403. function mediate(middleware, tech, method, arg) {
  9404. if (arg === void 0) {
  9405. arg = null;
  9406. }
  9407. var callMethod = 'call' + toTitleCase(method);
  9408. var middlewareValue = middleware.reduce(middlewareIterator(callMethod), arg);
  9409. var terminated = middlewareValue === TERMINATOR; // deprecated. The `null` return value should instead return TERMINATOR to
  9410. // prevent confusion if a techs method actually returns null.
  9411. var returnValue = terminated ? null : tech[method](middlewareValue);
  9412. executeRight(middleware, method, returnValue, terminated);
  9413. return returnValue;
  9414. }
  9415. /**
  9416. * Enumeration of allowed getters where the keys are method names.
  9417. *
  9418. * @type {Object}
  9419. */
  9420. var allowedGetters = {
  9421. buffered: 1,
  9422. currentTime: 1,
  9423. duration: 1,
  9424. seekable: 1,
  9425. played: 1,
  9426. paused: 1,
  9427. volume: 1
  9428. };
  9429. /**
  9430. * Enumeration of allowed setters where the keys are method names.
  9431. *
  9432. * @type {Object}
  9433. */
  9434. var allowedSetters = {
  9435. setCurrentTime: 1,
  9436. setVolume: 1
  9437. };
  9438. /**
  9439. * Enumeration of allowed mediators where the keys are method names.
  9440. *
  9441. * @type {Object}
  9442. */
  9443. var allowedMediators = {
  9444. play: 1,
  9445. pause: 1
  9446. };
  9447. function middlewareIterator(method) {
  9448. return function (value, mw) {
  9449. // if the previous middleware terminated, pass along the termination
  9450. if (value === TERMINATOR) {
  9451. return TERMINATOR;
  9452. }
  9453. if (mw[method]) {
  9454. return mw[method](value);
  9455. }
  9456. return value;
  9457. };
  9458. }
  9459. function executeRight(mws, method, value, terminated) {
  9460. for (var i = mws.length - 1; i >= 0; i--) {
  9461. var mw = mws[i];
  9462. if (mw[method]) {
  9463. mw[method](terminated, value);
  9464. }
  9465. }
  9466. }
  9467. /**
  9468. * Clear the middleware cache for a player.
  9469. *
  9470. * @param {Player} player
  9471. * A {@link Player} instance.
  9472. */
  9473. function clearCacheForPlayer(player) {
  9474. middlewareInstances[player.id()] = null;
  9475. }
  9476. /**
  9477. * {
  9478. * [playerId]: [[mwFactory, mwInstance], ...]
  9479. * }
  9480. *
  9481. * @private
  9482. */
  9483. function getOrCreateFactory(player, mwFactory) {
  9484. var mws = middlewareInstances[player.id()];
  9485. var mw = null;
  9486. if (mws === undefined || mws === null) {
  9487. mw = mwFactory(player);
  9488. middlewareInstances[player.id()] = [[mwFactory, mw]];
  9489. return mw;
  9490. }
  9491. for (var i = 0; i < mws.length; i++) {
  9492. var _mws$i = mws[i],
  9493. mwf = _mws$i[0],
  9494. mwi = _mws$i[1];
  9495. if (mwf !== mwFactory) {
  9496. continue;
  9497. }
  9498. mw = mwi;
  9499. }
  9500. if (mw === null) {
  9501. mw = mwFactory(player);
  9502. mws.push([mwFactory, mw]);
  9503. }
  9504. return mw;
  9505. }
  9506. function setSourceHelper(src, middleware, next, player, acc, lastRun) {
  9507. if (src === void 0) {
  9508. src = {};
  9509. }
  9510. if (middleware === void 0) {
  9511. middleware = [];
  9512. }
  9513. if (acc === void 0) {
  9514. acc = [];
  9515. }
  9516. if (lastRun === void 0) {
  9517. lastRun = false;
  9518. }
  9519. var _middleware = middleware,
  9520. mwFactory = _middleware[0],
  9521. mwrest = _middleware.slice(1); // if mwFactory is a string, then we're at a fork in the road
  9522. if (typeof mwFactory === 'string') {
  9523. setSourceHelper(src, middlewares[mwFactory], next, player, acc, lastRun); // if we have an mwFactory, call it with the player to get the mw,
  9524. // then call the mw's setSource method
  9525. } else if (mwFactory) {
  9526. var mw = getOrCreateFactory(player, mwFactory); // if setSource isn't present, implicitly select this middleware
  9527. if (!mw.setSource) {
  9528. acc.push(mw);
  9529. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  9530. }
  9531. mw.setSource(assign({}, src), function (err, _src) {
  9532. // something happened, try the next middleware on the current level
  9533. // make sure to use the old src
  9534. if (err) {
  9535. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  9536. } // we've succeeded, now we need to go deeper
  9537. acc.push(mw); // if it's the same type, continue down the current chain
  9538. // otherwise, we want to go down the new chain
  9539. setSourceHelper(_src, src.type === _src.type ? mwrest : middlewares[_src.type], next, player, acc, lastRun);
  9540. });
  9541. } else if (mwrest.length) {
  9542. setSourceHelper(src, mwrest, next, player, acc, lastRun);
  9543. } else if (lastRun) {
  9544. next(src, acc);
  9545. } else {
  9546. setSourceHelper(src, middlewares['*'], next, player, acc, true);
  9547. }
  9548. }
  9549. /**
  9550. * Mimetypes
  9551. *
  9552. * @see http://hul.harvard.edu/ois/////systems/wax/wax-public-help/mimetypes.htm
  9553. * @typedef Mimetypes~Kind
  9554. * @enum
  9555. */
  9556. var MimetypesKind = {
  9557. opus: 'video/ogg',
  9558. ogv: 'video/ogg',
  9559. mp4: 'video/mp4',
  9560. mov: 'video/mp4',
  9561. m4v: 'video/mp4',
  9562. mkv: 'video/x-matroska',
  9563. m4a: 'audio/mp4',
  9564. mp3: 'audio/mpeg',
  9565. aac: 'audio/aac',
  9566. oga: 'audio/ogg',
  9567. m3u8: 'application/x-mpegURL',
  9568. jpg: 'image/jpeg',
  9569. jpeg: 'image/jpeg',
  9570. gif: 'image/gif',
  9571. png: 'image/png',
  9572. svg: 'image/svg+xml',
  9573. webp: 'image/webp'
  9574. };
  9575. /**
  9576. * Get the mimetype of a given src url if possible
  9577. *
  9578. * @param {string} src
  9579. * The url to the src
  9580. *
  9581. * @return {string}
  9582. * return the mimetype if it was known or empty string otherwise
  9583. */
  9584. var getMimetype = function getMimetype(src) {
  9585. if (src === void 0) {
  9586. src = '';
  9587. }
  9588. var ext = getFileExtension(src);
  9589. var mimetype = MimetypesKind[ext.toLowerCase()];
  9590. return mimetype || '';
  9591. };
  9592. /**
  9593. * Find the mime type of a given source string if possible. Uses the player
  9594. * source cache.
  9595. *
  9596. * @param {Player} player
  9597. * The player object
  9598. *
  9599. * @param {string} src
  9600. * The source string
  9601. *
  9602. * @return {string}
  9603. * The type that was found
  9604. */
  9605. var findMimetype = function findMimetype(player, src) {
  9606. if (!src) {
  9607. return '';
  9608. } // 1. check for the type in the `source` cache
  9609. if (player.cache_.source.src === src && player.cache_.source.type) {
  9610. return player.cache_.source.type;
  9611. } // 2. see if we have this source in our `currentSources` cache
  9612. var matchingSources = player.cache_.sources.filter(function (s) {
  9613. return s.src === src;
  9614. });
  9615. if (matchingSources.length) {
  9616. return matchingSources[0].type;
  9617. } // 3. look for the src url in source elements and use the type there
  9618. var sources = player.$$('source');
  9619. for (var i = 0; i < sources.length; i++) {
  9620. var s = sources[i];
  9621. if (s.type && s.src && s.src === src) {
  9622. return s.type;
  9623. }
  9624. } // 4. finally fallback to our list of mime types based on src url extension
  9625. return getMimetype(src);
  9626. };
  9627. /**
  9628. * @module filter-source
  9629. */
  9630. /**
  9631. * Filter out single bad source objects or multiple source objects in an
  9632. * array. Also flattens nested source object arrays into a 1 dimensional
  9633. * array of source objects.
  9634. *
  9635. * @param {Tech~SourceObject|Tech~SourceObject[]} src
  9636. * The src object to filter
  9637. *
  9638. * @return {Tech~SourceObject[]}
  9639. * An array of sourceobjects containing only valid sources
  9640. *
  9641. * @private
  9642. */
  9643. var filterSource = function filterSource(src) {
  9644. // traverse array
  9645. if (Array.isArray(src)) {
  9646. var newsrc = [];
  9647. src.forEach(function (srcobj) {
  9648. srcobj = filterSource(srcobj);
  9649. if (Array.isArray(srcobj)) {
  9650. newsrc = newsrc.concat(srcobj);
  9651. } else if (isObject(srcobj)) {
  9652. newsrc.push(srcobj);
  9653. }
  9654. });
  9655. src = newsrc;
  9656. } else if (typeof src === 'string' && src.trim()) {
  9657. // convert string into object
  9658. src = [fixSource({
  9659. src: src
  9660. })];
  9661. } else if (isObject(src) && typeof src.src === 'string' && src.src && src.src.trim()) {
  9662. // src is already valid
  9663. src = [fixSource(src)];
  9664. } else {
  9665. // invalid source, turn it into an empty array
  9666. src = [];
  9667. }
  9668. return src;
  9669. };
  9670. /**
  9671. * Checks src mimetype, adding it when possible
  9672. *
  9673. * @param {Tech~SourceObject} src
  9674. * The src object to check
  9675. * @return {Tech~SourceObject}
  9676. * src Object with known type
  9677. */
  9678. function fixSource(src) {
  9679. if (!src.type) {
  9680. var mimetype = getMimetype(src.src);
  9681. if (mimetype) {
  9682. src.type = mimetype;
  9683. }
  9684. }
  9685. return src;
  9686. }
  9687. /**
  9688. * The `MediaLoader` is the `Component` that decides which playback technology to load
  9689. * when a player is initialized.
  9690. *
  9691. * @extends Component
  9692. */
  9693. var MediaLoader =
  9694. /*#__PURE__*/
  9695. function (_Component) {
  9696. _inheritsLoose(MediaLoader, _Component);
  9697. /**
  9698. * Create an instance of this class.
  9699. *
  9700. * @param {Player} player
  9701. * The `Player` that this class should attach to.
  9702. *
  9703. * @param {Object} [options]
  9704. * The key/value store of player options.
  9705. *
  9706. * @param {Component~ReadyCallback} [ready]
  9707. * The function that is run when this component is ready.
  9708. */
  9709. function MediaLoader(player, options, ready) {
  9710. var _this;
  9711. // MediaLoader has no element
  9712. var options_ = mergeOptions({
  9713. createEl: false
  9714. }, options);
  9715. _this = _Component.call(this, player, options_, ready) || this; // If there are no sources when the player is initialized,
  9716. // load the first supported playback technology.
  9717. if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
  9718. for (var i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
  9719. var techName = toTitleCase(j[i]);
  9720. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  9721. // Remove once that deprecated behavior is removed.
  9722. if (!techName) {
  9723. tech = Component.getComponent(techName);
  9724. } // Check if the browser supports this technology
  9725. if (tech && tech.isSupported()) {
  9726. player.loadTech_(techName);
  9727. break;
  9728. }
  9729. }
  9730. } else {
  9731. // Loop through playback technologies (HTML5, Flash) and check for support.
  9732. // Then load the best source.
  9733. // A few assumptions here:
  9734. // All playback technologies respect preload false.
  9735. player.src(options.playerOptions.sources);
  9736. }
  9737. return _this;
  9738. }
  9739. return MediaLoader;
  9740. }(Component);
  9741. Component.registerComponent('MediaLoader', MediaLoader);
  9742. /**
  9743. * Component which is clickable or keyboard actionable, but is not a
  9744. * native HTML button.
  9745. *
  9746. * @extends Component
  9747. */
  9748. var ClickableComponent =
  9749. /*#__PURE__*/
  9750. function (_Component) {
  9751. _inheritsLoose(ClickableComponent, _Component);
  9752. /**
  9753. * Creates an instance of this class.
  9754. *
  9755. * @param {Player} player
  9756. * The `Player` that this class should be attached to.
  9757. *
  9758. * @param {Object} [options]
  9759. * The key/value store of player options.
  9760. */
  9761. function ClickableComponent(player, options) {
  9762. var _this;
  9763. _this = _Component.call(this, player, options) || this;
  9764. _this.emitTapEvents();
  9765. _this.enable();
  9766. return _this;
  9767. }
  9768. /**
  9769. * Create the `ClickableComponent`s DOM element.
  9770. *
  9771. * @param {string} [tag=div]
  9772. * The element's node type.
  9773. *
  9774. * @param {Object} [props={}]
  9775. * An object of properties that should be set on the element.
  9776. *
  9777. * @param {Object} [attributes={}]
  9778. * An object of attributes that should be set on the element.
  9779. *
  9780. * @return {Element}
  9781. * The element that gets created.
  9782. */
  9783. var _proto = ClickableComponent.prototype;
  9784. _proto.createEl = function createEl(tag, props, attributes) {
  9785. if (tag === void 0) {
  9786. tag = 'div';
  9787. }
  9788. if (props === void 0) {
  9789. props = {};
  9790. }
  9791. if (attributes === void 0) {
  9792. attributes = {};
  9793. }
  9794. props = assign({
  9795. innerHTML: '<span aria-hidden="true" class="vjs-icon-placeholder"></span>',
  9796. className: this.buildCSSClass(),
  9797. tabIndex: 0
  9798. }, props);
  9799. if (tag === 'button') {
  9800. log.error("Creating a ClickableComponent with an HTML element of " + tag + " is not supported; use a Button instead.");
  9801. } // Add ARIA attributes for clickable element which is not a native HTML button
  9802. attributes = assign({
  9803. role: 'button'
  9804. }, attributes);
  9805. this.tabIndex_ = props.tabIndex;
  9806. var el = _Component.prototype.createEl.call(this, tag, props, attributes);
  9807. this.createControlTextEl(el);
  9808. return el;
  9809. };
  9810. _proto.dispose = function dispose() {
  9811. // remove controlTextEl_ on dispose
  9812. this.controlTextEl_ = null;
  9813. _Component.prototype.dispose.call(this);
  9814. }
  9815. /**
  9816. * Create a control text element on this `ClickableComponent`
  9817. *
  9818. * @param {Element} [el]
  9819. * Parent element for the control text.
  9820. *
  9821. * @return {Element}
  9822. * The control text element that gets created.
  9823. */
  9824. ;
  9825. _proto.createControlTextEl = function createControlTextEl(el) {
  9826. this.controlTextEl_ = createEl('span', {
  9827. className: 'vjs-control-text'
  9828. }, {
  9829. // let the screen reader user know that the text of the element may change
  9830. 'aria-live': 'polite'
  9831. });
  9832. if (el) {
  9833. el.appendChild(this.controlTextEl_);
  9834. }
  9835. this.controlText(this.controlText_, el);
  9836. return this.controlTextEl_;
  9837. }
  9838. /**
  9839. * Get or set the localize text to use for the controls on the `ClickableComponent`.
  9840. *
  9841. * @param {string} [text]
  9842. * Control text for element.
  9843. *
  9844. * @param {Element} [el=this.el()]
  9845. * Element to set the title on.
  9846. *
  9847. * @return {string}
  9848. * - The control text when getting
  9849. */
  9850. ;
  9851. _proto.controlText = function controlText(text, el) {
  9852. if (el === void 0) {
  9853. el = this.el();
  9854. }
  9855. if (text === undefined) {
  9856. return this.controlText_ || 'Need Text';
  9857. }
  9858. var localizedText = this.localize(text);
  9859. this.controlText_ = text;
  9860. textContent(this.controlTextEl_, localizedText);
  9861. if (!this.nonIconControl) {
  9862. // Set title attribute if only an icon is shown
  9863. el.setAttribute('title', localizedText);
  9864. }
  9865. }
  9866. /**
  9867. * Builds the default DOM `className`.
  9868. *
  9869. * @return {string}
  9870. * The DOM `className` for this object.
  9871. */
  9872. ;
  9873. _proto.buildCSSClass = function buildCSSClass() {
  9874. return "vjs-control vjs-button " + _Component.prototype.buildCSSClass.call(this);
  9875. }
  9876. /**
  9877. * Enable this `ClickableComponent`
  9878. */
  9879. ;
  9880. _proto.enable = function enable() {
  9881. if (!this.enabled_) {
  9882. this.enabled_ = true;
  9883. this.removeClass('vjs-disabled');
  9884. this.el_.setAttribute('aria-disabled', 'false');
  9885. if (typeof this.tabIndex_ !== 'undefined') {
  9886. this.el_.setAttribute('tabIndex', this.tabIndex_);
  9887. }
  9888. this.on(['tap', 'click'], this.handleClick);
  9889. this.on('keydown', this.handleKeyDown);
  9890. }
  9891. }
  9892. /**
  9893. * Disable this `ClickableComponent`
  9894. */
  9895. ;
  9896. _proto.disable = function disable() {
  9897. this.enabled_ = false;
  9898. this.addClass('vjs-disabled');
  9899. this.el_.setAttribute('aria-disabled', 'true');
  9900. if (typeof this.tabIndex_ !== 'undefined') {
  9901. this.el_.removeAttribute('tabIndex');
  9902. }
  9903. this.off('mouseover', this.handleMouseOver);
  9904. this.off('mouseout', this.handleMouseOut);
  9905. this.off(['tap', 'click'], this.handleClick);
  9906. this.off('keydown', this.handleKeyDown);
  9907. }
  9908. /**
  9909. * Event handler that is called when a `ClickableComponent` receives a
  9910. * `click` or `tap` event.
  9911. *
  9912. * @param {EventTarget~Event} event
  9913. * The `tap` or `click` event that caused this function to be called.
  9914. *
  9915. * @listens tap
  9916. * @listens click
  9917. * @abstract
  9918. */
  9919. ;
  9920. _proto.handleClick = function handleClick(event) {}
  9921. /**
  9922. * Event handler that is called when a `ClickableComponent` receives a
  9923. * `keydown` event.
  9924. *
  9925. * By default, if the key is Space or Enter, it will trigger a `click` event.
  9926. *
  9927. * @param {EventTarget~Event} event
  9928. * The `keydown` event that caused this function to be called.
  9929. *
  9930. * @listens keydown
  9931. */
  9932. ;
  9933. _proto.handleKeyDown = function handleKeyDown(event) {
  9934. // Support Space or Enter key operation to fire a click event. Also,
  9935. // prevent the event from propagating through the DOM and triggering
  9936. // Player hotkeys.
  9937. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  9938. event.preventDefault();
  9939. event.stopPropagation();
  9940. this.trigger('click');
  9941. } else {
  9942. // Pass keypress handling up for unsupported keys
  9943. _Component.prototype.handleKeyDown.call(this, event);
  9944. }
  9945. };
  9946. return ClickableComponent;
  9947. }(Component);
  9948. Component.registerComponent('ClickableComponent', ClickableComponent);
  9949. /**
  9950. * A `ClickableComponent` that handles showing the poster image for the player.
  9951. *
  9952. * @extends ClickableComponent
  9953. */
  9954. var PosterImage =
  9955. /*#__PURE__*/
  9956. function (_ClickableComponent) {
  9957. _inheritsLoose(PosterImage, _ClickableComponent);
  9958. /**
  9959. * Create an instance of this class.
  9960. *
  9961. * @param {Player} player
  9962. * The `Player` that this class should attach to.
  9963. *
  9964. * @param {Object} [options]
  9965. * The key/value store of player options.
  9966. */
  9967. function PosterImage(player, options) {
  9968. var _this;
  9969. _this = _ClickableComponent.call(this, player, options) || this;
  9970. _this.update();
  9971. player.on('posterchange', bind(_assertThisInitialized(_this), _this.update));
  9972. return _this;
  9973. }
  9974. /**
  9975. * Clean up and dispose of the `PosterImage`.
  9976. */
  9977. var _proto = PosterImage.prototype;
  9978. _proto.dispose = function dispose() {
  9979. this.player().off('posterchange', this.update);
  9980. _ClickableComponent.prototype.dispose.call(this);
  9981. }
  9982. /**
  9983. * Create the `PosterImage`s DOM element.
  9984. *
  9985. * @return {Element}
  9986. * The element that gets created.
  9987. */
  9988. ;
  9989. _proto.createEl = function createEl$1() {
  9990. var el = createEl('div', {
  9991. className: 'vjs-poster',
  9992. // Don't want poster to be tabbable.
  9993. tabIndex: -1
  9994. });
  9995. return el;
  9996. }
  9997. /**
  9998. * An {@link EventTarget~EventListener} for {@link Player#posterchange} events.
  9999. *
  10000. * @listens Player#posterchange
  10001. *
  10002. * @param {EventTarget~Event} [event]
  10003. * The `Player#posterchange` event that triggered this function.
  10004. */
  10005. ;
  10006. _proto.update = function update(event) {
  10007. var url = this.player().poster();
  10008. this.setSrc(url); // If there's no poster source we should display:none on this component
  10009. // so it's not still clickable or right-clickable
  10010. if (url) {
  10011. this.show();
  10012. } else {
  10013. this.hide();
  10014. }
  10015. }
  10016. /**
  10017. * Set the source of the `PosterImage` depending on the display method.
  10018. *
  10019. * @param {string} url
  10020. * The URL to the source for the `PosterImage`.
  10021. */
  10022. ;
  10023. _proto.setSrc = function setSrc(url) {
  10024. var backgroundImage = ''; // Any falsy value should stay as an empty string, otherwise
  10025. // this will throw an extra error
  10026. if (url) {
  10027. backgroundImage = "url(\"" + url + "\")";
  10028. }
  10029. this.el_.style.backgroundImage = backgroundImage;
  10030. }
  10031. /**
  10032. * An {@link EventTarget~EventListener} for clicks on the `PosterImage`. See
  10033. * {@link ClickableComponent#handleClick} for instances where this will be triggered.
  10034. *
  10035. * @listens tap
  10036. * @listens click
  10037. * @listens keydown
  10038. *
  10039. * @param {EventTarget~Event} event
  10040. + The `click`, `tap` or `keydown` event that caused this function to be called.
  10041. */
  10042. ;
  10043. _proto.handleClick = function handleClick(event) {
  10044. // We don't want a click to trigger playback when controls are disabled
  10045. if (!this.player_.controls()) {
  10046. return;
  10047. }
  10048. if (this.player_.tech(true)) {
  10049. this.player_.tech(true).focus();
  10050. }
  10051. if (this.player_.paused()) {
  10052. silencePromise(this.player_.play());
  10053. } else {
  10054. this.player_.pause();
  10055. }
  10056. };
  10057. return PosterImage;
  10058. }(ClickableComponent);
  10059. Component.registerComponent('PosterImage', PosterImage);
  10060. var darkGray = '#222';
  10061. var lightGray = '#ccc';
  10062. var fontMap = {
  10063. monospace: 'monospace',
  10064. sansSerif: 'sans-serif',
  10065. serif: 'serif',
  10066. monospaceSansSerif: '"Andale Mono", "Lucida Console", monospace',
  10067. monospaceSerif: '"Courier New", monospace',
  10068. proportionalSansSerif: 'sans-serif',
  10069. proportionalSerif: 'serif',
  10070. casual: '"Comic Sans MS", Impact, fantasy',
  10071. script: '"Monotype Corsiva", cursive',
  10072. smallcaps: '"Andale Mono", "Lucida Console", monospace, sans-serif'
  10073. };
  10074. /**
  10075. * Construct an rgba color from a given hex color code.
  10076. *
  10077. * @param {number} color
  10078. * Hex number for color, like #f0e or #f604e2.
  10079. *
  10080. * @param {number} opacity
  10081. * Value for opacity, 0.0 - 1.0.
  10082. *
  10083. * @return {string}
  10084. * The rgba color that was created, like 'rgba(255, 0, 0, 0.3)'.
  10085. */
  10086. function constructColor(color, opacity) {
  10087. var hex;
  10088. if (color.length === 4) {
  10089. // color looks like "#f0e"
  10090. hex = color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
  10091. } else if (color.length === 7) {
  10092. // color looks like "#f604e2"
  10093. hex = color.slice(1);
  10094. } else {
  10095. throw new Error('Invalid color code provided, ' + color + '; must be formatted as e.g. #f0e or #f604e2.');
  10096. }
  10097. return 'rgba(' + parseInt(hex.slice(0, 2), 16) + ',' + parseInt(hex.slice(2, 4), 16) + ',' + parseInt(hex.slice(4, 6), 16) + ',' + opacity + ')';
  10098. }
  10099. /**
  10100. * Try to update the style of a DOM element. Some style changes will throw an error,
  10101. * particularly in IE8. Those should be noops.
  10102. *
  10103. * @param {Element} el
  10104. * The DOM element to be styled.
  10105. *
  10106. * @param {string} style
  10107. * The CSS property on the element that should be styled.
  10108. *
  10109. * @param {string} rule
  10110. * The style rule that should be applied to the property.
  10111. *
  10112. * @private
  10113. */
  10114. function tryUpdateStyle(el, style, rule) {
  10115. try {
  10116. el.style[style] = rule;
  10117. } catch (e) {
  10118. // Satisfies linter.
  10119. return;
  10120. }
  10121. }
  10122. /**
  10123. * The component for displaying text track cues.
  10124. *
  10125. * @extends Component
  10126. */
  10127. var TextTrackDisplay =
  10128. /*#__PURE__*/
  10129. function (_Component) {
  10130. _inheritsLoose(TextTrackDisplay, _Component);
  10131. /**
  10132. * Creates an instance of this class.
  10133. *
  10134. * @param {Player} player
  10135. * The `Player` that this class should be attached to.
  10136. *
  10137. * @param {Object} [options]
  10138. * The key/value store of player options.
  10139. *
  10140. * @param {Component~ReadyCallback} [ready]
  10141. * The function to call when `TextTrackDisplay` is ready.
  10142. */
  10143. function TextTrackDisplay(player, options, ready) {
  10144. var _this;
  10145. _this = _Component.call(this, player, options, ready) || this;
  10146. var updateDisplayHandler = bind(_assertThisInitialized(_this), _this.updateDisplay);
  10147. player.on('loadstart', bind(_assertThisInitialized(_this), _this.toggleDisplay));
  10148. player.on('texttrackchange', updateDisplayHandler);
  10149. player.on('loadedmetadata', bind(_assertThisInitialized(_this), _this.preselectTrack)); // This used to be called during player init, but was causing an error
  10150. // if a track should show by default and the display hadn't loaded yet.
  10151. // Should probably be moved to an external track loader when we support
  10152. // tracks that don't need a display.
  10153. player.ready(bind(_assertThisInitialized(_this), function () {
  10154. if (player.tech_ && player.tech_.featuresNativeTextTracks) {
  10155. this.hide();
  10156. return;
  10157. }
  10158. player.on('fullscreenchange', updateDisplayHandler);
  10159. player.on('playerresize', updateDisplayHandler);
  10160. window$1.addEventListener('orientationchange', updateDisplayHandler);
  10161. player.on('dispose', function () {
  10162. return window$1.removeEventListener('orientationchange', updateDisplayHandler);
  10163. });
  10164. var tracks = this.options_.playerOptions.tracks || [];
  10165. for (var i = 0; i < tracks.length; i++) {
  10166. this.player_.addRemoteTextTrack(tracks[i], true);
  10167. }
  10168. this.preselectTrack();
  10169. }));
  10170. return _this;
  10171. }
  10172. /**
  10173. * Preselect a track following this precedence:
  10174. * - matches the previously selected {@link TextTrack}'s language and kind
  10175. * - matches the previously selected {@link TextTrack}'s language only
  10176. * - is the first default captions track
  10177. * - is the first default descriptions track
  10178. *
  10179. * @listens Player#loadstart
  10180. */
  10181. var _proto = TextTrackDisplay.prototype;
  10182. _proto.preselectTrack = function preselectTrack() {
  10183. var modes = {
  10184. captions: 1,
  10185. subtitles: 1
  10186. };
  10187. var trackList = this.player_.textTracks();
  10188. var userPref = this.player_.cache_.selectedLanguage;
  10189. var firstDesc;
  10190. var firstCaptions;
  10191. var preferredTrack;
  10192. for (var i = 0; i < trackList.length; i++) {
  10193. var track = trackList[i];
  10194. if (userPref && userPref.enabled && userPref.language && userPref.language === track.language && track.kind in modes) {
  10195. // Always choose the track that matches both language and kind
  10196. if (track.kind === userPref.kind) {
  10197. preferredTrack = track; // or choose the first track that matches language
  10198. } else if (!preferredTrack) {
  10199. preferredTrack = track;
  10200. } // clear everything if offTextTrackMenuItem was clicked
  10201. } else if (userPref && !userPref.enabled) {
  10202. preferredTrack = null;
  10203. firstDesc = null;
  10204. firstCaptions = null;
  10205. } else if (track["default"]) {
  10206. if (track.kind === 'descriptions' && !firstDesc) {
  10207. firstDesc = track;
  10208. } else if (track.kind in modes && !firstCaptions) {
  10209. firstCaptions = track;
  10210. }
  10211. }
  10212. } // The preferredTrack matches the user preference and takes
  10213. // precedence over all the other tracks.
  10214. // So, display the preferredTrack before the first default track
  10215. // and the subtitles/captions track before the descriptions track
  10216. if (preferredTrack) {
  10217. preferredTrack.mode = 'showing';
  10218. } else if (firstCaptions) {
  10219. firstCaptions.mode = 'showing';
  10220. } else if (firstDesc) {
  10221. firstDesc.mode = 'showing';
  10222. }
  10223. }
  10224. /**
  10225. * Turn display of {@link TextTrack}'s from the current state into the other state.
  10226. * There are only two states:
  10227. * - 'shown'
  10228. * - 'hidden'
  10229. *
  10230. * @listens Player#loadstart
  10231. */
  10232. ;
  10233. _proto.toggleDisplay = function toggleDisplay() {
  10234. if (this.player_.tech_ && this.player_.tech_.featuresNativeTextTracks) {
  10235. this.hide();
  10236. } else {
  10237. this.show();
  10238. }
  10239. }
  10240. /**
  10241. * Create the {@link Component}'s DOM element.
  10242. *
  10243. * @return {Element}
  10244. * The element that was created.
  10245. */
  10246. ;
  10247. _proto.createEl = function createEl() {
  10248. return _Component.prototype.createEl.call(this, 'div', {
  10249. className: 'vjs-text-track-display'
  10250. }, {
  10251. 'aria-live': 'off',
  10252. 'aria-atomic': 'true'
  10253. });
  10254. }
  10255. /**
  10256. * Clear all displayed {@link TextTrack}s.
  10257. */
  10258. ;
  10259. _proto.clearDisplay = function clearDisplay() {
  10260. if (typeof window$1.WebVTT === 'function') {
  10261. window$1.WebVTT.processCues(window$1, [], this.el_);
  10262. }
  10263. }
  10264. /**
  10265. * Update the displayed TextTrack when a either a {@link Player#texttrackchange} or
  10266. * a {@link Player#fullscreenchange} is fired.
  10267. *
  10268. * @listens Player#texttrackchange
  10269. * @listens Player#fullscreenchange
  10270. */
  10271. ;
  10272. _proto.updateDisplay = function updateDisplay() {
  10273. var tracks = this.player_.textTracks();
  10274. var allowMultipleShowingTracks = this.options_.allowMultipleShowingTracks;
  10275. this.clearDisplay();
  10276. if (allowMultipleShowingTracks) {
  10277. var showingTracks = [];
  10278. for (var _i = 0; _i < tracks.length; ++_i) {
  10279. var track = tracks[_i];
  10280. if (track.mode !== 'showing') {
  10281. continue;
  10282. }
  10283. showingTracks.push(track);
  10284. }
  10285. this.updateForTrack(showingTracks);
  10286. return;
  10287. } // Track display prioritization model: if multiple tracks are 'showing',
  10288. // display the first 'subtitles' or 'captions' track which is 'showing',
  10289. // otherwise display the first 'descriptions' track which is 'showing'
  10290. var descriptionsTrack = null;
  10291. var captionsSubtitlesTrack = null;
  10292. var i = tracks.length;
  10293. while (i--) {
  10294. var _track = tracks[i];
  10295. if (_track.mode === 'showing') {
  10296. if (_track.kind === 'descriptions') {
  10297. descriptionsTrack = _track;
  10298. } else {
  10299. captionsSubtitlesTrack = _track;
  10300. }
  10301. }
  10302. }
  10303. if (captionsSubtitlesTrack) {
  10304. if (this.getAttribute('aria-live') !== 'off') {
  10305. this.setAttribute('aria-live', 'off');
  10306. }
  10307. this.updateForTrack(captionsSubtitlesTrack);
  10308. } else if (descriptionsTrack) {
  10309. if (this.getAttribute('aria-live') !== 'assertive') {
  10310. this.setAttribute('aria-live', 'assertive');
  10311. }
  10312. this.updateForTrack(descriptionsTrack);
  10313. }
  10314. }
  10315. /**
  10316. * Style {@Link TextTrack} activeCues according to {@Link TextTrackSettings}.
  10317. *
  10318. * @param {TextTrack} track
  10319. * Text track object containing active cues to style.
  10320. */
  10321. ;
  10322. _proto.updateDisplayState = function updateDisplayState(track) {
  10323. var overrides = this.player_.textTrackSettings.getValues();
  10324. var cues = track.activeCues;
  10325. var i = cues.length;
  10326. while (i--) {
  10327. var cue = cues[i];
  10328. if (!cue) {
  10329. continue;
  10330. }
  10331. var cueDiv = cue.displayState;
  10332. if (overrides.color) {
  10333. cueDiv.firstChild.style.color = overrides.color;
  10334. }
  10335. if (overrides.textOpacity) {
  10336. tryUpdateStyle(cueDiv.firstChild, 'color', constructColor(overrides.color || '#fff', overrides.textOpacity));
  10337. }
  10338. if (overrides.backgroundColor) {
  10339. cueDiv.firstChild.style.backgroundColor = overrides.backgroundColor;
  10340. }
  10341. if (overrides.backgroundOpacity) {
  10342. tryUpdateStyle(cueDiv.firstChild, 'backgroundColor', constructColor(overrides.backgroundColor || '#000', overrides.backgroundOpacity));
  10343. }
  10344. if (overrides.windowColor) {
  10345. if (overrides.windowOpacity) {
  10346. tryUpdateStyle(cueDiv, 'backgroundColor', constructColor(overrides.windowColor, overrides.windowOpacity));
  10347. } else {
  10348. cueDiv.style.backgroundColor = overrides.windowColor;
  10349. }
  10350. }
  10351. if (overrides.edgeStyle) {
  10352. if (overrides.edgeStyle === 'dropshadow') {
  10353. cueDiv.firstChild.style.textShadow = "2px 2px 3px " + darkGray + ", 2px 2px 4px " + darkGray + ", 2px 2px 5px " + darkGray;
  10354. } else if (overrides.edgeStyle === 'raised') {
  10355. cueDiv.firstChild.style.textShadow = "1px 1px " + darkGray + ", 2px 2px " + darkGray + ", 3px 3px " + darkGray;
  10356. } else if (overrides.edgeStyle === 'depressed') {
  10357. cueDiv.firstChild.style.textShadow = "1px 1px " + lightGray + ", 0 1px " + lightGray + ", -1px -1px " + darkGray + ", 0 -1px " + darkGray;
  10358. } else if (overrides.edgeStyle === 'uniform') {
  10359. cueDiv.firstChild.style.textShadow = "0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray;
  10360. }
  10361. }
  10362. if (overrides.fontPercent && overrides.fontPercent !== 1) {
  10363. var fontSize = window$1.parseFloat(cueDiv.style.fontSize);
  10364. cueDiv.style.fontSize = fontSize * overrides.fontPercent + 'px';
  10365. cueDiv.style.height = 'auto';
  10366. cueDiv.style.top = 'auto';
  10367. cueDiv.style.bottom = '2px';
  10368. }
  10369. if (overrides.fontFamily && overrides.fontFamily !== 'default') {
  10370. if (overrides.fontFamily === 'small-caps') {
  10371. cueDiv.firstChild.style.fontVariant = 'small-caps';
  10372. } else {
  10373. cueDiv.firstChild.style.fontFamily = fontMap[overrides.fontFamily];
  10374. }
  10375. }
  10376. }
  10377. }
  10378. /**
  10379. * Add an {@link TextTrack} to to the {@link Tech}s {@link TextTrackList}.
  10380. *
  10381. * @param {TextTrack|TextTrack[]} tracks
  10382. * Text track object or text track array to be added to the list.
  10383. */
  10384. ;
  10385. _proto.updateForTrack = function updateForTrack(tracks) {
  10386. if (!Array.isArray(tracks)) {
  10387. tracks = [tracks];
  10388. }
  10389. if (typeof window$1.WebVTT !== 'function' || tracks.every(function (track) {
  10390. return !track.activeCues;
  10391. })) {
  10392. return;
  10393. }
  10394. var cues = []; // push all active track cues
  10395. for (var i = 0; i < tracks.length; ++i) {
  10396. var track = tracks[i];
  10397. for (var j = 0; j < track.activeCues.length; ++j) {
  10398. cues.push(track.activeCues[j]);
  10399. }
  10400. } // removes all cues before it processes new ones
  10401. window$1.WebVTT.processCues(window$1, cues, this.el_); // add unique class to each language text track & add settings styling if necessary
  10402. for (var _i2 = 0; _i2 < tracks.length; ++_i2) {
  10403. var _track2 = tracks[_i2];
  10404. for (var _j = 0; _j < _track2.activeCues.length; ++_j) {
  10405. var cueEl = _track2.activeCues[_j].displayState;
  10406. addClass(cueEl, 'vjs-text-track-cue');
  10407. addClass(cueEl, 'vjs-text-track-cue-' + (_track2.language ? _track2.language : _i2));
  10408. }
  10409. if (this.player_.textTrackSettings) {
  10410. this.updateDisplayState(_track2);
  10411. }
  10412. }
  10413. };
  10414. return TextTrackDisplay;
  10415. }(Component);
  10416. Component.registerComponent('TextTrackDisplay', TextTrackDisplay);
  10417. /**
  10418. * A loading spinner for use during waiting/loading events.
  10419. *
  10420. * @extends Component
  10421. */
  10422. var LoadingSpinner =
  10423. /*#__PURE__*/
  10424. function (_Component) {
  10425. _inheritsLoose(LoadingSpinner, _Component);
  10426. function LoadingSpinner() {
  10427. return _Component.apply(this, arguments) || this;
  10428. }
  10429. var _proto = LoadingSpinner.prototype;
  10430. /**
  10431. * Create the `LoadingSpinner`s DOM element.
  10432. *
  10433. * @return {Element}
  10434. * The dom element that gets created.
  10435. */
  10436. _proto.createEl = function createEl$1() {
  10437. var isAudio = this.player_.isAudio();
  10438. var playerType = this.localize(isAudio ? 'Audio Player' : 'Video Player');
  10439. var controlText = createEl('span', {
  10440. className: 'vjs-control-text',
  10441. innerHTML: this.localize('{1} is loading.', [playerType])
  10442. });
  10443. var el = _Component.prototype.createEl.call(this, 'div', {
  10444. className: 'vjs-loading-spinner',
  10445. dir: 'ltr'
  10446. });
  10447. el.appendChild(controlText);
  10448. return el;
  10449. };
  10450. return LoadingSpinner;
  10451. }(Component);
  10452. Component.registerComponent('LoadingSpinner', LoadingSpinner);
  10453. /**
  10454. * Base class for all buttons.
  10455. *
  10456. * @extends ClickableComponent
  10457. */
  10458. var Button =
  10459. /*#__PURE__*/
  10460. function (_ClickableComponent) {
  10461. _inheritsLoose(Button, _ClickableComponent);
  10462. function Button() {
  10463. return _ClickableComponent.apply(this, arguments) || this;
  10464. }
  10465. var _proto = Button.prototype;
  10466. /**
  10467. * Create the `Button`s DOM element.
  10468. *
  10469. * @param {string} [tag="button"]
  10470. * The element's node type. This argument is IGNORED: no matter what
  10471. * is passed, it will always create a `button` element.
  10472. *
  10473. * @param {Object} [props={}]
  10474. * An object of properties that should be set on the element.
  10475. *
  10476. * @param {Object} [attributes={}]
  10477. * An object of attributes that should be set on the element.
  10478. *
  10479. * @return {Element}
  10480. * The element that gets created.
  10481. */
  10482. _proto.createEl = function createEl(tag, props, attributes) {
  10483. if (props === void 0) {
  10484. props = {};
  10485. }
  10486. if (attributes === void 0) {
  10487. attributes = {};
  10488. }
  10489. tag = 'button';
  10490. props = assign({
  10491. innerHTML: '<span aria-hidden="true" class="vjs-icon-placeholder"></span>',
  10492. className: this.buildCSSClass()
  10493. }, props); // Add attributes for button element
  10494. attributes = assign({
  10495. // Necessary since the default button type is "submit"
  10496. type: 'button'
  10497. }, attributes);
  10498. var el = Component.prototype.createEl.call(this, tag, props, attributes);
  10499. this.createControlTextEl(el);
  10500. return el;
  10501. }
  10502. /**
  10503. * Add a child `Component` inside of this `Button`.
  10504. *
  10505. * @param {string|Component} child
  10506. * The name or instance of a child to add.
  10507. *
  10508. * @param {Object} [options={}]
  10509. * The key/value store of options that will get passed to children of
  10510. * the child.
  10511. *
  10512. * @return {Component}
  10513. * The `Component` that gets added as a child. When using a string the
  10514. * `Component` will get created by this process.
  10515. *
  10516. * @deprecated since version 5
  10517. */
  10518. ;
  10519. _proto.addChild = function addChild(child, options) {
  10520. if (options === void 0) {
  10521. options = {};
  10522. }
  10523. var className = this.constructor.name;
  10524. log.warn("Adding an actionable (user controllable) child to a Button (" + className + ") is not supported; use a ClickableComponent instead."); // Avoid the error message generated by ClickableComponent's addChild method
  10525. return Component.prototype.addChild.call(this, child, options);
  10526. }
  10527. /**
  10528. * Enable the `Button` element so that it can be activated or clicked. Use this with
  10529. * {@link Button#disable}.
  10530. */
  10531. ;
  10532. _proto.enable = function enable() {
  10533. _ClickableComponent.prototype.enable.call(this);
  10534. this.el_.removeAttribute('disabled');
  10535. }
  10536. /**
  10537. * Disable the `Button` element so that it cannot be activated or clicked. Use this with
  10538. * {@link Button#enable}.
  10539. */
  10540. ;
  10541. _proto.disable = function disable() {
  10542. _ClickableComponent.prototype.disable.call(this);
  10543. this.el_.setAttribute('disabled', 'disabled');
  10544. }
  10545. /**
  10546. * This gets called when a `Button` has focus and `keydown` is triggered via a key
  10547. * press.
  10548. *
  10549. * @param {EventTarget~Event} event
  10550. * The event that caused this function to get called.
  10551. *
  10552. * @listens keydown
  10553. */
  10554. ;
  10555. _proto.handleKeyDown = function handleKeyDown(event) {
  10556. // Ignore Space or Enter key operation, which is handled by the browser for
  10557. // a button - though not for its super class, ClickableComponent. Also,
  10558. // prevent the event from propagating through the DOM and triggering Player
  10559. // hotkeys. We do not preventDefault here because we _want_ the browser to
  10560. // handle it.
  10561. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  10562. event.stopPropagation();
  10563. return;
  10564. } // Pass keypress handling up for unsupported keys
  10565. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  10566. };
  10567. return Button;
  10568. }(ClickableComponent);
  10569. Component.registerComponent('Button', Button);
  10570. /**
  10571. * The initial play button that shows before the video has played. The hiding of the
  10572. * `BigPlayButton` get done via CSS and `Player` states.
  10573. *
  10574. * @extends Button
  10575. */
  10576. var BigPlayButton =
  10577. /*#__PURE__*/
  10578. function (_Button) {
  10579. _inheritsLoose(BigPlayButton, _Button);
  10580. function BigPlayButton(player, options) {
  10581. var _this;
  10582. _this = _Button.call(this, player, options) || this;
  10583. _this.mouseused_ = false;
  10584. _this.on('mousedown', _this.handleMouseDown);
  10585. return _this;
  10586. }
  10587. /**
  10588. * Builds the default DOM `className`.
  10589. *
  10590. * @return {string}
  10591. * The DOM `className` for this object. Always returns 'vjs-big-play-button'.
  10592. */
  10593. var _proto = BigPlayButton.prototype;
  10594. _proto.buildCSSClass = function buildCSSClass() {
  10595. return 'vjs-big-play-button';
  10596. }
  10597. /**
  10598. * This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
  10599. * for more detailed information on what a click can be.
  10600. *
  10601. * @param {EventTarget~Event} event
  10602. * The `keydown`, `tap`, or `click` event that caused this function to be
  10603. * called.
  10604. *
  10605. * @listens tap
  10606. * @listens click
  10607. */
  10608. ;
  10609. _proto.handleClick = function handleClick(event) {
  10610. var playPromise = this.player_.play(); // exit early if clicked via the mouse
  10611. if (this.mouseused_ && event.clientX && event.clientY) {
  10612. silencePromise(playPromise);
  10613. if (this.player_.tech(true)) {
  10614. this.player_.tech(true).focus();
  10615. }
  10616. return;
  10617. }
  10618. var cb = this.player_.getChild('controlBar');
  10619. var playToggle = cb && cb.getChild('playToggle');
  10620. if (!playToggle) {
  10621. this.player_.tech(true).focus();
  10622. return;
  10623. }
  10624. var playFocus = function playFocus() {
  10625. return playToggle.focus();
  10626. };
  10627. if (isPromise(playPromise)) {
  10628. playPromise.then(playFocus, function () {});
  10629. } else {
  10630. this.setTimeout(playFocus, 1);
  10631. }
  10632. };
  10633. _proto.handleKeyDown = function handleKeyDown(event) {
  10634. this.mouseused_ = false;
  10635. _Button.prototype.handleKeyDown.call(this, event);
  10636. };
  10637. _proto.handleMouseDown = function handleMouseDown(event) {
  10638. this.mouseused_ = true;
  10639. };
  10640. return BigPlayButton;
  10641. }(Button);
  10642. /**
  10643. * The text that should display over the `BigPlayButton`s controls. Added to for localization.
  10644. *
  10645. * @type {string}
  10646. * @private
  10647. */
  10648. BigPlayButton.prototype.controlText_ = 'Play Video';
  10649. Component.registerComponent('BigPlayButton', BigPlayButton);
  10650. /**
  10651. * The `CloseButton` is a `{@link Button}` that fires a `close` event when
  10652. * it gets clicked.
  10653. *
  10654. * @extends Button
  10655. */
  10656. var CloseButton =
  10657. /*#__PURE__*/
  10658. function (_Button) {
  10659. _inheritsLoose(CloseButton, _Button);
  10660. /**
  10661. * Creates an instance of the this class.
  10662. *
  10663. * @param {Player} player
  10664. * The `Player` that this class should be attached to.
  10665. *
  10666. * @param {Object} [options]
  10667. * The key/value store of player options.
  10668. */
  10669. function CloseButton(player, options) {
  10670. var _this;
  10671. _this = _Button.call(this, player, options) || this;
  10672. _this.controlText(options && options.controlText || _this.localize('Close'));
  10673. return _this;
  10674. }
  10675. /**
  10676. * Builds the default DOM `className`.
  10677. *
  10678. * @return {string}
  10679. * The DOM `className` for this object.
  10680. */
  10681. var _proto = CloseButton.prototype;
  10682. _proto.buildCSSClass = function buildCSSClass() {
  10683. return "vjs-close-button " + _Button.prototype.buildCSSClass.call(this);
  10684. }
  10685. /**
  10686. * This gets called when a `CloseButton` gets clicked. See
  10687. * {@link ClickableComponent#handleClick} for more information on when
  10688. * this will be triggered
  10689. *
  10690. * @param {EventTarget~Event} event
  10691. * The `keydown`, `tap`, or `click` event that caused this function to be
  10692. * called.
  10693. *
  10694. * @listens tap
  10695. * @listens click
  10696. * @fires CloseButton#close
  10697. */
  10698. ;
  10699. _proto.handleClick = function handleClick(event) {
  10700. /**
  10701. * Triggered when the a `CloseButton` is clicked.
  10702. *
  10703. * @event CloseButton#close
  10704. * @type {EventTarget~Event}
  10705. *
  10706. * @property {boolean} [bubbles=false]
  10707. * set to false so that the close event does not
  10708. * bubble up to parents if there is no listener
  10709. */
  10710. this.trigger({
  10711. type: 'close',
  10712. bubbles: false
  10713. });
  10714. }
  10715. /**
  10716. * Event handler that is called when a `CloseButton` receives a
  10717. * `keydown` event.
  10718. *
  10719. * By default, if the key is Esc, it will trigger a `click` event.
  10720. *
  10721. * @param {EventTarget~Event} event
  10722. * The `keydown` event that caused this function to be called.
  10723. *
  10724. * @listens keydown
  10725. */
  10726. ;
  10727. _proto.handleKeyDown = function handleKeyDown(event) {
  10728. // Esc button will trigger `click` event
  10729. if (keycode.isEventKey(event, 'Esc')) {
  10730. event.preventDefault();
  10731. event.stopPropagation();
  10732. this.trigger('click');
  10733. } else {
  10734. // Pass keypress handling up for unsupported keys
  10735. _Button.prototype.handleKeyDown.call(this, event);
  10736. }
  10737. };
  10738. return CloseButton;
  10739. }(Button);
  10740. Component.registerComponent('CloseButton', CloseButton);
  10741. /**
  10742. * Button to toggle between play and pause.
  10743. *
  10744. * @extends Button
  10745. */
  10746. var PlayToggle =
  10747. /*#__PURE__*/
  10748. function (_Button) {
  10749. _inheritsLoose(PlayToggle, _Button);
  10750. /**
  10751. * Creates an instance of this class.
  10752. *
  10753. * @param {Player} player
  10754. * The `Player` that this class should be attached to.
  10755. *
  10756. * @param {Object} [options={}]
  10757. * The key/value store of player options.
  10758. */
  10759. function PlayToggle(player, options) {
  10760. var _this;
  10761. if (options === void 0) {
  10762. options = {};
  10763. }
  10764. _this = _Button.call(this, player, options) || this; // show or hide replay icon
  10765. options.replay = options.replay === undefined || options.replay;
  10766. _this.on(player, 'play', _this.handlePlay);
  10767. _this.on(player, 'pause', _this.handlePause);
  10768. if (options.replay) {
  10769. _this.on(player, 'ended', _this.handleEnded);
  10770. }
  10771. return _this;
  10772. }
  10773. /**
  10774. * Builds the default DOM `className`.
  10775. *
  10776. * @return {string}
  10777. * The DOM `className` for this object.
  10778. */
  10779. var _proto = PlayToggle.prototype;
  10780. _proto.buildCSSClass = function buildCSSClass() {
  10781. return "vjs-play-control " + _Button.prototype.buildCSSClass.call(this);
  10782. }
  10783. /**
  10784. * This gets called when an `PlayToggle` is "clicked". See
  10785. * {@link ClickableComponent} for more detailed information on what a click can be.
  10786. *
  10787. * @param {EventTarget~Event} [event]
  10788. * The `keydown`, `tap`, or `click` event that caused this function to be
  10789. * called.
  10790. *
  10791. * @listens tap
  10792. * @listens click
  10793. */
  10794. ;
  10795. _proto.handleClick = function handleClick(event) {
  10796. if (this.player_.paused()) {
  10797. this.player_.play();
  10798. } else {
  10799. this.player_.pause();
  10800. }
  10801. }
  10802. /**
  10803. * This gets called once after the video has ended and the user seeks so that
  10804. * we can change the replay button back to a play button.
  10805. *
  10806. * @param {EventTarget~Event} [event]
  10807. * The event that caused this function to run.
  10808. *
  10809. * @listens Player#seeked
  10810. */
  10811. ;
  10812. _proto.handleSeeked = function handleSeeked(event) {
  10813. this.removeClass('vjs-ended');
  10814. if (this.player_.paused()) {
  10815. this.handlePause(event);
  10816. } else {
  10817. this.handlePlay(event);
  10818. }
  10819. }
  10820. /**
  10821. * Add the vjs-playing class to the element so it can change appearance.
  10822. *
  10823. * @param {EventTarget~Event} [event]
  10824. * The event that caused this function to run.
  10825. *
  10826. * @listens Player#play
  10827. */
  10828. ;
  10829. _proto.handlePlay = function handlePlay(event) {
  10830. this.removeClass('vjs-ended');
  10831. this.removeClass('vjs-paused');
  10832. this.addClass('vjs-playing'); // change the button text to "Pause"
  10833. this.controlText('Pause');
  10834. }
  10835. /**
  10836. * Add the vjs-paused class to the element so it can change appearance.
  10837. *
  10838. * @param {EventTarget~Event} [event]
  10839. * The event that caused this function to run.
  10840. *
  10841. * @listens Player#pause
  10842. */
  10843. ;
  10844. _proto.handlePause = function handlePause(event) {
  10845. this.removeClass('vjs-playing');
  10846. this.addClass('vjs-paused'); // change the button text to "Play"
  10847. this.controlText('Play');
  10848. }
  10849. /**
  10850. * Add the vjs-ended class to the element so it can change appearance
  10851. *
  10852. * @param {EventTarget~Event} [event]
  10853. * The event that caused this function to run.
  10854. *
  10855. * @listens Player#ended
  10856. */
  10857. ;
  10858. _proto.handleEnded = function handleEnded(event) {
  10859. this.removeClass('vjs-playing');
  10860. this.addClass('vjs-ended'); // change the button text to "Replay"
  10861. this.controlText('Replay'); // on the next seek remove the replay button
  10862. this.one(this.player_, 'seeked', this.handleSeeked);
  10863. };
  10864. return PlayToggle;
  10865. }(Button);
  10866. /**
  10867. * The text that should display over the `PlayToggle`s controls. Added for localization.
  10868. *
  10869. * @type {string}
  10870. * @private
  10871. */
  10872. PlayToggle.prototype.controlText_ = 'Play';
  10873. Component.registerComponent('PlayToggle', PlayToggle);
  10874. /**
  10875. * @file format-time.js
  10876. * @module format-time
  10877. */
  10878. /**
  10879. * Format seconds as a time string, H:MM:SS or M:SS. Supplying a guide (in
  10880. * seconds) will force a number of leading zeros to cover the length of the
  10881. * guide.
  10882. *
  10883. * @private
  10884. * @param {number} seconds
  10885. * Number of seconds to be turned into a string
  10886. *
  10887. * @param {number} guide
  10888. * Number (in seconds) to model the string after
  10889. *
  10890. * @return {string}
  10891. * Time formatted as H:MM:SS or M:SS
  10892. */
  10893. var defaultImplementation = function defaultImplementation(seconds, guide) {
  10894. seconds = seconds < 0 ? 0 : seconds;
  10895. var s = Math.floor(seconds % 60);
  10896. var m = Math.floor(seconds / 60 % 60);
  10897. var h = Math.floor(seconds / 3600);
  10898. var gm = Math.floor(guide / 60 % 60);
  10899. var gh = Math.floor(guide / 3600); // handle invalid times
  10900. if (isNaN(seconds) || seconds === Infinity) {
  10901. // '-' is false for all relational operators (e.g. <, >=) so this setting
  10902. // will add the minimum number of fields specified by the guide
  10903. h = m = s = '-';
  10904. } // Check if we need to show hours
  10905. h = h > 0 || gh > 0 ? h + ':' : ''; // If hours are showing, we may need to add a leading zero.
  10906. // Always show at least one digit of minutes.
  10907. m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':'; // Check if leading zero is need for seconds
  10908. s = s < 10 ? '0' + s : s;
  10909. return h + m + s;
  10910. }; // Internal pointer to the current implementation.
  10911. var implementation$3 = defaultImplementation;
  10912. /**
  10913. * Replaces the default formatTime implementation with a custom implementation.
  10914. *
  10915. * @param {Function} customImplementation
  10916. * A function which will be used in place of the default formatTime
  10917. * implementation. Will receive the current time in seconds and the
  10918. * guide (in seconds) as arguments.
  10919. */
  10920. function setFormatTime(customImplementation) {
  10921. implementation$3 = customImplementation;
  10922. }
  10923. /**
  10924. * Resets formatTime to the default implementation.
  10925. */
  10926. function resetFormatTime() {
  10927. implementation$3 = defaultImplementation;
  10928. }
  10929. /**
  10930. * Delegates to either the default time formatting function or a custom
  10931. * function supplied via `setFormatTime`.
  10932. *
  10933. * Formats seconds as a time string (H:MM:SS or M:SS). Supplying a
  10934. * guide (in seconds) will force a number of leading zeros to cover the
  10935. * length of the guide.
  10936. *
  10937. * @static
  10938. * @example formatTime(125, 600) === "02:05"
  10939. * @param {number} seconds
  10940. * Number of seconds to be turned into a string
  10941. *
  10942. * @param {number} guide
  10943. * Number (in seconds) to model the string after
  10944. *
  10945. * @return {string}
  10946. * Time formatted as H:MM:SS or M:SS
  10947. */
  10948. function formatTime(seconds, guide) {
  10949. if (guide === void 0) {
  10950. guide = seconds;
  10951. }
  10952. return implementation$3(seconds, guide);
  10953. }
  10954. /**
  10955. * Displays time information about the video
  10956. *
  10957. * @extends Component
  10958. */
  10959. var TimeDisplay =
  10960. /*#__PURE__*/
  10961. function (_Component) {
  10962. _inheritsLoose(TimeDisplay, _Component);
  10963. /**
  10964. * Creates an instance of this class.
  10965. *
  10966. * @param {Player} player
  10967. * The `Player` that this class should be attached to.
  10968. *
  10969. * @param {Object} [options]
  10970. * The key/value store of player options.
  10971. */
  10972. function TimeDisplay(player, options) {
  10973. var _this;
  10974. _this = _Component.call(this, player, options) || this;
  10975. _this.throttledUpdateContent = throttle(bind(_assertThisInitialized(_this), _this.updateContent), UPDATE_REFRESH_INTERVAL);
  10976. _this.on(player, 'timeupdate', _this.throttledUpdateContent);
  10977. return _this;
  10978. }
  10979. /**
  10980. * Create the `Component`'s DOM element
  10981. *
  10982. * @return {Element}
  10983. * The element that was created.
  10984. */
  10985. var _proto = TimeDisplay.prototype;
  10986. _proto.createEl = function createEl$1() {
  10987. var className = this.buildCSSClass();
  10988. var el = _Component.prototype.createEl.call(this, 'div', {
  10989. className: className + " vjs-time-control vjs-control",
  10990. innerHTML: "<span class=\"vjs-control-text\" role=\"presentation\">" + this.localize(this.labelText_) + "\xA0</span>"
  10991. });
  10992. this.contentEl_ = createEl('span', {
  10993. className: className + "-display"
  10994. }, {
  10995. // tell screen readers not to automatically read the time as it changes
  10996. 'aria-live': 'off',
  10997. // span elements have no implicit role, but some screen readers (notably VoiceOver)
  10998. // treat them as a break between items in the DOM when using arrow keys
  10999. // (or left-to-right swipes on iOS) to read contents of a page. Using
  11000. // role='presentation' causes VoiceOver to NOT treat this span as a break.
  11001. 'role': 'presentation'
  11002. });
  11003. this.updateTextNode_();
  11004. el.appendChild(this.contentEl_);
  11005. return el;
  11006. };
  11007. _proto.dispose = function dispose() {
  11008. this.contentEl_ = null;
  11009. this.textNode_ = null;
  11010. _Component.prototype.dispose.call(this);
  11011. }
  11012. /**
  11013. * Updates the "remaining time" text node with new content using the
  11014. * contents of the `formattedTime_` property.
  11015. *
  11016. * @private
  11017. */
  11018. ;
  11019. _proto.updateTextNode_ = function updateTextNode_() {
  11020. if (!this.contentEl_) {
  11021. return;
  11022. }
  11023. while (this.contentEl_.firstChild) {
  11024. this.contentEl_.removeChild(this.contentEl_.firstChild);
  11025. }
  11026. this.textNode_ = document.createTextNode(this.formattedTime_ || this.formatTime_(0));
  11027. this.contentEl_.appendChild(this.textNode_);
  11028. }
  11029. /**
  11030. * Generates a formatted time for this component to use in display.
  11031. *
  11032. * @param {number} time
  11033. * A numeric time, in seconds.
  11034. *
  11035. * @return {string}
  11036. * A formatted time
  11037. *
  11038. * @private
  11039. */
  11040. ;
  11041. _proto.formatTime_ = function formatTime_(time) {
  11042. return formatTime(time);
  11043. }
  11044. /**
  11045. * Updates the time display text node if it has what was passed in changed
  11046. * the formatted time.
  11047. *
  11048. * @param {number} time
  11049. * The time to update to
  11050. *
  11051. * @private
  11052. */
  11053. ;
  11054. _proto.updateFormattedTime_ = function updateFormattedTime_(time) {
  11055. var formattedTime = this.formatTime_(time);
  11056. if (formattedTime === this.formattedTime_) {
  11057. return;
  11058. }
  11059. this.formattedTime_ = formattedTime;
  11060. this.requestAnimationFrame(this.updateTextNode_);
  11061. }
  11062. /**
  11063. * To be filled out in the child class, should update the displayed time
  11064. * in accordance with the fact that the current time has changed.
  11065. *
  11066. * @param {EventTarget~Event} [event]
  11067. * The `timeupdate` event that caused this to run.
  11068. *
  11069. * @listens Player#timeupdate
  11070. */
  11071. ;
  11072. _proto.updateContent = function updateContent(event) {};
  11073. return TimeDisplay;
  11074. }(Component);
  11075. /**
  11076. * The text that is added to the `TimeDisplay` for screen reader users.
  11077. *
  11078. * @type {string}
  11079. * @private
  11080. */
  11081. TimeDisplay.prototype.labelText_ = 'Time';
  11082. /**
  11083. * The text that should display over the `TimeDisplay`s controls. Added to for localization.
  11084. *
  11085. * @type {string}
  11086. * @private
  11087. *
  11088. * @deprecated in v7; controlText_ is not used in non-active display Components
  11089. */
  11090. TimeDisplay.prototype.controlText_ = 'Time';
  11091. Component.registerComponent('TimeDisplay', TimeDisplay);
  11092. /**
  11093. * Displays the current time
  11094. *
  11095. * @extends Component
  11096. */
  11097. var CurrentTimeDisplay =
  11098. /*#__PURE__*/
  11099. function (_TimeDisplay) {
  11100. _inheritsLoose(CurrentTimeDisplay, _TimeDisplay);
  11101. /**
  11102. * Creates an instance of this class.
  11103. *
  11104. * @param {Player} player
  11105. * The `Player` that this class should be attached to.
  11106. *
  11107. * @param {Object} [options]
  11108. * The key/value store of player options.
  11109. */
  11110. function CurrentTimeDisplay(player, options) {
  11111. var _this;
  11112. _this = _TimeDisplay.call(this, player, options) || this;
  11113. _this.on(player, 'ended', _this.handleEnded);
  11114. return _this;
  11115. }
  11116. /**
  11117. * Builds the default DOM `className`.
  11118. *
  11119. * @return {string}
  11120. * The DOM `className` for this object.
  11121. */
  11122. var _proto = CurrentTimeDisplay.prototype;
  11123. _proto.buildCSSClass = function buildCSSClass() {
  11124. return 'vjs-current-time';
  11125. }
  11126. /**
  11127. * Update current time display
  11128. *
  11129. * @param {EventTarget~Event} [event]
  11130. * The `timeupdate` event that caused this function to run.
  11131. *
  11132. * @listens Player#timeupdate
  11133. */
  11134. ;
  11135. _proto.updateContent = function updateContent(event) {
  11136. // Allows for smooth scrubbing, when player can't keep up.
  11137. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  11138. this.updateFormattedTime_(time);
  11139. }
  11140. /**
  11141. * When the player fires ended there should be no time left. Sadly
  11142. * this is not always the case, lets make it seem like that is the case
  11143. * for users.
  11144. *
  11145. * @param {EventTarget~Event} [event]
  11146. * The `ended` event that caused this to run.
  11147. *
  11148. * @listens Player#ended
  11149. */
  11150. ;
  11151. _proto.handleEnded = function handleEnded(event) {
  11152. if (!this.player_.duration()) {
  11153. return;
  11154. }
  11155. this.updateFormattedTime_(this.player_.duration());
  11156. };
  11157. return CurrentTimeDisplay;
  11158. }(TimeDisplay);
  11159. /**
  11160. * The text that is added to the `CurrentTimeDisplay` for screen reader users.
  11161. *
  11162. * @type {string}
  11163. * @private
  11164. */
  11165. CurrentTimeDisplay.prototype.labelText_ = 'Current Time';
  11166. /**
  11167. * The text that should display over the `CurrentTimeDisplay`s controls. Added to for localization.
  11168. *
  11169. * @type {string}
  11170. * @private
  11171. *
  11172. * @deprecated in v7; controlText_ is not used in non-active display Components
  11173. */
  11174. CurrentTimeDisplay.prototype.controlText_ = 'Current Time';
  11175. Component.registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
  11176. /**
  11177. * Displays the duration
  11178. *
  11179. * @extends Component
  11180. */
  11181. var DurationDisplay =
  11182. /*#__PURE__*/
  11183. function (_TimeDisplay) {
  11184. _inheritsLoose(DurationDisplay, _TimeDisplay);
  11185. /**
  11186. * Creates an instance of this class.
  11187. *
  11188. * @param {Player} player
  11189. * The `Player` that this class should be attached to.
  11190. *
  11191. * @param {Object} [options]
  11192. * The key/value store of player options.
  11193. */
  11194. function DurationDisplay(player, options) {
  11195. var _this;
  11196. _this = _TimeDisplay.call(this, player, options) || this; // we do not want to/need to throttle duration changes,
  11197. // as they should always display the changed duration as
  11198. // it has changed
  11199. _this.on(player, 'durationchange', _this.updateContent); // Listen to loadstart because the player duration is reset when a new media element is loaded,
  11200. // but the durationchange on the user agent will not fire.
  11201. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  11202. _this.on(player, 'loadstart', _this.updateContent); // Also listen for timeupdate (in the parent) and loadedmetadata because removing those
  11203. // listeners could have broken dependent applications/libraries. These
  11204. // can likely be removed for 7.0.
  11205. _this.on(player, 'loadedmetadata', _this.throttledUpdateContent);
  11206. return _this;
  11207. }
  11208. /**
  11209. * Builds the default DOM `className`.
  11210. *
  11211. * @return {string}
  11212. * The DOM `className` for this object.
  11213. */
  11214. var _proto = DurationDisplay.prototype;
  11215. _proto.buildCSSClass = function buildCSSClass() {
  11216. return 'vjs-duration';
  11217. }
  11218. /**
  11219. * Update duration time display.
  11220. *
  11221. * @param {EventTarget~Event} [event]
  11222. * The `durationchange`, `timeupdate`, or `loadedmetadata` event that caused
  11223. * this function to be called.
  11224. *
  11225. * @listens Player#durationchange
  11226. * @listens Player#timeupdate
  11227. * @listens Player#loadedmetadata
  11228. */
  11229. ;
  11230. _proto.updateContent = function updateContent(event) {
  11231. var duration = this.player_.duration();
  11232. if (this.duration_ !== duration) {
  11233. this.duration_ = duration;
  11234. this.updateFormattedTime_(duration);
  11235. }
  11236. };
  11237. return DurationDisplay;
  11238. }(TimeDisplay);
  11239. /**
  11240. * The text that is added to the `DurationDisplay` for screen reader users.
  11241. *
  11242. * @type {string}
  11243. * @private
  11244. */
  11245. DurationDisplay.prototype.labelText_ = 'Duration';
  11246. /**
  11247. * The text that should display over the `DurationDisplay`s controls. Added to for localization.
  11248. *
  11249. * @type {string}
  11250. * @private
  11251. *
  11252. * @deprecated in v7; controlText_ is not used in non-active display Components
  11253. */
  11254. DurationDisplay.prototype.controlText_ = 'Duration';
  11255. Component.registerComponent('DurationDisplay', DurationDisplay);
  11256. /**
  11257. * The separator between the current time and duration.
  11258. * Can be hidden if it's not needed in the design.
  11259. *
  11260. * @extends Component
  11261. */
  11262. var TimeDivider =
  11263. /*#__PURE__*/
  11264. function (_Component) {
  11265. _inheritsLoose(TimeDivider, _Component);
  11266. function TimeDivider() {
  11267. return _Component.apply(this, arguments) || this;
  11268. }
  11269. var _proto = TimeDivider.prototype;
  11270. /**
  11271. * Create the component's DOM element
  11272. *
  11273. * @return {Element}
  11274. * The element that was created.
  11275. */
  11276. _proto.createEl = function createEl() {
  11277. return _Component.prototype.createEl.call(this, 'div', {
  11278. className: 'vjs-time-control vjs-time-divider',
  11279. innerHTML: '<div><span>/</span></div>'
  11280. }, {
  11281. // this element and its contents can be hidden from assistive techs since
  11282. // it is made extraneous by the announcement of the control text
  11283. // for the current time and duration displays
  11284. 'aria-hidden': true
  11285. });
  11286. };
  11287. return TimeDivider;
  11288. }(Component);
  11289. Component.registerComponent('TimeDivider', TimeDivider);
  11290. /**
  11291. * Displays the time left in the video
  11292. *
  11293. * @extends Component
  11294. */
  11295. var RemainingTimeDisplay =
  11296. /*#__PURE__*/
  11297. function (_TimeDisplay) {
  11298. _inheritsLoose(RemainingTimeDisplay, _TimeDisplay);
  11299. /**
  11300. * Creates an instance of this class.
  11301. *
  11302. * @param {Player} player
  11303. * The `Player` that this class should be attached to.
  11304. *
  11305. * @param {Object} [options]
  11306. * The key/value store of player options.
  11307. */
  11308. function RemainingTimeDisplay(player, options) {
  11309. var _this;
  11310. _this = _TimeDisplay.call(this, player, options) || this;
  11311. _this.on(player, 'durationchange', _this.throttledUpdateContent);
  11312. _this.on(player, 'ended', _this.handleEnded);
  11313. return _this;
  11314. }
  11315. /**
  11316. * Builds the default DOM `className`.
  11317. *
  11318. * @return {string}
  11319. * The DOM `className` for this object.
  11320. */
  11321. var _proto = RemainingTimeDisplay.prototype;
  11322. _proto.buildCSSClass = function buildCSSClass() {
  11323. return 'vjs-remaining-time';
  11324. }
  11325. /**
  11326. * Create the `Component`'s DOM element with the "minus" characted prepend to the time
  11327. *
  11328. * @return {Element}
  11329. * The element that was created.
  11330. */
  11331. ;
  11332. _proto.createEl = function createEl$1() {
  11333. var el = _TimeDisplay.prototype.createEl.call(this);
  11334. el.insertBefore(createEl('span', {}, {
  11335. 'aria-hidden': true
  11336. }, '-'), this.contentEl_);
  11337. return el;
  11338. }
  11339. /**
  11340. * Update remaining time display.
  11341. *
  11342. * @param {EventTarget~Event} [event]
  11343. * The `timeupdate` or `durationchange` event that caused this to run.
  11344. *
  11345. * @listens Player#timeupdate
  11346. * @listens Player#durationchange
  11347. */
  11348. ;
  11349. _proto.updateContent = function updateContent(event) {
  11350. if (typeof this.player_.duration() !== 'number') {
  11351. return;
  11352. } // @deprecated We should only use remainingTimeDisplay
  11353. // as of video.js 7
  11354. if (this.player_.remainingTimeDisplay) {
  11355. this.updateFormattedTime_(this.player_.remainingTimeDisplay());
  11356. } else {
  11357. this.updateFormattedTime_(this.player_.remainingTime());
  11358. }
  11359. }
  11360. /**
  11361. * When the player fires ended there should be no time left. Sadly
  11362. * this is not always the case, lets make it seem like that is the case
  11363. * for users.
  11364. *
  11365. * @param {EventTarget~Event} [event]
  11366. * The `ended` event that caused this to run.
  11367. *
  11368. * @listens Player#ended
  11369. */
  11370. ;
  11371. _proto.handleEnded = function handleEnded(event) {
  11372. if (!this.player_.duration()) {
  11373. return;
  11374. }
  11375. this.updateFormattedTime_(0);
  11376. };
  11377. return RemainingTimeDisplay;
  11378. }(TimeDisplay);
  11379. /**
  11380. * The text that is added to the `RemainingTimeDisplay` for screen reader users.
  11381. *
  11382. * @type {string}
  11383. * @private
  11384. */
  11385. RemainingTimeDisplay.prototype.labelText_ = 'Remaining Time';
  11386. /**
  11387. * The text that should display over the `RemainingTimeDisplay`s controls. Added to for localization.
  11388. *
  11389. * @type {string}
  11390. * @private
  11391. *
  11392. * @deprecated in v7; controlText_ is not used in non-active display Components
  11393. */
  11394. RemainingTimeDisplay.prototype.controlText_ = 'Remaining Time';
  11395. Component.registerComponent('RemainingTimeDisplay', RemainingTimeDisplay);
  11396. /**
  11397. * Displays the live indicator when duration is Infinity.
  11398. *
  11399. * @extends Component
  11400. */
  11401. var LiveDisplay =
  11402. /*#__PURE__*/
  11403. function (_Component) {
  11404. _inheritsLoose(LiveDisplay, _Component);
  11405. /**
  11406. * Creates an instance of this class.
  11407. *
  11408. * @param {Player} player
  11409. * The `Player` that this class should be attached to.
  11410. *
  11411. * @param {Object} [options]
  11412. * The key/value store of player options.
  11413. */
  11414. function LiveDisplay(player, options) {
  11415. var _this;
  11416. _this = _Component.call(this, player, options) || this;
  11417. _this.updateShowing();
  11418. _this.on(_this.player(), 'durationchange', _this.updateShowing);
  11419. return _this;
  11420. }
  11421. /**
  11422. * Create the `Component`'s DOM element
  11423. *
  11424. * @return {Element}
  11425. * The element that was created.
  11426. */
  11427. var _proto = LiveDisplay.prototype;
  11428. _proto.createEl = function createEl$1() {
  11429. var el = _Component.prototype.createEl.call(this, 'div', {
  11430. className: 'vjs-live-control vjs-control'
  11431. });
  11432. this.contentEl_ = createEl('div', {
  11433. className: 'vjs-live-display',
  11434. innerHTML: "<span class=\"vjs-control-text\">" + this.localize('Stream Type') + "\xA0</span>" + this.localize('LIVE')
  11435. }, {
  11436. 'aria-live': 'off'
  11437. });
  11438. el.appendChild(this.contentEl_);
  11439. return el;
  11440. };
  11441. _proto.dispose = function dispose() {
  11442. this.contentEl_ = null;
  11443. _Component.prototype.dispose.call(this);
  11444. }
  11445. /**
  11446. * Check the duration to see if the LiveDisplay should be showing or not. Then show/hide
  11447. * it accordingly
  11448. *
  11449. * @param {EventTarget~Event} [event]
  11450. * The {@link Player#durationchange} event that caused this function to run.
  11451. *
  11452. * @listens Player#durationchange
  11453. */
  11454. ;
  11455. _proto.updateShowing = function updateShowing(event) {
  11456. if (this.player().duration() === Infinity) {
  11457. this.show();
  11458. } else {
  11459. this.hide();
  11460. }
  11461. };
  11462. return LiveDisplay;
  11463. }(Component);
  11464. Component.registerComponent('LiveDisplay', LiveDisplay);
  11465. /**
  11466. * Displays the live indicator when duration is Infinity.
  11467. *
  11468. * @extends Component
  11469. */
  11470. var SeekToLive =
  11471. /*#__PURE__*/
  11472. function (_Button) {
  11473. _inheritsLoose(SeekToLive, _Button);
  11474. /**
  11475. * Creates an instance of this class.
  11476. *
  11477. * @param {Player} player
  11478. * The `Player` that this class should be attached to.
  11479. *
  11480. * @param {Object} [options]
  11481. * The key/value store of player options.
  11482. */
  11483. function SeekToLive(player, options) {
  11484. var _this;
  11485. _this = _Button.call(this, player, options) || this;
  11486. _this.updateLiveEdgeStatus();
  11487. if (_this.player_.liveTracker) {
  11488. _this.on(_this.player_.liveTracker, 'liveedgechange', _this.updateLiveEdgeStatus);
  11489. }
  11490. return _this;
  11491. }
  11492. /**
  11493. * Create the `Component`'s DOM element
  11494. *
  11495. * @return {Element}
  11496. * The element that was created.
  11497. */
  11498. var _proto = SeekToLive.prototype;
  11499. _proto.createEl = function createEl$1() {
  11500. var el = _Button.prototype.createEl.call(this, 'button', {
  11501. className: 'vjs-seek-to-live-control vjs-control'
  11502. });
  11503. this.textEl_ = createEl('span', {
  11504. className: 'vjs-seek-to-live-text',
  11505. innerHTML: this.localize('LIVE')
  11506. }, {
  11507. 'aria-hidden': 'true'
  11508. });
  11509. el.appendChild(this.textEl_);
  11510. return el;
  11511. }
  11512. /**
  11513. * Update the state of this button if we are at the live edge
  11514. * or not
  11515. */
  11516. ;
  11517. _proto.updateLiveEdgeStatus = function updateLiveEdgeStatus(e) {
  11518. // default to live edge
  11519. if (!this.player_.liveTracker || this.player_.liveTracker.atLiveEdge()) {
  11520. this.setAttribute('aria-disabled', true);
  11521. this.addClass('vjs-at-live-edge');
  11522. this.controlText('Seek to live, currently playing live');
  11523. } else {
  11524. this.setAttribute('aria-disabled', false);
  11525. this.removeClass('vjs-at-live-edge');
  11526. this.controlText('Seek to live, currently behind live');
  11527. }
  11528. }
  11529. /**
  11530. * On click bring us as near to the live point as possible.
  11531. * This requires that we wait for the next `live-seekable-change`
  11532. * event which will happen every segment length seconds.
  11533. */
  11534. ;
  11535. _proto.handleClick = function handleClick() {
  11536. this.player_.liveTracker.seekToLiveEdge();
  11537. }
  11538. /**
  11539. * Dispose of the element and stop tracking
  11540. */
  11541. ;
  11542. _proto.dispose = function dispose() {
  11543. if (this.player_.liveTracker) {
  11544. this.off(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatus);
  11545. }
  11546. this.textEl_ = null;
  11547. _Button.prototype.dispose.call(this);
  11548. };
  11549. return SeekToLive;
  11550. }(Button);
  11551. SeekToLive.prototype.controlText_ = 'Seek to live, currently playing live';
  11552. Component.registerComponent('SeekToLive', SeekToLive);
  11553. /**
  11554. * The base functionality for a slider. Can be vertical or horizontal.
  11555. * For instance the volume bar or the seek bar on a video is a slider.
  11556. *
  11557. * @extends Component
  11558. */
  11559. var Slider =
  11560. /*#__PURE__*/
  11561. function (_Component) {
  11562. _inheritsLoose(Slider, _Component);
  11563. /**
  11564. * Create an instance of this class
  11565. *
  11566. * @param {Player} player
  11567. * The `Player` that this class should be attached to.
  11568. *
  11569. * @param {Object} [options]
  11570. * The key/value store of player options.
  11571. */
  11572. function Slider(player, options) {
  11573. var _this;
  11574. _this = _Component.call(this, player, options) || this; // Set property names to bar to match with the child Slider class is looking for
  11575. _this.bar = _this.getChild(_this.options_.barName); // Set a horizontal or vertical class on the slider depending on the slider type
  11576. _this.vertical(!!_this.options_.vertical);
  11577. _this.enable();
  11578. return _this;
  11579. }
  11580. /**
  11581. * Are controls are currently enabled for this slider or not.
  11582. *
  11583. * @return {boolean}
  11584. * true if controls are enabled, false otherwise
  11585. */
  11586. var _proto = Slider.prototype;
  11587. _proto.enabled = function enabled() {
  11588. return this.enabled_;
  11589. }
  11590. /**
  11591. * Enable controls for this slider if they are disabled
  11592. */
  11593. ;
  11594. _proto.enable = function enable() {
  11595. if (this.enabled()) {
  11596. return;
  11597. }
  11598. this.on('mousedown', this.handleMouseDown);
  11599. this.on('touchstart', this.handleMouseDown);
  11600. this.on('keydown', this.handleKeyDown);
  11601. this.on('click', this.handleClick); // TODO: deprecated, controlsvisible does not seem to be fired
  11602. this.on(this.player_, 'controlsvisible', this.update);
  11603. if (this.playerEvent) {
  11604. this.on(this.player_, this.playerEvent, this.update);
  11605. }
  11606. this.removeClass('disabled');
  11607. this.setAttribute('tabindex', 0);
  11608. this.enabled_ = true;
  11609. }
  11610. /**
  11611. * Disable controls for this slider if they are enabled
  11612. */
  11613. ;
  11614. _proto.disable = function disable() {
  11615. if (!this.enabled()) {
  11616. return;
  11617. }
  11618. var doc = this.bar.el_.ownerDocument;
  11619. this.off('mousedown', this.handleMouseDown);
  11620. this.off('touchstart', this.handleMouseDown);
  11621. this.off('keydown', this.handleKeyDown);
  11622. this.off('click', this.handleClick);
  11623. this.off(this.player_, 'controlsvisible', this.update);
  11624. this.off(doc, 'mousemove', this.handleMouseMove);
  11625. this.off(doc, 'mouseup', this.handleMouseUp);
  11626. this.off(doc, 'touchmove', this.handleMouseMove);
  11627. this.off(doc, 'touchend', this.handleMouseUp);
  11628. this.removeAttribute('tabindex');
  11629. this.addClass('disabled');
  11630. if (this.playerEvent) {
  11631. this.off(this.player_, this.playerEvent, this.update);
  11632. }
  11633. this.enabled_ = false;
  11634. }
  11635. /**
  11636. * Create the `Slider`s DOM element.
  11637. *
  11638. * @param {string} type
  11639. * Type of element to create.
  11640. *
  11641. * @param {Object} [props={}]
  11642. * List of properties in Object form.
  11643. *
  11644. * @param {Object} [attributes={}]
  11645. * list of attributes in Object form.
  11646. *
  11647. * @return {Element}
  11648. * The element that gets created.
  11649. */
  11650. ;
  11651. _proto.createEl = function createEl(type, props, attributes) {
  11652. if (props === void 0) {
  11653. props = {};
  11654. }
  11655. if (attributes === void 0) {
  11656. attributes = {};
  11657. }
  11658. // Add the slider element class to all sub classes
  11659. props.className = props.className + ' vjs-slider';
  11660. props = assign({
  11661. tabIndex: 0
  11662. }, props);
  11663. attributes = assign({
  11664. 'role': 'slider',
  11665. 'aria-valuenow': 0,
  11666. 'aria-valuemin': 0,
  11667. 'aria-valuemax': 100,
  11668. 'tabIndex': 0
  11669. }, attributes);
  11670. return _Component.prototype.createEl.call(this, type, props, attributes);
  11671. }
  11672. /**
  11673. * Handle `mousedown` or `touchstart` events on the `Slider`.
  11674. *
  11675. * @param {EventTarget~Event} event
  11676. * `mousedown` or `touchstart` event that triggered this function
  11677. *
  11678. * @listens mousedown
  11679. * @listens touchstart
  11680. * @fires Slider#slideractive
  11681. */
  11682. ;
  11683. _proto.handleMouseDown = function handleMouseDown(event) {
  11684. var doc = this.bar.el_.ownerDocument;
  11685. if (event.type === 'mousedown') {
  11686. event.preventDefault();
  11687. } // Do not call preventDefault() on touchstart in Chrome
  11688. // to avoid console warnings. Use a 'touch-action: none' style
  11689. // instead to prevent unintented scrolling.
  11690. // https://developers.google.com/web/updates/2017/01/scrolling-intervention
  11691. if (event.type === 'touchstart' && !IS_CHROME) {
  11692. event.preventDefault();
  11693. }
  11694. blockTextSelection();
  11695. this.addClass('vjs-sliding');
  11696. /**
  11697. * Triggered when the slider is in an active state
  11698. *
  11699. * @event Slider#slideractive
  11700. * @type {EventTarget~Event}
  11701. */
  11702. this.trigger('slideractive');
  11703. this.on(doc, 'mousemove', this.handleMouseMove);
  11704. this.on(doc, 'mouseup', this.handleMouseUp);
  11705. this.on(doc, 'touchmove', this.handleMouseMove);
  11706. this.on(doc, 'touchend', this.handleMouseUp);
  11707. this.handleMouseMove(event);
  11708. }
  11709. /**
  11710. * Handle the `mousemove`, `touchmove`, and `mousedown` events on this `Slider`.
  11711. * The `mousemove` and `touchmove` events will only only trigger this function during
  11712. * `mousedown` and `touchstart`. This is due to {@link Slider#handleMouseDown} and
  11713. * {@link Slider#handleMouseUp}.
  11714. *
  11715. * @param {EventTarget~Event} event
  11716. * `mousedown`, `mousemove`, `touchstart`, or `touchmove` event that triggered
  11717. * this function
  11718. *
  11719. * @listens mousemove
  11720. * @listens touchmove
  11721. */
  11722. ;
  11723. _proto.handleMouseMove = function handleMouseMove(event) {}
  11724. /**
  11725. * Handle `mouseup` or `touchend` events on the `Slider`.
  11726. *
  11727. * @param {EventTarget~Event} event
  11728. * `mouseup` or `touchend` event that triggered this function.
  11729. *
  11730. * @listens touchend
  11731. * @listens mouseup
  11732. * @fires Slider#sliderinactive
  11733. */
  11734. ;
  11735. _proto.handleMouseUp = function handleMouseUp() {
  11736. var doc = this.bar.el_.ownerDocument;
  11737. unblockTextSelection();
  11738. this.removeClass('vjs-sliding');
  11739. /**
  11740. * Triggered when the slider is no longer in an active state.
  11741. *
  11742. * @event Slider#sliderinactive
  11743. * @type {EventTarget~Event}
  11744. */
  11745. this.trigger('sliderinactive');
  11746. this.off(doc, 'mousemove', this.handleMouseMove);
  11747. this.off(doc, 'mouseup', this.handleMouseUp);
  11748. this.off(doc, 'touchmove', this.handleMouseMove);
  11749. this.off(doc, 'touchend', this.handleMouseUp);
  11750. this.update();
  11751. }
  11752. /**
  11753. * Update the progress bar of the `Slider`.
  11754. *
  11755. * @return {number}
  11756. * The percentage of progress the progress bar represents as a
  11757. * number from 0 to 1.
  11758. */
  11759. ;
  11760. _proto.update = function update() {
  11761. // In VolumeBar init we have a setTimeout for update that pops and update
  11762. // to the end of the execution stack. The player is destroyed before then
  11763. // update will cause an error
  11764. if (!this.el_) {
  11765. return;
  11766. } // If scrubbing, we could use a cached value to make the handle keep up
  11767. // with the user's mouse. On HTML5 browsers scrubbing is really smooth, but
  11768. // some flash players are slow, so we might want to utilize this later.
  11769. // var progress = (this.player_.scrubbing()) ? this.player_.getCache().currentTime / this.player_.duration() : this.player_.currentTime() / this.player_.duration();
  11770. var progress = this.getPercent();
  11771. var bar = this.bar; // If there's no bar...
  11772. if (!bar) {
  11773. return;
  11774. } // Protect against no duration and other division issues
  11775. if (typeof progress !== 'number' || progress !== progress || progress < 0 || progress === Infinity) {
  11776. progress = 0;
  11777. } // Convert to a percentage for setting
  11778. var percentage = (progress * 100).toFixed(2) + '%';
  11779. var style = bar.el().style; // Set the new bar width or height
  11780. var sizeKey = this.vertical() ? 'height' : 'width';
  11781. if (style[sizeKey] !== percentage) {
  11782. style[sizeKey] = percentage;
  11783. }
  11784. return progress;
  11785. }
  11786. /**
  11787. * Calculate distance for slider
  11788. *
  11789. * @param {EventTarget~Event} event
  11790. * The event that caused this function to run.
  11791. *
  11792. * @return {number}
  11793. * The current position of the Slider.
  11794. * - position.x for vertical `Slider`s
  11795. * - position.y for horizontal `Slider`s
  11796. */
  11797. ;
  11798. _proto.calculateDistance = function calculateDistance(event) {
  11799. var position = getPointerPosition(this.el_, event);
  11800. if (this.vertical()) {
  11801. return position.y;
  11802. }
  11803. return position.x;
  11804. }
  11805. /**
  11806. * Handle a `keydown` event on the `Slider`. Watches for left, rigth, up, and down
  11807. * arrow keys. This function will only be called when the slider has focus. See
  11808. * {@link Slider#handleFocus} and {@link Slider#handleBlur}.
  11809. *
  11810. * @param {EventTarget~Event} event
  11811. * the `keydown` event that caused this function to run.
  11812. *
  11813. * @listens keydown
  11814. */
  11815. ;
  11816. _proto.handleKeyDown = function handleKeyDown(event) {
  11817. // Left and Down Arrows
  11818. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  11819. event.preventDefault();
  11820. event.stopPropagation();
  11821. this.stepBack(); // Up and Right Arrows
  11822. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  11823. event.preventDefault();
  11824. event.stopPropagation();
  11825. this.stepForward();
  11826. } else {
  11827. // Pass keydown handling up for unsupported keys
  11828. _Component.prototype.handleKeyDown.call(this, event);
  11829. }
  11830. }
  11831. /**
  11832. * Listener for click events on slider, used to prevent clicks
  11833. * from bubbling up to parent elements like button menus.
  11834. *
  11835. * @param {Object} event
  11836. * Event that caused this object to run
  11837. */
  11838. ;
  11839. _proto.handleClick = function handleClick(event) {
  11840. event.stopPropagation();
  11841. event.preventDefault();
  11842. }
  11843. /**
  11844. * Get/set if slider is horizontal for vertical
  11845. *
  11846. * @param {boolean} [bool]
  11847. * - true if slider is vertical,
  11848. * - false is horizontal
  11849. *
  11850. * @return {boolean}
  11851. * - true if slider is vertical, and getting
  11852. * - false if the slider is horizontal, and getting
  11853. */
  11854. ;
  11855. _proto.vertical = function vertical(bool) {
  11856. if (bool === undefined) {
  11857. return this.vertical_ || false;
  11858. }
  11859. this.vertical_ = !!bool;
  11860. if (this.vertical_) {
  11861. this.addClass('vjs-slider-vertical');
  11862. } else {
  11863. this.addClass('vjs-slider-horizontal');
  11864. }
  11865. };
  11866. return Slider;
  11867. }(Component);
  11868. Component.registerComponent('Slider', Slider);
  11869. /**
  11870. * Shows loading progress
  11871. *
  11872. * @extends Component
  11873. */
  11874. var LoadProgressBar =
  11875. /*#__PURE__*/
  11876. function (_Component) {
  11877. _inheritsLoose(LoadProgressBar, _Component);
  11878. /**
  11879. * Creates an instance of this class.
  11880. *
  11881. * @param {Player} player
  11882. * The `Player` that this class should be attached to.
  11883. *
  11884. * @param {Object} [options]
  11885. * The key/value store of player options.
  11886. */
  11887. function LoadProgressBar(player, options) {
  11888. var _this;
  11889. _this = _Component.call(this, player, options) || this;
  11890. _this.partEls_ = [];
  11891. _this.on(player, 'progress', _this.update);
  11892. return _this;
  11893. }
  11894. /**
  11895. * Create the `Component`'s DOM element
  11896. *
  11897. * @return {Element}
  11898. * The element that was created.
  11899. */
  11900. var _proto = LoadProgressBar.prototype;
  11901. _proto.createEl = function createEl() {
  11902. return _Component.prototype.createEl.call(this, 'div', {
  11903. className: 'vjs-load-progress',
  11904. innerHTML: "<span class=\"vjs-control-text\"><span>" + this.localize('Loaded') + "</span>: <span class=\"vjs-control-text-loaded-percentage\">0%</span></span>"
  11905. });
  11906. };
  11907. _proto.dispose = function dispose() {
  11908. this.partEls_ = null;
  11909. _Component.prototype.dispose.call(this);
  11910. }
  11911. /**
  11912. * Update progress bar
  11913. *
  11914. * @param {EventTarget~Event} [event]
  11915. * The `progress` event that caused this function to run.
  11916. *
  11917. * @listens Player#progress
  11918. */
  11919. ;
  11920. _proto.update = function update(event) {
  11921. var liveTracker = this.player_.liveTracker;
  11922. var buffered = this.player_.buffered();
  11923. var duration = liveTracker && liveTracker.isLive() ? liveTracker.seekableEnd() : this.player_.duration();
  11924. var bufferedEnd = this.player_.bufferedEnd();
  11925. var children = this.partEls_;
  11926. var controlTextPercentage = this.$('.vjs-control-text-loaded-percentage'); // get the percent width of a time compared to the total end
  11927. var percentify = function percentify(time, end, rounded) {
  11928. // no NaN
  11929. var percent = time / end || 0;
  11930. percent = (percent >= 1 ? 1 : percent) * 100;
  11931. if (rounded) {
  11932. percent = percent.toFixed(2);
  11933. }
  11934. return percent + '%';
  11935. }; // update the width of the progress bar
  11936. this.el_.style.width = percentify(bufferedEnd, duration); // update the control-text
  11937. textContent(controlTextPercentage, percentify(bufferedEnd, duration, true)); // add child elements to represent the individual buffered time ranges
  11938. for (var i = 0; i < buffered.length; i++) {
  11939. var start = buffered.start(i);
  11940. var end = buffered.end(i);
  11941. var part = children[i];
  11942. if (!part) {
  11943. part = this.el_.appendChild(createEl());
  11944. children[i] = part;
  11945. } // set the percent based on the width of the progress bar (bufferedEnd)
  11946. part.style.left = percentify(start, bufferedEnd);
  11947. part.style.width = percentify(end - start, bufferedEnd);
  11948. } // remove unused buffered range elements
  11949. for (var _i = children.length; _i > buffered.length; _i--) {
  11950. this.el_.removeChild(children[_i - 1]);
  11951. }
  11952. children.length = buffered.length;
  11953. };
  11954. return LoadProgressBar;
  11955. }(Component);
  11956. Component.registerComponent('LoadProgressBar', LoadProgressBar);
  11957. /**
  11958. * Time tooltips display a time above the progress bar.
  11959. *
  11960. * @extends Component
  11961. */
  11962. var TimeTooltip =
  11963. /*#__PURE__*/
  11964. function (_Component) {
  11965. _inheritsLoose(TimeTooltip, _Component);
  11966. /**
  11967. * Creates an instance of this class.
  11968. *
  11969. * @param {Player} player
  11970. * The {@link Player} that this class should be attached to.
  11971. *
  11972. * @param {Object} [options]
  11973. * The key/value store of player options.
  11974. */
  11975. function TimeTooltip(player, options) {
  11976. var _this;
  11977. _this = _Component.call(this, player, options) || this;
  11978. _this.update = throttle(bind(_assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  11979. return _this;
  11980. }
  11981. /**
  11982. * Create the time tooltip DOM element
  11983. *
  11984. * @return {Element}
  11985. * The element that was created.
  11986. */
  11987. var _proto = TimeTooltip.prototype;
  11988. _proto.createEl = function createEl() {
  11989. return _Component.prototype.createEl.call(this, 'div', {
  11990. className: 'vjs-time-tooltip'
  11991. }, {
  11992. 'aria-hidden': 'true'
  11993. });
  11994. }
  11995. /**
  11996. * Updates the position of the time tooltip relative to the `SeekBar`.
  11997. *
  11998. * @param {Object} seekBarRect
  11999. * The `ClientRect` for the {@link SeekBar} element.
  12000. *
  12001. * @param {number} seekBarPoint
  12002. * A number from 0 to 1, representing a horizontal reference point
  12003. * from the left edge of the {@link SeekBar}
  12004. */
  12005. ;
  12006. _proto.update = function update(seekBarRect, seekBarPoint, content) {
  12007. var tooltipRect = getBoundingClientRect(this.el_);
  12008. var playerRect = getBoundingClientRect(this.player_.el());
  12009. var seekBarPointPx = seekBarRect.width * seekBarPoint; // do nothing if either rect isn't available
  12010. // for example, if the player isn't in the DOM for testing
  12011. if (!playerRect || !tooltipRect) {
  12012. return;
  12013. } // This is the space left of the `seekBarPoint` available within the bounds
  12014. // of the player. We calculate any gap between the left edge of the player
  12015. // and the left edge of the `SeekBar` and add the number of pixels in the
  12016. // `SeekBar` before hitting the `seekBarPoint`
  12017. var spaceLeftOfPoint = seekBarRect.left - playerRect.left + seekBarPointPx; // This is the space right of the `seekBarPoint` available within the bounds
  12018. // of the player. We calculate the number of pixels from the `seekBarPoint`
  12019. // to the right edge of the `SeekBar` and add to that any gap between the
  12020. // right edge of the `SeekBar` and the player.
  12021. var spaceRightOfPoint = seekBarRect.width - seekBarPointPx + (playerRect.right - seekBarRect.right); // This is the number of pixels by which the tooltip will need to be pulled
  12022. // further to the right to center it over the `seekBarPoint`.
  12023. var pullTooltipBy = tooltipRect.width / 2; // Adjust the `pullTooltipBy` distance to the left or right depending on
  12024. // the results of the space calculations above.
  12025. if (spaceLeftOfPoint < pullTooltipBy) {
  12026. pullTooltipBy += pullTooltipBy - spaceLeftOfPoint;
  12027. } else if (spaceRightOfPoint < pullTooltipBy) {
  12028. pullTooltipBy = spaceRightOfPoint;
  12029. } // Due to the imprecision of decimal/ratio based calculations and varying
  12030. // rounding behaviors, there are cases where the spacing adjustment is off
  12031. // by a pixel or two. This adds insurance to these calculations.
  12032. if (pullTooltipBy < 0) {
  12033. pullTooltipBy = 0;
  12034. } else if (pullTooltipBy > tooltipRect.width) {
  12035. pullTooltipBy = tooltipRect.width;
  12036. }
  12037. this.el_.style.right = "-" + pullTooltipBy + "px";
  12038. this.write(content);
  12039. }
  12040. /**
  12041. * Write the time to the tooltip DOM element.
  12042. *
  12043. * @param {string} content
  12044. * The formatted time for the tooltip.
  12045. */
  12046. ;
  12047. _proto.write = function write(content) {
  12048. textContent(this.el_, content);
  12049. }
  12050. /**
  12051. * Updates the position of the time tooltip relative to the `SeekBar`.
  12052. *
  12053. * @param {Object} seekBarRect
  12054. * The `ClientRect` for the {@link SeekBar} element.
  12055. *
  12056. * @param {number} seekBarPoint
  12057. * A number from 0 to 1, representing a horizontal reference point
  12058. * from the left edge of the {@link SeekBar}
  12059. *
  12060. * @param {number} time
  12061. * The time to update the tooltip to, not used during live playback
  12062. *
  12063. * @param {Function} cb
  12064. * A function that will be called during the request animation frame
  12065. * for tooltips that need to do additional animations from the default
  12066. */
  12067. ;
  12068. _proto.updateTime = function updateTime(seekBarRect, seekBarPoint, time, cb) {
  12069. var _this2 = this;
  12070. // If there is an existing rAF ID, cancel it so we don't over-queue.
  12071. if (this.rafId_) {
  12072. this.cancelAnimationFrame(this.rafId_);
  12073. }
  12074. this.rafId_ = this.requestAnimationFrame(function () {
  12075. var content;
  12076. var duration = _this2.player_.duration();
  12077. if (_this2.player_.liveTracker && _this2.player_.liveTracker.isLive()) {
  12078. var liveWindow = _this2.player_.liveTracker.liveWindow();
  12079. var secondsBehind = liveWindow - seekBarPoint * liveWindow;
  12080. content = (secondsBehind < 1 ? '' : '-') + formatTime(secondsBehind, liveWindow);
  12081. } else {
  12082. content = formatTime(time, duration);
  12083. }
  12084. _this2.update(seekBarRect, seekBarPoint, content);
  12085. if (cb) {
  12086. cb();
  12087. }
  12088. });
  12089. };
  12090. return TimeTooltip;
  12091. }(Component);
  12092. Component.registerComponent('TimeTooltip', TimeTooltip);
  12093. /**
  12094. * Used by {@link SeekBar} to display media playback progress as part of the
  12095. * {@link ProgressControl}.
  12096. *
  12097. * @extends Component
  12098. */
  12099. var PlayProgressBar =
  12100. /*#__PURE__*/
  12101. function (_Component) {
  12102. _inheritsLoose(PlayProgressBar, _Component);
  12103. /**
  12104. * Creates an instance of this class.
  12105. *
  12106. * @param {Player} player
  12107. * The {@link Player} that this class should be attached to.
  12108. *
  12109. * @param {Object} [options]
  12110. * The key/value store of player options.
  12111. */
  12112. function PlayProgressBar(player, options) {
  12113. var _this;
  12114. _this = _Component.call(this, player, options) || this;
  12115. _this.update = throttle(bind(_assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  12116. return _this;
  12117. }
  12118. /**
  12119. * Create the the DOM element for this class.
  12120. *
  12121. * @return {Element}
  12122. * The element that was created.
  12123. */
  12124. var _proto = PlayProgressBar.prototype;
  12125. _proto.createEl = function createEl() {
  12126. return _Component.prototype.createEl.call(this, 'div', {
  12127. className: 'vjs-play-progress vjs-slider-bar'
  12128. }, {
  12129. 'aria-hidden': 'true'
  12130. });
  12131. }
  12132. /**
  12133. * Enqueues updates to its own DOM as well as the DOM of its
  12134. * {@link TimeTooltip} child.
  12135. *
  12136. * @param {Object} seekBarRect
  12137. * The `ClientRect` for the {@link SeekBar} element.
  12138. *
  12139. * @param {number} seekBarPoint
  12140. * A number from 0 to 1, representing a horizontal reference point
  12141. * from the left edge of the {@link SeekBar}
  12142. */
  12143. ;
  12144. _proto.update = function update(seekBarRect, seekBarPoint) {
  12145. var timeTooltip = this.getChild('timeTooltip');
  12146. if (!timeTooltip) {
  12147. return;
  12148. }
  12149. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  12150. timeTooltip.updateTime(seekBarRect, seekBarPoint, time);
  12151. };
  12152. return PlayProgressBar;
  12153. }(Component);
  12154. /**
  12155. * Default options for {@link PlayProgressBar}.
  12156. *
  12157. * @type {Object}
  12158. * @private
  12159. */
  12160. PlayProgressBar.prototype.options_ = {
  12161. children: []
  12162. }; // Time tooltips should not be added to a player on mobile devices
  12163. if (!IS_IOS && !IS_ANDROID) {
  12164. PlayProgressBar.prototype.options_.children.push('timeTooltip');
  12165. }
  12166. Component.registerComponent('PlayProgressBar', PlayProgressBar);
  12167. /**
  12168. * The {@link MouseTimeDisplay} component tracks mouse movement over the
  12169. * {@link ProgressControl}. It displays an indicator and a {@link TimeTooltip}
  12170. * indicating the time which is represented by a given point in the
  12171. * {@link ProgressControl}.
  12172. *
  12173. * @extends Component
  12174. */
  12175. var MouseTimeDisplay =
  12176. /*#__PURE__*/
  12177. function (_Component) {
  12178. _inheritsLoose(MouseTimeDisplay, _Component);
  12179. /**
  12180. * Creates an instance of this class.
  12181. *
  12182. * @param {Player} player
  12183. * The {@link Player} that this class should be attached to.
  12184. *
  12185. * @param {Object} [options]
  12186. * The key/value store of player options.
  12187. */
  12188. function MouseTimeDisplay(player, options) {
  12189. var _this;
  12190. _this = _Component.call(this, player, options) || this;
  12191. _this.update = throttle(bind(_assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  12192. return _this;
  12193. }
  12194. /**
  12195. * Create the DOM element for this class.
  12196. *
  12197. * @return {Element}
  12198. * The element that was created.
  12199. */
  12200. var _proto = MouseTimeDisplay.prototype;
  12201. _proto.createEl = function createEl() {
  12202. return _Component.prototype.createEl.call(this, 'div', {
  12203. className: 'vjs-mouse-display'
  12204. });
  12205. }
  12206. /**
  12207. * Enqueues updates to its own DOM as well as the DOM of its
  12208. * {@link TimeTooltip} child.
  12209. *
  12210. * @param {Object} seekBarRect
  12211. * The `ClientRect` for the {@link SeekBar} element.
  12212. *
  12213. * @param {number} seekBarPoint
  12214. * A number from 0 to 1, representing a horizontal reference point
  12215. * from the left edge of the {@link SeekBar}
  12216. */
  12217. ;
  12218. _proto.update = function update(seekBarRect, seekBarPoint) {
  12219. var _this2 = this;
  12220. var time = seekBarPoint * this.player_.duration();
  12221. this.getChild('timeTooltip').updateTime(seekBarRect, seekBarPoint, time, function () {
  12222. _this2.el_.style.left = seekBarRect.width * seekBarPoint + "px";
  12223. });
  12224. };
  12225. return MouseTimeDisplay;
  12226. }(Component);
  12227. /**
  12228. * Default options for `MouseTimeDisplay`
  12229. *
  12230. * @type {Object}
  12231. * @private
  12232. */
  12233. MouseTimeDisplay.prototype.options_ = {
  12234. children: ['timeTooltip']
  12235. };
  12236. Component.registerComponent('MouseTimeDisplay', MouseTimeDisplay);
  12237. var STEP_SECONDS = 5; // The multiplier of STEP_SECONDS that PgUp/PgDown move the timeline.
  12238. var PAGE_KEY_MULTIPLIER = 12; // The interval at which the bar should update as it progresses.
  12239. var UPDATE_REFRESH_INTERVAL$1 = 30;
  12240. /**
  12241. * Seek bar and container for the progress bars. Uses {@link PlayProgressBar}
  12242. * as its `bar`.
  12243. *
  12244. * @extends Slider
  12245. */
  12246. var SeekBar =
  12247. /*#__PURE__*/
  12248. function (_Slider) {
  12249. _inheritsLoose(SeekBar, _Slider);
  12250. /**
  12251. * Creates an instance of this class.
  12252. *
  12253. * @param {Player} player
  12254. * The `Player` that this class should be attached to.
  12255. *
  12256. * @param {Object} [options]
  12257. * The key/value store of player options.
  12258. */
  12259. function SeekBar(player, options) {
  12260. var _this;
  12261. _this = _Slider.call(this, player, options) || this;
  12262. _this.setEventHandlers_();
  12263. return _this;
  12264. }
  12265. /**
  12266. * Sets the event handlers
  12267. *
  12268. * @private
  12269. */
  12270. var _proto = SeekBar.prototype;
  12271. _proto.setEventHandlers_ = function setEventHandlers_() {
  12272. this.update = throttle(bind(this, this.update), UPDATE_REFRESH_INTERVAL$1);
  12273. this.on(this.player_, 'timeupdate', this.update);
  12274. this.on(this.player_, 'ended', this.handleEnded);
  12275. this.on(this.player_, 'durationchange', this.update);
  12276. if (this.player_.liveTracker) {
  12277. this.on(this.player_.liveTracker, 'liveedgechange', this.update);
  12278. } // when playing, let's ensure we smoothly update the play progress bar
  12279. // via an interval
  12280. this.updateInterval = null;
  12281. this.on(this.player_, ['playing'], this.enableInterval_);
  12282. this.on(this.player_, ['ended', 'pause', 'waiting'], this.disableInterval_); // we don't need to update the play progress if the document is hidden,
  12283. // also, this causes the CPU to spike and eventually crash the page on IE11.
  12284. if ('hidden' in document && 'visibilityState' in document) {
  12285. this.on(document, 'visibilitychange', this.toggleVisibility_);
  12286. }
  12287. };
  12288. _proto.toggleVisibility_ = function toggleVisibility_(e) {
  12289. if (document.hidden) {
  12290. this.disableInterval_(e);
  12291. } else {
  12292. this.enableInterval_(); // we just switched back to the page and someone may be looking, so, update ASAP
  12293. this.requestAnimationFrame(this.update);
  12294. }
  12295. };
  12296. _proto.enableInterval_ = function enableInterval_() {
  12297. var _this2 = this;
  12298. this.clearInterval(this.updateInterval);
  12299. this.updateInterval = this.setInterval(function () {
  12300. _this2.requestAnimationFrame(_this2.update);
  12301. }, UPDATE_REFRESH_INTERVAL$1);
  12302. };
  12303. _proto.disableInterval_ = function disableInterval_(e) {
  12304. if (this.player_.liveTracker && this.player_.liveTracker.isLive() && e.type !== 'ended') {
  12305. return;
  12306. }
  12307. this.clearInterval(this.updateInterval);
  12308. }
  12309. /**
  12310. * Create the `Component`'s DOM element
  12311. *
  12312. * @return {Element}
  12313. * The element that was created.
  12314. */
  12315. ;
  12316. _proto.createEl = function createEl() {
  12317. return _Slider.prototype.createEl.call(this, 'div', {
  12318. className: 'vjs-progress-holder'
  12319. }, {
  12320. 'aria-label': this.localize('Progress Bar')
  12321. });
  12322. }
  12323. /**
  12324. * This function updates the play progress bar and accessibility
  12325. * attributes to whatever is passed in.
  12326. *
  12327. * @param {number} currentTime
  12328. * The currentTime value that should be used for accessibility
  12329. *
  12330. * @param {number} percent
  12331. * The percentage as a decimal that the bar should be filled from 0-1.
  12332. *
  12333. * @private
  12334. */
  12335. ;
  12336. _proto.update_ = function update_(currentTime, percent) {
  12337. var liveTracker = this.player_.liveTracker;
  12338. var duration = this.player_.duration();
  12339. if (liveTracker && liveTracker.isLive()) {
  12340. duration = this.player_.liveTracker.liveCurrentTime();
  12341. } // machine readable value of progress bar (percentage complete)
  12342. this.el_.setAttribute('aria-valuenow', (percent * 100).toFixed(2)); // human readable value of progress bar (time complete)
  12343. this.el_.setAttribute('aria-valuetext', this.localize('progress bar timing: currentTime={1} duration={2}', [formatTime(currentTime, duration), formatTime(duration, duration)], '{1} of {2}')); // Update the `PlayProgressBar`.
  12344. if (this.bar) {
  12345. this.bar.update(getBoundingClientRect(this.el_), percent);
  12346. }
  12347. }
  12348. /**
  12349. * Update the seek bar's UI.
  12350. *
  12351. * @param {EventTarget~Event} [event]
  12352. * The `timeupdate` or `ended` event that caused this to run.
  12353. *
  12354. * @listens Player#timeupdate
  12355. *
  12356. * @return {number}
  12357. * The current percent at a number from 0-1
  12358. */
  12359. ;
  12360. _proto.update = function update(event) {
  12361. // if the offsetParent is null, then this element is hidden, in which case
  12362. // we don't need to update it.
  12363. if (this.el().offsetParent === null) {
  12364. return;
  12365. }
  12366. var percent = _Slider.prototype.update.call(this);
  12367. this.update_(this.getCurrentTime_(), percent);
  12368. return percent;
  12369. }
  12370. /**
  12371. * Get the value of current time but allows for smooth scrubbing,
  12372. * when player can't keep up.
  12373. *
  12374. * @return {number}
  12375. * The current time value to display
  12376. *
  12377. * @private
  12378. */
  12379. ;
  12380. _proto.getCurrentTime_ = function getCurrentTime_() {
  12381. return this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  12382. }
  12383. /**
  12384. * We want the seek bar to be full on ended
  12385. * no matter what the actual internal values are. so we force it.
  12386. *
  12387. * @param {EventTarget~Event} [event]
  12388. * The `timeupdate` or `ended` event that caused this to run.
  12389. *
  12390. * @listens Player#ended
  12391. */
  12392. ;
  12393. _proto.handleEnded = function handleEnded(event) {
  12394. this.update_(this.player_.duration(), 1);
  12395. }
  12396. /**
  12397. * Get the percentage of media played so far.
  12398. *
  12399. * @return {number}
  12400. * The percentage of media played so far (0 to 1).
  12401. */
  12402. ;
  12403. _proto.getPercent = function getPercent() {
  12404. var currentTime = this.getCurrentTime_();
  12405. var percent;
  12406. var liveTracker = this.player_.liveTracker;
  12407. if (liveTracker && liveTracker.isLive()) {
  12408. percent = (currentTime - liveTracker.seekableStart()) / liveTracker.liveWindow(); // prevent the percent from changing at the live edge
  12409. if (liveTracker.atLiveEdge()) {
  12410. percent = 1;
  12411. }
  12412. } else {
  12413. percent = currentTime / this.player_.duration();
  12414. }
  12415. return percent >= 1 ? 1 : percent || 0;
  12416. }
  12417. /**
  12418. * Handle mouse down on seek bar
  12419. *
  12420. * @param {EventTarget~Event} event
  12421. * The `mousedown` event that caused this to run.
  12422. *
  12423. * @listens mousedown
  12424. */
  12425. ;
  12426. _proto.handleMouseDown = function handleMouseDown(event) {
  12427. if (!isSingleLeftClick(event)) {
  12428. return;
  12429. } // Stop event propagation to prevent double fire in progress-control.js
  12430. event.stopPropagation();
  12431. this.player_.scrubbing(true);
  12432. this.videoWasPlaying = !this.player_.paused();
  12433. this.player_.pause();
  12434. _Slider.prototype.handleMouseDown.call(this, event);
  12435. }
  12436. /**
  12437. * Handle mouse move on seek bar
  12438. *
  12439. * @param {EventTarget~Event} event
  12440. * The `mousemove` event that caused this to run.
  12441. *
  12442. * @listens mousemove
  12443. */
  12444. ;
  12445. _proto.handleMouseMove = function handleMouseMove(event) {
  12446. if (!isSingleLeftClick(event)) {
  12447. return;
  12448. }
  12449. var newTime;
  12450. var distance = this.calculateDistance(event);
  12451. var liveTracker = this.player_.liveTracker;
  12452. if (!liveTracker || !liveTracker.isLive()) {
  12453. newTime = distance * this.player_.duration(); // Don't let video end while scrubbing.
  12454. if (newTime === this.player_.duration()) {
  12455. newTime = newTime - 0.1;
  12456. }
  12457. } else {
  12458. var seekableStart = liveTracker.seekableStart();
  12459. var seekableEnd = liveTracker.liveCurrentTime();
  12460. newTime = seekableStart + distance * liveTracker.liveWindow(); // Don't let video end while scrubbing.
  12461. if (newTime >= seekableEnd) {
  12462. newTime = seekableEnd;
  12463. } // Compensate for precision differences so that currentTime is not less
  12464. // than seekable start
  12465. if (newTime <= seekableStart) {
  12466. newTime = seekableStart + 0.1;
  12467. } // On android seekableEnd can be Infinity sometimes,
  12468. // this will cause newTime to be Infinity, which is
  12469. // not a valid currentTime.
  12470. if (newTime === Infinity) {
  12471. return;
  12472. }
  12473. } // Set new time (tell player to seek to new time)
  12474. this.player_.currentTime(newTime);
  12475. };
  12476. _proto.enable = function enable() {
  12477. _Slider.prototype.enable.call(this);
  12478. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  12479. if (!mouseTimeDisplay) {
  12480. return;
  12481. }
  12482. mouseTimeDisplay.show();
  12483. };
  12484. _proto.disable = function disable() {
  12485. _Slider.prototype.disable.call(this);
  12486. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  12487. if (!mouseTimeDisplay) {
  12488. return;
  12489. }
  12490. mouseTimeDisplay.hide();
  12491. }
  12492. /**
  12493. * Handle mouse up on seek bar
  12494. *
  12495. * @param {EventTarget~Event} event
  12496. * The `mouseup` event that caused this to run.
  12497. *
  12498. * @listens mouseup
  12499. */
  12500. ;
  12501. _proto.handleMouseUp = function handleMouseUp(event) {
  12502. _Slider.prototype.handleMouseUp.call(this, event); // Stop event propagation to prevent double fire in progress-control.js
  12503. if (event) {
  12504. event.stopPropagation();
  12505. }
  12506. this.player_.scrubbing(false);
  12507. /**
  12508. * Trigger timeupdate because we're done seeking and the time has changed.
  12509. * This is particularly useful for if the player is paused to time the time displays.
  12510. *
  12511. * @event Tech#timeupdate
  12512. * @type {EventTarget~Event}
  12513. */
  12514. this.player_.trigger({
  12515. type: 'timeupdate',
  12516. target: this,
  12517. manuallyTriggered: true
  12518. });
  12519. if (this.videoWasPlaying) {
  12520. silencePromise(this.player_.play());
  12521. }
  12522. }
  12523. /**
  12524. * Move more quickly fast forward for keyboard-only users
  12525. */
  12526. ;
  12527. _proto.stepForward = function stepForward() {
  12528. this.player_.currentTime(this.player_.currentTime() + STEP_SECONDS);
  12529. }
  12530. /**
  12531. * Move more quickly rewind for keyboard-only users
  12532. */
  12533. ;
  12534. _proto.stepBack = function stepBack() {
  12535. this.player_.currentTime(this.player_.currentTime() - STEP_SECONDS);
  12536. }
  12537. /**
  12538. * Toggles the playback state of the player
  12539. * This gets called when enter or space is used on the seekbar
  12540. *
  12541. * @param {EventTarget~Event} event
  12542. * The `keydown` event that caused this function to be called
  12543. *
  12544. */
  12545. ;
  12546. _proto.handleAction = function handleAction(event) {
  12547. if (this.player_.paused()) {
  12548. this.player_.play();
  12549. } else {
  12550. this.player_.pause();
  12551. }
  12552. }
  12553. /**
  12554. * Called when this SeekBar has focus and a key gets pressed down.
  12555. * Supports the following keys:
  12556. *
  12557. * Space or Enter key fire a click event
  12558. * Home key moves to start of the timeline
  12559. * End key moves to end of the timeline
  12560. * Digit "0" through "9" keys move to 0%, 10% ... 80%, 90% of the timeline
  12561. * PageDown key moves back a larger step than ArrowDown
  12562. * PageUp key moves forward a large step
  12563. *
  12564. * @param {EventTarget~Event} event
  12565. * The `keydown` event that caused this function to be called.
  12566. *
  12567. * @listens keydown
  12568. */
  12569. ;
  12570. _proto.handleKeyDown = function handleKeyDown(event) {
  12571. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  12572. event.preventDefault();
  12573. event.stopPropagation();
  12574. this.handleAction(event);
  12575. } else if (keycode.isEventKey(event, 'Home')) {
  12576. event.preventDefault();
  12577. event.stopPropagation();
  12578. this.player_.currentTime(0);
  12579. } else if (keycode.isEventKey(event, 'End')) {
  12580. event.preventDefault();
  12581. event.stopPropagation();
  12582. this.player_.currentTime(this.player_.duration());
  12583. } else if (/^[0-9]$/.test(keycode(event))) {
  12584. event.preventDefault();
  12585. event.stopPropagation();
  12586. var gotoFraction = (keycode.codes[keycode(event)] - keycode.codes['0']) * 10.0 / 100.0;
  12587. this.player_.currentTime(this.player_.duration() * gotoFraction);
  12588. } else if (keycode.isEventKey(event, 'PgDn')) {
  12589. event.preventDefault();
  12590. event.stopPropagation();
  12591. this.player_.currentTime(this.player_.currentTime() - STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  12592. } else if (keycode.isEventKey(event, 'PgUp')) {
  12593. event.preventDefault();
  12594. event.stopPropagation();
  12595. this.player_.currentTime(this.player_.currentTime() + STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  12596. } else {
  12597. // Pass keydown handling up for unsupported keys
  12598. _Slider.prototype.handleKeyDown.call(this, event);
  12599. }
  12600. };
  12601. return SeekBar;
  12602. }(Slider);
  12603. /**
  12604. * Default options for the `SeekBar`
  12605. *
  12606. * @type {Object}
  12607. * @private
  12608. */
  12609. SeekBar.prototype.options_ = {
  12610. children: ['loadProgressBar', 'playProgressBar'],
  12611. barName: 'playProgressBar'
  12612. }; // MouseTimeDisplay tooltips should not be added to a player on mobile devices
  12613. if (!IS_IOS && !IS_ANDROID) {
  12614. SeekBar.prototype.options_.children.splice(1, 0, 'mouseTimeDisplay');
  12615. }
  12616. Component.registerComponent('SeekBar', SeekBar);
  12617. /**
  12618. * The Progress Control component contains the seek bar, load progress,
  12619. * and play progress.
  12620. *
  12621. * @extends Component
  12622. */
  12623. var ProgressControl =
  12624. /*#__PURE__*/
  12625. function (_Component) {
  12626. _inheritsLoose(ProgressControl, _Component);
  12627. /**
  12628. * Creates an instance of this class.
  12629. *
  12630. * @param {Player} player
  12631. * The `Player` that this class should be attached to.
  12632. *
  12633. * @param {Object} [options]
  12634. * The key/value store of player options.
  12635. */
  12636. function ProgressControl(player, options) {
  12637. var _this;
  12638. _this = _Component.call(this, player, options) || this;
  12639. _this.handleMouseMove = throttle(bind(_assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  12640. _this.throttledHandleMouseSeek = throttle(bind(_assertThisInitialized(_this), _this.handleMouseSeek), UPDATE_REFRESH_INTERVAL);
  12641. _this.enable();
  12642. return _this;
  12643. }
  12644. /**
  12645. * Create the `Component`'s DOM element
  12646. *
  12647. * @return {Element}
  12648. * The element that was created.
  12649. */
  12650. var _proto = ProgressControl.prototype;
  12651. _proto.createEl = function createEl() {
  12652. return _Component.prototype.createEl.call(this, 'div', {
  12653. className: 'vjs-progress-control vjs-control'
  12654. });
  12655. }
  12656. /**
  12657. * When the mouse moves over the `ProgressControl`, the pointer position
  12658. * gets passed down to the `MouseTimeDisplay` component.
  12659. *
  12660. * @param {EventTarget~Event} event
  12661. * The `mousemove` event that caused this function to run.
  12662. *
  12663. * @listen mousemove
  12664. */
  12665. ;
  12666. _proto.handleMouseMove = function handleMouseMove(event) {
  12667. var seekBar = this.getChild('seekBar');
  12668. if (seekBar) {
  12669. var mouseTimeDisplay = seekBar.getChild('mouseTimeDisplay');
  12670. var seekBarEl = seekBar.el();
  12671. var seekBarRect = getBoundingClientRect(seekBarEl);
  12672. var seekBarPoint = getPointerPosition(seekBarEl, event).x; // The default skin has a gap on either side of the `SeekBar`. This means
  12673. // that it's possible to trigger this behavior outside the boundaries of
  12674. // the `SeekBar`. This ensures we stay within it at all times.
  12675. if (seekBarPoint > 1) {
  12676. seekBarPoint = 1;
  12677. } else if (seekBarPoint < 0) {
  12678. seekBarPoint = 0;
  12679. }
  12680. if (mouseTimeDisplay) {
  12681. mouseTimeDisplay.update(seekBarRect, seekBarPoint);
  12682. }
  12683. }
  12684. }
  12685. /**
  12686. * A throttled version of the {@link ProgressControl#handleMouseSeek} listener.
  12687. *
  12688. * @method ProgressControl#throttledHandleMouseSeek
  12689. * @param {EventTarget~Event} event
  12690. * The `mousemove` event that caused this function to run.
  12691. *
  12692. * @listen mousemove
  12693. * @listen touchmove
  12694. */
  12695. /**
  12696. * Handle `mousemove` or `touchmove` events on the `ProgressControl`.
  12697. *
  12698. * @param {EventTarget~Event} event
  12699. * `mousedown` or `touchstart` event that triggered this function
  12700. *
  12701. * @listens mousemove
  12702. * @listens touchmove
  12703. */
  12704. ;
  12705. _proto.handleMouseSeek = function handleMouseSeek(event) {
  12706. var seekBar = this.getChild('seekBar');
  12707. if (seekBar) {
  12708. seekBar.handleMouseMove(event);
  12709. }
  12710. }
  12711. /**
  12712. * Are controls are currently enabled for this progress control.
  12713. *
  12714. * @return {boolean}
  12715. * true if controls are enabled, false otherwise
  12716. */
  12717. ;
  12718. _proto.enabled = function enabled() {
  12719. return this.enabled_;
  12720. }
  12721. /**
  12722. * Disable all controls on the progress control and its children
  12723. */
  12724. ;
  12725. _proto.disable = function disable() {
  12726. this.children().forEach(function (child) {
  12727. return child.disable && child.disable();
  12728. });
  12729. if (!this.enabled()) {
  12730. return;
  12731. }
  12732. this.off(['mousedown', 'touchstart'], this.handleMouseDown);
  12733. this.off(this.el_, 'mousemove', this.handleMouseMove);
  12734. this.handleMouseUp();
  12735. this.addClass('disabled');
  12736. this.enabled_ = false;
  12737. }
  12738. /**
  12739. * Enable all controls on the progress control and its children
  12740. */
  12741. ;
  12742. _proto.enable = function enable() {
  12743. this.children().forEach(function (child) {
  12744. return child.enable && child.enable();
  12745. });
  12746. if (this.enabled()) {
  12747. return;
  12748. }
  12749. this.on(['mousedown', 'touchstart'], this.handleMouseDown);
  12750. this.on(this.el_, 'mousemove', this.handleMouseMove);
  12751. this.removeClass('disabled');
  12752. this.enabled_ = true;
  12753. }
  12754. /**
  12755. * Handle `mousedown` or `touchstart` events on the `ProgressControl`.
  12756. *
  12757. * @param {EventTarget~Event} event
  12758. * `mousedown` or `touchstart` event that triggered this function
  12759. *
  12760. * @listens mousedown
  12761. * @listens touchstart
  12762. */
  12763. ;
  12764. _proto.handleMouseDown = function handleMouseDown(event) {
  12765. var doc = this.el_.ownerDocument;
  12766. var seekBar = this.getChild('seekBar');
  12767. if (seekBar) {
  12768. seekBar.handleMouseDown(event);
  12769. }
  12770. this.on(doc, 'mousemove', this.throttledHandleMouseSeek);
  12771. this.on(doc, 'touchmove', this.throttledHandleMouseSeek);
  12772. this.on(doc, 'mouseup', this.handleMouseUp);
  12773. this.on(doc, 'touchend', this.handleMouseUp);
  12774. }
  12775. /**
  12776. * Handle `mouseup` or `touchend` events on the `ProgressControl`.
  12777. *
  12778. * @param {EventTarget~Event} event
  12779. * `mouseup` or `touchend` event that triggered this function.
  12780. *
  12781. * @listens touchend
  12782. * @listens mouseup
  12783. */
  12784. ;
  12785. _proto.handleMouseUp = function handleMouseUp(event) {
  12786. var doc = this.el_.ownerDocument;
  12787. var seekBar = this.getChild('seekBar');
  12788. if (seekBar) {
  12789. seekBar.handleMouseUp(event);
  12790. }
  12791. this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
  12792. this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
  12793. this.off(doc, 'mouseup', this.handleMouseUp);
  12794. this.off(doc, 'touchend', this.handleMouseUp);
  12795. };
  12796. return ProgressControl;
  12797. }(Component);
  12798. /**
  12799. * Default options for `ProgressControl`
  12800. *
  12801. * @type {Object}
  12802. * @private
  12803. */
  12804. ProgressControl.prototype.options_ = {
  12805. children: ['seekBar']
  12806. };
  12807. Component.registerComponent('ProgressControl', ProgressControl);
  12808. /**
  12809. * Toggle Picture-in-Picture mode
  12810. *
  12811. * @extends Button
  12812. */
  12813. var PictureInPictureToggle =
  12814. /*#__PURE__*/
  12815. function (_Button) {
  12816. _inheritsLoose(PictureInPictureToggle, _Button);
  12817. /**
  12818. * Creates an instance of this class.
  12819. *
  12820. * @param {Player} player
  12821. * The `Player` that this class should be attached to.
  12822. *
  12823. * @param {Object} [options]
  12824. * The key/value store of player options.
  12825. *
  12826. * @listens Player#enterpictureinpicture
  12827. * @listens Player#leavepictureinpicture
  12828. */
  12829. function PictureInPictureToggle(player, options) {
  12830. var _this;
  12831. _this = _Button.call(this, player, options) || this;
  12832. _this.on(player, ['enterpictureinpicture', 'leavepictureinpicture'], _this.handlePictureInPictureChange); // TODO: Activate button on player loadedmetadata event.
  12833. // TODO: Deactivate button on player emptied event.
  12834. // TODO: Deactivate button if disablepictureinpicture attribute is present.
  12835. if (!document.pictureInPictureEnabled) {
  12836. _this.disable();
  12837. }
  12838. return _this;
  12839. }
  12840. /**
  12841. * Builds the default DOM `className`.
  12842. *
  12843. * @return {string}
  12844. * The DOM `className` for this object.
  12845. */
  12846. var _proto = PictureInPictureToggle.prototype;
  12847. _proto.buildCSSClass = function buildCSSClass() {
  12848. return "vjs-picture-in-picture-control " + _Button.prototype.buildCSSClass.call(this);
  12849. }
  12850. /**
  12851. * Handles enterpictureinpicture and leavepictureinpicture on the player and change control text accordingly.
  12852. *
  12853. * @param {EventTarget~Event} [event]
  12854. * The {@link Player#enterpictureinpicture} or {@link Player#leavepictureinpicture} event that caused this function to be
  12855. * called.
  12856. *
  12857. * @listens Player#enterpictureinpicture
  12858. * @listens Player#leavepictureinpicture
  12859. */
  12860. ;
  12861. _proto.handlePictureInPictureChange = function handlePictureInPictureChange(event) {
  12862. if (this.player_.isInPictureInPicture()) {
  12863. this.controlText('Exit Picture-in-Picture');
  12864. } else {
  12865. this.controlText('Picture-in-Picture');
  12866. }
  12867. }
  12868. /**
  12869. * This gets called when an `PictureInPictureToggle` is "clicked". See
  12870. * {@link ClickableComponent} for more detailed information on what a click can be.
  12871. *
  12872. * @param {EventTarget~Event} [event]
  12873. * The `keydown`, `tap`, or `click` event that caused this function to be
  12874. * called.
  12875. *
  12876. * @listens tap
  12877. * @listens click
  12878. */
  12879. ;
  12880. _proto.handleClick = function handleClick(event) {
  12881. if (!this.player_.isInPictureInPicture()) {
  12882. this.player_.requestPictureInPicture();
  12883. } else {
  12884. this.player_.exitPictureInPicture();
  12885. }
  12886. };
  12887. return PictureInPictureToggle;
  12888. }(Button);
  12889. /**
  12890. * The text that should display over the `PictureInPictureToggle`s controls. Added for localization.
  12891. *
  12892. * @type {string}
  12893. * @private
  12894. */
  12895. PictureInPictureToggle.prototype.controlText_ = 'Picture-in-Picture';
  12896. Component.registerComponent('PictureInPictureToggle', PictureInPictureToggle);
  12897. /**
  12898. * Toggle fullscreen video
  12899. *
  12900. * @extends Button
  12901. */
  12902. var FullscreenToggle =
  12903. /*#__PURE__*/
  12904. function (_Button) {
  12905. _inheritsLoose(FullscreenToggle, _Button);
  12906. /**
  12907. * Creates an instance of this class.
  12908. *
  12909. * @param {Player} player
  12910. * The `Player` that this class should be attached to.
  12911. *
  12912. * @param {Object} [options]
  12913. * The key/value store of player options.
  12914. */
  12915. function FullscreenToggle(player, options) {
  12916. var _this;
  12917. _this = _Button.call(this, player, options) || this;
  12918. _this.on(player, 'fullscreenchange', _this.handleFullscreenChange);
  12919. if (document[player.fsApi_.fullscreenEnabled] === false) {
  12920. _this.disable();
  12921. }
  12922. return _this;
  12923. }
  12924. /**
  12925. * Builds the default DOM `className`.
  12926. *
  12927. * @return {string}
  12928. * The DOM `className` for this object.
  12929. */
  12930. var _proto = FullscreenToggle.prototype;
  12931. _proto.buildCSSClass = function buildCSSClass() {
  12932. return "vjs-fullscreen-control " + _Button.prototype.buildCSSClass.call(this);
  12933. }
  12934. /**
  12935. * Handles fullscreenchange on the player and change control text accordingly.
  12936. *
  12937. * @param {EventTarget~Event} [event]
  12938. * The {@link Player#fullscreenchange} event that caused this function to be
  12939. * called.
  12940. *
  12941. * @listens Player#fullscreenchange
  12942. */
  12943. ;
  12944. _proto.handleFullscreenChange = function handleFullscreenChange(event) {
  12945. if (this.player_.isFullscreen()) {
  12946. this.controlText('Non-Fullscreen');
  12947. } else {
  12948. this.controlText('Fullscreen');
  12949. }
  12950. }
  12951. /**
  12952. * This gets called when an `FullscreenToggle` is "clicked". See
  12953. * {@link ClickableComponent} for more detailed information on what a click can be.
  12954. *
  12955. * @param {EventTarget~Event} [event]
  12956. * The `keydown`, `tap`, or `click` event that caused this function to be
  12957. * called.
  12958. *
  12959. * @listens tap
  12960. * @listens click
  12961. */
  12962. ;
  12963. _proto.handleClick = function handleClick(event) {
  12964. if (!this.player_.isFullscreen()) {
  12965. this.player_.requestFullscreen();
  12966. } else {
  12967. this.player_.exitFullscreen();
  12968. }
  12969. };
  12970. return FullscreenToggle;
  12971. }(Button);
  12972. /**
  12973. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  12974. *
  12975. * @type {string}
  12976. * @private
  12977. */
  12978. FullscreenToggle.prototype.controlText_ = 'Fullscreen';
  12979. Component.registerComponent('FullscreenToggle', FullscreenToggle);
  12980. /**
  12981. * Check if volume control is supported and if it isn't hide the
  12982. * `Component` that was passed using the `vjs-hidden` class.
  12983. *
  12984. * @param {Component} self
  12985. * The component that should be hidden if volume is unsupported
  12986. *
  12987. * @param {Player} player
  12988. * A reference to the player
  12989. *
  12990. * @private
  12991. */
  12992. var checkVolumeSupport = function checkVolumeSupport(self, player) {
  12993. // hide volume controls when they're not supported by the current tech
  12994. if (player.tech_ && !player.tech_.featuresVolumeControl) {
  12995. self.addClass('vjs-hidden');
  12996. }
  12997. self.on(player, 'loadstart', function () {
  12998. if (!player.tech_.featuresVolumeControl) {
  12999. self.addClass('vjs-hidden');
  13000. } else {
  13001. self.removeClass('vjs-hidden');
  13002. }
  13003. });
  13004. };
  13005. /**
  13006. * Shows volume level
  13007. *
  13008. * @extends Component
  13009. */
  13010. var VolumeLevel =
  13011. /*#__PURE__*/
  13012. function (_Component) {
  13013. _inheritsLoose(VolumeLevel, _Component);
  13014. function VolumeLevel() {
  13015. return _Component.apply(this, arguments) || this;
  13016. }
  13017. var _proto = VolumeLevel.prototype;
  13018. /**
  13019. * Create the `Component`'s DOM element
  13020. *
  13021. * @return {Element}
  13022. * The element that was created.
  13023. */
  13024. _proto.createEl = function createEl() {
  13025. return _Component.prototype.createEl.call(this, 'div', {
  13026. className: 'vjs-volume-level',
  13027. innerHTML: '<span class="vjs-control-text"></span>'
  13028. });
  13029. };
  13030. return VolumeLevel;
  13031. }(Component);
  13032. Component.registerComponent('VolumeLevel', VolumeLevel);
  13033. /**
  13034. * The bar that contains the volume level and can be clicked on to adjust the level
  13035. *
  13036. * @extends Slider
  13037. */
  13038. var VolumeBar =
  13039. /*#__PURE__*/
  13040. function (_Slider) {
  13041. _inheritsLoose(VolumeBar, _Slider);
  13042. /**
  13043. * Creates an instance of this class.
  13044. *
  13045. * @param {Player} player
  13046. * The `Player` that this class should be attached to.
  13047. *
  13048. * @param {Object} [options]
  13049. * The key/value store of player options.
  13050. */
  13051. function VolumeBar(player, options) {
  13052. var _this;
  13053. _this = _Slider.call(this, player, options) || this;
  13054. _this.on('slideractive', _this.updateLastVolume_);
  13055. _this.on(player, 'volumechange', _this.updateARIAAttributes);
  13056. player.ready(function () {
  13057. return _this.updateARIAAttributes();
  13058. });
  13059. return _this;
  13060. }
  13061. /**
  13062. * Create the `Component`'s DOM element
  13063. *
  13064. * @return {Element}
  13065. * The element that was created.
  13066. */
  13067. var _proto = VolumeBar.prototype;
  13068. _proto.createEl = function createEl() {
  13069. return _Slider.prototype.createEl.call(this, 'div', {
  13070. className: 'vjs-volume-bar vjs-slider-bar'
  13071. }, {
  13072. 'aria-label': this.localize('Volume Level'),
  13073. 'aria-live': 'polite'
  13074. });
  13075. }
  13076. /**
  13077. * Handle mouse down on volume bar
  13078. *
  13079. * @param {EventTarget~Event} event
  13080. * The `mousedown` event that caused this to run.
  13081. *
  13082. * @listens mousedown
  13083. */
  13084. ;
  13085. _proto.handleMouseDown = function handleMouseDown(event) {
  13086. if (!isSingleLeftClick(event)) {
  13087. return;
  13088. }
  13089. _Slider.prototype.handleMouseDown.call(this, event);
  13090. }
  13091. /**
  13092. * Handle movement events on the {@link VolumeMenuButton}.
  13093. *
  13094. * @param {EventTarget~Event} event
  13095. * The event that caused this function to run.
  13096. *
  13097. * @listens mousemove
  13098. */
  13099. ;
  13100. _proto.handleMouseMove = function handleMouseMove(event) {
  13101. if (!isSingleLeftClick(event)) {
  13102. return;
  13103. }
  13104. this.checkMuted();
  13105. this.player_.volume(this.calculateDistance(event));
  13106. }
  13107. /**
  13108. * If the player is muted unmute it.
  13109. */
  13110. ;
  13111. _proto.checkMuted = function checkMuted() {
  13112. if (this.player_.muted()) {
  13113. this.player_.muted(false);
  13114. }
  13115. }
  13116. /**
  13117. * Get percent of volume level
  13118. *
  13119. * @return {number}
  13120. * Volume level percent as a decimal number.
  13121. */
  13122. ;
  13123. _proto.getPercent = function getPercent() {
  13124. if (this.player_.muted()) {
  13125. return 0;
  13126. }
  13127. return this.player_.volume();
  13128. }
  13129. /**
  13130. * Increase volume level for keyboard users
  13131. */
  13132. ;
  13133. _proto.stepForward = function stepForward() {
  13134. this.checkMuted();
  13135. this.player_.volume(this.player_.volume() + 0.1);
  13136. }
  13137. /**
  13138. * Decrease volume level for keyboard users
  13139. */
  13140. ;
  13141. _proto.stepBack = function stepBack() {
  13142. this.checkMuted();
  13143. this.player_.volume(this.player_.volume() - 0.1);
  13144. }
  13145. /**
  13146. * Update ARIA accessibility attributes
  13147. *
  13148. * @param {EventTarget~Event} [event]
  13149. * The `volumechange` event that caused this function to run.
  13150. *
  13151. * @listens Player#volumechange
  13152. */
  13153. ;
  13154. _proto.updateARIAAttributes = function updateARIAAttributes(event) {
  13155. var ariaValue = this.player_.muted() ? 0 : this.volumeAsPercentage_();
  13156. this.el_.setAttribute('aria-valuenow', ariaValue);
  13157. this.el_.setAttribute('aria-valuetext', ariaValue + '%');
  13158. }
  13159. /**
  13160. * Returns the current value of the player volume as a percentage
  13161. *
  13162. * @private
  13163. */
  13164. ;
  13165. _proto.volumeAsPercentage_ = function volumeAsPercentage_() {
  13166. return Math.round(this.player_.volume() * 100);
  13167. }
  13168. /**
  13169. * When user starts dragging the VolumeBar, store the volume and listen for
  13170. * the end of the drag. When the drag ends, if the volume was set to zero,
  13171. * set lastVolume to the stored volume.
  13172. *
  13173. * @listens slideractive
  13174. * @private
  13175. */
  13176. ;
  13177. _proto.updateLastVolume_ = function updateLastVolume_() {
  13178. var _this2 = this;
  13179. var volumeBeforeDrag = this.player_.volume();
  13180. this.one('sliderinactive', function () {
  13181. if (_this2.player_.volume() === 0) {
  13182. _this2.player_.lastVolume_(volumeBeforeDrag);
  13183. }
  13184. });
  13185. };
  13186. return VolumeBar;
  13187. }(Slider);
  13188. /**
  13189. * Default options for the `VolumeBar`
  13190. *
  13191. * @type {Object}
  13192. * @private
  13193. */
  13194. VolumeBar.prototype.options_ = {
  13195. children: ['volumeLevel'],
  13196. barName: 'volumeLevel'
  13197. };
  13198. /**
  13199. * Call the update event for this Slider when this event happens on the player.
  13200. *
  13201. * @type {string}
  13202. */
  13203. VolumeBar.prototype.playerEvent = 'volumechange';
  13204. Component.registerComponent('VolumeBar', VolumeBar);
  13205. /**
  13206. * The component for controlling the volume level
  13207. *
  13208. * @extends Component
  13209. */
  13210. var VolumeControl =
  13211. /*#__PURE__*/
  13212. function (_Component) {
  13213. _inheritsLoose(VolumeControl, _Component);
  13214. /**
  13215. * Creates an instance of this class.
  13216. *
  13217. * @param {Player} player
  13218. * The `Player` that this class should be attached to.
  13219. *
  13220. * @param {Object} [options={}]
  13221. * The key/value store of player options.
  13222. */
  13223. function VolumeControl(player, options) {
  13224. var _this;
  13225. if (options === void 0) {
  13226. options = {};
  13227. }
  13228. options.vertical = options.vertical || false; // Pass the vertical option down to the VolumeBar if
  13229. // the VolumeBar is turned on.
  13230. if (typeof options.volumeBar === 'undefined' || isPlain(options.volumeBar)) {
  13231. options.volumeBar = options.volumeBar || {};
  13232. options.volumeBar.vertical = options.vertical;
  13233. }
  13234. _this = _Component.call(this, player, options) || this; // hide this control if volume support is missing
  13235. checkVolumeSupport(_assertThisInitialized(_this), player);
  13236. _this.throttledHandleMouseMove = throttle(bind(_assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  13237. _this.on('mousedown', _this.handleMouseDown);
  13238. _this.on('touchstart', _this.handleMouseDown); // while the slider is active (the mouse has been pressed down and
  13239. // is dragging) or in focus we do not want to hide the VolumeBar
  13240. _this.on(_this.volumeBar, ['focus', 'slideractive'], function () {
  13241. _this.volumeBar.addClass('vjs-slider-active');
  13242. _this.addClass('vjs-slider-active');
  13243. _this.trigger('slideractive');
  13244. });
  13245. _this.on(_this.volumeBar, ['blur', 'sliderinactive'], function () {
  13246. _this.volumeBar.removeClass('vjs-slider-active');
  13247. _this.removeClass('vjs-slider-active');
  13248. _this.trigger('sliderinactive');
  13249. });
  13250. return _this;
  13251. }
  13252. /**
  13253. * Create the `Component`'s DOM element
  13254. *
  13255. * @return {Element}
  13256. * The element that was created.
  13257. */
  13258. var _proto = VolumeControl.prototype;
  13259. _proto.createEl = function createEl() {
  13260. var orientationClass = 'vjs-volume-horizontal';
  13261. if (this.options_.vertical) {
  13262. orientationClass = 'vjs-volume-vertical';
  13263. }
  13264. return _Component.prototype.createEl.call(this, 'div', {
  13265. className: "vjs-volume-control vjs-control " + orientationClass
  13266. });
  13267. }
  13268. /**
  13269. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  13270. *
  13271. * @param {EventTarget~Event} event
  13272. * `mousedown` or `touchstart` event that triggered this function
  13273. *
  13274. * @listens mousedown
  13275. * @listens touchstart
  13276. */
  13277. ;
  13278. _proto.handleMouseDown = function handleMouseDown(event) {
  13279. var doc = this.el_.ownerDocument;
  13280. this.on(doc, 'mousemove', this.throttledHandleMouseMove);
  13281. this.on(doc, 'touchmove', this.throttledHandleMouseMove);
  13282. this.on(doc, 'mouseup', this.handleMouseUp);
  13283. this.on(doc, 'touchend', this.handleMouseUp);
  13284. }
  13285. /**
  13286. * Handle `mouseup` or `touchend` events on the `VolumeControl`.
  13287. *
  13288. * @param {EventTarget~Event} event
  13289. * `mouseup` or `touchend` event that triggered this function.
  13290. *
  13291. * @listens touchend
  13292. * @listens mouseup
  13293. */
  13294. ;
  13295. _proto.handleMouseUp = function handleMouseUp(event) {
  13296. var doc = this.el_.ownerDocument;
  13297. this.off(doc, 'mousemove', this.throttledHandleMouseMove);
  13298. this.off(doc, 'touchmove', this.throttledHandleMouseMove);
  13299. this.off(doc, 'mouseup', this.handleMouseUp);
  13300. this.off(doc, 'touchend', this.handleMouseUp);
  13301. }
  13302. /**
  13303. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  13304. *
  13305. * @param {EventTarget~Event} event
  13306. * `mousedown` or `touchstart` event that triggered this function
  13307. *
  13308. * @listens mousedown
  13309. * @listens touchstart
  13310. */
  13311. ;
  13312. _proto.handleMouseMove = function handleMouseMove(event) {
  13313. this.volumeBar.handleMouseMove(event);
  13314. };
  13315. return VolumeControl;
  13316. }(Component);
  13317. /**
  13318. * Default options for the `VolumeControl`
  13319. *
  13320. * @type {Object}
  13321. * @private
  13322. */
  13323. VolumeControl.prototype.options_ = {
  13324. children: ['volumeBar']
  13325. };
  13326. Component.registerComponent('VolumeControl', VolumeControl);
  13327. /**
  13328. * Check if muting volume is supported and if it isn't hide the mute toggle
  13329. * button.
  13330. *
  13331. * @param {Component} self
  13332. * A reference to the mute toggle button
  13333. *
  13334. * @param {Player} player
  13335. * A reference to the player
  13336. *
  13337. * @private
  13338. */
  13339. var checkMuteSupport = function checkMuteSupport(self, player) {
  13340. // hide mute toggle button if it's not supported by the current tech
  13341. if (player.tech_ && !player.tech_.featuresMuteControl) {
  13342. self.addClass('vjs-hidden');
  13343. }
  13344. self.on(player, 'loadstart', function () {
  13345. if (!player.tech_.featuresMuteControl) {
  13346. self.addClass('vjs-hidden');
  13347. } else {
  13348. self.removeClass('vjs-hidden');
  13349. }
  13350. });
  13351. };
  13352. /**
  13353. * A button component for muting the audio.
  13354. *
  13355. * @extends Button
  13356. */
  13357. var MuteToggle =
  13358. /*#__PURE__*/
  13359. function (_Button) {
  13360. _inheritsLoose(MuteToggle, _Button);
  13361. /**
  13362. * Creates an instance of this class.
  13363. *
  13364. * @param {Player} player
  13365. * The `Player` that this class should be attached to.
  13366. *
  13367. * @param {Object} [options]
  13368. * The key/value store of player options.
  13369. */
  13370. function MuteToggle(player, options) {
  13371. var _this;
  13372. _this = _Button.call(this, player, options) || this; // hide this control if volume support is missing
  13373. checkMuteSupport(_assertThisInitialized(_this), player);
  13374. _this.on(player, ['loadstart', 'volumechange'], _this.update);
  13375. return _this;
  13376. }
  13377. /**
  13378. * Builds the default DOM `className`.
  13379. *
  13380. * @return {string}
  13381. * The DOM `className` for this object.
  13382. */
  13383. var _proto = MuteToggle.prototype;
  13384. _proto.buildCSSClass = function buildCSSClass() {
  13385. return "vjs-mute-control " + _Button.prototype.buildCSSClass.call(this);
  13386. }
  13387. /**
  13388. * This gets called when an `MuteToggle` is "clicked". See
  13389. * {@link ClickableComponent} for more detailed information on what a click can be.
  13390. *
  13391. * @param {EventTarget~Event} [event]
  13392. * The `keydown`, `tap`, or `click` event that caused this function to be
  13393. * called.
  13394. *
  13395. * @listens tap
  13396. * @listens click
  13397. */
  13398. ;
  13399. _proto.handleClick = function handleClick(event) {
  13400. var vol = this.player_.volume();
  13401. var lastVolume = this.player_.lastVolume_();
  13402. if (vol === 0) {
  13403. var volumeToSet = lastVolume < 0.1 ? 0.1 : lastVolume;
  13404. this.player_.volume(volumeToSet);
  13405. this.player_.muted(false);
  13406. } else {
  13407. this.player_.muted(this.player_.muted() ? false : true);
  13408. }
  13409. }
  13410. /**
  13411. * Update the `MuteToggle` button based on the state of `volume` and `muted`
  13412. * on the player.
  13413. *
  13414. * @param {EventTarget~Event} [event]
  13415. * The {@link Player#loadstart} event if this function was called
  13416. * through an event.
  13417. *
  13418. * @listens Player#loadstart
  13419. * @listens Player#volumechange
  13420. */
  13421. ;
  13422. _proto.update = function update(event) {
  13423. this.updateIcon_();
  13424. this.updateControlText_();
  13425. }
  13426. /**
  13427. * Update the appearance of the `MuteToggle` icon.
  13428. *
  13429. * Possible states (given `level` variable below):
  13430. * - 0: crossed out
  13431. * - 1: zero bars of volume
  13432. * - 2: one bar of volume
  13433. * - 3: two bars of volume
  13434. *
  13435. * @private
  13436. */
  13437. ;
  13438. _proto.updateIcon_ = function updateIcon_() {
  13439. var vol = this.player_.volume();
  13440. var level = 3; // in iOS when a player is loaded with muted attribute
  13441. // and volume is changed with a native mute button
  13442. // we want to make sure muted state is updated
  13443. if (IS_IOS && this.player_.tech_ && this.player_.tech_.el_) {
  13444. this.player_.muted(this.player_.tech_.el_.muted);
  13445. }
  13446. if (vol === 0 || this.player_.muted()) {
  13447. level = 0;
  13448. } else if (vol < 0.33) {
  13449. level = 1;
  13450. } else if (vol < 0.67) {
  13451. level = 2;
  13452. } // TODO improve muted icon classes
  13453. for (var i = 0; i < 4; i++) {
  13454. removeClass(this.el_, "vjs-vol-" + i);
  13455. }
  13456. addClass(this.el_, "vjs-vol-" + level);
  13457. }
  13458. /**
  13459. * If `muted` has changed on the player, update the control text
  13460. * (`title` attribute on `vjs-mute-control` element and content of
  13461. * `vjs-control-text` element).
  13462. *
  13463. * @private
  13464. */
  13465. ;
  13466. _proto.updateControlText_ = function updateControlText_() {
  13467. var soundOff = this.player_.muted() || this.player_.volume() === 0;
  13468. var text = soundOff ? 'Unmute' : 'Mute';
  13469. if (this.controlText() !== text) {
  13470. this.controlText(text);
  13471. }
  13472. };
  13473. return MuteToggle;
  13474. }(Button);
  13475. /**
  13476. * The text that should display over the `MuteToggle`s controls. Added for localization.
  13477. *
  13478. * @type {string}
  13479. * @private
  13480. */
  13481. MuteToggle.prototype.controlText_ = 'Mute';
  13482. Component.registerComponent('MuteToggle', MuteToggle);
  13483. /**
  13484. * A Component to contain the MuteToggle and VolumeControl so that
  13485. * they can work together.
  13486. *
  13487. * @extends Component
  13488. */
  13489. var VolumePanel =
  13490. /*#__PURE__*/
  13491. function (_Component) {
  13492. _inheritsLoose(VolumePanel, _Component);
  13493. /**
  13494. * Creates an instance of this class.
  13495. *
  13496. * @param {Player} player
  13497. * The `Player` that this class should be attached to.
  13498. *
  13499. * @param {Object} [options={}]
  13500. * The key/value store of player options.
  13501. */
  13502. function VolumePanel(player, options) {
  13503. var _this;
  13504. if (options === void 0) {
  13505. options = {};
  13506. }
  13507. if (typeof options.inline !== 'undefined') {
  13508. options.inline = options.inline;
  13509. } else {
  13510. options.inline = true;
  13511. } // pass the inline option down to the VolumeControl as vertical if
  13512. // the VolumeControl is on.
  13513. if (typeof options.volumeControl === 'undefined' || isPlain(options.volumeControl)) {
  13514. options.volumeControl = options.volumeControl || {};
  13515. options.volumeControl.vertical = !options.inline;
  13516. }
  13517. _this = _Component.call(this, player, options) || this;
  13518. _this.on(player, ['loadstart'], _this.volumePanelState_);
  13519. _this.on(_this.muteToggle, 'keyup', _this.handleKeyPress);
  13520. _this.on(_this.volumeControl, 'keyup', _this.handleVolumeControlKeyUp);
  13521. _this.on('keydown', _this.handleKeyPress);
  13522. _this.on('mouseover', _this.handleMouseOver);
  13523. _this.on('mouseout', _this.handleMouseOut); // while the slider is active (the mouse has been pressed down and
  13524. // is dragging) we do not want to hide the VolumeBar
  13525. _this.on(_this.volumeControl, ['slideractive'], _this.sliderActive_);
  13526. _this.on(_this.volumeControl, ['sliderinactive'], _this.sliderInactive_);
  13527. return _this;
  13528. }
  13529. /**
  13530. * Add vjs-slider-active class to the VolumePanel
  13531. *
  13532. * @listens VolumeControl#slideractive
  13533. * @private
  13534. */
  13535. var _proto = VolumePanel.prototype;
  13536. _proto.sliderActive_ = function sliderActive_() {
  13537. this.addClass('vjs-slider-active');
  13538. }
  13539. /**
  13540. * Removes vjs-slider-active class to the VolumePanel
  13541. *
  13542. * @listens VolumeControl#sliderinactive
  13543. * @private
  13544. */
  13545. ;
  13546. _proto.sliderInactive_ = function sliderInactive_() {
  13547. this.removeClass('vjs-slider-active');
  13548. }
  13549. /**
  13550. * Adds vjs-hidden or vjs-mute-toggle-only to the VolumePanel
  13551. * depending on MuteToggle and VolumeControl state
  13552. *
  13553. * @listens Player#loadstart
  13554. * @private
  13555. */
  13556. ;
  13557. _proto.volumePanelState_ = function volumePanelState_() {
  13558. // hide volume panel if neither volume control or mute toggle
  13559. // are displayed
  13560. if (this.volumeControl.hasClass('vjs-hidden') && this.muteToggle.hasClass('vjs-hidden')) {
  13561. this.addClass('vjs-hidden');
  13562. } // if only mute toggle is visible we don't want
  13563. // volume panel expanding when hovered or active
  13564. if (this.volumeControl.hasClass('vjs-hidden') && !this.muteToggle.hasClass('vjs-hidden')) {
  13565. this.addClass('vjs-mute-toggle-only');
  13566. }
  13567. }
  13568. /**
  13569. * Create the `Component`'s DOM element
  13570. *
  13571. * @return {Element}
  13572. * The element that was created.
  13573. */
  13574. ;
  13575. _proto.createEl = function createEl() {
  13576. var orientationClass = 'vjs-volume-panel-horizontal';
  13577. if (!this.options_.inline) {
  13578. orientationClass = 'vjs-volume-panel-vertical';
  13579. }
  13580. return _Component.prototype.createEl.call(this, 'div', {
  13581. className: "vjs-volume-panel vjs-control " + orientationClass
  13582. });
  13583. }
  13584. /**
  13585. * Dispose of the `volume-panel` and all child components.
  13586. */
  13587. ;
  13588. _proto.dispose = function dispose() {
  13589. this.handleMouseOut();
  13590. _Component.prototype.dispose.call(this);
  13591. }
  13592. /**
  13593. * Handles `keyup` events on the `VolumeControl`, looking for ESC, which closes
  13594. * the volume panel and sets focus on `MuteToggle`.
  13595. *
  13596. * @param {EventTarget~Event} event
  13597. * The `keyup` event that caused this function to be called.
  13598. *
  13599. * @listens keyup
  13600. */
  13601. ;
  13602. _proto.handleVolumeControlKeyUp = function handleVolumeControlKeyUp(event) {
  13603. if (keycode.isEventKey(event, 'Esc')) {
  13604. this.muteToggle.focus();
  13605. }
  13606. }
  13607. /**
  13608. * This gets called when a `VolumePanel` gains hover via a `mouseover` event.
  13609. * Turns on listening for `mouseover` event. When they happen it
  13610. * calls `this.handleMouseOver`.
  13611. *
  13612. * @param {EventTarget~Event} event
  13613. * The `mouseover` event that caused this function to be called.
  13614. *
  13615. * @listens mouseover
  13616. */
  13617. ;
  13618. _proto.handleMouseOver = function handleMouseOver(event) {
  13619. this.addClass('vjs-hover');
  13620. on(document, 'keyup', bind(this, this.handleKeyPress));
  13621. }
  13622. /**
  13623. * This gets called when a `VolumePanel` gains hover via a `mouseout` event.
  13624. * Turns on listening for `mouseout` event. When they happen it
  13625. * calls `this.handleMouseOut`.
  13626. *
  13627. * @param {EventTarget~Event} event
  13628. * The `mouseout` event that caused this function to be called.
  13629. *
  13630. * @listens mouseout
  13631. */
  13632. ;
  13633. _proto.handleMouseOut = function handleMouseOut(event) {
  13634. this.removeClass('vjs-hover');
  13635. off(document, 'keyup', bind(this, this.handleKeyPress));
  13636. }
  13637. /**
  13638. * Handles `keyup` event on the document or `keydown` event on the `VolumePanel`,
  13639. * looking for ESC, which hides the `VolumeControl`.
  13640. *
  13641. * @param {EventTarget~Event} event
  13642. * The keypress that triggered this event.
  13643. *
  13644. * @listens keydown | keyup
  13645. */
  13646. ;
  13647. _proto.handleKeyPress = function handleKeyPress(event) {
  13648. if (keycode.isEventKey(event, 'Esc')) {
  13649. this.handleMouseOut();
  13650. }
  13651. };
  13652. return VolumePanel;
  13653. }(Component);
  13654. /**
  13655. * Default options for the `VolumeControl`
  13656. *
  13657. * @type {Object}
  13658. * @private
  13659. */
  13660. VolumePanel.prototype.options_ = {
  13661. children: ['muteToggle', 'volumeControl']
  13662. };
  13663. Component.registerComponent('VolumePanel', VolumePanel);
  13664. /**
  13665. * The Menu component is used to build popup menus, including subtitle and
  13666. * captions selection menus.
  13667. *
  13668. * @extends Component
  13669. */
  13670. var Menu =
  13671. /*#__PURE__*/
  13672. function (_Component) {
  13673. _inheritsLoose(Menu, _Component);
  13674. /**
  13675. * Create an instance of this class.
  13676. *
  13677. * @param {Player} player
  13678. * the player that this component should attach to
  13679. *
  13680. * @param {Object} [options]
  13681. * Object of option names and values
  13682. *
  13683. */
  13684. function Menu(player, options) {
  13685. var _this;
  13686. _this = _Component.call(this, player, options) || this;
  13687. if (options) {
  13688. _this.menuButton_ = options.menuButton;
  13689. }
  13690. _this.focusedChild_ = -1;
  13691. _this.on('keydown', _this.handleKeyDown); // All the menu item instances share the same blur handler provided by the menu container.
  13692. _this.boundHandleBlur_ = bind(_assertThisInitialized(_this), _this.handleBlur);
  13693. _this.boundHandleTapClick_ = bind(_assertThisInitialized(_this), _this.handleTapClick);
  13694. return _this;
  13695. }
  13696. /**
  13697. * Add event listeners to the {@link MenuItem}.
  13698. *
  13699. * @param {Object} component
  13700. * The instance of the `MenuItem` to add listeners to.
  13701. *
  13702. */
  13703. var _proto = Menu.prototype;
  13704. _proto.addEventListenerForItem = function addEventListenerForItem(component) {
  13705. if (!(component instanceof Component)) {
  13706. return;
  13707. }
  13708. this.on(component, 'blur', this.boundHandleBlur_);
  13709. this.on(component, ['tap', 'click'], this.boundHandleTapClick_);
  13710. }
  13711. /**
  13712. * Remove event listeners from the {@link MenuItem}.
  13713. *
  13714. * @param {Object} component
  13715. * The instance of the `MenuItem` to remove listeners.
  13716. *
  13717. */
  13718. ;
  13719. _proto.removeEventListenerForItem = function removeEventListenerForItem(component) {
  13720. if (!(component instanceof Component)) {
  13721. return;
  13722. }
  13723. this.off(component, 'blur', this.boundHandleBlur_);
  13724. this.off(component, ['tap', 'click'], this.boundHandleTapClick_);
  13725. }
  13726. /**
  13727. * This method will be called indirectly when the component has been added
  13728. * before the component adds to the new menu instance by `addItem`.
  13729. * In this case, the original menu instance will remove the component
  13730. * by calling `removeChild`.
  13731. *
  13732. * @param {Object} component
  13733. * The instance of the `MenuItem`
  13734. */
  13735. ;
  13736. _proto.removeChild = function removeChild(component) {
  13737. if (typeof component === 'string') {
  13738. component = this.getChild(component);
  13739. }
  13740. this.removeEventListenerForItem(component);
  13741. _Component.prototype.removeChild.call(this, component);
  13742. }
  13743. /**
  13744. * Add a {@link MenuItem} to the menu.
  13745. *
  13746. * @param {Object|string} component
  13747. * The name or instance of the `MenuItem` to add.
  13748. *
  13749. */
  13750. ;
  13751. _proto.addItem = function addItem(component) {
  13752. var childComponent = this.addChild(component);
  13753. if (childComponent) {
  13754. this.addEventListenerForItem(childComponent);
  13755. }
  13756. }
  13757. /**
  13758. * Create the `Menu`s DOM element.
  13759. *
  13760. * @return {Element}
  13761. * the element that was created
  13762. */
  13763. ;
  13764. _proto.createEl = function createEl$1() {
  13765. var contentElType = this.options_.contentElType || 'ul';
  13766. this.contentEl_ = createEl(contentElType, {
  13767. className: 'vjs-menu-content'
  13768. });
  13769. this.contentEl_.setAttribute('role', 'menu');
  13770. var el = _Component.prototype.createEl.call(this, 'div', {
  13771. append: this.contentEl_,
  13772. className: 'vjs-menu'
  13773. });
  13774. el.appendChild(this.contentEl_); // Prevent clicks from bubbling up. Needed for Menu Buttons,
  13775. // where a click on the parent is significant
  13776. on(el, 'click', function (event) {
  13777. event.preventDefault();
  13778. event.stopImmediatePropagation();
  13779. });
  13780. return el;
  13781. };
  13782. _proto.dispose = function dispose() {
  13783. this.contentEl_ = null;
  13784. this.boundHandleBlur_ = null;
  13785. this.boundHandleTapClick_ = null;
  13786. _Component.prototype.dispose.call(this);
  13787. }
  13788. /**
  13789. * Called when a `MenuItem` loses focus.
  13790. *
  13791. * @param {EventTarget~Event} event
  13792. * The `blur` event that caused this function to be called.
  13793. *
  13794. * @listens blur
  13795. */
  13796. ;
  13797. _proto.handleBlur = function handleBlur(event) {
  13798. var relatedTarget = event.relatedTarget || document.activeElement; // Close menu popup when a user clicks outside the menu
  13799. if (!this.children().some(function (element) {
  13800. return element.el() === relatedTarget;
  13801. })) {
  13802. var btn = this.menuButton_;
  13803. if (btn && btn.buttonPressed_ && relatedTarget !== btn.el().firstChild) {
  13804. btn.unpressButton();
  13805. }
  13806. }
  13807. }
  13808. /**
  13809. * Called when a `MenuItem` gets clicked or tapped.
  13810. *
  13811. * @param {EventTarget~Event} event
  13812. * The `click` or `tap` event that caused this function to be called.
  13813. *
  13814. * @listens click,tap
  13815. */
  13816. ;
  13817. _proto.handleTapClick = function handleTapClick(event) {
  13818. // Unpress the associated MenuButton, and move focus back to it
  13819. if (this.menuButton_) {
  13820. this.menuButton_.unpressButton();
  13821. var childComponents = this.children();
  13822. if (!Array.isArray(childComponents)) {
  13823. return;
  13824. }
  13825. var foundComponent = childComponents.filter(function (component) {
  13826. return component.el() === event.target;
  13827. })[0];
  13828. if (!foundComponent) {
  13829. return;
  13830. } // don't focus menu button if item is a caption settings item
  13831. // because focus will move elsewhere
  13832. if (foundComponent.name() !== 'CaptionSettingsMenuItem') {
  13833. this.menuButton_.focus();
  13834. }
  13835. }
  13836. }
  13837. /**
  13838. * Handle a `keydown` event on this menu. This listener is added in the constructor.
  13839. *
  13840. * @param {EventTarget~Event} event
  13841. * A `keydown` event that happened on the menu.
  13842. *
  13843. * @listens keydown
  13844. */
  13845. ;
  13846. _proto.handleKeyDown = function handleKeyDown(event) {
  13847. // Left and Down Arrows
  13848. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  13849. event.preventDefault();
  13850. event.stopPropagation();
  13851. this.stepForward(); // Up and Right Arrows
  13852. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  13853. event.preventDefault();
  13854. event.stopPropagation();
  13855. this.stepBack();
  13856. }
  13857. }
  13858. /**
  13859. * Move to next (lower) menu item for keyboard users.
  13860. */
  13861. ;
  13862. _proto.stepForward = function stepForward() {
  13863. var stepChild = 0;
  13864. if (this.focusedChild_ !== undefined) {
  13865. stepChild = this.focusedChild_ + 1;
  13866. }
  13867. this.focus(stepChild);
  13868. }
  13869. /**
  13870. * Move to previous (higher) menu item for keyboard users.
  13871. */
  13872. ;
  13873. _proto.stepBack = function stepBack() {
  13874. var stepChild = 0;
  13875. if (this.focusedChild_ !== undefined) {
  13876. stepChild = this.focusedChild_ - 1;
  13877. }
  13878. this.focus(stepChild);
  13879. }
  13880. /**
  13881. * Set focus on a {@link MenuItem} in the `Menu`.
  13882. *
  13883. * @param {Object|string} [item=0]
  13884. * Index of child item set focus on.
  13885. */
  13886. ;
  13887. _proto.focus = function focus(item) {
  13888. if (item === void 0) {
  13889. item = 0;
  13890. }
  13891. var children = this.children().slice();
  13892. var haveTitle = children.length && children[0].className && /vjs-menu-title/.test(children[0].className);
  13893. if (haveTitle) {
  13894. children.shift();
  13895. }
  13896. if (children.length > 0) {
  13897. if (item < 0) {
  13898. item = 0;
  13899. } else if (item >= children.length) {
  13900. item = children.length - 1;
  13901. }
  13902. this.focusedChild_ = item;
  13903. children[item].el_.focus();
  13904. }
  13905. };
  13906. return Menu;
  13907. }(Component);
  13908. Component.registerComponent('Menu', Menu);
  13909. /**
  13910. * A `MenuButton` class for any popup {@link Menu}.
  13911. *
  13912. * @extends Component
  13913. */
  13914. var MenuButton =
  13915. /*#__PURE__*/
  13916. function (_Component) {
  13917. _inheritsLoose(MenuButton, _Component);
  13918. /**
  13919. * Creates an instance of this class.
  13920. *
  13921. * @param {Player} player
  13922. * The `Player` that this class should be attached to.
  13923. *
  13924. * @param {Object} [options={}]
  13925. * The key/value store of player options.
  13926. */
  13927. function MenuButton(player, options) {
  13928. var _this;
  13929. if (options === void 0) {
  13930. options = {};
  13931. }
  13932. _this = _Component.call(this, player, options) || this;
  13933. _this.menuButton_ = new Button(player, options);
  13934. _this.menuButton_.controlText(_this.controlText_);
  13935. _this.menuButton_.el_.setAttribute('aria-haspopup', 'true'); // Add buildCSSClass values to the button, not the wrapper
  13936. var buttonClass = Button.prototype.buildCSSClass();
  13937. _this.menuButton_.el_.className = _this.buildCSSClass() + ' ' + buttonClass;
  13938. _this.menuButton_.removeClass('vjs-control');
  13939. _this.addChild(_this.menuButton_);
  13940. _this.update();
  13941. _this.enabled_ = true;
  13942. _this.on(_this.menuButton_, 'tap', _this.handleClick);
  13943. _this.on(_this.menuButton_, 'click', _this.handleClick);
  13944. _this.on(_this.menuButton_, 'keydown', _this.handleKeyDown);
  13945. _this.on(_this.menuButton_, 'mouseenter', function () {
  13946. _this.addClass('vjs-hover');
  13947. _this.menu.show();
  13948. on(document, 'keyup', bind(_assertThisInitialized(_this), _this.handleMenuKeyUp));
  13949. });
  13950. _this.on('mouseleave', _this.handleMouseLeave);
  13951. _this.on('keydown', _this.handleSubmenuKeyDown);
  13952. return _this;
  13953. }
  13954. /**
  13955. * Update the menu based on the current state of its items.
  13956. */
  13957. var _proto = MenuButton.prototype;
  13958. _proto.update = function update() {
  13959. var menu = this.createMenu();
  13960. if (this.menu) {
  13961. this.menu.dispose();
  13962. this.removeChild(this.menu);
  13963. }
  13964. this.menu = menu;
  13965. this.addChild(menu);
  13966. /**
  13967. * Track the state of the menu button
  13968. *
  13969. * @type {Boolean}
  13970. * @private
  13971. */
  13972. this.buttonPressed_ = false;
  13973. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  13974. if (this.items && this.items.length <= this.hideThreshold_) {
  13975. this.hide();
  13976. } else {
  13977. this.show();
  13978. }
  13979. }
  13980. /**
  13981. * Create the menu and add all items to it.
  13982. *
  13983. * @return {Menu}
  13984. * The constructed menu
  13985. */
  13986. ;
  13987. _proto.createMenu = function createMenu() {
  13988. var menu = new Menu(this.player_, {
  13989. menuButton: this
  13990. });
  13991. /**
  13992. * Hide the menu if the number of items is less than or equal to this threshold. This defaults
  13993. * to 0 and whenever we add items which can be hidden to the menu we'll increment it. We list
  13994. * it here because every time we run `createMenu` we need to reset the value.
  13995. *
  13996. * @protected
  13997. * @type {Number}
  13998. */
  13999. this.hideThreshold_ = 0; // Add a title list item to the top
  14000. if (this.options_.title) {
  14001. var titleEl = createEl('li', {
  14002. className: 'vjs-menu-title',
  14003. innerHTML: toTitleCase(this.options_.title),
  14004. tabIndex: -1
  14005. });
  14006. this.hideThreshold_ += 1;
  14007. var titleComponent = new Component(this.player_, {
  14008. el: titleEl
  14009. });
  14010. menu.addItem(titleComponent);
  14011. }
  14012. this.items = this.createItems();
  14013. if (this.items) {
  14014. // Add menu items to the menu
  14015. for (var i = 0; i < this.items.length; i++) {
  14016. menu.addItem(this.items[i]);
  14017. }
  14018. }
  14019. return menu;
  14020. }
  14021. /**
  14022. * Create the list of menu items. Specific to each subclass.
  14023. *
  14024. * @abstract
  14025. */
  14026. ;
  14027. _proto.createItems = function createItems() {}
  14028. /**
  14029. * Create the `MenuButtons`s DOM element.
  14030. *
  14031. * @return {Element}
  14032. * The element that gets created.
  14033. */
  14034. ;
  14035. _proto.createEl = function createEl() {
  14036. return _Component.prototype.createEl.call(this, 'div', {
  14037. className: this.buildWrapperCSSClass()
  14038. }, {});
  14039. }
  14040. /**
  14041. * Allow sub components to stack CSS class names for the wrapper element
  14042. *
  14043. * @return {string}
  14044. * The constructed wrapper DOM `className`
  14045. */
  14046. ;
  14047. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  14048. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  14049. if (this.options_.inline === true) {
  14050. menuButtonClass += '-inline';
  14051. } else {
  14052. menuButtonClass += '-popup';
  14053. } // TODO: Fix the CSS so that this isn't necessary
  14054. var buttonClass = Button.prototype.buildCSSClass();
  14055. return "vjs-menu-button " + menuButtonClass + " " + buttonClass + " " + _Component.prototype.buildCSSClass.call(this);
  14056. }
  14057. /**
  14058. * Builds the default DOM `className`.
  14059. *
  14060. * @return {string}
  14061. * The DOM `className` for this object.
  14062. */
  14063. ;
  14064. _proto.buildCSSClass = function buildCSSClass() {
  14065. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  14066. if (this.options_.inline === true) {
  14067. menuButtonClass += '-inline';
  14068. } else {
  14069. menuButtonClass += '-popup';
  14070. }
  14071. return "vjs-menu-button " + menuButtonClass + " " + _Component.prototype.buildCSSClass.call(this);
  14072. }
  14073. /**
  14074. * Get or set the localized control text that will be used for accessibility.
  14075. *
  14076. * > NOTE: This will come from the internal `menuButton_` element.
  14077. *
  14078. * @param {string} [text]
  14079. * Control text for element.
  14080. *
  14081. * @param {Element} [el=this.menuButton_.el()]
  14082. * Element to set the title on.
  14083. *
  14084. * @return {string}
  14085. * - The control text when getting
  14086. */
  14087. ;
  14088. _proto.controlText = function controlText(text, el) {
  14089. if (el === void 0) {
  14090. el = this.menuButton_.el();
  14091. }
  14092. return this.menuButton_.controlText(text, el);
  14093. }
  14094. /**
  14095. * Dispose of the `menu-button` and all child components.
  14096. */
  14097. ;
  14098. _proto.dispose = function dispose() {
  14099. this.handleMouseLeave();
  14100. _Component.prototype.dispose.call(this);
  14101. }
  14102. /**
  14103. * Handle a click on a `MenuButton`.
  14104. * See {@link ClickableComponent#handleClick} for instances where this is called.
  14105. *
  14106. * @param {EventTarget~Event} event
  14107. * The `keydown`, `tap`, or `click` event that caused this function to be
  14108. * called.
  14109. *
  14110. * @listens tap
  14111. * @listens click
  14112. */
  14113. ;
  14114. _proto.handleClick = function handleClick(event) {
  14115. if (this.buttonPressed_) {
  14116. this.unpressButton();
  14117. } else {
  14118. this.pressButton();
  14119. }
  14120. }
  14121. /**
  14122. * Handle `mouseleave` for `MenuButton`.
  14123. *
  14124. * @param {EventTarget~Event} event
  14125. * The `mouseleave` event that caused this function to be called.
  14126. *
  14127. * @listens mouseleave
  14128. */
  14129. ;
  14130. _proto.handleMouseLeave = function handleMouseLeave(event) {
  14131. this.removeClass('vjs-hover');
  14132. off(document, 'keyup', bind(this, this.handleMenuKeyUp));
  14133. }
  14134. /**
  14135. * Set the focus to the actual button, not to this element
  14136. */
  14137. ;
  14138. _proto.focus = function focus() {
  14139. this.menuButton_.focus();
  14140. }
  14141. /**
  14142. * Remove the focus from the actual button, not this element
  14143. */
  14144. ;
  14145. _proto.blur = function blur() {
  14146. this.menuButton_.blur();
  14147. }
  14148. /**
  14149. * Handle tab, escape, down arrow, and up arrow keys for `MenuButton`. See
  14150. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  14151. *
  14152. * @param {EventTarget~Event} event
  14153. * The `keydown` event that caused this function to be called.
  14154. *
  14155. * @listens keydown
  14156. */
  14157. ;
  14158. _proto.handleKeyDown = function handleKeyDown(event) {
  14159. // Escape or Tab unpress the 'button'
  14160. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  14161. if (this.buttonPressed_) {
  14162. this.unpressButton();
  14163. } // Don't preventDefault for Tab key - we still want to lose focus
  14164. if (!keycode.isEventKey(event, 'Tab')) {
  14165. event.preventDefault(); // Set focus back to the menu button's button
  14166. this.menuButton_.focus();
  14167. } // Up Arrow or Down Arrow also 'press' the button to open the menu
  14168. } else if (keycode.isEventKey(event, 'Up') || keycode.isEventKey(event, 'Down')) {
  14169. if (!this.buttonPressed_) {
  14170. event.preventDefault();
  14171. this.pressButton();
  14172. }
  14173. }
  14174. }
  14175. /**
  14176. * Handle a `keyup` event on a `MenuButton`. The listener for this is added in
  14177. * the constructor.
  14178. *
  14179. * @param {EventTarget~Event} event
  14180. * Key press event
  14181. *
  14182. * @listens keyup
  14183. */
  14184. ;
  14185. _proto.handleMenuKeyUp = function handleMenuKeyUp(event) {
  14186. // Escape hides popup menu
  14187. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  14188. this.removeClass('vjs-hover');
  14189. }
  14190. }
  14191. /**
  14192. * This method name now delegates to `handleSubmenuKeyDown`. This means
  14193. * anyone calling `handleSubmenuKeyPress` will not see their method calls
  14194. * stop working.
  14195. *
  14196. * @param {EventTarget~Event} event
  14197. * The event that caused this function to be called.
  14198. */
  14199. ;
  14200. _proto.handleSubmenuKeyPress = function handleSubmenuKeyPress(event) {
  14201. this.handleSubmenuKeyDown(event);
  14202. }
  14203. /**
  14204. * Handle a `keydown` event on a sub-menu. The listener for this is added in
  14205. * the constructor.
  14206. *
  14207. * @param {EventTarget~Event} event
  14208. * Key press event
  14209. *
  14210. * @listens keydown
  14211. */
  14212. ;
  14213. _proto.handleSubmenuKeyDown = function handleSubmenuKeyDown(event) {
  14214. // Escape or Tab unpress the 'button'
  14215. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  14216. if (this.buttonPressed_) {
  14217. this.unpressButton();
  14218. } // Don't preventDefault for Tab key - we still want to lose focus
  14219. if (!keycode.isEventKey(event, 'Tab')) {
  14220. event.preventDefault(); // Set focus back to the menu button's button
  14221. this.menuButton_.focus();
  14222. }
  14223. }
  14224. }
  14225. /**
  14226. * Put the current `MenuButton` into a pressed state.
  14227. */
  14228. ;
  14229. _proto.pressButton = function pressButton() {
  14230. if (this.enabled_) {
  14231. this.buttonPressed_ = true;
  14232. this.menu.show();
  14233. this.menu.lockShowing();
  14234. this.menuButton_.el_.setAttribute('aria-expanded', 'true'); // set the focus into the submenu, except on iOS where it is resulting in
  14235. // undesired scrolling behavior when the player is in an iframe
  14236. if (IS_IOS && isInFrame()) {
  14237. // Return early so that the menu isn't focused
  14238. return;
  14239. }
  14240. this.menu.focus();
  14241. }
  14242. }
  14243. /**
  14244. * Take the current `MenuButton` out of a pressed state.
  14245. */
  14246. ;
  14247. _proto.unpressButton = function unpressButton() {
  14248. if (this.enabled_) {
  14249. this.buttonPressed_ = false;
  14250. this.menu.unlockShowing();
  14251. this.menu.hide();
  14252. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  14253. }
  14254. }
  14255. /**
  14256. * Disable the `MenuButton`. Don't allow it to be clicked.
  14257. */
  14258. ;
  14259. _proto.disable = function disable() {
  14260. this.unpressButton();
  14261. this.enabled_ = false;
  14262. this.addClass('vjs-disabled');
  14263. this.menuButton_.disable();
  14264. }
  14265. /**
  14266. * Enable the `MenuButton`. Allow it to be clicked.
  14267. */
  14268. ;
  14269. _proto.enable = function enable() {
  14270. this.enabled_ = true;
  14271. this.removeClass('vjs-disabled');
  14272. this.menuButton_.enable();
  14273. };
  14274. return MenuButton;
  14275. }(Component);
  14276. Component.registerComponent('MenuButton', MenuButton);
  14277. /**
  14278. * The base class for buttons that toggle specific track types (e.g. subtitles).
  14279. *
  14280. * @extends MenuButton
  14281. */
  14282. var TrackButton =
  14283. /*#__PURE__*/
  14284. function (_MenuButton) {
  14285. _inheritsLoose(TrackButton, _MenuButton);
  14286. /**
  14287. * Creates an instance of this class.
  14288. *
  14289. * @param {Player} player
  14290. * The `Player` that this class should be attached to.
  14291. *
  14292. * @param {Object} [options]
  14293. * The key/value store of player options.
  14294. */
  14295. function TrackButton(player, options) {
  14296. var _this;
  14297. var tracks = options.tracks;
  14298. _this = _MenuButton.call(this, player, options) || this;
  14299. if (_this.items.length <= 1) {
  14300. _this.hide();
  14301. }
  14302. if (!tracks) {
  14303. return _assertThisInitialized(_this);
  14304. }
  14305. var updateHandler = bind(_assertThisInitialized(_this), _this.update);
  14306. tracks.addEventListener('removetrack', updateHandler);
  14307. tracks.addEventListener('addtrack', updateHandler);
  14308. _this.player_.on('ready', updateHandler);
  14309. _this.player_.on('dispose', function () {
  14310. tracks.removeEventListener('removetrack', updateHandler);
  14311. tracks.removeEventListener('addtrack', updateHandler);
  14312. });
  14313. return _this;
  14314. }
  14315. return TrackButton;
  14316. }(MenuButton);
  14317. Component.registerComponent('TrackButton', TrackButton);
  14318. /**
  14319. * @file menu-keys.js
  14320. */
  14321. /**
  14322. * All keys used for operation of a menu (`MenuButton`, `Menu`, and `MenuItem`)
  14323. * Note that 'Enter' and 'Space' are not included here (otherwise they would
  14324. * prevent the `MenuButton` and `MenuItem` from being keyboard-clickable)
  14325. * @typedef MenuKeys
  14326. * @array
  14327. */
  14328. var MenuKeys = ['Tab', 'Esc', 'Up', 'Down', 'Right', 'Left'];
  14329. /**
  14330. * The component for a menu item. `<li>`
  14331. *
  14332. * @extends ClickableComponent
  14333. */
  14334. var MenuItem =
  14335. /*#__PURE__*/
  14336. function (_ClickableComponent) {
  14337. _inheritsLoose(MenuItem, _ClickableComponent);
  14338. /**
  14339. * Creates an instance of the this class.
  14340. *
  14341. * @param {Player} player
  14342. * The `Player` that this class should be attached to.
  14343. *
  14344. * @param {Object} [options={}]
  14345. * The key/value store of player options.
  14346. *
  14347. */
  14348. function MenuItem(player, options) {
  14349. var _this;
  14350. _this = _ClickableComponent.call(this, player, options) || this;
  14351. _this.selectable = options.selectable;
  14352. _this.isSelected_ = options.selected || false;
  14353. _this.multiSelectable = options.multiSelectable;
  14354. _this.selected(_this.isSelected_);
  14355. if (_this.selectable) {
  14356. if (_this.multiSelectable) {
  14357. _this.el_.setAttribute('role', 'menuitemcheckbox');
  14358. } else {
  14359. _this.el_.setAttribute('role', 'menuitemradio');
  14360. }
  14361. } else {
  14362. _this.el_.setAttribute('role', 'menuitem');
  14363. }
  14364. return _this;
  14365. }
  14366. /**
  14367. * Create the `MenuItem's DOM element
  14368. *
  14369. * @param {string} [type=li]
  14370. * Element's node type, not actually used, always set to `li`.
  14371. *
  14372. * @param {Object} [props={}]
  14373. * An object of properties that should be set on the element
  14374. *
  14375. * @param {Object} [attrs={}]
  14376. * An object of attributes that should be set on the element
  14377. *
  14378. * @return {Element}
  14379. * The element that gets created.
  14380. */
  14381. var _proto = MenuItem.prototype;
  14382. _proto.createEl = function createEl(type, props, attrs) {
  14383. // The control is textual, not just an icon
  14384. this.nonIconControl = true;
  14385. return _ClickableComponent.prototype.createEl.call(this, 'li', assign({
  14386. className: 'vjs-menu-item',
  14387. innerHTML: "<span class=\"vjs-menu-item-text\">" + this.localize(this.options_.label) + "</span>",
  14388. tabIndex: -1
  14389. }, props), attrs);
  14390. }
  14391. /**
  14392. * Ignore keys which are used by the menu, but pass any other ones up. See
  14393. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  14394. *
  14395. * @param {EventTarget~Event} event
  14396. * The `keydown` event that caused this function to be called.
  14397. *
  14398. * @listens keydown
  14399. */
  14400. ;
  14401. _proto.handleKeyDown = function handleKeyDown(event) {
  14402. if (!MenuKeys.some(function (key) {
  14403. return keycode.isEventKey(event, key);
  14404. })) {
  14405. // Pass keydown handling up for unused keys
  14406. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  14407. }
  14408. }
  14409. /**
  14410. * Any click on a `MenuItem` puts it into the selected state.
  14411. * See {@link ClickableComponent#handleClick} for instances where this is called.
  14412. *
  14413. * @param {EventTarget~Event} event
  14414. * The `keydown`, `tap`, or `click` event that caused this function to be
  14415. * called.
  14416. *
  14417. * @listens tap
  14418. * @listens click
  14419. */
  14420. ;
  14421. _proto.handleClick = function handleClick(event) {
  14422. this.selected(true);
  14423. }
  14424. /**
  14425. * Set the state for this menu item as selected or not.
  14426. *
  14427. * @param {boolean} selected
  14428. * if the menu item is selected or not
  14429. */
  14430. ;
  14431. _proto.selected = function selected(_selected) {
  14432. if (this.selectable) {
  14433. if (_selected) {
  14434. this.addClass('vjs-selected');
  14435. this.el_.setAttribute('aria-checked', 'true'); // aria-checked isn't fully supported by browsers/screen readers,
  14436. // so indicate selected state to screen reader in the control text.
  14437. this.controlText(', selected');
  14438. this.isSelected_ = true;
  14439. } else {
  14440. this.removeClass('vjs-selected');
  14441. this.el_.setAttribute('aria-checked', 'false'); // Indicate un-selected state to screen reader
  14442. this.controlText('');
  14443. this.isSelected_ = false;
  14444. }
  14445. }
  14446. };
  14447. return MenuItem;
  14448. }(ClickableComponent);
  14449. Component.registerComponent('MenuItem', MenuItem);
  14450. /**
  14451. * The specific menu item type for selecting a language within a text track kind
  14452. *
  14453. * @extends MenuItem
  14454. */
  14455. var TextTrackMenuItem =
  14456. /*#__PURE__*/
  14457. function (_MenuItem) {
  14458. _inheritsLoose(TextTrackMenuItem, _MenuItem);
  14459. /**
  14460. * Creates an instance of this class.
  14461. *
  14462. * @param {Player} player
  14463. * The `Player` that this class should be attached to.
  14464. *
  14465. * @param {Object} [options]
  14466. * The key/value store of player options.
  14467. */
  14468. function TextTrackMenuItem(player, options) {
  14469. var _this;
  14470. var track = options.track;
  14471. var tracks = player.textTracks(); // Modify options for parent MenuItem class's init.
  14472. options.label = track.label || track.language || 'Unknown';
  14473. options.selected = track.mode === 'showing';
  14474. _this = _MenuItem.call(this, player, options) || this;
  14475. _this.track = track; // Determine the relevant kind(s) of tracks for this component and filter
  14476. // out empty kinds.
  14477. _this.kinds = (options.kinds || [options.kind || _this.track.kind]).filter(Boolean);
  14478. var changeHandler = function changeHandler() {
  14479. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  14480. args[_key] = arguments[_key];
  14481. }
  14482. _this.handleTracksChange.apply(_assertThisInitialized(_this), args);
  14483. };
  14484. var selectedLanguageChangeHandler = function selectedLanguageChangeHandler() {
  14485. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  14486. args[_key2] = arguments[_key2];
  14487. }
  14488. _this.handleSelectedLanguageChange.apply(_assertThisInitialized(_this), args);
  14489. };
  14490. player.on(['loadstart', 'texttrackchange'], changeHandler);
  14491. tracks.addEventListener('change', changeHandler);
  14492. tracks.addEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  14493. _this.on('dispose', function () {
  14494. player.off(['loadstart', 'texttrackchange'], changeHandler);
  14495. tracks.removeEventListener('change', changeHandler);
  14496. tracks.removeEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  14497. }); // iOS7 doesn't dispatch change events to TextTrackLists when an
  14498. // associated track's mode changes. Without something like
  14499. // Object.observe() (also not present on iOS7), it's not
  14500. // possible to detect changes to the mode attribute and polyfill
  14501. // the change event. As a poor substitute, we manually dispatch
  14502. // change events whenever the controls modify the mode.
  14503. if (tracks.onchange === undefined) {
  14504. var event;
  14505. _this.on(['tap', 'click'], function () {
  14506. if (typeof window$1.Event !== 'object') {
  14507. // Android 2.3 throws an Illegal Constructor error for window.Event
  14508. try {
  14509. event = new window$1.Event('change');
  14510. } catch (err) {// continue regardless of error
  14511. }
  14512. }
  14513. if (!event) {
  14514. event = document.createEvent('Event');
  14515. event.initEvent('change', true, true);
  14516. }
  14517. tracks.dispatchEvent(event);
  14518. });
  14519. } // set the default state based on current tracks
  14520. _this.handleTracksChange();
  14521. return _this;
  14522. }
  14523. /**
  14524. * This gets called when an `TextTrackMenuItem` is "clicked". See
  14525. * {@link ClickableComponent} for more detailed information on what a click can be.
  14526. *
  14527. * @param {EventTarget~Event} event
  14528. * The `keydown`, `tap`, or `click` event that caused this function to be
  14529. * called.
  14530. *
  14531. * @listens tap
  14532. * @listens click
  14533. */
  14534. var _proto = TextTrackMenuItem.prototype;
  14535. _proto.handleClick = function handleClick(event) {
  14536. var referenceTrack = this.track;
  14537. var tracks = this.player_.textTracks();
  14538. _MenuItem.prototype.handleClick.call(this, event);
  14539. if (!tracks) {
  14540. return;
  14541. }
  14542. for (var i = 0; i < tracks.length; i++) {
  14543. var track = tracks[i]; // If the track from the text tracks list is not of the right kind,
  14544. // skip it. We do not want to affect tracks of incompatible kind(s).
  14545. if (this.kinds.indexOf(track.kind) === -1) {
  14546. continue;
  14547. } // If this text track is the component's track and it is not showing,
  14548. // set it to showing.
  14549. if (track === referenceTrack) {
  14550. if (track.mode !== 'showing') {
  14551. track.mode = 'showing';
  14552. } // If this text track is not the component's track and it is not
  14553. // disabled, set it to disabled.
  14554. } else if (track.mode !== 'disabled') {
  14555. track.mode = 'disabled';
  14556. }
  14557. }
  14558. }
  14559. /**
  14560. * Handle text track list change
  14561. *
  14562. * @param {EventTarget~Event} event
  14563. * The `change` event that caused this function to be called.
  14564. *
  14565. * @listens TextTrackList#change
  14566. */
  14567. ;
  14568. _proto.handleTracksChange = function handleTracksChange(event) {
  14569. var shouldBeSelected = this.track.mode === 'showing'; // Prevent redundant selected() calls because they may cause
  14570. // screen readers to read the appended control text unnecessarily
  14571. if (shouldBeSelected !== this.isSelected_) {
  14572. this.selected(shouldBeSelected);
  14573. }
  14574. };
  14575. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  14576. if (this.track.mode === 'showing') {
  14577. var selectedLanguage = this.player_.cache_.selectedLanguage; // Don't replace the kind of track across the same language
  14578. if (selectedLanguage && selectedLanguage.enabled && selectedLanguage.language === this.track.language && selectedLanguage.kind !== this.track.kind) {
  14579. return;
  14580. }
  14581. this.player_.cache_.selectedLanguage = {
  14582. enabled: true,
  14583. language: this.track.language,
  14584. kind: this.track.kind
  14585. };
  14586. }
  14587. };
  14588. _proto.dispose = function dispose() {
  14589. // remove reference to track object on dispose
  14590. this.track = null;
  14591. _MenuItem.prototype.dispose.call(this);
  14592. };
  14593. return TextTrackMenuItem;
  14594. }(MenuItem);
  14595. Component.registerComponent('TextTrackMenuItem', TextTrackMenuItem);
  14596. /**
  14597. * A special menu item for turning of a specific type of text track
  14598. *
  14599. * @extends TextTrackMenuItem
  14600. */
  14601. var OffTextTrackMenuItem =
  14602. /*#__PURE__*/
  14603. function (_TextTrackMenuItem) {
  14604. _inheritsLoose(OffTextTrackMenuItem, _TextTrackMenuItem);
  14605. /**
  14606. * Creates an instance of this class.
  14607. *
  14608. * @param {Player} player
  14609. * The `Player` that this class should be attached to.
  14610. *
  14611. * @param {Object} [options]
  14612. * The key/value store of player options.
  14613. */
  14614. function OffTextTrackMenuItem(player, options) {
  14615. // Create pseudo track info
  14616. // Requires options['kind']
  14617. options.track = {
  14618. player: player,
  14619. // it is no longer necessary to store `kind` or `kinds` on the track itself
  14620. // since they are now stored in the `kinds` property of all instances of
  14621. // TextTrackMenuItem, but this will remain for backwards compatibility
  14622. kind: options.kind,
  14623. kinds: options.kinds,
  14624. "default": false,
  14625. mode: 'disabled'
  14626. };
  14627. if (!options.kinds) {
  14628. options.kinds = [options.kind];
  14629. }
  14630. if (options.label) {
  14631. options.track.label = options.label;
  14632. } else {
  14633. options.track.label = options.kinds.join(' and ') + ' off';
  14634. } // MenuItem is selectable
  14635. options.selectable = true; // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  14636. options.multiSelectable = false;
  14637. return _TextTrackMenuItem.call(this, player, options) || this;
  14638. }
  14639. /**
  14640. * Handle text track change
  14641. *
  14642. * @param {EventTarget~Event} event
  14643. * The event that caused this function to run
  14644. */
  14645. var _proto = OffTextTrackMenuItem.prototype;
  14646. _proto.handleTracksChange = function handleTracksChange(event) {
  14647. var tracks = this.player().textTracks();
  14648. var shouldBeSelected = true;
  14649. for (var i = 0, l = tracks.length; i < l; i++) {
  14650. var track = tracks[i];
  14651. if (this.options_.kinds.indexOf(track.kind) > -1 && track.mode === 'showing') {
  14652. shouldBeSelected = false;
  14653. break;
  14654. }
  14655. } // Prevent redundant selected() calls because they may cause
  14656. // screen readers to read the appended control text unnecessarily
  14657. if (shouldBeSelected !== this.isSelected_) {
  14658. this.selected(shouldBeSelected);
  14659. }
  14660. };
  14661. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  14662. var tracks = this.player().textTracks();
  14663. var allHidden = true;
  14664. for (var i = 0, l = tracks.length; i < l; i++) {
  14665. var track = tracks[i];
  14666. if (['captions', 'descriptions', 'subtitles'].indexOf(track.kind) > -1 && track.mode === 'showing') {
  14667. allHidden = false;
  14668. break;
  14669. }
  14670. }
  14671. if (allHidden) {
  14672. this.player_.cache_.selectedLanguage = {
  14673. enabled: false
  14674. };
  14675. }
  14676. };
  14677. return OffTextTrackMenuItem;
  14678. }(TextTrackMenuItem);
  14679. Component.registerComponent('OffTextTrackMenuItem', OffTextTrackMenuItem);
  14680. /**
  14681. * The base class for buttons that toggle specific text track types (e.g. subtitles)
  14682. *
  14683. * @extends MenuButton
  14684. */
  14685. var TextTrackButton =
  14686. /*#__PURE__*/
  14687. function (_TrackButton) {
  14688. _inheritsLoose(TextTrackButton, _TrackButton);
  14689. /**
  14690. * Creates an instance of this class.
  14691. *
  14692. * @param {Player} player
  14693. * The `Player` that this class should be attached to.
  14694. *
  14695. * @param {Object} [options={}]
  14696. * The key/value store of player options.
  14697. */
  14698. function TextTrackButton(player, options) {
  14699. if (options === void 0) {
  14700. options = {};
  14701. }
  14702. options.tracks = player.textTracks();
  14703. return _TrackButton.call(this, player, options) || this;
  14704. }
  14705. /**
  14706. * Create a menu item for each text track
  14707. *
  14708. * @param {TextTrackMenuItem[]} [items=[]]
  14709. * Existing array of items to use during creation
  14710. *
  14711. * @return {TextTrackMenuItem[]}
  14712. * Array of menu items that were created
  14713. */
  14714. var _proto = TextTrackButton.prototype;
  14715. _proto.createItems = function createItems(items, TrackMenuItem) {
  14716. if (items === void 0) {
  14717. items = [];
  14718. }
  14719. if (TrackMenuItem === void 0) {
  14720. TrackMenuItem = TextTrackMenuItem;
  14721. }
  14722. // Label is an override for the [track] off label
  14723. // USed to localise captions/subtitles
  14724. var label;
  14725. if (this.label_) {
  14726. label = this.label_ + " off";
  14727. } // Add an OFF menu item to turn all tracks off
  14728. items.push(new OffTextTrackMenuItem(this.player_, {
  14729. kinds: this.kinds_,
  14730. kind: this.kind_,
  14731. label: label
  14732. }));
  14733. this.hideThreshold_ += 1;
  14734. var tracks = this.player_.textTracks();
  14735. if (!Array.isArray(this.kinds_)) {
  14736. this.kinds_ = [this.kind_];
  14737. }
  14738. for (var i = 0; i < tracks.length; i++) {
  14739. var track = tracks[i]; // only add tracks that are of an appropriate kind and have a label
  14740. if (this.kinds_.indexOf(track.kind) > -1) {
  14741. var item = new TrackMenuItem(this.player_, {
  14742. track: track,
  14743. kinds: this.kinds_,
  14744. kind: this.kind_,
  14745. // MenuItem is selectable
  14746. selectable: true,
  14747. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  14748. multiSelectable: false
  14749. });
  14750. item.addClass("vjs-" + track.kind + "-menu-item");
  14751. items.push(item);
  14752. }
  14753. }
  14754. return items;
  14755. };
  14756. return TextTrackButton;
  14757. }(TrackButton);
  14758. Component.registerComponent('TextTrackButton', TextTrackButton);
  14759. /**
  14760. * The chapter track menu item
  14761. *
  14762. * @extends MenuItem
  14763. */
  14764. var ChaptersTrackMenuItem =
  14765. /*#__PURE__*/
  14766. function (_MenuItem) {
  14767. _inheritsLoose(ChaptersTrackMenuItem, _MenuItem);
  14768. /**
  14769. * Creates an instance of this class.
  14770. *
  14771. * @param {Player} player
  14772. * The `Player` that this class should be attached to.
  14773. *
  14774. * @param {Object} [options]
  14775. * The key/value store of player options.
  14776. */
  14777. function ChaptersTrackMenuItem(player, options) {
  14778. var _this;
  14779. var track = options.track;
  14780. var cue = options.cue;
  14781. var currentTime = player.currentTime(); // Modify options for parent MenuItem class's init.
  14782. options.selectable = true;
  14783. options.multiSelectable = false;
  14784. options.label = cue.text;
  14785. options.selected = cue.startTime <= currentTime && currentTime < cue.endTime;
  14786. _this = _MenuItem.call(this, player, options) || this;
  14787. _this.track = track;
  14788. _this.cue = cue;
  14789. track.addEventListener('cuechange', bind(_assertThisInitialized(_this), _this.update));
  14790. return _this;
  14791. }
  14792. /**
  14793. * This gets called when an `ChaptersTrackMenuItem` is "clicked". See
  14794. * {@link ClickableComponent} for more detailed information on what a click can be.
  14795. *
  14796. * @param {EventTarget~Event} [event]
  14797. * The `keydown`, `tap`, or `click` event that caused this function to be
  14798. * called.
  14799. *
  14800. * @listens tap
  14801. * @listens click
  14802. */
  14803. var _proto = ChaptersTrackMenuItem.prototype;
  14804. _proto.handleClick = function handleClick(event) {
  14805. _MenuItem.prototype.handleClick.call(this);
  14806. this.player_.currentTime(this.cue.startTime);
  14807. this.update(this.cue.startTime);
  14808. }
  14809. /**
  14810. * Update chapter menu item
  14811. *
  14812. * @param {EventTarget~Event} [event]
  14813. * The `cuechange` event that caused this function to run.
  14814. *
  14815. * @listens TextTrack#cuechange
  14816. */
  14817. ;
  14818. _proto.update = function update(event) {
  14819. var cue = this.cue;
  14820. var currentTime = this.player_.currentTime(); // vjs.log(currentTime, cue.startTime);
  14821. this.selected(cue.startTime <= currentTime && currentTime < cue.endTime);
  14822. };
  14823. return ChaptersTrackMenuItem;
  14824. }(MenuItem);
  14825. Component.registerComponent('ChaptersTrackMenuItem', ChaptersTrackMenuItem);
  14826. /**
  14827. * The button component for toggling and selecting chapters
  14828. * Chapters act much differently than other text tracks
  14829. * Cues are navigation vs. other tracks of alternative languages
  14830. *
  14831. * @extends TextTrackButton
  14832. */
  14833. var ChaptersButton =
  14834. /*#__PURE__*/
  14835. function (_TextTrackButton) {
  14836. _inheritsLoose(ChaptersButton, _TextTrackButton);
  14837. /**
  14838. * Creates an instance of this class.
  14839. *
  14840. * @param {Player} player
  14841. * The `Player` that this class should be attached to.
  14842. *
  14843. * @param {Object} [options]
  14844. * The key/value store of player options.
  14845. *
  14846. * @param {Component~ReadyCallback} [ready]
  14847. * The function to call when this function is ready.
  14848. */
  14849. function ChaptersButton(player, options, ready) {
  14850. return _TextTrackButton.call(this, player, options, ready) || this;
  14851. }
  14852. /**
  14853. * Builds the default DOM `className`.
  14854. *
  14855. * @return {string}
  14856. * The DOM `className` for this object.
  14857. */
  14858. var _proto = ChaptersButton.prototype;
  14859. _proto.buildCSSClass = function buildCSSClass() {
  14860. return "vjs-chapters-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  14861. };
  14862. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  14863. return "vjs-chapters-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  14864. }
  14865. /**
  14866. * Update the menu based on the current state of its items.
  14867. *
  14868. * @param {EventTarget~Event} [event]
  14869. * An event that triggered this function to run.
  14870. *
  14871. * @listens TextTrackList#addtrack
  14872. * @listens TextTrackList#removetrack
  14873. * @listens TextTrackList#change
  14874. */
  14875. ;
  14876. _proto.update = function update(event) {
  14877. if (!this.track_ || event && (event.type === 'addtrack' || event.type === 'removetrack')) {
  14878. this.setTrack(this.findChaptersTrack());
  14879. }
  14880. _TextTrackButton.prototype.update.call(this);
  14881. }
  14882. /**
  14883. * Set the currently selected track for the chapters button.
  14884. *
  14885. * @param {TextTrack} track
  14886. * The new track to select. Nothing will change if this is the currently selected
  14887. * track.
  14888. */
  14889. ;
  14890. _proto.setTrack = function setTrack(track) {
  14891. if (this.track_ === track) {
  14892. return;
  14893. }
  14894. if (!this.updateHandler_) {
  14895. this.updateHandler_ = this.update.bind(this);
  14896. } // here this.track_ refers to the old track instance
  14897. if (this.track_) {
  14898. var remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  14899. if (remoteTextTrackEl) {
  14900. remoteTextTrackEl.removeEventListener('load', this.updateHandler_);
  14901. }
  14902. this.track_ = null;
  14903. }
  14904. this.track_ = track; // here this.track_ refers to the new track instance
  14905. if (this.track_) {
  14906. this.track_.mode = 'hidden';
  14907. var _remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  14908. if (_remoteTextTrackEl) {
  14909. _remoteTextTrackEl.addEventListener('load', this.updateHandler_);
  14910. }
  14911. }
  14912. }
  14913. /**
  14914. * Find the track object that is currently in use by this ChaptersButton
  14915. *
  14916. * @return {TextTrack|undefined}
  14917. * The current track or undefined if none was found.
  14918. */
  14919. ;
  14920. _proto.findChaptersTrack = function findChaptersTrack() {
  14921. var tracks = this.player_.textTracks() || [];
  14922. for (var i = tracks.length - 1; i >= 0; i--) {
  14923. // We will always choose the last track as our chaptersTrack
  14924. var track = tracks[i];
  14925. if (track.kind === this.kind_) {
  14926. return track;
  14927. }
  14928. }
  14929. }
  14930. /**
  14931. * Get the caption for the ChaptersButton based on the track label. This will also
  14932. * use the current tracks localized kind as a fallback if a label does not exist.
  14933. *
  14934. * @return {string}
  14935. * The tracks current label or the localized track kind.
  14936. */
  14937. ;
  14938. _proto.getMenuCaption = function getMenuCaption() {
  14939. if (this.track_ && this.track_.label) {
  14940. return this.track_.label;
  14941. }
  14942. return this.localize(toTitleCase(this.kind_));
  14943. }
  14944. /**
  14945. * Create menu from chapter track
  14946. *
  14947. * @return {Menu}
  14948. * New menu for the chapter buttons
  14949. */
  14950. ;
  14951. _proto.createMenu = function createMenu() {
  14952. this.options_.title = this.getMenuCaption();
  14953. return _TextTrackButton.prototype.createMenu.call(this);
  14954. }
  14955. /**
  14956. * Create a menu item for each text track
  14957. *
  14958. * @return {TextTrackMenuItem[]}
  14959. * Array of menu items
  14960. */
  14961. ;
  14962. _proto.createItems = function createItems() {
  14963. var items = [];
  14964. if (!this.track_) {
  14965. return items;
  14966. }
  14967. var cues = this.track_.cues;
  14968. if (!cues) {
  14969. return items;
  14970. }
  14971. for (var i = 0, l = cues.length; i < l; i++) {
  14972. var cue = cues[i];
  14973. var mi = new ChaptersTrackMenuItem(this.player_, {
  14974. track: this.track_,
  14975. cue: cue
  14976. });
  14977. items.push(mi);
  14978. }
  14979. return items;
  14980. };
  14981. return ChaptersButton;
  14982. }(TextTrackButton);
  14983. /**
  14984. * `kind` of TextTrack to look for to associate it with this menu.
  14985. *
  14986. * @type {string}
  14987. * @private
  14988. */
  14989. ChaptersButton.prototype.kind_ = 'chapters';
  14990. /**
  14991. * The text that should display over the `ChaptersButton`s controls. Added for localization.
  14992. *
  14993. * @type {string}
  14994. * @private
  14995. */
  14996. ChaptersButton.prototype.controlText_ = 'Chapters';
  14997. Component.registerComponent('ChaptersButton', ChaptersButton);
  14998. /**
  14999. * The button component for toggling and selecting descriptions
  15000. *
  15001. * @extends TextTrackButton
  15002. */
  15003. var DescriptionsButton =
  15004. /*#__PURE__*/
  15005. function (_TextTrackButton) {
  15006. _inheritsLoose(DescriptionsButton, _TextTrackButton);
  15007. /**
  15008. * Creates an instance of this class.
  15009. *
  15010. * @param {Player} player
  15011. * The `Player` that this class should be attached to.
  15012. *
  15013. * @param {Object} [options]
  15014. * The key/value store of player options.
  15015. *
  15016. * @param {Component~ReadyCallback} [ready]
  15017. * The function to call when this component is ready.
  15018. */
  15019. function DescriptionsButton(player, options, ready) {
  15020. var _this;
  15021. _this = _TextTrackButton.call(this, player, options, ready) || this;
  15022. var tracks = player.textTracks();
  15023. var changeHandler = bind(_assertThisInitialized(_this), _this.handleTracksChange);
  15024. tracks.addEventListener('change', changeHandler);
  15025. _this.on('dispose', function () {
  15026. tracks.removeEventListener('change', changeHandler);
  15027. });
  15028. return _this;
  15029. }
  15030. /**
  15031. * Handle text track change
  15032. *
  15033. * @param {EventTarget~Event} event
  15034. * The event that caused this function to run
  15035. *
  15036. * @listens TextTrackList#change
  15037. */
  15038. var _proto = DescriptionsButton.prototype;
  15039. _proto.handleTracksChange = function handleTracksChange(event) {
  15040. var tracks = this.player().textTracks();
  15041. var disabled = false; // Check whether a track of a different kind is showing
  15042. for (var i = 0, l = tracks.length; i < l; i++) {
  15043. var track = tracks[i];
  15044. if (track.kind !== this.kind_ && track.mode === 'showing') {
  15045. disabled = true;
  15046. break;
  15047. }
  15048. } // If another track is showing, disable this menu button
  15049. if (disabled) {
  15050. this.disable();
  15051. } else {
  15052. this.enable();
  15053. }
  15054. }
  15055. /**
  15056. * Builds the default DOM `className`.
  15057. *
  15058. * @return {string}
  15059. * The DOM `className` for this object.
  15060. */
  15061. ;
  15062. _proto.buildCSSClass = function buildCSSClass() {
  15063. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15064. };
  15065. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15066. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15067. };
  15068. return DescriptionsButton;
  15069. }(TextTrackButton);
  15070. /**
  15071. * `kind` of TextTrack to look for to associate it with this menu.
  15072. *
  15073. * @type {string}
  15074. * @private
  15075. */
  15076. DescriptionsButton.prototype.kind_ = 'descriptions';
  15077. /**
  15078. * The text that should display over the `DescriptionsButton`s controls. Added for localization.
  15079. *
  15080. * @type {string}
  15081. * @private
  15082. */
  15083. DescriptionsButton.prototype.controlText_ = 'Descriptions';
  15084. Component.registerComponent('DescriptionsButton', DescriptionsButton);
  15085. /**
  15086. * The button component for toggling and selecting subtitles
  15087. *
  15088. * @extends TextTrackButton
  15089. */
  15090. var SubtitlesButton =
  15091. /*#__PURE__*/
  15092. function (_TextTrackButton) {
  15093. _inheritsLoose(SubtitlesButton, _TextTrackButton);
  15094. /**
  15095. * Creates an instance of this class.
  15096. *
  15097. * @param {Player} player
  15098. * The `Player` that this class should be attached to.
  15099. *
  15100. * @param {Object} [options]
  15101. * The key/value store of player options.
  15102. *
  15103. * @param {Component~ReadyCallback} [ready]
  15104. * The function to call when this component is ready.
  15105. */
  15106. function SubtitlesButton(player, options, ready) {
  15107. return _TextTrackButton.call(this, player, options, ready) || this;
  15108. }
  15109. /**
  15110. * Builds the default DOM `className`.
  15111. *
  15112. * @return {string}
  15113. * The DOM `className` for this object.
  15114. */
  15115. var _proto = SubtitlesButton.prototype;
  15116. _proto.buildCSSClass = function buildCSSClass() {
  15117. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15118. };
  15119. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15120. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15121. };
  15122. return SubtitlesButton;
  15123. }(TextTrackButton);
  15124. /**
  15125. * `kind` of TextTrack to look for to associate it with this menu.
  15126. *
  15127. * @type {string}
  15128. * @private
  15129. */
  15130. SubtitlesButton.prototype.kind_ = 'subtitles';
  15131. /**
  15132. * The text that should display over the `SubtitlesButton`s controls. Added for localization.
  15133. *
  15134. * @type {string}
  15135. * @private
  15136. */
  15137. SubtitlesButton.prototype.controlText_ = 'Subtitles';
  15138. Component.registerComponent('SubtitlesButton', SubtitlesButton);
  15139. /**
  15140. * The menu item for caption track settings menu
  15141. *
  15142. * @extends TextTrackMenuItem
  15143. */
  15144. var CaptionSettingsMenuItem =
  15145. /*#__PURE__*/
  15146. function (_TextTrackMenuItem) {
  15147. _inheritsLoose(CaptionSettingsMenuItem, _TextTrackMenuItem);
  15148. /**
  15149. * Creates an instance of this class.
  15150. *
  15151. * @param {Player} player
  15152. * The `Player` that this class should be attached to.
  15153. *
  15154. * @param {Object} [options]
  15155. * The key/value store of player options.
  15156. */
  15157. function CaptionSettingsMenuItem(player, options) {
  15158. var _this;
  15159. options.track = {
  15160. player: player,
  15161. kind: options.kind,
  15162. label: options.kind + ' settings',
  15163. selectable: false,
  15164. "default": false,
  15165. mode: 'disabled'
  15166. }; // CaptionSettingsMenuItem has no concept of 'selected'
  15167. options.selectable = false;
  15168. options.name = 'CaptionSettingsMenuItem';
  15169. _this = _TextTrackMenuItem.call(this, player, options) || this;
  15170. _this.addClass('vjs-texttrack-settings');
  15171. _this.controlText(', opens ' + options.kind + ' settings dialog');
  15172. return _this;
  15173. }
  15174. /**
  15175. * This gets called when an `CaptionSettingsMenuItem` is "clicked". See
  15176. * {@link ClickableComponent} for more detailed information on what a click can be.
  15177. *
  15178. * @param {EventTarget~Event} [event]
  15179. * The `keydown`, `tap`, or `click` event that caused this function to be
  15180. * called.
  15181. *
  15182. * @listens tap
  15183. * @listens click
  15184. */
  15185. var _proto = CaptionSettingsMenuItem.prototype;
  15186. _proto.handleClick = function handleClick(event) {
  15187. this.player().getChild('textTrackSettings').open();
  15188. };
  15189. return CaptionSettingsMenuItem;
  15190. }(TextTrackMenuItem);
  15191. Component.registerComponent('CaptionSettingsMenuItem', CaptionSettingsMenuItem);
  15192. /**
  15193. * The button component for toggling and selecting captions
  15194. *
  15195. * @extends TextTrackButton
  15196. */
  15197. var CaptionsButton =
  15198. /*#__PURE__*/
  15199. function (_TextTrackButton) {
  15200. _inheritsLoose(CaptionsButton, _TextTrackButton);
  15201. /**
  15202. * Creates an instance of this class.
  15203. *
  15204. * @param {Player} player
  15205. * The `Player` that this class should be attached to.
  15206. *
  15207. * @param {Object} [options]
  15208. * The key/value store of player options.
  15209. *
  15210. * @param {Component~ReadyCallback} [ready]
  15211. * The function to call when this component is ready.
  15212. */
  15213. function CaptionsButton(player, options, ready) {
  15214. return _TextTrackButton.call(this, player, options, ready) || this;
  15215. }
  15216. /**
  15217. * Builds the default DOM `className`.
  15218. *
  15219. * @return {string}
  15220. * The DOM `className` for this object.
  15221. */
  15222. var _proto = CaptionsButton.prototype;
  15223. _proto.buildCSSClass = function buildCSSClass() {
  15224. return "vjs-captions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15225. };
  15226. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15227. return "vjs-captions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15228. }
  15229. /**
  15230. * Create caption menu items
  15231. *
  15232. * @return {CaptionSettingsMenuItem[]}
  15233. * The array of current menu items.
  15234. */
  15235. ;
  15236. _proto.createItems = function createItems() {
  15237. var items = [];
  15238. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  15239. items.push(new CaptionSettingsMenuItem(this.player_, {
  15240. kind: this.kind_
  15241. }));
  15242. this.hideThreshold_ += 1;
  15243. }
  15244. return _TextTrackButton.prototype.createItems.call(this, items);
  15245. };
  15246. return CaptionsButton;
  15247. }(TextTrackButton);
  15248. /**
  15249. * `kind` of TextTrack to look for to associate it with this menu.
  15250. *
  15251. * @type {string}
  15252. * @private
  15253. */
  15254. CaptionsButton.prototype.kind_ = 'captions';
  15255. /**
  15256. * The text that should display over the `CaptionsButton`s controls. Added for localization.
  15257. *
  15258. * @type {string}
  15259. * @private
  15260. */
  15261. CaptionsButton.prototype.controlText_ = 'Captions';
  15262. Component.registerComponent('CaptionsButton', CaptionsButton);
  15263. /**
  15264. * SubsCapsMenuItem has an [cc] icon to distinguish captions from subtitles
  15265. * in the SubsCapsMenu.
  15266. *
  15267. * @extends TextTrackMenuItem
  15268. */
  15269. var SubsCapsMenuItem =
  15270. /*#__PURE__*/
  15271. function (_TextTrackMenuItem) {
  15272. _inheritsLoose(SubsCapsMenuItem, _TextTrackMenuItem);
  15273. function SubsCapsMenuItem() {
  15274. return _TextTrackMenuItem.apply(this, arguments) || this;
  15275. }
  15276. var _proto = SubsCapsMenuItem.prototype;
  15277. _proto.createEl = function createEl(type, props, attrs) {
  15278. var innerHTML = "<span class=\"vjs-menu-item-text\">" + this.localize(this.options_.label);
  15279. if (this.options_.track.kind === 'captions') {
  15280. innerHTML += "\n <span aria-hidden=\"true\" class=\"vjs-icon-placeholder\"></span>\n <span class=\"vjs-control-text\"> " + this.localize('Captions') + "</span>\n ";
  15281. }
  15282. innerHTML += '</span>';
  15283. var el = _TextTrackMenuItem.prototype.createEl.call(this, type, assign({
  15284. innerHTML: innerHTML
  15285. }, props), attrs);
  15286. return el;
  15287. };
  15288. return SubsCapsMenuItem;
  15289. }(TextTrackMenuItem);
  15290. Component.registerComponent('SubsCapsMenuItem', SubsCapsMenuItem);
  15291. /**
  15292. * The button component for toggling and selecting captions and/or subtitles
  15293. *
  15294. * @extends TextTrackButton
  15295. */
  15296. var SubsCapsButton =
  15297. /*#__PURE__*/
  15298. function (_TextTrackButton) {
  15299. _inheritsLoose(SubsCapsButton, _TextTrackButton);
  15300. function SubsCapsButton(player, options) {
  15301. var _this;
  15302. if (options === void 0) {
  15303. options = {};
  15304. }
  15305. _this = _TextTrackButton.call(this, player, options) || this; // Although North America uses "captions" in most cases for
  15306. // "captions and subtitles" other locales use "subtitles"
  15307. _this.label_ = 'subtitles';
  15308. if (['en', 'en-us', 'en-ca', 'fr-ca'].indexOf(_this.player_.language_) > -1) {
  15309. _this.label_ = 'captions';
  15310. }
  15311. _this.menuButton_.controlText(toTitleCase(_this.label_));
  15312. return _this;
  15313. }
  15314. /**
  15315. * Builds the default DOM `className`.
  15316. *
  15317. * @return {string}
  15318. * The DOM `className` for this object.
  15319. */
  15320. var _proto = SubsCapsButton.prototype;
  15321. _proto.buildCSSClass = function buildCSSClass() {
  15322. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  15323. };
  15324. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15325. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  15326. }
  15327. /**
  15328. * Create caption/subtitles menu items
  15329. *
  15330. * @return {CaptionSettingsMenuItem[]}
  15331. * The array of current menu items.
  15332. */
  15333. ;
  15334. _proto.createItems = function createItems() {
  15335. var items = [];
  15336. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  15337. items.push(new CaptionSettingsMenuItem(this.player_, {
  15338. kind: this.label_
  15339. }));
  15340. this.hideThreshold_ += 1;
  15341. }
  15342. items = _TextTrackButton.prototype.createItems.call(this, items, SubsCapsMenuItem);
  15343. return items;
  15344. };
  15345. return SubsCapsButton;
  15346. }(TextTrackButton);
  15347. /**
  15348. * `kind`s of TextTrack to look for to associate it with this menu.
  15349. *
  15350. * @type {array}
  15351. * @private
  15352. */
  15353. SubsCapsButton.prototype.kinds_ = ['captions', 'subtitles'];
  15354. /**
  15355. * The text that should display over the `SubsCapsButton`s controls.
  15356. *
  15357. *
  15358. * @type {string}
  15359. * @private
  15360. */
  15361. SubsCapsButton.prototype.controlText_ = 'Subtitles';
  15362. Component.registerComponent('SubsCapsButton', SubsCapsButton);
  15363. /**
  15364. * An {@link AudioTrack} {@link MenuItem}
  15365. *
  15366. * @extends MenuItem
  15367. */
  15368. var AudioTrackMenuItem =
  15369. /*#__PURE__*/
  15370. function (_MenuItem) {
  15371. _inheritsLoose(AudioTrackMenuItem, _MenuItem);
  15372. /**
  15373. * Creates an instance of this class.
  15374. *
  15375. * @param {Player} player
  15376. * The `Player` that this class should be attached to.
  15377. *
  15378. * @param {Object} [options]
  15379. * The key/value store of player options.
  15380. */
  15381. function AudioTrackMenuItem(player, options) {
  15382. var _this;
  15383. var track = options.track;
  15384. var tracks = player.audioTracks(); // Modify options for parent MenuItem class's init.
  15385. options.label = track.label || track.language || 'Unknown';
  15386. options.selected = track.enabled;
  15387. _this = _MenuItem.call(this, player, options) || this;
  15388. _this.track = track;
  15389. _this.addClass("vjs-" + track.kind + "-menu-item");
  15390. var changeHandler = function changeHandler() {
  15391. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  15392. args[_key] = arguments[_key];
  15393. }
  15394. _this.handleTracksChange.apply(_assertThisInitialized(_this), args);
  15395. };
  15396. tracks.addEventListener('change', changeHandler);
  15397. _this.on('dispose', function () {
  15398. tracks.removeEventListener('change', changeHandler);
  15399. });
  15400. return _this;
  15401. }
  15402. var _proto = AudioTrackMenuItem.prototype;
  15403. _proto.createEl = function createEl(type, props, attrs) {
  15404. var innerHTML = "<span class=\"vjs-menu-item-text\">" + this.localize(this.options_.label);
  15405. if (this.options_.track.kind === 'main-desc') {
  15406. innerHTML += "\n <span aria-hidden=\"true\" class=\"vjs-icon-placeholder\"></span>\n <span class=\"vjs-control-text\"> " + this.localize('Descriptions') + "</span>\n ";
  15407. }
  15408. innerHTML += '</span>';
  15409. var el = _MenuItem.prototype.createEl.call(this, type, assign({
  15410. innerHTML: innerHTML
  15411. }, props), attrs);
  15412. return el;
  15413. }
  15414. /**
  15415. * This gets called when an `AudioTrackMenuItem is "clicked". See {@link ClickableComponent}
  15416. * for more detailed information on what a click can be.
  15417. *
  15418. * @param {EventTarget~Event} [event]
  15419. * The `keydown`, `tap`, or `click` event that caused this function to be
  15420. * called.
  15421. *
  15422. * @listens tap
  15423. * @listens click
  15424. */
  15425. ;
  15426. _proto.handleClick = function handleClick(event) {
  15427. var tracks = this.player_.audioTracks();
  15428. _MenuItem.prototype.handleClick.call(this, event);
  15429. for (var i = 0; i < tracks.length; i++) {
  15430. var track = tracks[i];
  15431. track.enabled = track === this.track;
  15432. }
  15433. }
  15434. /**
  15435. * Handle any {@link AudioTrack} change.
  15436. *
  15437. * @param {EventTarget~Event} [event]
  15438. * The {@link AudioTrackList#change} event that caused this to run.
  15439. *
  15440. * @listens AudioTrackList#change
  15441. */
  15442. ;
  15443. _proto.handleTracksChange = function handleTracksChange(event) {
  15444. this.selected(this.track.enabled);
  15445. };
  15446. return AudioTrackMenuItem;
  15447. }(MenuItem);
  15448. Component.registerComponent('AudioTrackMenuItem', AudioTrackMenuItem);
  15449. /**
  15450. * The base class for buttons that toggle specific {@link AudioTrack} types.
  15451. *
  15452. * @extends TrackButton
  15453. */
  15454. var AudioTrackButton =
  15455. /*#__PURE__*/
  15456. function (_TrackButton) {
  15457. _inheritsLoose(AudioTrackButton, _TrackButton);
  15458. /**
  15459. * Creates an instance of this class.
  15460. *
  15461. * @param {Player} player
  15462. * The `Player` that this class should be attached to.
  15463. *
  15464. * @param {Object} [options={}]
  15465. * The key/value store of player options.
  15466. */
  15467. function AudioTrackButton(player, options) {
  15468. if (options === void 0) {
  15469. options = {};
  15470. }
  15471. options.tracks = player.audioTracks();
  15472. return _TrackButton.call(this, player, options) || this;
  15473. }
  15474. /**
  15475. * Builds the default DOM `className`.
  15476. *
  15477. * @return {string}
  15478. * The DOM `className` for this object.
  15479. */
  15480. var _proto = AudioTrackButton.prototype;
  15481. _proto.buildCSSClass = function buildCSSClass() {
  15482. return "vjs-audio-button " + _TrackButton.prototype.buildCSSClass.call(this);
  15483. };
  15484. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15485. return "vjs-audio-button " + _TrackButton.prototype.buildWrapperCSSClass.call(this);
  15486. }
  15487. /**
  15488. * Create a menu item for each audio track
  15489. *
  15490. * @param {AudioTrackMenuItem[]} [items=[]]
  15491. * An array of existing menu items to use.
  15492. *
  15493. * @return {AudioTrackMenuItem[]}
  15494. * An array of menu items
  15495. */
  15496. ;
  15497. _proto.createItems = function createItems(items) {
  15498. if (items === void 0) {
  15499. items = [];
  15500. }
  15501. // if there's only one audio track, there no point in showing it
  15502. this.hideThreshold_ = 1;
  15503. var tracks = this.player_.audioTracks();
  15504. for (var i = 0; i < tracks.length; i++) {
  15505. var track = tracks[i];
  15506. items.push(new AudioTrackMenuItem(this.player_, {
  15507. track: track,
  15508. // MenuItem is selectable
  15509. selectable: true,
  15510. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  15511. multiSelectable: false
  15512. }));
  15513. }
  15514. return items;
  15515. };
  15516. return AudioTrackButton;
  15517. }(TrackButton);
  15518. /**
  15519. * The text that should display over the `AudioTrackButton`s controls. Added for localization.
  15520. *
  15521. * @type {string}
  15522. * @private
  15523. */
  15524. AudioTrackButton.prototype.controlText_ = 'Audio Track';
  15525. Component.registerComponent('AudioTrackButton', AudioTrackButton);
  15526. /**
  15527. * The specific menu item type for selecting a playback rate.
  15528. *
  15529. * @extends MenuItem
  15530. */
  15531. var PlaybackRateMenuItem =
  15532. /*#__PURE__*/
  15533. function (_MenuItem) {
  15534. _inheritsLoose(PlaybackRateMenuItem, _MenuItem);
  15535. /**
  15536. * Creates an instance of this class.
  15537. *
  15538. * @param {Player} player
  15539. * The `Player` that this class should be attached to.
  15540. *
  15541. * @param {Object} [options]
  15542. * The key/value store of player options.
  15543. */
  15544. function PlaybackRateMenuItem(player, options) {
  15545. var _this;
  15546. var label = options.rate;
  15547. var rate = parseFloat(label, 10); // Modify options for parent MenuItem class's init.
  15548. options.label = label;
  15549. options.selected = rate === 1;
  15550. options.selectable = true;
  15551. options.multiSelectable = false;
  15552. _this = _MenuItem.call(this, player, options) || this;
  15553. _this.label = label;
  15554. _this.rate = rate;
  15555. _this.on(player, 'ratechange', _this.update);
  15556. return _this;
  15557. }
  15558. /**
  15559. * This gets called when an `PlaybackRateMenuItem` is "clicked". See
  15560. * {@link ClickableComponent} for more detailed information on what a click can be.
  15561. *
  15562. * @param {EventTarget~Event} [event]
  15563. * The `keydown`, `tap`, or `click` event that caused this function to be
  15564. * called.
  15565. *
  15566. * @listens tap
  15567. * @listens click
  15568. */
  15569. var _proto = PlaybackRateMenuItem.prototype;
  15570. _proto.handleClick = function handleClick(event) {
  15571. _MenuItem.prototype.handleClick.call(this);
  15572. this.player().playbackRate(this.rate);
  15573. }
  15574. /**
  15575. * Update the PlaybackRateMenuItem when the playbackrate changes.
  15576. *
  15577. * @param {EventTarget~Event} [event]
  15578. * The `ratechange` event that caused this function to run.
  15579. *
  15580. * @listens Player#ratechange
  15581. */
  15582. ;
  15583. _proto.update = function update(event) {
  15584. this.selected(this.player().playbackRate() === this.rate);
  15585. };
  15586. return PlaybackRateMenuItem;
  15587. }(MenuItem);
  15588. /**
  15589. * The text that should display over the `PlaybackRateMenuItem`s controls. Added for localization.
  15590. *
  15591. * @type {string}
  15592. * @private
  15593. */
  15594. PlaybackRateMenuItem.prototype.contentElType = 'button';
  15595. Component.registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem);
  15596. /**
  15597. * The component for controlling the playback rate.
  15598. *
  15599. * @extends MenuButton
  15600. */
  15601. var PlaybackRateMenuButton =
  15602. /*#__PURE__*/
  15603. function (_MenuButton) {
  15604. _inheritsLoose(PlaybackRateMenuButton, _MenuButton);
  15605. /**
  15606. * Creates an instance of this class.
  15607. *
  15608. * @param {Player} player
  15609. * The `Player` that this class should be attached to.
  15610. *
  15611. * @param {Object} [options]
  15612. * The key/value store of player options.
  15613. */
  15614. function PlaybackRateMenuButton(player, options) {
  15615. var _this;
  15616. _this = _MenuButton.call(this, player, options) || this;
  15617. _this.updateVisibility();
  15618. _this.updateLabel();
  15619. _this.on(player, 'loadstart', _this.updateVisibility);
  15620. _this.on(player, 'ratechange', _this.updateLabel);
  15621. return _this;
  15622. }
  15623. /**
  15624. * Create the `Component`'s DOM element
  15625. *
  15626. * @return {Element}
  15627. * The element that was created.
  15628. */
  15629. var _proto = PlaybackRateMenuButton.prototype;
  15630. _proto.createEl = function createEl$1() {
  15631. var el = _MenuButton.prototype.createEl.call(this);
  15632. this.labelEl_ = createEl('div', {
  15633. className: 'vjs-playback-rate-value',
  15634. innerHTML: '1x'
  15635. });
  15636. el.appendChild(this.labelEl_);
  15637. return el;
  15638. };
  15639. _proto.dispose = function dispose() {
  15640. this.labelEl_ = null;
  15641. _MenuButton.prototype.dispose.call(this);
  15642. }
  15643. /**
  15644. * Builds the default DOM `className`.
  15645. *
  15646. * @return {string}
  15647. * The DOM `className` for this object.
  15648. */
  15649. ;
  15650. _proto.buildCSSClass = function buildCSSClass() {
  15651. return "vjs-playback-rate " + _MenuButton.prototype.buildCSSClass.call(this);
  15652. };
  15653. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15654. return "vjs-playback-rate " + _MenuButton.prototype.buildWrapperCSSClass.call(this);
  15655. }
  15656. /**
  15657. * Create the playback rate menu
  15658. *
  15659. * @return {Menu}
  15660. * Menu object populated with {@link PlaybackRateMenuItem}s
  15661. */
  15662. ;
  15663. _proto.createMenu = function createMenu() {
  15664. var menu = new Menu(this.player());
  15665. var rates = this.playbackRates();
  15666. if (rates) {
  15667. for (var i = rates.length - 1; i >= 0; i--) {
  15668. menu.addChild(new PlaybackRateMenuItem(this.player(), {
  15669. rate: rates[i] + 'x'
  15670. }));
  15671. }
  15672. }
  15673. return menu;
  15674. }
  15675. /**
  15676. * Updates ARIA accessibility attributes
  15677. */
  15678. ;
  15679. _proto.updateARIAAttributes = function updateARIAAttributes() {
  15680. // Current playback rate
  15681. this.el().setAttribute('aria-valuenow', this.player().playbackRate());
  15682. }
  15683. /**
  15684. * This gets called when an `PlaybackRateMenuButton` is "clicked". See
  15685. * {@link ClickableComponent} for more detailed information on what a click can be.
  15686. *
  15687. * @param {EventTarget~Event} [event]
  15688. * The `keydown`, `tap`, or `click` event that caused this function to be
  15689. * called.
  15690. *
  15691. * @listens tap
  15692. * @listens click
  15693. */
  15694. ;
  15695. _proto.handleClick = function handleClick(event) {
  15696. // select next rate option
  15697. var currentRate = this.player().playbackRate();
  15698. var rates = this.playbackRates(); // this will select first one if the last one currently selected
  15699. var newRate = rates[0];
  15700. for (var i = 0; i < rates.length; i++) {
  15701. if (rates[i] > currentRate) {
  15702. newRate = rates[i];
  15703. break;
  15704. }
  15705. }
  15706. this.player().playbackRate(newRate);
  15707. }
  15708. /**
  15709. * Get possible playback rates
  15710. *
  15711. * @return {Array}
  15712. * All possible playback rates
  15713. */
  15714. ;
  15715. _proto.playbackRates = function playbackRates() {
  15716. return this.options_.playbackRates || this.options_.playerOptions && this.options_.playerOptions.playbackRates;
  15717. }
  15718. /**
  15719. * Get whether playback rates is supported by the tech
  15720. * and an array of playback rates exists
  15721. *
  15722. * @return {boolean}
  15723. * Whether changing playback rate is supported
  15724. */
  15725. ;
  15726. _proto.playbackRateSupported = function playbackRateSupported() {
  15727. return this.player().tech_ && this.player().tech_.featuresPlaybackRate && this.playbackRates() && this.playbackRates().length > 0;
  15728. }
  15729. /**
  15730. * Hide playback rate controls when they're no playback rate options to select
  15731. *
  15732. * @param {EventTarget~Event} [event]
  15733. * The event that caused this function to run.
  15734. *
  15735. * @listens Player#loadstart
  15736. */
  15737. ;
  15738. _proto.updateVisibility = function updateVisibility(event) {
  15739. if (this.playbackRateSupported()) {
  15740. this.removeClass('vjs-hidden');
  15741. } else {
  15742. this.addClass('vjs-hidden');
  15743. }
  15744. }
  15745. /**
  15746. * Update button label when rate changed
  15747. *
  15748. * @param {EventTarget~Event} [event]
  15749. * The event that caused this function to run.
  15750. *
  15751. * @listens Player#ratechange
  15752. */
  15753. ;
  15754. _proto.updateLabel = function updateLabel(event) {
  15755. if (this.playbackRateSupported()) {
  15756. this.labelEl_.innerHTML = this.player().playbackRate() + 'x';
  15757. }
  15758. };
  15759. return PlaybackRateMenuButton;
  15760. }(MenuButton);
  15761. /**
  15762. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  15763. *
  15764. * @type {string}
  15765. * @private
  15766. */
  15767. PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
  15768. Component.registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
  15769. /**
  15770. * Just an empty spacer element that can be used as an append point for plugins, etc.
  15771. * Also can be used to create space between elements when necessary.
  15772. *
  15773. * @extends Component
  15774. */
  15775. var Spacer =
  15776. /*#__PURE__*/
  15777. function (_Component) {
  15778. _inheritsLoose(Spacer, _Component);
  15779. function Spacer() {
  15780. return _Component.apply(this, arguments) || this;
  15781. }
  15782. var _proto = Spacer.prototype;
  15783. /**
  15784. * Builds the default DOM `className`.
  15785. *
  15786. * @return {string}
  15787. * The DOM `className` for this object.
  15788. */
  15789. _proto.buildCSSClass = function buildCSSClass() {
  15790. return "vjs-spacer " + _Component.prototype.buildCSSClass.call(this);
  15791. }
  15792. /**
  15793. * Create the `Component`'s DOM element
  15794. *
  15795. * @return {Element}
  15796. * The element that was created.
  15797. */
  15798. ;
  15799. _proto.createEl = function createEl() {
  15800. return _Component.prototype.createEl.call(this, 'div', {
  15801. className: this.buildCSSClass()
  15802. });
  15803. };
  15804. return Spacer;
  15805. }(Component);
  15806. Component.registerComponent('Spacer', Spacer);
  15807. /**
  15808. * Spacer specifically meant to be used as an insertion point for new plugins, etc.
  15809. *
  15810. * @extends Spacer
  15811. */
  15812. var CustomControlSpacer =
  15813. /*#__PURE__*/
  15814. function (_Spacer) {
  15815. _inheritsLoose(CustomControlSpacer, _Spacer);
  15816. function CustomControlSpacer() {
  15817. return _Spacer.apply(this, arguments) || this;
  15818. }
  15819. var _proto = CustomControlSpacer.prototype;
  15820. /**
  15821. * Builds the default DOM `className`.
  15822. *
  15823. * @return {string}
  15824. * The DOM `className` for this object.
  15825. */
  15826. _proto.buildCSSClass = function buildCSSClass() {
  15827. return "vjs-custom-control-spacer " + _Spacer.prototype.buildCSSClass.call(this);
  15828. }
  15829. /**
  15830. * Create the `Component`'s DOM element
  15831. *
  15832. * @return {Element}
  15833. * The element that was created.
  15834. */
  15835. ;
  15836. _proto.createEl = function createEl() {
  15837. var el = _Spacer.prototype.createEl.call(this, {
  15838. className: this.buildCSSClass()
  15839. }); // No-flex/table-cell mode requires there be some content
  15840. // in the cell to fill the remaining space of the table.
  15841. el.innerHTML = "\xA0";
  15842. return el;
  15843. };
  15844. return CustomControlSpacer;
  15845. }(Spacer);
  15846. Component.registerComponent('CustomControlSpacer', CustomControlSpacer);
  15847. /**
  15848. * Container of main controls.
  15849. *
  15850. * @extends Component
  15851. */
  15852. var ControlBar =
  15853. /*#__PURE__*/
  15854. function (_Component) {
  15855. _inheritsLoose(ControlBar, _Component);
  15856. function ControlBar() {
  15857. return _Component.apply(this, arguments) || this;
  15858. }
  15859. var _proto = ControlBar.prototype;
  15860. /**
  15861. * Create the `Component`'s DOM element
  15862. *
  15863. * @return {Element}
  15864. * The element that was created.
  15865. */
  15866. _proto.createEl = function createEl() {
  15867. return _Component.prototype.createEl.call(this, 'div', {
  15868. className: 'vjs-control-bar',
  15869. dir: 'ltr'
  15870. });
  15871. };
  15872. return ControlBar;
  15873. }(Component);
  15874. /**
  15875. * Default options for `ControlBar`
  15876. *
  15877. * @type {Object}
  15878. * @private
  15879. */
  15880. ControlBar.prototype.options_ = {
  15881. children: ['playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'seekToLive', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'descriptionsButton', 'subsCapsButton', 'audioTrackButton', 'fullscreenToggle']
  15882. };
  15883. if ('exitPictureInPicture' in document) {
  15884. ControlBar.prototype.options_.children.splice(ControlBar.prototype.options_.children.length - 1, 0, 'pictureInPictureToggle');
  15885. }
  15886. Component.registerComponent('ControlBar', ControlBar);
  15887. /**
  15888. * A display that indicates an error has occurred. This means that the video
  15889. * is unplayable.
  15890. *
  15891. * @extends ModalDialog
  15892. */
  15893. var ErrorDisplay =
  15894. /*#__PURE__*/
  15895. function (_ModalDialog) {
  15896. _inheritsLoose(ErrorDisplay, _ModalDialog);
  15897. /**
  15898. * Creates an instance of this class.
  15899. *
  15900. * @param {Player} player
  15901. * The `Player` that this class should be attached to.
  15902. *
  15903. * @param {Object} [options]
  15904. * The key/value store of player options.
  15905. */
  15906. function ErrorDisplay(player, options) {
  15907. var _this;
  15908. _this = _ModalDialog.call(this, player, options) || this;
  15909. _this.on(player, 'error', _this.open);
  15910. return _this;
  15911. }
  15912. /**
  15913. * Builds the default DOM `className`.
  15914. *
  15915. * @return {string}
  15916. * The DOM `className` for this object.
  15917. *
  15918. * @deprecated Since version 5.
  15919. */
  15920. var _proto = ErrorDisplay.prototype;
  15921. _proto.buildCSSClass = function buildCSSClass() {
  15922. return "vjs-error-display " + _ModalDialog.prototype.buildCSSClass.call(this);
  15923. }
  15924. /**
  15925. * Gets the localized error message based on the `Player`s error.
  15926. *
  15927. * @return {string}
  15928. * The `Player`s error message localized or an empty string.
  15929. */
  15930. ;
  15931. _proto.content = function content() {
  15932. var error = this.player().error();
  15933. return error ? this.localize(error.message) : '';
  15934. };
  15935. return ErrorDisplay;
  15936. }(ModalDialog);
  15937. /**
  15938. * The default options for an `ErrorDisplay`.
  15939. *
  15940. * @private
  15941. */
  15942. ErrorDisplay.prototype.options_ = mergeOptions(ModalDialog.prototype.options_, {
  15943. pauseOnOpen: false,
  15944. fillAlways: true,
  15945. temporary: false,
  15946. uncloseable: true
  15947. });
  15948. Component.registerComponent('ErrorDisplay', ErrorDisplay);
  15949. var LOCAL_STORAGE_KEY = 'vjs-text-track-settings';
  15950. var COLOR_BLACK = ['#000', 'Black'];
  15951. var COLOR_BLUE = ['#00F', 'Blue'];
  15952. var COLOR_CYAN = ['#0FF', 'Cyan'];
  15953. var COLOR_GREEN = ['#0F0', 'Green'];
  15954. var COLOR_MAGENTA = ['#F0F', 'Magenta'];
  15955. var COLOR_RED = ['#F00', 'Red'];
  15956. var COLOR_WHITE = ['#FFF', 'White'];
  15957. var COLOR_YELLOW = ['#FF0', 'Yellow'];
  15958. var OPACITY_OPAQUE = ['1', 'Opaque'];
  15959. var OPACITY_SEMI = ['0.5', 'Semi-Transparent'];
  15960. var OPACITY_TRANS = ['0', 'Transparent']; // Configuration for the various <select> elements in the DOM of this component.
  15961. //
  15962. // Possible keys include:
  15963. //
  15964. // `default`:
  15965. // The default option index. Only needs to be provided if not zero.
  15966. // `parser`:
  15967. // A function which is used to parse the value from the selected option in
  15968. // a customized way.
  15969. // `selector`:
  15970. // The selector used to find the associated <select> element.
  15971. var selectConfigs = {
  15972. backgroundColor: {
  15973. selector: '.vjs-bg-color > select',
  15974. id: 'captions-background-color-%s',
  15975. label: 'Color',
  15976. options: [COLOR_BLACK, COLOR_WHITE, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  15977. },
  15978. backgroundOpacity: {
  15979. selector: '.vjs-bg-opacity > select',
  15980. id: 'captions-background-opacity-%s',
  15981. label: 'Transparency',
  15982. options: [OPACITY_OPAQUE, OPACITY_SEMI, OPACITY_TRANS]
  15983. },
  15984. color: {
  15985. selector: '.vjs-fg-color > select',
  15986. id: 'captions-foreground-color-%s',
  15987. label: 'Color',
  15988. options: [COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  15989. },
  15990. edgeStyle: {
  15991. selector: '.vjs-edge-style > select',
  15992. id: '%s',
  15993. label: 'Text Edge Style',
  15994. options: [['none', 'None'], ['raised', 'Raised'], ['depressed', 'Depressed'], ['uniform', 'Uniform'], ['dropshadow', 'Dropshadow']]
  15995. },
  15996. fontFamily: {
  15997. selector: '.vjs-font-family > select',
  15998. id: 'captions-font-family-%s',
  15999. label: 'Font Family',
  16000. options: [['proportionalSansSerif', 'Proportional Sans-Serif'], ['monospaceSansSerif', 'Monospace Sans-Serif'], ['proportionalSerif', 'Proportional Serif'], ['monospaceSerif', 'Monospace Serif'], ['casual', 'Casual'], ['script', 'Script'], ['small-caps', 'Small Caps']]
  16001. },
  16002. fontPercent: {
  16003. selector: '.vjs-font-percent > select',
  16004. id: 'captions-font-size-%s',
  16005. label: 'Font Size',
  16006. options: [['0.50', '50%'], ['0.75', '75%'], ['1.00', '100%'], ['1.25', '125%'], ['1.50', '150%'], ['1.75', '175%'], ['2.00', '200%'], ['3.00', '300%'], ['4.00', '400%']],
  16007. "default": 2,
  16008. parser: function parser(v) {
  16009. return v === '1.00' ? null : Number(v);
  16010. }
  16011. },
  16012. textOpacity: {
  16013. selector: '.vjs-text-opacity > select',
  16014. id: 'captions-foreground-opacity-%s',
  16015. label: 'Transparency',
  16016. options: [OPACITY_OPAQUE, OPACITY_SEMI]
  16017. },
  16018. // Options for this object are defined below.
  16019. windowColor: {
  16020. selector: '.vjs-window-color > select',
  16021. id: 'captions-window-color-%s',
  16022. label: 'Color'
  16023. },
  16024. // Options for this object are defined below.
  16025. windowOpacity: {
  16026. selector: '.vjs-window-opacity > select',
  16027. id: 'captions-window-opacity-%s',
  16028. label: 'Transparency',
  16029. options: [OPACITY_TRANS, OPACITY_SEMI, OPACITY_OPAQUE]
  16030. }
  16031. };
  16032. selectConfigs.windowColor.options = selectConfigs.backgroundColor.options;
  16033. /**
  16034. * Get the actual value of an option.
  16035. *
  16036. * @param {string} value
  16037. * The value to get
  16038. *
  16039. * @param {Function} [parser]
  16040. * Optional function to adjust the value.
  16041. *
  16042. * @return {Mixed}
  16043. * - Will be `undefined` if no value exists
  16044. * - Will be `undefined` if the given value is "none".
  16045. * - Will be the actual value otherwise.
  16046. *
  16047. * @private
  16048. */
  16049. function parseOptionValue(value, parser) {
  16050. if (parser) {
  16051. value = parser(value);
  16052. }
  16053. if (value && value !== 'none') {
  16054. return value;
  16055. }
  16056. }
  16057. /**
  16058. * Gets the value of the selected <option> element within a <select> element.
  16059. *
  16060. * @param {Element} el
  16061. * the element to look in
  16062. *
  16063. * @param {Function} [parser]
  16064. * Optional function to adjust the value.
  16065. *
  16066. * @return {Mixed}
  16067. * - Will be `undefined` if no value exists
  16068. * - Will be `undefined` if the given value is "none".
  16069. * - Will be the actual value otherwise.
  16070. *
  16071. * @private
  16072. */
  16073. function getSelectedOptionValue(el, parser) {
  16074. var value = el.options[el.options.selectedIndex].value;
  16075. return parseOptionValue(value, parser);
  16076. }
  16077. /**
  16078. * Sets the selected <option> element within a <select> element based on a
  16079. * given value.
  16080. *
  16081. * @param {Element} el
  16082. * The element to look in.
  16083. *
  16084. * @param {string} value
  16085. * the property to look on.
  16086. *
  16087. * @param {Function} [parser]
  16088. * Optional function to adjust the value before comparing.
  16089. *
  16090. * @private
  16091. */
  16092. function setSelectedOption(el, value, parser) {
  16093. if (!value) {
  16094. return;
  16095. }
  16096. for (var i = 0; i < el.options.length; i++) {
  16097. if (parseOptionValue(el.options[i].value, parser) === value) {
  16098. el.selectedIndex = i;
  16099. break;
  16100. }
  16101. }
  16102. }
  16103. /**
  16104. * Manipulate Text Tracks settings.
  16105. *
  16106. * @extends ModalDialog
  16107. */
  16108. var TextTrackSettings =
  16109. /*#__PURE__*/
  16110. function (_ModalDialog) {
  16111. _inheritsLoose(TextTrackSettings, _ModalDialog);
  16112. /**
  16113. * Creates an instance of this class.
  16114. *
  16115. * @param {Player} player
  16116. * The `Player` that this class should be attached to.
  16117. *
  16118. * @param {Object} [options]
  16119. * The key/value store of player options.
  16120. */
  16121. function TextTrackSettings(player, options) {
  16122. var _this;
  16123. options.temporary = false;
  16124. _this = _ModalDialog.call(this, player, options) || this;
  16125. _this.updateDisplay = bind(_assertThisInitialized(_this), _this.updateDisplay); // fill the modal and pretend we have opened it
  16126. _this.fill();
  16127. _this.hasBeenOpened_ = _this.hasBeenFilled_ = true;
  16128. _this.endDialog = createEl('p', {
  16129. className: 'vjs-control-text',
  16130. textContent: _this.localize('End of dialog window.')
  16131. });
  16132. _this.el().appendChild(_this.endDialog);
  16133. _this.setDefaults(); // Grab `persistTextTrackSettings` from the player options if not passed in child options
  16134. if (options.persistTextTrackSettings === undefined) {
  16135. _this.options_.persistTextTrackSettings = _this.options_.playerOptions.persistTextTrackSettings;
  16136. }
  16137. _this.on(_this.$('.vjs-done-button'), 'click', function () {
  16138. _this.saveSettings();
  16139. _this.close();
  16140. });
  16141. _this.on(_this.$('.vjs-default-button'), 'click', function () {
  16142. _this.setDefaults();
  16143. _this.updateDisplay();
  16144. });
  16145. each(selectConfigs, function (config) {
  16146. _this.on(_this.$(config.selector), 'change', _this.updateDisplay);
  16147. });
  16148. if (_this.options_.persistTextTrackSettings) {
  16149. _this.restoreSettings();
  16150. }
  16151. return _this;
  16152. }
  16153. var _proto = TextTrackSettings.prototype;
  16154. _proto.dispose = function dispose() {
  16155. this.endDialog = null;
  16156. _ModalDialog.prototype.dispose.call(this);
  16157. }
  16158. /**
  16159. * Create a <select> element with configured options.
  16160. *
  16161. * @param {string} key
  16162. * Configuration key to use during creation.
  16163. *
  16164. * @return {string}
  16165. * An HTML string.
  16166. *
  16167. * @private
  16168. */
  16169. ;
  16170. _proto.createElSelect_ = function createElSelect_(key, legendId, type) {
  16171. var _this2 = this;
  16172. if (legendId === void 0) {
  16173. legendId = '';
  16174. }
  16175. if (type === void 0) {
  16176. type = 'label';
  16177. }
  16178. var config = selectConfigs[key];
  16179. var id = config.id.replace('%s', this.id_);
  16180. var selectLabelledbyIds = [legendId, id].join(' ').trim();
  16181. return ["<" + type + " id=\"" + id + "\" class=\"" + (type === 'label' ? 'vjs-label' : '') + "\">", this.localize(config.label), "</" + type + ">", "<select aria-labelledby=\"" + selectLabelledbyIds + "\">"].concat(config.options.map(function (o) {
  16182. var optionId = id + '-' + o[1].replace(/\W+/g, '');
  16183. return ["<option id=\"" + optionId + "\" value=\"" + o[0] + "\" ", "aria-labelledby=\"" + selectLabelledbyIds + " " + optionId + "\">", _this2.localize(o[1]), '</option>'].join('');
  16184. })).concat('</select>').join('');
  16185. }
  16186. /**
  16187. * Create foreground color element for the component
  16188. *
  16189. * @return {string}
  16190. * An HTML string.
  16191. *
  16192. * @private
  16193. */
  16194. ;
  16195. _proto.createElFgColor_ = function createElFgColor_() {
  16196. var legendId = "captions-text-legend-" + this.id_;
  16197. return ['<fieldset class="vjs-fg-color vjs-track-setting">', "<legend id=\"" + legendId + "\">", this.localize('Text'), '</legend>', this.createElSelect_('color', legendId), '<span class="vjs-text-opacity vjs-opacity">', this.createElSelect_('textOpacity', legendId), '</span>', '</fieldset>'].join('');
  16198. }
  16199. /**
  16200. * Create background color element for the component
  16201. *
  16202. * @return {string}
  16203. * An HTML string.
  16204. *
  16205. * @private
  16206. */
  16207. ;
  16208. _proto.createElBgColor_ = function createElBgColor_() {
  16209. var legendId = "captions-background-" + this.id_;
  16210. return ['<fieldset class="vjs-bg-color vjs-track-setting">', "<legend id=\"" + legendId + "\">", this.localize('Background'), '</legend>', this.createElSelect_('backgroundColor', legendId), '<span class="vjs-bg-opacity vjs-opacity">', this.createElSelect_('backgroundOpacity', legendId), '</span>', '</fieldset>'].join('');
  16211. }
  16212. /**
  16213. * Create window color element for the component
  16214. *
  16215. * @return {string}
  16216. * An HTML string.
  16217. *
  16218. * @private
  16219. */
  16220. ;
  16221. _proto.createElWinColor_ = function createElWinColor_() {
  16222. var legendId = "captions-window-" + this.id_;
  16223. return ['<fieldset class="vjs-window-color vjs-track-setting">', "<legend id=\"" + legendId + "\">", this.localize('Window'), '</legend>', this.createElSelect_('windowColor', legendId), '<span class="vjs-window-opacity vjs-opacity">', this.createElSelect_('windowOpacity', legendId), '</span>', '</fieldset>'].join('');
  16224. }
  16225. /**
  16226. * Create color elements for the component
  16227. *
  16228. * @return {Element}
  16229. * The element that was created
  16230. *
  16231. * @private
  16232. */
  16233. ;
  16234. _proto.createElColors_ = function createElColors_() {
  16235. return createEl('div', {
  16236. className: 'vjs-track-settings-colors',
  16237. innerHTML: [this.createElFgColor_(), this.createElBgColor_(), this.createElWinColor_()].join('')
  16238. });
  16239. }
  16240. /**
  16241. * Create font elements for the component
  16242. *
  16243. * @return {Element}
  16244. * The element that was created.
  16245. *
  16246. * @private
  16247. */
  16248. ;
  16249. _proto.createElFont_ = function createElFont_() {
  16250. return createEl('div', {
  16251. className: 'vjs-track-settings-font',
  16252. innerHTML: ['<fieldset class="vjs-font-percent vjs-track-setting">', this.createElSelect_('fontPercent', '', 'legend'), '</fieldset>', '<fieldset class="vjs-edge-style vjs-track-setting">', this.createElSelect_('edgeStyle', '', 'legend'), '</fieldset>', '<fieldset class="vjs-font-family vjs-track-setting">', this.createElSelect_('fontFamily', '', 'legend'), '</fieldset>'].join('')
  16253. });
  16254. }
  16255. /**
  16256. * Create controls for the component
  16257. *
  16258. * @return {Element}
  16259. * The element that was created.
  16260. *
  16261. * @private
  16262. */
  16263. ;
  16264. _proto.createElControls_ = function createElControls_() {
  16265. var defaultsDescription = this.localize('restore all settings to the default values');
  16266. return createEl('div', {
  16267. className: 'vjs-track-settings-controls',
  16268. innerHTML: ["<button type=\"button\" class=\"vjs-default-button\" title=\"" + defaultsDescription + "\">", this.localize('Reset'), "<span class=\"vjs-control-text\"> " + defaultsDescription + "</span>", '</button>', "<button type=\"button\" class=\"vjs-done-button\">" + this.localize('Done') + "</button>"].join('')
  16269. });
  16270. };
  16271. _proto.content = function content() {
  16272. return [this.createElColors_(), this.createElFont_(), this.createElControls_()];
  16273. };
  16274. _proto.label = function label() {
  16275. return this.localize('Caption Settings Dialog');
  16276. };
  16277. _proto.description = function description() {
  16278. return this.localize('Beginning of dialog window. Escape will cancel and close the window.');
  16279. };
  16280. _proto.buildCSSClass = function buildCSSClass() {
  16281. return _ModalDialog.prototype.buildCSSClass.call(this) + ' vjs-text-track-settings';
  16282. }
  16283. /**
  16284. * Gets an object of text track settings (or null).
  16285. *
  16286. * @return {Object}
  16287. * An object with config values parsed from the DOM or localStorage.
  16288. */
  16289. ;
  16290. _proto.getValues = function getValues() {
  16291. var _this3 = this;
  16292. return reduce(selectConfigs, function (accum, config, key) {
  16293. var value = getSelectedOptionValue(_this3.$(config.selector), config.parser);
  16294. if (value !== undefined) {
  16295. accum[key] = value;
  16296. }
  16297. return accum;
  16298. }, {});
  16299. }
  16300. /**
  16301. * Sets text track settings from an object of values.
  16302. *
  16303. * @param {Object} values
  16304. * An object with config values parsed from the DOM or localStorage.
  16305. */
  16306. ;
  16307. _proto.setValues = function setValues(values) {
  16308. var _this4 = this;
  16309. each(selectConfigs, function (config, key) {
  16310. setSelectedOption(_this4.$(config.selector), values[key], config.parser);
  16311. });
  16312. }
  16313. /**
  16314. * Sets all `<select>` elements to their default values.
  16315. */
  16316. ;
  16317. _proto.setDefaults = function setDefaults() {
  16318. var _this5 = this;
  16319. each(selectConfigs, function (config) {
  16320. var index = config.hasOwnProperty('default') ? config["default"] : 0;
  16321. _this5.$(config.selector).selectedIndex = index;
  16322. });
  16323. }
  16324. /**
  16325. * Restore texttrack settings from localStorage
  16326. */
  16327. ;
  16328. _proto.restoreSettings = function restoreSettings() {
  16329. var values;
  16330. try {
  16331. values = JSON.parse(window$1.localStorage.getItem(LOCAL_STORAGE_KEY));
  16332. } catch (err) {
  16333. log.warn(err);
  16334. }
  16335. if (values) {
  16336. this.setValues(values);
  16337. }
  16338. }
  16339. /**
  16340. * Save text track settings to localStorage
  16341. */
  16342. ;
  16343. _proto.saveSettings = function saveSettings() {
  16344. if (!this.options_.persistTextTrackSettings) {
  16345. return;
  16346. }
  16347. var values = this.getValues();
  16348. try {
  16349. if (Object.keys(values).length) {
  16350. window$1.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(values));
  16351. } else {
  16352. window$1.localStorage.removeItem(LOCAL_STORAGE_KEY);
  16353. }
  16354. } catch (err) {
  16355. log.warn(err);
  16356. }
  16357. }
  16358. /**
  16359. * Update display of text track settings
  16360. */
  16361. ;
  16362. _proto.updateDisplay = function updateDisplay() {
  16363. var ttDisplay = this.player_.getChild('textTrackDisplay');
  16364. if (ttDisplay) {
  16365. ttDisplay.updateDisplay();
  16366. }
  16367. }
  16368. /**
  16369. * conditionally blur the element and refocus the captions button
  16370. *
  16371. * @private
  16372. */
  16373. ;
  16374. _proto.conditionalBlur_ = function conditionalBlur_() {
  16375. this.previouslyActiveEl_ = null;
  16376. var cb = this.player_.controlBar;
  16377. var subsCapsBtn = cb && cb.subsCapsButton;
  16378. var ccBtn = cb && cb.captionsButton;
  16379. if (subsCapsBtn) {
  16380. subsCapsBtn.focus();
  16381. } else if (ccBtn) {
  16382. ccBtn.focus();
  16383. }
  16384. };
  16385. return TextTrackSettings;
  16386. }(ModalDialog);
  16387. Component.registerComponent('TextTrackSettings', TextTrackSettings);
  16388. /**
  16389. * A Resize Manager. It is in charge of triggering `playerresize` on the player in the right conditions.
  16390. *
  16391. * It'll either create an iframe and use a debounced resize handler on it or use the new {@link https://wicg.github.io/ResizeObserver/|ResizeObserver}.
  16392. *
  16393. * If the ResizeObserver is available natively, it will be used. A polyfill can be passed in as an option.
  16394. * If a `playerresize` event is not needed, the ResizeManager component can be removed from the player, see the example below.
  16395. * @example <caption>How to disable the resize manager</caption>
  16396. * const player = videojs('#vid', {
  16397. * resizeManager: false
  16398. * });
  16399. *
  16400. * @see {@link https://wicg.github.io/ResizeObserver/|ResizeObserver specification}
  16401. *
  16402. * @extends Component
  16403. */
  16404. var ResizeManager =
  16405. /*#__PURE__*/
  16406. function (_Component) {
  16407. _inheritsLoose(ResizeManager, _Component);
  16408. /**
  16409. * Create the ResizeManager.
  16410. *
  16411. * @param {Object} player
  16412. * The `Player` that this class should be attached to.
  16413. *
  16414. * @param {Object} [options]
  16415. * The key/value store of ResizeManager options.
  16416. *
  16417. * @param {Object} [options.ResizeObserver]
  16418. * A polyfill for ResizeObserver can be passed in here.
  16419. * If this is set to null it will ignore the native ResizeObserver and fall back to the iframe fallback.
  16420. */
  16421. function ResizeManager(player, options) {
  16422. var _this;
  16423. var RESIZE_OBSERVER_AVAILABLE = options.ResizeObserver || window$1.ResizeObserver; // if `null` was passed, we want to disable the ResizeObserver
  16424. if (options.ResizeObserver === null) {
  16425. RESIZE_OBSERVER_AVAILABLE = false;
  16426. } // Only create an element when ResizeObserver isn't available
  16427. var options_ = mergeOptions({
  16428. createEl: !RESIZE_OBSERVER_AVAILABLE,
  16429. reportTouchActivity: false
  16430. }, options);
  16431. _this = _Component.call(this, player, options_) || this;
  16432. _this.ResizeObserver = options.ResizeObserver || window$1.ResizeObserver;
  16433. _this.loadListener_ = null;
  16434. _this.resizeObserver_ = null;
  16435. _this.debouncedHandler_ = debounce(function () {
  16436. _this.resizeHandler();
  16437. }, 100, false, _assertThisInitialized(_this));
  16438. if (RESIZE_OBSERVER_AVAILABLE) {
  16439. _this.resizeObserver_ = new _this.ResizeObserver(_this.debouncedHandler_);
  16440. _this.resizeObserver_.observe(player.el());
  16441. } else {
  16442. _this.loadListener_ = function () {
  16443. if (!_this.el_ || !_this.el_.contentWindow) {
  16444. return;
  16445. }
  16446. var debouncedHandler_ = _this.debouncedHandler_;
  16447. var unloadListener_ = _this.unloadListener_ = function () {
  16448. off(this, 'resize', debouncedHandler_);
  16449. off(this, 'unload', unloadListener_);
  16450. unloadListener_ = null;
  16451. }; // safari and edge can unload the iframe before resizemanager dispose
  16452. // we have to dispose of event handlers correctly before that happens
  16453. on(_this.el_.contentWindow, 'unload', unloadListener_);
  16454. on(_this.el_.contentWindow, 'resize', debouncedHandler_);
  16455. };
  16456. _this.one('load', _this.loadListener_);
  16457. }
  16458. return _this;
  16459. }
  16460. var _proto = ResizeManager.prototype;
  16461. _proto.createEl = function createEl() {
  16462. return _Component.prototype.createEl.call(this, 'iframe', {
  16463. className: 'vjs-resize-manager',
  16464. tabIndex: -1
  16465. }, {
  16466. 'aria-hidden': 'true'
  16467. });
  16468. }
  16469. /**
  16470. * Called when a resize is triggered on the iframe or a resize is observed via the ResizeObserver
  16471. *
  16472. * @fires Player#playerresize
  16473. */
  16474. ;
  16475. _proto.resizeHandler = function resizeHandler() {
  16476. /**
  16477. * Called when the player size has changed
  16478. *
  16479. * @event Player#playerresize
  16480. * @type {EventTarget~Event}
  16481. */
  16482. // make sure player is still around to trigger
  16483. // prevents this from causing an error after dispose
  16484. if (!this.player_ || !this.player_.trigger) {
  16485. return;
  16486. }
  16487. this.player_.trigger('playerresize');
  16488. };
  16489. _proto.dispose = function dispose() {
  16490. if (this.debouncedHandler_) {
  16491. this.debouncedHandler_.cancel();
  16492. }
  16493. if (this.resizeObserver_) {
  16494. if (this.player_.el()) {
  16495. this.resizeObserver_.unobserve(this.player_.el());
  16496. }
  16497. this.resizeObserver_.disconnect();
  16498. }
  16499. if (this.loadListener_) {
  16500. this.off('load', this.loadListener_);
  16501. }
  16502. if (this.el_ && this.el_.contentWindow && this.unloadListener_) {
  16503. this.unloadListener_.call(this.el_.contentWindow);
  16504. }
  16505. this.ResizeObserver = null;
  16506. this.resizeObserver = null;
  16507. this.debouncedHandler_ = null;
  16508. this.loadListener_ = null;
  16509. _Component.prototype.dispose.call(this);
  16510. };
  16511. return ResizeManager;
  16512. }(Component);
  16513. Component.registerComponent('ResizeManager', ResizeManager);
  16514. /**
  16515. * Computes the median of an array.
  16516. *
  16517. * @param {number[]} arr
  16518. * Input array of numbers.
  16519. *
  16520. * @return {number}
  16521. * Median value.
  16522. */
  16523. var median = function median(arr) {
  16524. var mid = Math.floor(arr.length / 2);
  16525. var sortedList = [].concat(arr).sort(function (a, b) {
  16526. return a - b;
  16527. });
  16528. return arr.length % 2 !== 0 ? sortedList[mid] : (sortedList[mid - 1] + sortedList[mid]) / 2;
  16529. };
  16530. /* track when we are at the live edge, and other helpers for live playback */
  16531. var LiveTracker =
  16532. /*#__PURE__*/
  16533. function (_Component) {
  16534. _inheritsLoose(LiveTracker, _Component);
  16535. function LiveTracker(player, options) {
  16536. var _this;
  16537. // LiveTracker does not need an element
  16538. var options_ = mergeOptions({
  16539. createEl: false
  16540. }, options);
  16541. _this = _Component.call(this, player, options_) || this;
  16542. _this.reset_();
  16543. _this.on(_this.player_, 'durationchange', _this.handleDurationchange); // we don't need to track live playback if the document is hidden,
  16544. // also, tracking when the document is hidden can
  16545. // cause the CPU to spike and eventually crash the page on IE11.
  16546. if (IE_VERSION && 'hidden' in document && 'visibilityState' in document) {
  16547. _this.on(document, 'visibilitychange', _this.handleVisibilityChange);
  16548. }
  16549. return _this;
  16550. }
  16551. var _proto = LiveTracker.prototype;
  16552. _proto.handleVisibilityChange = function handleVisibilityChange() {
  16553. if (this.player_.duration() !== Infinity) {
  16554. return;
  16555. }
  16556. if (document.hidden) {
  16557. this.stopTracking();
  16558. } else {
  16559. this.startTracking();
  16560. }
  16561. };
  16562. _proto.isBehind_ = function isBehind_() {
  16563. // don't report that we are behind until a timeupdate has been seen
  16564. if (!this.timeupdateSeen_) {
  16565. return false;
  16566. }
  16567. var liveCurrentTime = this.liveCurrentTime();
  16568. var currentTime = this.player_.currentTime(); // the live edge window is the amount of seconds away from live
  16569. // that a player can be, but still be considered live.
  16570. // we add 0.07 because the live tracking happens every 30ms
  16571. // and we want some wiggle room for short segment live playback
  16572. var liveEdgeWindow = this.seekableIncrement_ * 2 + 0.07; // on Android liveCurrentTime can bee Infinity, because seekableEnd
  16573. // can be Infinity, so we handle that case.
  16574. return liveCurrentTime !== Infinity && liveCurrentTime - liveEdgeWindow >= currentTime;
  16575. } // all the functionality for tracking when seek end changes
  16576. // and for tracking how far past seek end we should be
  16577. ;
  16578. _proto.trackLive_ = function trackLive_() {
  16579. this.pastSeekEnd_ = this.pastSeekEnd_;
  16580. var seekable = this.player_.seekable(); // skip undefined seekable
  16581. if (!seekable || !seekable.length) {
  16582. return;
  16583. }
  16584. var newSeekEnd = this.seekableEnd(); // we can only tell if we are behind live, when seekable changes
  16585. // once we detect that seekable has changed we check the new seek
  16586. // end against current time, with a fudge value of half a second.
  16587. if (newSeekEnd !== this.lastSeekEnd_) {
  16588. if (this.lastSeekEnd_) {
  16589. // we try to get the best fit value for the seeking increment
  16590. // variable from the last 12 values.
  16591. this.seekableIncrementList_ = this.seekableIncrementList_.slice(-11);
  16592. this.seekableIncrementList_.push(Math.abs(newSeekEnd - this.lastSeekEnd_));
  16593. if (this.seekableIncrementList_.length > 3) {
  16594. this.seekableIncrement_ = median(this.seekableIncrementList_);
  16595. }
  16596. }
  16597. this.pastSeekEnd_ = 0;
  16598. this.lastSeekEnd_ = newSeekEnd;
  16599. this.trigger('seekableendchange');
  16600. }
  16601. this.pastSeekEnd_ = this.pastSeekEnd() + 0.03;
  16602. if (this.isBehind_() !== this.behindLiveEdge()) {
  16603. this.behindLiveEdge_ = this.isBehind_();
  16604. this.trigger('liveedgechange');
  16605. }
  16606. }
  16607. /**
  16608. * handle a durationchange event on the player
  16609. * and start/stop tracking accordingly.
  16610. */
  16611. ;
  16612. _proto.handleDurationchange = function handleDurationchange() {
  16613. if (this.player_.duration() === Infinity) {
  16614. this.startTracking();
  16615. } else {
  16616. this.stopTracking();
  16617. }
  16618. }
  16619. /**
  16620. * start tracking live playback
  16621. */
  16622. ;
  16623. _proto.startTracking = function startTracking() {
  16624. var _this2 = this;
  16625. if (this.isTracking()) {
  16626. return;
  16627. } // If we haven't seen a timeupdate, we need to check whether playback
  16628. // began before this component started tracking. This can happen commonly
  16629. // when using autoplay.
  16630. if (!this.timeupdateSeen_) {
  16631. this.timeupdateSeen_ = this.player_.hasStarted();
  16632. }
  16633. this.trackingInterval_ = this.setInterval(this.trackLive_, 30);
  16634. this.trackLive_();
  16635. this.on(this.player_, 'play', this.trackLive_);
  16636. this.on(this.player_, 'pause', this.trackLive_); // this is to prevent showing that we are not live
  16637. // before a video starts to play
  16638. if (!this.timeupdateSeen_) {
  16639. this.one(this.player_, 'play', this.handlePlay);
  16640. this.handleTimeupdate = function () {
  16641. _this2.timeupdateSeen_ = true;
  16642. _this2.handleTimeupdate = null;
  16643. };
  16644. this.one(this.player_, 'timeupdate', this.handleTimeupdate);
  16645. }
  16646. };
  16647. _proto.handlePlay = function handlePlay() {
  16648. this.one(this.player_, 'timeupdate', this.seekToLiveEdge);
  16649. }
  16650. /**
  16651. * Stop tracking, and set all internal variables to
  16652. * their initial value.
  16653. */
  16654. ;
  16655. _proto.reset_ = function reset_() {
  16656. this.pastSeekEnd_ = 0;
  16657. this.lastSeekEnd_ = null;
  16658. this.behindLiveEdge_ = null;
  16659. this.timeupdateSeen_ = false;
  16660. this.clearInterval(this.trackingInterval_);
  16661. this.trackingInterval_ = null;
  16662. this.seekableIncrement_ = 12;
  16663. this.seekableIncrementList_ = [];
  16664. this.off(this.player_, 'play', this.trackLive_);
  16665. this.off(this.player_, 'pause', this.trackLive_);
  16666. this.off(this.player_, 'play', this.handlePlay);
  16667. this.off(this.player_, 'timeupdate', this.seekToLiveEdge);
  16668. if (this.handleTimeupdate) {
  16669. this.off(this.player_, 'timeupdate', this.handleTimeupdate);
  16670. this.handleTimeupdate = null;
  16671. }
  16672. }
  16673. /**
  16674. * stop tracking live playback
  16675. */
  16676. ;
  16677. _proto.stopTracking = function stopTracking() {
  16678. if (!this.isTracking()) {
  16679. return;
  16680. }
  16681. this.reset_();
  16682. }
  16683. /**
  16684. * A helper to get the player seekable end
  16685. * so that we don't have to null check everywhere
  16686. */
  16687. ;
  16688. _proto.seekableEnd = function seekableEnd() {
  16689. var seekable = this.player_.seekable();
  16690. var seekableEnds = [];
  16691. var i = seekable ? seekable.length : 0;
  16692. while (i--) {
  16693. seekableEnds.push(seekable.end(i));
  16694. } // grab the furthest seekable end after sorting, or if there are none
  16695. // default to Infinity
  16696. return seekableEnds.length ? seekableEnds.sort()[seekableEnds.length - 1] : Infinity;
  16697. }
  16698. /**
  16699. * A helper to get the player seekable start
  16700. * so that we don't have to null check everywhere
  16701. */
  16702. ;
  16703. _proto.seekableStart = function seekableStart() {
  16704. var seekable = this.player_.seekable();
  16705. var seekableStarts = [];
  16706. var i = seekable ? seekable.length : 0;
  16707. while (i--) {
  16708. seekableStarts.push(seekable.start(i));
  16709. } // grab the first seekable start after sorting, or if there are none
  16710. // default to 0
  16711. return seekableStarts.length ? seekableStarts.sort()[0] : 0;
  16712. }
  16713. /**
  16714. * Get the live time window
  16715. */
  16716. ;
  16717. _proto.liveWindow = function liveWindow() {
  16718. var liveCurrentTime = this.liveCurrentTime();
  16719. if (liveCurrentTime === Infinity) {
  16720. return Infinity;
  16721. }
  16722. return liveCurrentTime - this.seekableStart();
  16723. }
  16724. /**
  16725. * Determines if the player is live, only checks if this component
  16726. * is tracking live playback or not
  16727. */
  16728. ;
  16729. _proto.isLive = function isLive() {
  16730. return this.isTracking();
  16731. }
  16732. /**
  16733. * Determines if currentTime is at the live edge and won't fall behind
  16734. * on each seekableendchange
  16735. */
  16736. ;
  16737. _proto.atLiveEdge = function atLiveEdge() {
  16738. return !this.behindLiveEdge();
  16739. }
  16740. /**
  16741. * get what we expect the live current time to be
  16742. */
  16743. ;
  16744. _proto.liveCurrentTime = function liveCurrentTime() {
  16745. return this.pastSeekEnd() + this.seekableEnd();
  16746. }
  16747. /**
  16748. * Returns how far past seek end we expect current time to be
  16749. */
  16750. ;
  16751. _proto.pastSeekEnd = function pastSeekEnd() {
  16752. return this.pastSeekEnd_;
  16753. }
  16754. /**
  16755. * If we are currently behind the live edge, aka currentTime will be
  16756. * behind on a seekableendchange
  16757. */
  16758. ;
  16759. _proto.behindLiveEdge = function behindLiveEdge() {
  16760. return this.behindLiveEdge_;
  16761. };
  16762. _proto.isTracking = function isTracking() {
  16763. return typeof this.trackingInterval_ === 'number';
  16764. }
  16765. /**
  16766. * Seek to the live edge if we are behind the live edge
  16767. */
  16768. ;
  16769. _proto.seekToLiveEdge = function seekToLiveEdge() {
  16770. if (this.atLiveEdge()) {
  16771. return;
  16772. }
  16773. this.player_.currentTime(this.liveCurrentTime());
  16774. if (this.player_.paused()) {
  16775. this.player_.play();
  16776. }
  16777. };
  16778. _proto.dispose = function dispose() {
  16779. this.stopTracking();
  16780. _Component.prototype.dispose.call(this);
  16781. };
  16782. return LiveTracker;
  16783. }(Component);
  16784. Component.registerComponent('LiveTracker', LiveTracker);
  16785. /**
  16786. * This function is used to fire a sourceset when there is something
  16787. * similar to `mediaEl.load()` being called. It will try to find the source via
  16788. * the `src` attribute and then the `<source>` elements. It will then fire `sourceset`
  16789. * with the source that was found or empty string if we cannot know. If it cannot
  16790. * find a source then `sourceset` will not be fired.
  16791. *
  16792. * @param {Html5} tech
  16793. * The tech object that sourceset was setup on
  16794. *
  16795. * @return {boolean}
  16796. * returns false if the sourceset was not fired and true otherwise.
  16797. */
  16798. var sourcesetLoad = function sourcesetLoad(tech) {
  16799. var el = tech.el(); // if `el.src` is set, that source will be loaded.
  16800. if (el.hasAttribute('src')) {
  16801. tech.triggerSourceset(el.src);
  16802. return true;
  16803. }
  16804. /**
  16805. * Since there isn't a src property on the media element, source elements will be used for
  16806. * implementing the source selection algorithm. This happens asynchronously and
  16807. * for most cases were there is more than one source we cannot tell what source will
  16808. * be loaded, without re-implementing the source selection algorithm. At this time we are not
  16809. * going to do that. There are three special cases that we do handle here though:
  16810. *
  16811. * 1. If there are no sources, do not fire `sourceset`.
  16812. * 2. If there is only one `<source>` with a `src` property/attribute that is our `src`
  16813. * 3. If there is more than one `<source>` but all of them have the same `src` url.
  16814. * That will be our src.
  16815. */
  16816. var sources = tech.$$('source');
  16817. var srcUrls = [];
  16818. var src = ''; // if there are no sources, do not fire sourceset
  16819. if (!sources.length) {
  16820. return false;
  16821. } // only count valid/non-duplicate source elements
  16822. for (var i = 0; i < sources.length; i++) {
  16823. var url = sources[i].src;
  16824. if (url && srcUrls.indexOf(url) === -1) {
  16825. srcUrls.push(url);
  16826. }
  16827. } // there were no valid sources
  16828. if (!srcUrls.length) {
  16829. return false;
  16830. } // there is only one valid source element url
  16831. // use that
  16832. if (srcUrls.length === 1) {
  16833. src = srcUrls[0];
  16834. }
  16835. tech.triggerSourceset(src);
  16836. return true;
  16837. };
  16838. /**
  16839. * our implementation of an `innerHTML` descriptor for browsers
  16840. * that do not have one.
  16841. */
  16842. var innerHTMLDescriptorPolyfill = Object.defineProperty({}, 'innerHTML', {
  16843. get: function get() {
  16844. return this.cloneNode(true).innerHTML;
  16845. },
  16846. set: function set(v) {
  16847. // make a dummy node to use innerHTML on
  16848. var dummy = document.createElement(this.nodeName.toLowerCase()); // set innerHTML to the value provided
  16849. dummy.innerHTML = v; // make a document fragment to hold the nodes from dummy
  16850. var docFrag = document.createDocumentFragment(); // copy all of the nodes created by the innerHTML on dummy
  16851. // to the document fragment
  16852. while (dummy.childNodes.length) {
  16853. docFrag.appendChild(dummy.childNodes[0]);
  16854. } // remove content
  16855. this.innerText = ''; // now we add all of that html in one by appending the
  16856. // document fragment. This is how innerHTML does it.
  16857. window$1.Element.prototype.appendChild.call(this, docFrag); // then return the result that innerHTML's setter would
  16858. return this.innerHTML;
  16859. }
  16860. });
  16861. /**
  16862. * Get a property descriptor given a list of priorities and the
  16863. * property to get.
  16864. */
  16865. var getDescriptor = function getDescriptor(priority, prop) {
  16866. var descriptor = {};
  16867. for (var i = 0; i < priority.length; i++) {
  16868. descriptor = Object.getOwnPropertyDescriptor(priority[i], prop);
  16869. if (descriptor && descriptor.set && descriptor.get) {
  16870. break;
  16871. }
  16872. }
  16873. descriptor.enumerable = true;
  16874. descriptor.configurable = true;
  16875. return descriptor;
  16876. };
  16877. var getInnerHTMLDescriptor = function getInnerHTMLDescriptor(tech) {
  16878. return getDescriptor([tech.el(), window$1.HTMLMediaElement.prototype, window$1.Element.prototype, innerHTMLDescriptorPolyfill], 'innerHTML');
  16879. };
  16880. /**
  16881. * Patches browser internal functions so that we can tell synchronously
  16882. * if a `<source>` was appended to the media element. For some reason this
  16883. * causes a `sourceset` if the the media element is ready and has no source.
  16884. * This happens when:
  16885. * - The page has just loaded and the media element does not have a source.
  16886. * - The media element was emptied of all sources, then `load()` was called.
  16887. *
  16888. * It does this by patching the following functions/properties when they are supported:
  16889. *
  16890. * - `append()` - can be used to add a `<source>` element to the media element
  16891. * - `appendChild()` - can be used to add a `<source>` element to the media element
  16892. * - `insertAdjacentHTML()` - can be used to add a `<source>` element to the media element
  16893. * - `innerHTML` - can be used to add a `<source>` element to the media element
  16894. *
  16895. * @param {Html5} tech
  16896. * The tech object that sourceset is being setup on.
  16897. */
  16898. var firstSourceWatch = function firstSourceWatch(tech) {
  16899. var el = tech.el(); // make sure firstSourceWatch isn't setup twice.
  16900. if (el.resetSourceWatch_) {
  16901. return;
  16902. }
  16903. var old = {};
  16904. var innerDescriptor = getInnerHTMLDescriptor(tech);
  16905. var appendWrapper = function appendWrapper(appendFn) {
  16906. return function () {
  16907. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  16908. args[_key] = arguments[_key];
  16909. }
  16910. var retval = appendFn.apply(el, args);
  16911. sourcesetLoad(tech);
  16912. return retval;
  16913. };
  16914. };
  16915. ['append', 'appendChild', 'insertAdjacentHTML'].forEach(function (k) {
  16916. if (!el[k]) {
  16917. return;
  16918. } // store the old function
  16919. old[k] = el[k]; // call the old function with a sourceset if a source
  16920. // was loaded
  16921. el[k] = appendWrapper(old[k]);
  16922. });
  16923. Object.defineProperty(el, 'innerHTML', mergeOptions(innerDescriptor, {
  16924. set: appendWrapper(innerDescriptor.set)
  16925. }));
  16926. el.resetSourceWatch_ = function () {
  16927. el.resetSourceWatch_ = null;
  16928. Object.keys(old).forEach(function (k) {
  16929. el[k] = old[k];
  16930. });
  16931. Object.defineProperty(el, 'innerHTML', innerDescriptor);
  16932. }; // on the first sourceset, we need to revert our changes
  16933. tech.one('sourceset', el.resetSourceWatch_);
  16934. };
  16935. /**
  16936. * our implementation of a `src` descriptor for browsers
  16937. * that do not have one.
  16938. */
  16939. var srcDescriptorPolyfill = Object.defineProperty({}, 'src', {
  16940. get: function get() {
  16941. if (this.hasAttribute('src')) {
  16942. return getAbsoluteURL(window$1.Element.prototype.getAttribute.call(this, 'src'));
  16943. }
  16944. return '';
  16945. },
  16946. set: function set(v) {
  16947. window$1.Element.prototype.setAttribute.call(this, 'src', v);
  16948. return v;
  16949. }
  16950. });
  16951. var getSrcDescriptor = function getSrcDescriptor(tech) {
  16952. return getDescriptor([tech.el(), window$1.HTMLMediaElement.prototype, srcDescriptorPolyfill], 'src');
  16953. };
  16954. /**
  16955. * setup `sourceset` handling on the `Html5` tech. This function
  16956. * patches the following element properties/functions:
  16957. *
  16958. * - `src` - to determine when `src` is set
  16959. * - `setAttribute()` - to determine when `src` is set
  16960. * - `load()` - this re-triggers the source selection algorithm, and can
  16961. * cause a sourceset.
  16962. *
  16963. * If there is no source when we are adding `sourceset` support or during a `load()`
  16964. * we also patch the functions listed in `firstSourceWatch`.
  16965. *
  16966. * @param {Html5} tech
  16967. * The tech to patch
  16968. */
  16969. var setupSourceset = function setupSourceset(tech) {
  16970. if (!tech.featuresSourceset) {
  16971. return;
  16972. }
  16973. var el = tech.el(); // make sure sourceset isn't setup twice.
  16974. if (el.resetSourceset_) {
  16975. return;
  16976. }
  16977. var srcDescriptor = getSrcDescriptor(tech);
  16978. var oldSetAttribute = el.setAttribute;
  16979. var oldLoad = el.load;
  16980. Object.defineProperty(el, 'src', mergeOptions(srcDescriptor, {
  16981. set: function set(v) {
  16982. var retval = srcDescriptor.set.call(el, v); // we use the getter here to get the actual value set on src
  16983. tech.triggerSourceset(el.src);
  16984. return retval;
  16985. }
  16986. }));
  16987. el.setAttribute = function (n, v) {
  16988. var retval = oldSetAttribute.call(el, n, v);
  16989. if (/src/i.test(n)) {
  16990. tech.triggerSourceset(el.src);
  16991. }
  16992. return retval;
  16993. };
  16994. el.load = function () {
  16995. var retval = oldLoad.call(el); // if load was called, but there was no source to fire
  16996. // sourceset on. We have to watch for a source append
  16997. // as that can trigger a `sourceset` when the media element
  16998. // has no source
  16999. if (!sourcesetLoad(tech)) {
  17000. tech.triggerSourceset('');
  17001. firstSourceWatch(tech);
  17002. }
  17003. return retval;
  17004. };
  17005. if (el.currentSrc) {
  17006. tech.triggerSourceset(el.currentSrc);
  17007. } else if (!sourcesetLoad(tech)) {
  17008. firstSourceWatch(tech);
  17009. }
  17010. el.resetSourceset_ = function () {
  17011. el.resetSourceset_ = null;
  17012. el.load = oldLoad;
  17013. el.setAttribute = oldSetAttribute;
  17014. Object.defineProperty(el, 'src', srcDescriptor);
  17015. if (el.resetSourceWatch_) {
  17016. el.resetSourceWatch_();
  17017. }
  17018. };
  17019. };
  17020. /**
  17021. * HTML5 Media Controller - Wrapper for HTML5 Media API
  17022. *
  17023. * @mixes Tech~SourceHandlerAdditions
  17024. * @extends Tech
  17025. */
  17026. var Html5 =
  17027. /*#__PURE__*/
  17028. function (_Tech) {
  17029. _inheritsLoose(Html5, _Tech);
  17030. /**
  17031. * Create an instance of this Tech.
  17032. *
  17033. * @param {Object} [options]
  17034. * The key/value store of player options.
  17035. *
  17036. * @param {Component~ReadyCallback} ready
  17037. * Callback function to call when the `HTML5` Tech is ready.
  17038. */
  17039. function Html5(options, ready) {
  17040. var _this;
  17041. _this = _Tech.call(this, options, ready) || this;
  17042. var source = options.source;
  17043. var crossoriginTracks = false; // Set the source if one is provided
  17044. // 1) Check if the source is new (if not, we want to keep the original so playback isn't interrupted)
  17045. // 2) Check to see if the network state of the tag was failed at init, and if so, reset the source
  17046. // anyway so the error gets fired.
  17047. if (source && (_this.el_.currentSrc !== source.src || options.tag && options.tag.initNetworkState_ === 3)) {
  17048. _this.setSource(source);
  17049. } else {
  17050. _this.handleLateInit_(_this.el_);
  17051. } // setup sourceset after late sourceset/init
  17052. if (options.enableSourceset) {
  17053. _this.setupSourcesetHandling_();
  17054. }
  17055. if (_this.el_.hasChildNodes()) {
  17056. var nodes = _this.el_.childNodes;
  17057. var nodesLength = nodes.length;
  17058. var removeNodes = [];
  17059. while (nodesLength--) {
  17060. var node = nodes[nodesLength];
  17061. var nodeName = node.nodeName.toLowerCase();
  17062. if (nodeName === 'track') {
  17063. if (!_this.featuresNativeTextTracks) {
  17064. // Empty video tag tracks so the built-in player doesn't use them also.
  17065. // This may not be fast enough to stop HTML5 browsers from reading the tags
  17066. // so we'll need to turn off any default tracks if we're manually doing
  17067. // captions and subtitles. videoElement.textTracks
  17068. removeNodes.push(node);
  17069. } else {
  17070. // store HTMLTrackElement and TextTrack to remote list
  17071. _this.remoteTextTrackEls().addTrackElement_(node);
  17072. _this.remoteTextTracks().addTrack(node.track);
  17073. _this.textTracks().addTrack(node.track);
  17074. if (!crossoriginTracks && !_this.el_.hasAttribute('crossorigin') && isCrossOrigin(node.src)) {
  17075. crossoriginTracks = true;
  17076. }
  17077. }
  17078. }
  17079. }
  17080. for (var i = 0; i < removeNodes.length; i++) {
  17081. _this.el_.removeChild(removeNodes[i]);
  17082. }
  17083. }
  17084. _this.proxyNativeTracks_();
  17085. if (_this.featuresNativeTextTracks && crossoriginTracks) {
  17086. log.warn('Text Tracks are being loaded from another origin but the crossorigin attribute isn\'t used.\n' + 'This may prevent text tracks from loading.');
  17087. } // prevent iOS Safari from disabling metadata text tracks during native playback
  17088. _this.restoreMetadataTracksInIOSNativePlayer_(); // Determine if native controls should be used
  17089. // Our goal should be to get the custom controls on mobile solid everywhere
  17090. // so we can remove this all together. Right now this will block custom
  17091. // controls on touch enabled laptops like the Chrome Pixel
  17092. if ((TOUCH_ENABLED || IS_IPHONE || IS_NATIVE_ANDROID) && options.nativeControlsForTouch === true) {
  17093. _this.setControls(true);
  17094. } // on iOS, we want to proxy `webkitbeginfullscreen` and `webkitendfullscreen`
  17095. // into a `fullscreenchange` event
  17096. _this.proxyWebkitFullscreen_();
  17097. _this.triggerReady();
  17098. return _this;
  17099. }
  17100. /**
  17101. * Dispose of `HTML5` media element and remove all tracks.
  17102. */
  17103. var _proto = Html5.prototype;
  17104. _proto.dispose = function dispose() {
  17105. if (this.el_ && this.el_.resetSourceset_) {
  17106. this.el_.resetSourceset_();
  17107. }
  17108. Html5.disposeMediaElement(this.el_);
  17109. this.options_ = null; // tech will handle clearing of the emulated track list
  17110. _Tech.prototype.dispose.call(this);
  17111. }
  17112. /**
  17113. * Modify the media element so that we can detect when
  17114. * the source is changed. Fires `sourceset` just after the source has changed
  17115. */
  17116. ;
  17117. _proto.setupSourcesetHandling_ = function setupSourcesetHandling_() {
  17118. setupSourceset(this);
  17119. }
  17120. /**
  17121. * When a captions track is enabled in the iOS Safari native player, all other
  17122. * tracks are disabled (including metadata tracks), which nulls all of their
  17123. * associated cue points. This will restore metadata tracks to their pre-fullscreen
  17124. * state in those cases so that cue points are not needlessly lost.
  17125. *
  17126. * @private
  17127. */
  17128. ;
  17129. _proto.restoreMetadataTracksInIOSNativePlayer_ = function restoreMetadataTracksInIOSNativePlayer_() {
  17130. var textTracks = this.textTracks();
  17131. var metadataTracksPreFullscreenState; // captures a snapshot of every metadata track's current state
  17132. var takeMetadataTrackSnapshot = function takeMetadataTrackSnapshot() {
  17133. metadataTracksPreFullscreenState = [];
  17134. for (var i = 0; i < textTracks.length; i++) {
  17135. var track = textTracks[i];
  17136. if (track.kind === 'metadata') {
  17137. metadataTracksPreFullscreenState.push({
  17138. track: track,
  17139. storedMode: track.mode
  17140. });
  17141. }
  17142. }
  17143. }; // snapshot each metadata track's initial state, and update the snapshot
  17144. // each time there is a track 'change' event
  17145. takeMetadataTrackSnapshot();
  17146. textTracks.addEventListener('change', takeMetadataTrackSnapshot);
  17147. this.on('dispose', function () {
  17148. return textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  17149. });
  17150. var restoreTrackMode = function restoreTrackMode() {
  17151. for (var i = 0; i < metadataTracksPreFullscreenState.length; i++) {
  17152. var storedTrack = metadataTracksPreFullscreenState[i];
  17153. if (storedTrack.track.mode === 'disabled' && storedTrack.track.mode !== storedTrack.storedMode) {
  17154. storedTrack.track.mode = storedTrack.storedMode;
  17155. }
  17156. } // we only want this handler to be executed on the first 'change' event
  17157. textTracks.removeEventListener('change', restoreTrackMode);
  17158. }; // when we enter fullscreen playback, stop updating the snapshot and
  17159. // restore all track modes to their pre-fullscreen state
  17160. this.on('webkitbeginfullscreen', function () {
  17161. textTracks.removeEventListener('change', takeMetadataTrackSnapshot); // remove the listener before adding it just in case it wasn't previously removed
  17162. textTracks.removeEventListener('change', restoreTrackMode);
  17163. textTracks.addEventListener('change', restoreTrackMode);
  17164. }); // start updating the snapshot again after leaving fullscreen
  17165. this.on('webkitendfullscreen', function () {
  17166. // remove the listener before adding it just in case it wasn't previously removed
  17167. textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  17168. textTracks.addEventListener('change', takeMetadataTrackSnapshot); // remove the restoreTrackMode handler in case it wasn't triggered during fullscreen playback
  17169. textTracks.removeEventListener('change', restoreTrackMode);
  17170. });
  17171. }
  17172. /**
  17173. * Attempt to force override of tracks for the given type
  17174. *
  17175. * @param {string} type - Track type to override, possible values include 'Audio',
  17176. * 'Video', and 'Text'.
  17177. * @param {boolean} override - If set to true native audio/video will be overridden,
  17178. * otherwise native audio/video will potentially be used.
  17179. * @private
  17180. */
  17181. ;
  17182. _proto.overrideNative_ = function overrideNative_(type, override) {
  17183. var _this2 = this;
  17184. // If there is no behavioral change don't add/remove listeners
  17185. if (override !== this["featuresNative" + type + "Tracks"]) {
  17186. return;
  17187. }
  17188. var lowerCaseType = type.toLowerCase();
  17189. if (this[lowerCaseType + "TracksListeners_"]) {
  17190. Object.keys(this[lowerCaseType + "TracksListeners_"]).forEach(function (eventName) {
  17191. var elTracks = _this2.el()[lowerCaseType + "Tracks"];
  17192. elTracks.removeEventListener(eventName, _this2[lowerCaseType + "TracksListeners_"][eventName]);
  17193. });
  17194. }
  17195. this["featuresNative" + type + "Tracks"] = !override;
  17196. this[lowerCaseType + "TracksListeners_"] = null;
  17197. this.proxyNativeTracksForType_(lowerCaseType);
  17198. }
  17199. /**
  17200. * Attempt to force override of native audio tracks.
  17201. *
  17202. * @param {boolean} override - If set to true native audio will be overridden,
  17203. * otherwise native audio will potentially be used.
  17204. */
  17205. ;
  17206. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks(override) {
  17207. this.overrideNative_('Audio', override);
  17208. }
  17209. /**
  17210. * Attempt to force override of native video tracks.
  17211. *
  17212. * @param {boolean} override - If set to true native video will be overridden,
  17213. * otherwise native video will potentially be used.
  17214. */
  17215. ;
  17216. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks(override) {
  17217. this.overrideNative_('Video', override);
  17218. }
  17219. /**
  17220. * Proxy native track list events for the given type to our track
  17221. * lists if the browser we are playing in supports that type of track list.
  17222. *
  17223. * @param {string} name - Track type; values include 'audio', 'video', and 'text'
  17224. * @private
  17225. */
  17226. ;
  17227. _proto.proxyNativeTracksForType_ = function proxyNativeTracksForType_(name) {
  17228. var _this3 = this;
  17229. var props = NORMAL[name];
  17230. var elTracks = this.el()[props.getterName];
  17231. var techTracks = this[props.getterName]();
  17232. if (!this["featuresNative" + props.capitalName + "Tracks"] || !elTracks || !elTracks.addEventListener) {
  17233. return;
  17234. }
  17235. var listeners = {
  17236. change: function change(e) {
  17237. techTracks.trigger({
  17238. type: 'change',
  17239. target: techTracks,
  17240. currentTarget: techTracks,
  17241. srcElement: techTracks
  17242. });
  17243. },
  17244. addtrack: function addtrack(e) {
  17245. techTracks.addTrack(e.track);
  17246. },
  17247. removetrack: function removetrack(e) {
  17248. techTracks.removeTrack(e.track);
  17249. }
  17250. };
  17251. var removeOldTracks = function removeOldTracks() {
  17252. var removeTracks = [];
  17253. for (var i = 0; i < techTracks.length; i++) {
  17254. var found = false;
  17255. for (var j = 0; j < elTracks.length; j++) {
  17256. if (elTracks[j] === techTracks[i]) {
  17257. found = true;
  17258. break;
  17259. }
  17260. }
  17261. if (!found) {
  17262. removeTracks.push(techTracks[i]);
  17263. }
  17264. }
  17265. while (removeTracks.length) {
  17266. techTracks.removeTrack(removeTracks.shift());
  17267. }
  17268. };
  17269. this[props.getterName + 'Listeners_'] = listeners;
  17270. Object.keys(listeners).forEach(function (eventName) {
  17271. var listener = listeners[eventName];
  17272. elTracks.addEventListener(eventName, listener);
  17273. _this3.on('dispose', function (e) {
  17274. return elTracks.removeEventListener(eventName, listener);
  17275. });
  17276. }); // Remove (native) tracks that are not used anymore
  17277. this.on('loadstart', removeOldTracks);
  17278. this.on('dispose', function (e) {
  17279. return _this3.off('loadstart', removeOldTracks);
  17280. });
  17281. }
  17282. /**
  17283. * Proxy all native track list events to our track lists if the browser we are playing
  17284. * in supports that type of track list.
  17285. *
  17286. * @private
  17287. */
  17288. ;
  17289. _proto.proxyNativeTracks_ = function proxyNativeTracks_() {
  17290. var _this4 = this;
  17291. NORMAL.names.forEach(function (name) {
  17292. _this4.proxyNativeTracksForType_(name);
  17293. });
  17294. }
  17295. /**
  17296. * Create the `Html5` Tech's DOM element.
  17297. *
  17298. * @return {Element}
  17299. * The element that gets created.
  17300. */
  17301. ;
  17302. _proto.createEl = function createEl() {
  17303. var el = this.options_.tag; // Check if this browser supports moving the element into the box.
  17304. // On the iPhone video will break if you move the element,
  17305. // So we have to create a brand new element.
  17306. // If we ingested the player div, we do not need to move the media element.
  17307. if (!el || !(this.options_.playerElIngest || this.movingMediaElementInDOM)) {
  17308. // If the original tag is still there, clone and remove it.
  17309. if (el) {
  17310. var clone = el.cloneNode(true);
  17311. if (el.parentNode) {
  17312. el.parentNode.insertBefore(clone, el);
  17313. }
  17314. Html5.disposeMediaElement(el);
  17315. el = clone;
  17316. } else {
  17317. el = document.createElement('video'); // determine if native controls should be used
  17318. var tagAttributes = this.options_.tag && getAttributes(this.options_.tag);
  17319. var attributes = mergeOptions({}, tagAttributes);
  17320. if (!TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
  17321. delete attributes.controls;
  17322. }
  17323. setAttributes(el, assign(attributes, {
  17324. id: this.options_.techId,
  17325. "class": 'vjs-tech'
  17326. }));
  17327. }
  17328. el.playerId = this.options_.playerId;
  17329. }
  17330. if (typeof this.options_.preload !== 'undefined') {
  17331. setAttribute(el, 'preload', this.options_.preload);
  17332. } // Update specific tag settings, in case they were overridden
  17333. // `autoplay` has to be *last* so that `muted` and `playsinline` are present
  17334. // when iOS/Safari or other browsers attempt to autoplay.
  17335. var settingsAttrs = ['loop', 'muted', 'playsinline', 'autoplay'];
  17336. for (var i = 0; i < settingsAttrs.length; i++) {
  17337. var attr = settingsAttrs[i];
  17338. var value = this.options_[attr];
  17339. if (typeof value !== 'undefined') {
  17340. if (value) {
  17341. setAttribute(el, attr, attr);
  17342. } else {
  17343. removeAttribute(el, attr);
  17344. }
  17345. el[attr] = value;
  17346. }
  17347. }
  17348. return el;
  17349. }
  17350. /**
  17351. * This will be triggered if the loadstart event has already fired, before videojs was
  17352. * ready. Two known examples of when this can happen are:
  17353. * 1. If we're loading the playback object after it has started loading
  17354. * 2. The media is already playing the (often with autoplay on) then
  17355. *
  17356. * This function will fire another loadstart so that videojs can catchup.
  17357. *
  17358. * @fires Tech#loadstart
  17359. *
  17360. * @return {undefined}
  17361. * returns nothing.
  17362. */
  17363. ;
  17364. _proto.handleLateInit_ = function handleLateInit_(el) {
  17365. if (el.networkState === 0 || el.networkState === 3) {
  17366. // The video element hasn't started loading the source yet
  17367. // or didn't find a source
  17368. return;
  17369. }
  17370. if (el.readyState === 0) {
  17371. // NetworkState is set synchronously BUT loadstart is fired at the
  17372. // end of the current stack, usually before setInterval(fn, 0).
  17373. // So at this point we know loadstart may have already fired or is
  17374. // about to fire, and either way the player hasn't seen it yet.
  17375. // We don't want to fire loadstart prematurely here and cause a
  17376. // double loadstart so we'll wait and see if it happens between now
  17377. // and the next loop, and fire it if not.
  17378. // HOWEVER, we also want to make sure it fires before loadedmetadata
  17379. // which could also happen between now and the next loop, so we'll
  17380. // watch for that also.
  17381. var loadstartFired = false;
  17382. var setLoadstartFired = function setLoadstartFired() {
  17383. loadstartFired = true;
  17384. };
  17385. this.on('loadstart', setLoadstartFired);
  17386. var triggerLoadstart = function triggerLoadstart() {
  17387. // We did miss the original loadstart. Make sure the player
  17388. // sees loadstart before loadedmetadata
  17389. if (!loadstartFired) {
  17390. this.trigger('loadstart');
  17391. }
  17392. };
  17393. this.on('loadedmetadata', triggerLoadstart);
  17394. this.ready(function () {
  17395. this.off('loadstart', setLoadstartFired);
  17396. this.off('loadedmetadata', triggerLoadstart);
  17397. if (!loadstartFired) {
  17398. // We did miss the original native loadstart. Fire it now.
  17399. this.trigger('loadstart');
  17400. }
  17401. });
  17402. return;
  17403. } // From here on we know that loadstart already fired and we missed it.
  17404. // The other readyState events aren't as much of a problem if we double
  17405. // them, so not going to go to as much trouble as loadstart to prevent
  17406. // that unless we find reason to.
  17407. var eventsToTrigger = ['loadstart']; // loadedmetadata: newly equal to HAVE_METADATA (1) or greater
  17408. eventsToTrigger.push('loadedmetadata'); // loadeddata: newly increased to HAVE_CURRENT_DATA (2) or greater
  17409. if (el.readyState >= 2) {
  17410. eventsToTrigger.push('loadeddata');
  17411. } // canplay: newly increased to HAVE_FUTURE_DATA (3) or greater
  17412. if (el.readyState >= 3) {
  17413. eventsToTrigger.push('canplay');
  17414. } // canplaythrough: newly equal to HAVE_ENOUGH_DATA (4)
  17415. if (el.readyState >= 4) {
  17416. eventsToTrigger.push('canplaythrough');
  17417. } // We still need to give the player time to add event listeners
  17418. this.ready(function () {
  17419. eventsToTrigger.forEach(function (type) {
  17420. this.trigger(type);
  17421. }, this);
  17422. });
  17423. }
  17424. /**
  17425. * Set current time for the `HTML5` tech.
  17426. *
  17427. * @param {number} seconds
  17428. * Set the current time of the media to this.
  17429. */
  17430. ;
  17431. _proto.setCurrentTime = function setCurrentTime(seconds) {
  17432. try {
  17433. this.el_.currentTime = seconds;
  17434. } catch (e) {
  17435. log(e, 'Video is not ready. (Video.js)'); // this.warning(VideoJS.warnings.videoNotReady);
  17436. }
  17437. }
  17438. /**
  17439. * Get the current duration of the HTML5 media element.
  17440. *
  17441. * @return {number}
  17442. * The duration of the media or 0 if there is no duration.
  17443. */
  17444. ;
  17445. _proto.duration = function duration() {
  17446. var _this5 = this;
  17447. // Android Chrome will report duration as Infinity for VOD HLS until after
  17448. // playback has started, which triggers the live display erroneously.
  17449. // Return NaN if playback has not started and trigger a durationupdate once
  17450. // the duration can be reliably known.
  17451. if (this.el_.duration === Infinity && IS_ANDROID && IS_CHROME && this.el_.currentTime === 0) {
  17452. // Wait for the first `timeupdate` with currentTime > 0 - there may be
  17453. // several with 0
  17454. var checkProgress = function checkProgress() {
  17455. if (_this5.el_.currentTime > 0) {
  17456. // Trigger durationchange for genuinely live video
  17457. if (_this5.el_.duration === Infinity) {
  17458. _this5.trigger('durationchange');
  17459. }
  17460. _this5.off('timeupdate', checkProgress);
  17461. }
  17462. };
  17463. this.on('timeupdate', checkProgress);
  17464. return NaN;
  17465. }
  17466. return this.el_.duration || NaN;
  17467. }
  17468. /**
  17469. * Get the current width of the HTML5 media element.
  17470. *
  17471. * @return {number}
  17472. * The width of the HTML5 media element.
  17473. */
  17474. ;
  17475. _proto.width = function width() {
  17476. return this.el_.offsetWidth;
  17477. }
  17478. /**
  17479. * Get the current height of the HTML5 media element.
  17480. *
  17481. * @return {number}
  17482. * The height of the HTML5 media element.
  17483. */
  17484. ;
  17485. _proto.height = function height() {
  17486. return this.el_.offsetHeight;
  17487. }
  17488. /**
  17489. * Proxy iOS `webkitbeginfullscreen` and `webkitendfullscreen` into
  17490. * `fullscreenchange` event.
  17491. *
  17492. * @private
  17493. * @fires fullscreenchange
  17494. * @listens webkitendfullscreen
  17495. * @listens webkitbeginfullscreen
  17496. * @listens webkitbeginfullscreen
  17497. */
  17498. ;
  17499. _proto.proxyWebkitFullscreen_ = function proxyWebkitFullscreen_() {
  17500. var _this6 = this;
  17501. if (!('webkitDisplayingFullscreen' in this.el_)) {
  17502. return;
  17503. }
  17504. var endFn = function endFn() {
  17505. this.trigger('fullscreenchange', {
  17506. isFullscreen: false
  17507. });
  17508. };
  17509. var beginFn = function beginFn() {
  17510. if ('webkitPresentationMode' in this.el_ && this.el_.webkitPresentationMode !== 'picture-in-picture') {
  17511. this.one('webkitendfullscreen', endFn);
  17512. this.trigger('fullscreenchange', {
  17513. isFullscreen: true
  17514. });
  17515. }
  17516. };
  17517. this.on('webkitbeginfullscreen', beginFn);
  17518. this.on('dispose', function () {
  17519. _this6.off('webkitbeginfullscreen', beginFn);
  17520. _this6.off('webkitendfullscreen', endFn);
  17521. });
  17522. }
  17523. /**
  17524. * Check if fullscreen is supported on the current playback device.
  17525. *
  17526. * @return {boolean}
  17527. * - True if fullscreen is supported.
  17528. * - False if fullscreen is not supported.
  17529. */
  17530. ;
  17531. _proto.supportsFullScreen = function supportsFullScreen() {
  17532. if (typeof this.el_.webkitEnterFullScreen === 'function') {
  17533. var userAgent = window$1.navigator && window$1.navigator.userAgent || ''; // Seems to be broken in Chromium/Chrome && Safari in Leopard
  17534. if (/Android/.test(userAgent) || !/Chrome|Mac OS X 10.5/.test(userAgent)) {
  17535. return true;
  17536. }
  17537. }
  17538. return false;
  17539. }
  17540. /**
  17541. * Request that the `HTML5` Tech enter fullscreen.
  17542. */
  17543. ;
  17544. _proto.enterFullScreen = function enterFullScreen() {
  17545. var video = this.el_;
  17546. if (video.paused && video.networkState <= video.HAVE_METADATA) {
  17547. // attempt to prime the video element for programmatic access
  17548. // this isn't necessary on the desktop but shouldn't hurt
  17549. this.el_.play(); // playing and pausing synchronously during the transition to fullscreen
  17550. // can get iOS ~6.1 devices into a play/pause loop
  17551. this.setTimeout(function () {
  17552. video.pause();
  17553. video.webkitEnterFullScreen();
  17554. }, 0);
  17555. } else {
  17556. video.webkitEnterFullScreen();
  17557. }
  17558. }
  17559. /**
  17560. * Request that the `HTML5` Tech exit fullscreen.
  17561. */
  17562. ;
  17563. _proto.exitFullScreen = function exitFullScreen() {
  17564. this.el_.webkitExitFullScreen();
  17565. }
  17566. /**
  17567. * Create a floating video window always on top of other windows so that users may
  17568. * continue consuming media while they interact with other content sites, or
  17569. * applications on their device.
  17570. *
  17571. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  17572. *
  17573. * @return {Promise}
  17574. * A promise with a Picture-in-Picture window.
  17575. */
  17576. ;
  17577. _proto.requestPictureInPicture = function requestPictureInPicture() {
  17578. return this.el_.requestPictureInPicture();
  17579. }
  17580. /**
  17581. * A getter/setter for the `Html5` Tech's source object.
  17582. * > Note: Please use {@link Html5#setSource}
  17583. *
  17584. * @param {Tech~SourceObject} [src]
  17585. * The source object you want to set on the `HTML5` techs element.
  17586. *
  17587. * @return {Tech~SourceObject|undefined}
  17588. * - The current source object when a source is not passed in.
  17589. * - undefined when setting
  17590. *
  17591. * @deprecated Since version 5.
  17592. */
  17593. ;
  17594. _proto.src = function src(_src) {
  17595. if (_src === undefined) {
  17596. return this.el_.src;
  17597. } // Setting src through `src` instead of `setSrc` will be deprecated
  17598. this.setSrc(_src);
  17599. }
  17600. /**
  17601. * Reset the tech by removing all sources and then calling
  17602. * {@link Html5.resetMediaElement}.
  17603. */
  17604. ;
  17605. _proto.reset = function reset() {
  17606. Html5.resetMediaElement(this.el_);
  17607. }
  17608. /**
  17609. * Get the current source on the `HTML5` Tech. Falls back to returning the source from
  17610. * the HTML5 media element.
  17611. *
  17612. * @return {Tech~SourceObject}
  17613. * The current source object from the HTML5 tech. With a fallback to the
  17614. * elements source.
  17615. */
  17616. ;
  17617. _proto.currentSrc = function currentSrc() {
  17618. if (this.currentSource_) {
  17619. return this.currentSource_.src;
  17620. }
  17621. return this.el_.currentSrc;
  17622. }
  17623. /**
  17624. * Set controls attribute for the HTML5 media Element.
  17625. *
  17626. * @param {string} val
  17627. * Value to set the controls attribute to
  17628. */
  17629. ;
  17630. _proto.setControls = function setControls(val) {
  17631. this.el_.controls = !!val;
  17632. }
  17633. /**
  17634. * Create and returns a remote {@link TextTrack} object.
  17635. *
  17636. * @param {string} kind
  17637. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  17638. *
  17639. * @param {string} [label]
  17640. * Label to identify the text track
  17641. *
  17642. * @param {string} [language]
  17643. * Two letter language abbreviation
  17644. *
  17645. * @return {TextTrack}
  17646. * The TextTrack that gets created.
  17647. */
  17648. ;
  17649. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  17650. if (!this.featuresNativeTextTracks) {
  17651. return _Tech.prototype.addTextTrack.call(this, kind, label, language);
  17652. }
  17653. return this.el_.addTextTrack(kind, label, language);
  17654. }
  17655. /**
  17656. * Creates either native TextTrack or an emulated TextTrack depending
  17657. * on the value of `featuresNativeTextTracks`
  17658. *
  17659. * @param {Object} options
  17660. * The object should contain the options to initialize the TextTrack with.
  17661. *
  17662. * @param {string} [options.kind]
  17663. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  17664. *
  17665. * @param {string} [options.label]
  17666. * Label to identify the text track
  17667. *
  17668. * @param {string} [options.language]
  17669. * Two letter language abbreviation.
  17670. *
  17671. * @param {boolean} [options.default]
  17672. * Default this track to on.
  17673. *
  17674. * @param {string} [options.id]
  17675. * The internal id to assign this track.
  17676. *
  17677. * @param {string} [options.src]
  17678. * A source url for the track.
  17679. *
  17680. * @return {HTMLTrackElement}
  17681. * The track element that gets created.
  17682. */
  17683. ;
  17684. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  17685. if (!this.featuresNativeTextTracks) {
  17686. return _Tech.prototype.createRemoteTextTrack.call(this, options);
  17687. }
  17688. var htmlTrackElement = document.createElement('track');
  17689. if (options.kind) {
  17690. htmlTrackElement.kind = options.kind;
  17691. }
  17692. if (options.label) {
  17693. htmlTrackElement.label = options.label;
  17694. }
  17695. if (options.language || options.srclang) {
  17696. htmlTrackElement.srclang = options.language || options.srclang;
  17697. }
  17698. if (options["default"]) {
  17699. htmlTrackElement["default"] = options["default"];
  17700. }
  17701. if (options.id) {
  17702. htmlTrackElement.id = options.id;
  17703. }
  17704. if (options.src) {
  17705. htmlTrackElement.src = options.src;
  17706. }
  17707. return htmlTrackElement;
  17708. }
  17709. /**
  17710. * Creates a remote text track object and returns an html track element.
  17711. *
  17712. * @param {Object} options The object should contain values for
  17713. * kind, language, label, and src (location of the WebVTT file)
  17714. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  17715. * automatically removed from the video element whenever the source changes
  17716. * @return {HTMLTrackElement} An Html Track Element.
  17717. * This can be an emulated {@link HTMLTrackElement} or a native one.
  17718. * @deprecated The default value of the "manualCleanup" parameter will default
  17719. * to "false" in upcoming versions of Video.js
  17720. */
  17721. ;
  17722. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  17723. var htmlTrackElement = _Tech.prototype.addRemoteTextTrack.call(this, options, manualCleanup);
  17724. if (this.featuresNativeTextTracks) {
  17725. this.el().appendChild(htmlTrackElement);
  17726. }
  17727. return htmlTrackElement;
  17728. }
  17729. /**
  17730. * Remove remote `TextTrack` from `TextTrackList` object
  17731. *
  17732. * @param {TextTrack} track
  17733. * `TextTrack` object to remove
  17734. */
  17735. ;
  17736. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  17737. _Tech.prototype.removeRemoteTextTrack.call(this, track);
  17738. if (this.featuresNativeTextTracks) {
  17739. var tracks = this.$$('track');
  17740. var i = tracks.length;
  17741. while (i--) {
  17742. if (track === tracks[i] || track === tracks[i].track) {
  17743. this.el().removeChild(tracks[i]);
  17744. }
  17745. }
  17746. }
  17747. }
  17748. /**
  17749. * Gets available media playback quality metrics as specified by the W3C's Media
  17750. * Playback Quality API.
  17751. *
  17752. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  17753. *
  17754. * @return {Object}
  17755. * An object with supported media playback quality metrics
  17756. */
  17757. ;
  17758. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  17759. if (typeof this.el().getVideoPlaybackQuality === 'function') {
  17760. return this.el().getVideoPlaybackQuality();
  17761. }
  17762. var videoPlaybackQuality = {};
  17763. if (typeof this.el().webkitDroppedFrameCount !== 'undefined' && typeof this.el().webkitDecodedFrameCount !== 'undefined') {
  17764. videoPlaybackQuality.droppedVideoFrames = this.el().webkitDroppedFrameCount;
  17765. videoPlaybackQuality.totalVideoFrames = this.el().webkitDecodedFrameCount;
  17766. }
  17767. if (window$1.performance && typeof window$1.performance.now === 'function') {
  17768. videoPlaybackQuality.creationTime = window$1.performance.now();
  17769. } else if (window$1.performance && window$1.performance.timing && typeof window$1.performance.timing.navigationStart === 'number') {
  17770. videoPlaybackQuality.creationTime = window$1.Date.now() - window$1.performance.timing.navigationStart;
  17771. }
  17772. return videoPlaybackQuality;
  17773. };
  17774. return Html5;
  17775. }(Tech);
  17776. /* HTML5 Support Testing ---------------------------------------------------- */
  17777. if (isReal()) {
  17778. /**
  17779. * Element for testing browser HTML5 media capabilities
  17780. *
  17781. * @type {Element}
  17782. * @constant
  17783. * @private
  17784. */
  17785. Html5.TEST_VID = document.createElement('video');
  17786. var track = document.createElement('track');
  17787. track.kind = 'captions';
  17788. track.srclang = 'en';
  17789. track.label = 'English';
  17790. Html5.TEST_VID.appendChild(track);
  17791. }
  17792. /**
  17793. * Check if HTML5 media is supported by this browser/device.
  17794. *
  17795. * @return {boolean}
  17796. * - True if HTML5 media is supported.
  17797. * - False if HTML5 media is not supported.
  17798. */
  17799. Html5.isSupported = function () {
  17800. // IE with no Media Player is a LIAR! (#984)
  17801. try {
  17802. Html5.TEST_VID.volume = 0.5;
  17803. } catch (e) {
  17804. return false;
  17805. }
  17806. return !!(Html5.TEST_VID && Html5.TEST_VID.canPlayType);
  17807. };
  17808. /**
  17809. * Check if the tech can support the given type
  17810. *
  17811. * @param {string} type
  17812. * The mimetype to check
  17813. * @return {string} 'probably', 'maybe', or '' (empty string)
  17814. */
  17815. Html5.canPlayType = function (type) {
  17816. return Html5.TEST_VID.canPlayType(type);
  17817. };
  17818. /**
  17819. * Check if the tech can support the given source
  17820. *
  17821. * @param {Object} srcObj
  17822. * The source object
  17823. * @param {Object} options
  17824. * The options passed to the tech
  17825. * @return {string} 'probably', 'maybe', or '' (empty string)
  17826. */
  17827. Html5.canPlaySource = function (srcObj, options) {
  17828. return Html5.canPlayType(srcObj.type);
  17829. };
  17830. /**
  17831. * Check if the volume can be changed in this browser/device.
  17832. * Volume cannot be changed in a lot of mobile devices.
  17833. * Specifically, it can't be changed from 1 on iOS.
  17834. *
  17835. * @return {boolean}
  17836. * - True if volume can be controlled
  17837. * - False otherwise
  17838. */
  17839. Html5.canControlVolume = function () {
  17840. // IE will error if Windows Media Player not installed #3315
  17841. try {
  17842. var volume = Html5.TEST_VID.volume;
  17843. Html5.TEST_VID.volume = volume / 2 + 0.1;
  17844. return volume !== Html5.TEST_VID.volume;
  17845. } catch (e) {
  17846. return false;
  17847. }
  17848. };
  17849. /**
  17850. * Check if the volume can be muted in this browser/device.
  17851. * Some devices, e.g. iOS, don't allow changing volume
  17852. * but permits muting/unmuting.
  17853. *
  17854. * @return {bolean}
  17855. * - True if volume can be muted
  17856. * - False otherwise
  17857. */
  17858. Html5.canMuteVolume = function () {
  17859. try {
  17860. var muted = Html5.TEST_VID.muted; // in some versions of iOS muted property doesn't always
  17861. // work, so we want to set both property and attribute
  17862. Html5.TEST_VID.muted = !muted;
  17863. if (Html5.TEST_VID.muted) {
  17864. setAttribute(Html5.TEST_VID, 'muted', 'muted');
  17865. } else {
  17866. removeAttribute(Html5.TEST_VID, 'muted', 'muted');
  17867. }
  17868. return muted !== Html5.TEST_VID.muted;
  17869. } catch (e) {
  17870. return false;
  17871. }
  17872. };
  17873. /**
  17874. * Check if the playback rate can be changed in this browser/device.
  17875. *
  17876. * @return {boolean}
  17877. * - True if playback rate can be controlled
  17878. * - False otherwise
  17879. */
  17880. Html5.canControlPlaybackRate = function () {
  17881. // Playback rate API is implemented in Android Chrome, but doesn't do anything
  17882. // https://github.com/videojs/video.js/issues/3180
  17883. if (IS_ANDROID && IS_CHROME && CHROME_VERSION < 58) {
  17884. return false;
  17885. } // IE will error if Windows Media Player not installed #3315
  17886. try {
  17887. var playbackRate = Html5.TEST_VID.playbackRate;
  17888. Html5.TEST_VID.playbackRate = playbackRate / 2 + 0.1;
  17889. return playbackRate !== Html5.TEST_VID.playbackRate;
  17890. } catch (e) {
  17891. return false;
  17892. }
  17893. };
  17894. /**
  17895. * Check if we can override a video/audio elements attributes, with
  17896. * Object.defineProperty.
  17897. *
  17898. * @return {boolean}
  17899. * - True if builtin attributes can be overridden
  17900. * - False otherwise
  17901. */
  17902. Html5.canOverrideAttributes = function () {
  17903. // if we cannot overwrite the src/innerHTML property, there is no support
  17904. // iOS 7 safari for instance cannot do this.
  17905. try {
  17906. var noop = function noop() {};
  17907. Object.defineProperty(document.createElement('video'), 'src', {
  17908. get: noop,
  17909. set: noop
  17910. });
  17911. Object.defineProperty(document.createElement('audio'), 'src', {
  17912. get: noop,
  17913. set: noop
  17914. });
  17915. Object.defineProperty(document.createElement('video'), 'innerHTML', {
  17916. get: noop,
  17917. set: noop
  17918. });
  17919. Object.defineProperty(document.createElement('audio'), 'innerHTML', {
  17920. get: noop,
  17921. set: noop
  17922. });
  17923. } catch (e) {
  17924. return false;
  17925. }
  17926. return true;
  17927. };
  17928. /**
  17929. * Check to see if native `TextTrack`s are supported by this browser/device.
  17930. *
  17931. * @return {boolean}
  17932. * - True if native `TextTrack`s are supported.
  17933. * - False otherwise
  17934. */
  17935. Html5.supportsNativeTextTracks = function () {
  17936. return IS_ANY_SAFARI || IS_IOS && IS_CHROME;
  17937. };
  17938. /**
  17939. * Check to see if native `VideoTrack`s are supported by this browser/device
  17940. *
  17941. * @return {boolean}
  17942. * - True if native `VideoTrack`s are supported.
  17943. * - False otherwise
  17944. */
  17945. Html5.supportsNativeVideoTracks = function () {
  17946. return !!(Html5.TEST_VID && Html5.TEST_VID.videoTracks);
  17947. };
  17948. /**
  17949. * Check to see if native `AudioTrack`s are supported by this browser/device
  17950. *
  17951. * @return {boolean}
  17952. * - True if native `AudioTrack`s are supported.
  17953. * - False otherwise
  17954. */
  17955. Html5.supportsNativeAudioTracks = function () {
  17956. return !!(Html5.TEST_VID && Html5.TEST_VID.audioTracks);
  17957. };
  17958. /**
  17959. * An array of events available on the Html5 tech.
  17960. *
  17961. * @private
  17962. * @type {Array}
  17963. */
  17964. Html5.Events = ['loadstart', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'loadedmetadata', 'loadeddata', 'canplay', 'canplaythrough', 'playing', 'waiting', 'seeking', 'seeked', 'ended', 'durationchange', 'timeupdate', 'progress', 'play', 'pause', 'ratechange', 'resize', 'volumechange'];
  17965. /**
  17966. * Boolean indicating whether the `Tech` supports volume control.
  17967. *
  17968. * @type {boolean}
  17969. * @default {@link Html5.canControlVolume}
  17970. */
  17971. Html5.prototype.featuresVolumeControl = Html5.canControlVolume();
  17972. /**
  17973. * Boolean indicating whether the `Tech` supports muting volume.
  17974. *
  17975. * @type {bolean}
  17976. * @default {@link Html5.canMuteVolume}
  17977. */
  17978. Html5.prototype.featuresMuteControl = Html5.canMuteVolume();
  17979. /**
  17980. * Boolean indicating whether the `Tech` supports changing the speed at which the media
  17981. * plays. Examples:
  17982. * - Set player to play 2x (twice) as fast
  17983. * - Set player to play 0.5x (half) as fast
  17984. *
  17985. * @type {boolean}
  17986. * @default {@link Html5.canControlPlaybackRate}
  17987. */
  17988. Html5.prototype.featuresPlaybackRate = Html5.canControlPlaybackRate();
  17989. /**
  17990. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  17991. *
  17992. * @type {boolean}
  17993. * @default
  17994. */
  17995. Html5.prototype.featuresSourceset = Html5.canOverrideAttributes();
  17996. /**
  17997. * Boolean indicating whether the `HTML5` tech currently supports the media element
  17998. * moving in the DOM. iOS breaks if you move the media element, so this is set this to
  17999. * false there. Everywhere else this should be true.
  18000. *
  18001. * @type {boolean}
  18002. * @default
  18003. */
  18004. Html5.prototype.movingMediaElementInDOM = !IS_IOS; // TODO: Previous comment: No longer appears to be used. Can probably be removed.
  18005. // Is this true?
  18006. /**
  18007. * Boolean indicating whether the `HTML5` tech currently supports automatic media resize
  18008. * when going into fullscreen.
  18009. *
  18010. * @type {boolean}
  18011. * @default
  18012. */
  18013. Html5.prototype.featuresFullscreenResize = true;
  18014. /**
  18015. * Boolean indicating whether the `HTML5` tech currently supports the progress event.
  18016. * If this is false, manual `progress` events will be triggered instead.
  18017. *
  18018. * @type {boolean}
  18019. * @default
  18020. */
  18021. Html5.prototype.featuresProgressEvents = true;
  18022. /**
  18023. * Boolean indicating whether the `HTML5` tech currently supports the timeupdate event.
  18024. * If this is false, manual `timeupdate` events will be triggered instead.
  18025. *
  18026. * @default
  18027. */
  18028. Html5.prototype.featuresTimeupdateEvents = true;
  18029. /**
  18030. * Boolean indicating whether the `HTML5` tech currently supports native `TextTrack`s.
  18031. *
  18032. * @type {boolean}
  18033. * @default {@link Html5.supportsNativeTextTracks}
  18034. */
  18035. Html5.prototype.featuresNativeTextTracks = Html5.supportsNativeTextTracks();
  18036. /**
  18037. * Boolean indicating whether the `HTML5` tech currently supports native `VideoTrack`s.
  18038. *
  18039. * @type {boolean}
  18040. * @default {@link Html5.supportsNativeVideoTracks}
  18041. */
  18042. Html5.prototype.featuresNativeVideoTracks = Html5.supportsNativeVideoTracks();
  18043. /**
  18044. * Boolean indicating whether the `HTML5` tech currently supports native `AudioTrack`s.
  18045. *
  18046. * @type {boolean}
  18047. * @default {@link Html5.supportsNativeAudioTracks}
  18048. */
  18049. Html5.prototype.featuresNativeAudioTracks = Html5.supportsNativeAudioTracks(); // HTML5 Feature detection and Device Fixes --------------------------------- //
  18050. var canPlayType = Html5.TEST_VID && Html5.TEST_VID.constructor.prototype.canPlayType;
  18051. var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
  18052. Html5.patchCanPlayType = function () {
  18053. // Android 4.0 and above can play HLS to some extent but it reports being unable to do so
  18054. // Firefox and Chrome report correctly
  18055. if (ANDROID_VERSION >= 4.0 && !IS_FIREFOX && !IS_CHROME) {
  18056. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  18057. if (type && mpegurlRE.test(type)) {
  18058. return 'maybe';
  18059. }
  18060. return canPlayType.call(this, type);
  18061. };
  18062. }
  18063. };
  18064. Html5.unpatchCanPlayType = function () {
  18065. var r = Html5.TEST_VID.constructor.prototype.canPlayType;
  18066. Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
  18067. return r;
  18068. }; // by default, patch the media element
  18069. Html5.patchCanPlayType();
  18070. Html5.disposeMediaElement = function (el) {
  18071. if (!el) {
  18072. return;
  18073. }
  18074. if (el.parentNode) {
  18075. el.parentNode.removeChild(el);
  18076. } // remove any child track or source nodes to prevent their loading
  18077. while (el.hasChildNodes()) {
  18078. el.removeChild(el.firstChild);
  18079. } // remove any src reference. not setting `src=''` because that causes a warning
  18080. // in firefox
  18081. el.removeAttribute('src'); // force the media element to update its loading state by calling load()
  18082. // however IE on Windows 7N has a bug that throws an error so need a try/catch (#793)
  18083. if (typeof el.load === 'function') {
  18084. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  18085. (function () {
  18086. try {
  18087. el.load();
  18088. } catch (e) {// not supported
  18089. }
  18090. })();
  18091. }
  18092. };
  18093. Html5.resetMediaElement = function (el) {
  18094. if (!el) {
  18095. return;
  18096. }
  18097. var sources = el.querySelectorAll('source');
  18098. var i = sources.length;
  18099. while (i--) {
  18100. el.removeChild(sources[i]);
  18101. } // remove any src reference.
  18102. // not setting `src=''` because that throws an error
  18103. el.removeAttribute('src');
  18104. if (typeof el.load === 'function') {
  18105. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  18106. (function () {
  18107. try {
  18108. el.load();
  18109. } catch (e) {// satisfy linter
  18110. }
  18111. })();
  18112. }
  18113. };
  18114. /* Native HTML5 element property wrapping ----------------------------------- */
  18115. // Wrap native boolean attributes with getters that check both property and attribute
  18116. // The list is as followed:
  18117. // muted, defaultMuted, autoplay, controls, loop, playsinline
  18118. [
  18119. /**
  18120. * Get the value of `muted` from the media element. `muted` indicates
  18121. * that the volume for the media should be set to silent. This does not actually change
  18122. * the `volume` attribute.
  18123. *
  18124. * @method Html5#muted
  18125. * @return {boolean}
  18126. * - True if the value of `volume` should be ignored and the audio set to silent.
  18127. * - False if the value of `volume` should be used.
  18128. *
  18129. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  18130. */
  18131. 'muted',
  18132. /**
  18133. * Get the value of `defaultMuted` from the media element. `defaultMuted` indicates
  18134. * whether the media should start muted or not. Only changes the default state of the
  18135. * media. `muted` and `defaultMuted` can have different values. {@link Html5#muted} indicates the
  18136. * current state.
  18137. *
  18138. * @method Html5#defaultMuted
  18139. * @return {boolean}
  18140. * - The value of `defaultMuted` from the media element.
  18141. * - True indicates that the media should start muted.
  18142. * - False indicates that the media should not start muted
  18143. *
  18144. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  18145. */
  18146. 'defaultMuted',
  18147. /**
  18148. * Get the value of `autoplay` from the media element. `autoplay` indicates
  18149. * that the media should start to play as soon as the page is ready.
  18150. *
  18151. * @method Html5#autoplay
  18152. * @return {boolean}
  18153. * - The value of `autoplay` from the media element.
  18154. * - True indicates that the media should start as soon as the page loads.
  18155. * - False indicates that the media should not start as soon as the page loads.
  18156. *
  18157. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  18158. */
  18159. 'autoplay',
  18160. /**
  18161. * Get the value of `controls` from the media element. `controls` indicates
  18162. * whether the native media controls should be shown or hidden.
  18163. *
  18164. * @method Html5#controls
  18165. * @return {boolean}
  18166. * - The value of `controls` from the media element.
  18167. * - True indicates that native controls should be showing.
  18168. * - False indicates that native controls should be hidden.
  18169. *
  18170. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-controls}
  18171. */
  18172. 'controls',
  18173. /**
  18174. * Get the value of `loop` from the media element. `loop` indicates
  18175. * that the media should return to the start of the media and continue playing once
  18176. * it reaches the end.
  18177. *
  18178. * @method Html5#loop
  18179. * @return {boolean}
  18180. * - The value of `loop` from the media element.
  18181. * - True indicates that playback should seek back to start once
  18182. * the end of a media is reached.
  18183. * - False indicates that playback should not loop back to the start when the
  18184. * end of the media is reached.
  18185. *
  18186. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  18187. */
  18188. 'loop',
  18189. /**
  18190. * Get the value of `playsinline` from the media element. `playsinline` indicates
  18191. * to the browser that non-fullscreen playback is preferred when fullscreen
  18192. * playback is the native default, such as in iOS Safari.
  18193. *
  18194. * @method Html5#playsinline
  18195. * @return {boolean}
  18196. * - The value of `playsinline` from the media element.
  18197. * - True indicates that the media should play inline.
  18198. * - False indicates that the media should not play inline.
  18199. *
  18200. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  18201. */
  18202. 'playsinline'].forEach(function (prop) {
  18203. Html5.prototype[prop] = function () {
  18204. return this.el_[prop] || this.el_.hasAttribute(prop);
  18205. };
  18206. }); // Wrap native boolean attributes with setters that set both property and attribute
  18207. // The list is as followed:
  18208. // setMuted, setDefaultMuted, setAutoplay, setLoop, setPlaysinline
  18209. // setControls is special-cased above
  18210. [
  18211. /**
  18212. * Set the value of `muted` on the media element. `muted` indicates that the current
  18213. * audio level should be silent.
  18214. *
  18215. * @method Html5#setMuted
  18216. * @param {boolean} muted
  18217. * - True if the audio should be set to silent
  18218. * - False otherwise
  18219. *
  18220. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  18221. */
  18222. 'muted',
  18223. /**
  18224. * Set the value of `defaultMuted` on the media element. `defaultMuted` indicates that the current
  18225. * audio level should be silent, but will only effect the muted level on intial playback..
  18226. *
  18227. * @method Html5.prototype.setDefaultMuted
  18228. * @param {boolean} defaultMuted
  18229. * - True if the audio should be set to silent
  18230. * - False otherwise
  18231. *
  18232. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  18233. */
  18234. 'defaultMuted',
  18235. /**
  18236. * Set the value of `autoplay` on the media element. `autoplay` indicates
  18237. * that the media should start to play as soon as the page is ready.
  18238. *
  18239. * @method Html5#setAutoplay
  18240. * @param {boolean} autoplay
  18241. * - True indicates that the media should start as soon as the page loads.
  18242. * - False indicates that the media should not start as soon as the page loads.
  18243. *
  18244. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  18245. */
  18246. 'autoplay',
  18247. /**
  18248. * Set the value of `loop` on the media element. `loop` indicates
  18249. * that the media should return to the start of the media and continue playing once
  18250. * it reaches the end.
  18251. *
  18252. * @method Html5#setLoop
  18253. * @param {boolean} loop
  18254. * - True indicates that playback should seek back to start once
  18255. * the end of a media is reached.
  18256. * - False indicates that playback should not loop back to the start when the
  18257. * end of the media is reached.
  18258. *
  18259. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  18260. */
  18261. 'loop',
  18262. /**
  18263. * Set the value of `playsinline` from the media element. `playsinline` indicates
  18264. * to the browser that non-fullscreen playback is preferred when fullscreen
  18265. * playback is the native default, such as in iOS Safari.
  18266. *
  18267. * @method Html5#setPlaysinline
  18268. * @param {boolean} playsinline
  18269. * - True indicates that the media should play inline.
  18270. * - False indicates that the media should not play inline.
  18271. *
  18272. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  18273. */
  18274. 'playsinline'].forEach(function (prop) {
  18275. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  18276. this.el_[prop] = v;
  18277. if (v) {
  18278. this.el_.setAttribute(prop, prop);
  18279. } else {
  18280. this.el_.removeAttribute(prop);
  18281. }
  18282. };
  18283. }); // Wrap native properties with a getter
  18284. // The list is as followed
  18285. // paused, currentTime, buffered, volume, poster, preload, error, seeking
  18286. // seekable, ended, playbackRate, defaultPlaybackRate, played, networkState
  18287. // readyState, videoWidth, videoHeight
  18288. [
  18289. /**
  18290. * Get the value of `paused` from the media element. `paused` indicates whether the media element
  18291. * is currently paused or not.
  18292. *
  18293. * @method Html5#paused
  18294. * @return {boolean}
  18295. * The value of `paused` from the media element.
  18296. *
  18297. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-paused}
  18298. */
  18299. 'paused',
  18300. /**
  18301. * Get the value of `currentTime` from the media element. `currentTime` indicates
  18302. * the current second that the media is at in playback.
  18303. *
  18304. * @method Html5#currentTime
  18305. * @return {number}
  18306. * The value of `currentTime` from the media element.
  18307. *
  18308. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-currenttime}
  18309. */
  18310. 'currentTime',
  18311. /**
  18312. * Get the value of `buffered` from the media element. `buffered` is a `TimeRange`
  18313. * object that represents the parts of the media that are already downloaded and
  18314. * available for playback.
  18315. *
  18316. * @method Html5#buffered
  18317. * @return {TimeRange}
  18318. * The value of `buffered` from the media element.
  18319. *
  18320. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-buffered}
  18321. */
  18322. 'buffered',
  18323. /**
  18324. * Get the value of `volume` from the media element. `volume` indicates
  18325. * the current playback volume of audio for a media. `volume` will be a value from 0
  18326. * (silent) to 1 (loudest and default).
  18327. *
  18328. * @method Html5#volume
  18329. * @return {number}
  18330. * The value of `volume` from the media element. Value will be between 0-1.
  18331. *
  18332. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  18333. */
  18334. 'volume',
  18335. /**
  18336. * Get the value of `poster` from the media element. `poster` indicates
  18337. * that the url of an image file that can/will be shown when no media data is available.
  18338. *
  18339. * @method Html5#poster
  18340. * @return {string}
  18341. * The value of `poster` from the media element. Value will be a url to an
  18342. * image.
  18343. *
  18344. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster}
  18345. */
  18346. 'poster',
  18347. /**
  18348. * Get the value of `preload` from the media element. `preload` indicates
  18349. * what should download before the media is interacted with. It can have the following
  18350. * values:
  18351. * - none: nothing should be downloaded
  18352. * - metadata: poster and the first few frames of the media may be downloaded to get
  18353. * media dimensions and other metadata
  18354. * - auto: allow the media and metadata for the media to be downloaded before
  18355. * interaction
  18356. *
  18357. * @method Html5#preload
  18358. * @return {string}
  18359. * The value of `preload` from the media element. Will be 'none', 'metadata',
  18360. * or 'auto'.
  18361. *
  18362. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  18363. */
  18364. 'preload',
  18365. /**
  18366. * Get the value of the `error` from the media element. `error` indicates any
  18367. * MediaError that may have occurred during playback. If error returns null there is no
  18368. * current error.
  18369. *
  18370. * @method Html5#error
  18371. * @return {MediaError|null}
  18372. * The value of `error` from the media element. Will be `MediaError` if there
  18373. * is a current error and null otherwise.
  18374. *
  18375. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-error}
  18376. */
  18377. 'error',
  18378. /**
  18379. * Get the value of `seeking` from the media element. `seeking` indicates whether the
  18380. * media is currently seeking to a new position or not.
  18381. *
  18382. * @method Html5#seeking
  18383. * @return {boolean}
  18384. * - The value of `seeking` from the media element.
  18385. * - True indicates that the media is currently seeking to a new position.
  18386. * - False indicates that the media is not seeking to a new position at this time.
  18387. *
  18388. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seeking}
  18389. */
  18390. 'seeking',
  18391. /**
  18392. * Get the value of `seekable` from the media element. `seekable` returns a
  18393. * `TimeRange` object indicating ranges of time that can currently be `seeked` to.
  18394. *
  18395. * @method Html5#seekable
  18396. * @return {TimeRange}
  18397. * The value of `seekable` from the media element. A `TimeRange` object
  18398. * indicating the current ranges of time that can be seeked to.
  18399. *
  18400. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seekable}
  18401. */
  18402. 'seekable',
  18403. /**
  18404. * Get the value of `ended` from the media element. `ended` indicates whether
  18405. * the media has reached the end or not.
  18406. *
  18407. * @method Html5#ended
  18408. * @return {boolean}
  18409. * - The value of `ended` from the media element.
  18410. * - True indicates that the media has ended.
  18411. * - False indicates that the media has not ended.
  18412. *
  18413. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
  18414. */
  18415. 'ended',
  18416. /**
  18417. * Get the value of `playbackRate` from the media element. `playbackRate` indicates
  18418. * the rate at which the media is currently playing back. Examples:
  18419. * - if playbackRate is set to 2, media will play twice as fast.
  18420. * - if playbackRate is set to 0.5, media will play half as fast.
  18421. *
  18422. * @method Html5#playbackRate
  18423. * @return {number}
  18424. * The value of `playbackRate` from the media element. A number indicating
  18425. * the current playback speed of the media, where 1 is normal speed.
  18426. *
  18427. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  18428. */
  18429. 'playbackRate',
  18430. /**
  18431. * Get the value of `defaultPlaybackRate` from the media element. `defaultPlaybackRate` indicates
  18432. * the rate at which the media is currently playing back. This value will not indicate the current
  18433. * `playbackRate` after playback has started, use {@link Html5#playbackRate} for that.
  18434. *
  18435. * Examples:
  18436. * - if defaultPlaybackRate is set to 2, media will play twice as fast.
  18437. * - if defaultPlaybackRate is set to 0.5, media will play half as fast.
  18438. *
  18439. * @method Html5.prototype.defaultPlaybackRate
  18440. * @return {number}
  18441. * The value of `defaultPlaybackRate` from the media element. A number indicating
  18442. * the current playback speed of the media, where 1 is normal speed.
  18443. *
  18444. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  18445. */
  18446. 'defaultPlaybackRate',
  18447. /**
  18448. * Get the value of `played` from the media element. `played` returns a `TimeRange`
  18449. * object representing points in the media timeline that have been played.
  18450. *
  18451. * @method Html5#played
  18452. * @return {TimeRange}
  18453. * The value of `played` from the media element. A `TimeRange` object indicating
  18454. * the ranges of time that have been played.
  18455. *
  18456. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-played}
  18457. */
  18458. 'played',
  18459. /**
  18460. * Get the value of `networkState` from the media element. `networkState` indicates
  18461. * the current network state. It returns an enumeration from the following list:
  18462. * - 0: NETWORK_EMPTY
  18463. * - 1: NETWORK_IDLE
  18464. * - 2: NETWORK_LOADING
  18465. * - 3: NETWORK_NO_SOURCE
  18466. *
  18467. * @method Html5#networkState
  18468. * @return {number}
  18469. * The value of `networkState` from the media element. This will be a number
  18470. * from the list in the description.
  18471. *
  18472. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-networkstate}
  18473. */
  18474. 'networkState',
  18475. /**
  18476. * Get the value of `readyState` from the media element. `readyState` indicates
  18477. * the current state of the media element. It returns an enumeration from the
  18478. * following list:
  18479. * - 0: HAVE_NOTHING
  18480. * - 1: HAVE_METADATA
  18481. * - 2: HAVE_CURRENT_DATA
  18482. * - 3: HAVE_FUTURE_DATA
  18483. * - 4: HAVE_ENOUGH_DATA
  18484. *
  18485. * @method Html5#readyState
  18486. * @return {number}
  18487. * The value of `readyState` from the media element. This will be a number
  18488. * from the list in the description.
  18489. *
  18490. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#ready-states}
  18491. */
  18492. 'readyState',
  18493. /**
  18494. * Get the value of `videoWidth` from the video element. `videoWidth` indicates
  18495. * the current width of the video in css pixels.
  18496. *
  18497. * @method Html5#videoWidth
  18498. * @return {number}
  18499. * The value of `videoWidth` from the video element. This will be a number
  18500. * in css pixels.
  18501. *
  18502. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  18503. */
  18504. 'videoWidth',
  18505. /**
  18506. * Get the value of `videoHeight` from the video element. `videoHeight` indicates
  18507. * the current height of the video in css pixels.
  18508. *
  18509. * @method Html5#videoHeight
  18510. * @return {number}
  18511. * The value of `videoHeight` from the video element. This will be a number
  18512. * in css pixels.
  18513. *
  18514. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  18515. */
  18516. 'videoHeight'].forEach(function (prop) {
  18517. Html5.prototype[prop] = function () {
  18518. return this.el_[prop];
  18519. };
  18520. }); // Wrap native properties with a setter in this format:
  18521. // set + toTitleCase(name)
  18522. // The list is as follows:
  18523. // setVolume, setSrc, setPoster, setPreload, setPlaybackRate, setDefaultPlaybackRate
  18524. [
  18525. /**
  18526. * Set the value of `volume` on the media element. `volume` indicates the current
  18527. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  18528. * so on.
  18529. *
  18530. * @method Html5#setVolume
  18531. * @param {number} percentAsDecimal
  18532. * The volume percent as a decimal. Valid range is from 0-1.
  18533. *
  18534. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  18535. */
  18536. 'volume',
  18537. /**
  18538. * Set the value of `src` on the media element. `src` indicates the current
  18539. * {@link Tech~SourceObject} for the media.
  18540. *
  18541. * @method Html5#setSrc
  18542. * @param {Tech~SourceObject} src
  18543. * The source object to set as the current source.
  18544. *
  18545. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-src}
  18546. */
  18547. 'src',
  18548. /**
  18549. * Set the value of `poster` on the media element. `poster` is the url to
  18550. * an image file that can/will be shown when no media data is available.
  18551. *
  18552. * @method Html5#setPoster
  18553. * @param {string} poster
  18554. * The url to an image that should be used as the `poster` for the media
  18555. * element.
  18556. *
  18557. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-poster}
  18558. */
  18559. 'poster',
  18560. /**
  18561. * Set the value of `preload` on the media element. `preload` indicates
  18562. * what should download before the media is interacted with. It can have the following
  18563. * values:
  18564. * - none: nothing should be downloaded
  18565. * - metadata: poster and the first few frames of the media may be downloaded to get
  18566. * media dimensions and other metadata
  18567. * - auto: allow the media and metadata for the media to be downloaded before
  18568. * interaction
  18569. *
  18570. * @method Html5#setPreload
  18571. * @param {string} preload
  18572. * The value of `preload` to set on the media element. Must be 'none', 'metadata',
  18573. * or 'auto'.
  18574. *
  18575. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  18576. */
  18577. 'preload',
  18578. /**
  18579. * Set the value of `playbackRate` on the media element. `playbackRate` indicates
  18580. * the rate at which the media should play back. Examples:
  18581. * - if playbackRate is set to 2, media will play twice as fast.
  18582. * - if playbackRate is set to 0.5, media will play half as fast.
  18583. *
  18584. * @method Html5#setPlaybackRate
  18585. * @return {number}
  18586. * The value of `playbackRate` from the media element. A number indicating
  18587. * the current playback speed of the media, where 1 is normal speed.
  18588. *
  18589. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  18590. */
  18591. 'playbackRate',
  18592. /**
  18593. * Set the value of `defaultPlaybackRate` on the media element. `defaultPlaybackRate` indicates
  18594. * the rate at which the media should play back upon initial startup. Changing this value
  18595. * after a video has started will do nothing. Instead you should used {@link Html5#setPlaybackRate}.
  18596. *
  18597. * Example Values:
  18598. * - if playbackRate is set to 2, media will play twice as fast.
  18599. * - if playbackRate is set to 0.5, media will play half as fast.
  18600. *
  18601. * @method Html5.prototype.setDefaultPlaybackRate
  18602. * @return {number}
  18603. * The value of `defaultPlaybackRate` from the media element. A number indicating
  18604. * the current playback speed of the media, where 1 is normal speed.
  18605. *
  18606. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultplaybackrate}
  18607. */
  18608. 'defaultPlaybackRate'].forEach(function (prop) {
  18609. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  18610. this.el_[prop] = v;
  18611. };
  18612. }); // wrap native functions with a function
  18613. // The list is as follows:
  18614. // pause, load, play
  18615. [
  18616. /**
  18617. * A wrapper around the media elements `pause` function. This will call the `HTML5`
  18618. * media elements `pause` function.
  18619. *
  18620. * @method Html5#pause
  18621. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-pause}
  18622. */
  18623. 'pause',
  18624. /**
  18625. * A wrapper around the media elements `load` function. This will call the `HTML5`s
  18626. * media element `load` function.
  18627. *
  18628. * @method Html5#load
  18629. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-load}
  18630. */
  18631. 'load',
  18632. /**
  18633. * A wrapper around the media elements `play` function. This will call the `HTML5`s
  18634. * media element `play` function.
  18635. *
  18636. * @method Html5#play
  18637. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-play}
  18638. */
  18639. 'play'].forEach(function (prop) {
  18640. Html5.prototype[prop] = function () {
  18641. return this.el_[prop]();
  18642. };
  18643. });
  18644. Tech.withSourceHandlers(Html5);
  18645. /**
  18646. * Native source handler for Html5, simply passes the source to the media element.
  18647. *
  18648. * @property {Tech~SourceObject} source
  18649. * The source object
  18650. *
  18651. * @property {Html5} tech
  18652. * The instance of the HTML5 tech.
  18653. */
  18654. Html5.nativeSourceHandler = {};
  18655. /**
  18656. * Check if the media element can play the given mime type.
  18657. *
  18658. * @param {string} type
  18659. * The mimetype to check
  18660. *
  18661. * @return {string}
  18662. * 'probably', 'maybe', or '' (empty string)
  18663. */
  18664. Html5.nativeSourceHandler.canPlayType = function (type) {
  18665. // IE without MediaPlayer throws an error (#519)
  18666. try {
  18667. return Html5.TEST_VID.canPlayType(type);
  18668. } catch (e) {
  18669. return '';
  18670. }
  18671. };
  18672. /**
  18673. * Check if the media element can handle a source natively.
  18674. *
  18675. * @param {Tech~SourceObject} source
  18676. * The source object
  18677. *
  18678. * @param {Object} [options]
  18679. * Options to be passed to the tech.
  18680. *
  18681. * @return {string}
  18682. * 'probably', 'maybe', or '' (empty string).
  18683. */
  18684. Html5.nativeSourceHandler.canHandleSource = function (source, options) {
  18685. // If a type was provided we should rely on that
  18686. if (source.type) {
  18687. return Html5.nativeSourceHandler.canPlayType(source.type); // If no type, fall back to checking 'video/[EXTENSION]'
  18688. } else if (source.src) {
  18689. var ext = getFileExtension(source.src);
  18690. return Html5.nativeSourceHandler.canPlayType("video/" + ext);
  18691. }
  18692. return '';
  18693. };
  18694. /**
  18695. * Pass the source to the native media element.
  18696. *
  18697. * @param {Tech~SourceObject} source
  18698. * The source object
  18699. *
  18700. * @param {Html5} tech
  18701. * The instance of the Html5 tech
  18702. *
  18703. * @param {Object} [options]
  18704. * The options to pass to the source
  18705. */
  18706. Html5.nativeSourceHandler.handleSource = function (source, tech, options) {
  18707. tech.setSrc(source.src);
  18708. };
  18709. /**
  18710. * A noop for the native dispose function, as cleanup is not needed.
  18711. */
  18712. Html5.nativeSourceHandler.dispose = function () {}; // Register the native source handler
  18713. Html5.registerSourceHandler(Html5.nativeSourceHandler);
  18714. Tech.registerTech('Html5', Html5);
  18715. // on the player when they happen
  18716. var TECH_EVENTS_RETRIGGER = [
  18717. /**
  18718. * Fired while the user agent is downloading media data.
  18719. *
  18720. * @event Player#progress
  18721. * @type {EventTarget~Event}
  18722. */
  18723. /**
  18724. * Retrigger the `progress` event that was triggered by the {@link Tech}.
  18725. *
  18726. * @private
  18727. * @method Player#handleTechProgress_
  18728. * @fires Player#progress
  18729. * @listens Tech#progress
  18730. */
  18731. 'progress',
  18732. /**
  18733. * Fires when the loading of an audio/video is aborted.
  18734. *
  18735. * @event Player#abort
  18736. * @type {EventTarget~Event}
  18737. */
  18738. /**
  18739. * Retrigger the `abort` event that was triggered by the {@link Tech}.
  18740. *
  18741. * @private
  18742. * @method Player#handleTechAbort_
  18743. * @fires Player#abort
  18744. * @listens Tech#abort
  18745. */
  18746. 'abort',
  18747. /**
  18748. * Fires when the browser is intentionally not getting media data.
  18749. *
  18750. * @event Player#suspend
  18751. * @type {EventTarget~Event}
  18752. */
  18753. /**
  18754. * Retrigger the `suspend` event that was triggered by the {@link Tech}.
  18755. *
  18756. * @private
  18757. * @method Player#handleTechSuspend_
  18758. * @fires Player#suspend
  18759. * @listens Tech#suspend
  18760. */
  18761. 'suspend',
  18762. /**
  18763. * Fires when the current playlist is empty.
  18764. *
  18765. * @event Player#emptied
  18766. * @type {EventTarget~Event}
  18767. */
  18768. /**
  18769. * Retrigger the `emptied` event that was triggered by the {@link Tech}.
  18770. *
  18771. * @private
  18772. * @method Player#handleTechEmptied_
  18773. * @fires Player#emptied
  18774. * @listens Tech#emptied
  18775. */
  18776. 'emptied',
  18777. /**
  18778. * Fires when the browser is trying to get media data, but data is not available.
  18779. *
  18780. * @event Player#stalled
  18781. * @type {EventTarget~Event}
  18782. */
  18783. /**
  18784. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  18785. *
  18786. * @private
  18787. * @method Player#handleTechStalled_
  18788. * @fires Player#stalled
  18789. * @listens Tech#stalled
  18790. */
  18791. 'stalled',
  18792. /**
  18793. * Fires when the browser has loaded meta data for the audio/video.
  18794. *
  18795. * @event Player#loadedmetadata
  18796. * @type {EventTarget~Event}
  18797. */
  18798. /**
  18799. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  18800. *
  18801. * @private
  18802. * @method Player#handleTechLoadedmetadata_
  18803. * @fires Player#loadedmetadata
  18804. * @listens Tech#loadedmetadata
  18805. */
  18806. 'loadedmetadata',
  18807. /**
  18808. * Fires when the browser has loaded the current frame of the audio/video.
  18809. *
  18810. * @event Player#loadeddata
  18811. * @type {event}
  18812. */
  18813. /**
  18814. * Retrigger the `loadeddata` event that was triggered by the {@link Tech}.
  18815. *
  18816. * @private
  18817. * @method Player#handleTechLoaddeddata_
  18818. * @fires Player#loadeddata
  18819. * @listens Tech#loadeddata
  18820. */
  18821. 'loadeddata',
  18822. /**
  18823. * Fires when the current playback position has changed.
  18824. *
  18825. * @event Player#timeupdate
  18826. * @type {event}
  18827. */
  18828. /**
  18829. * Retrigger the `timeupdate` event that was triggered by the {@link Tech}.
  18830. *
  18831. * @private
  18832. * @method Player#handleTechTimeUpdate_
  18833. * @fires Player#timeupdate
  18834. * @listens Tech#timeupdate
  18835. */
  18836. 'timeupdate',
  18837. /**
  18838. * Fires when the video's intrinsic dimensions change
  18839. *
  18840. * @event Player#resize
  18841. * @type {event}
  18842. */
  18843. /**
  18844. * Retrigger the `resize` event that was triggered by the {@link Tech}.
  18845. *
  18846. * @private
  18847. * @method Player#handleTechResize_
  18848. * @fires Player#resize
  18849. * @listens Tech#resize
  18850. */
  18851. 'resize',
  18852. /**
  18853. * Fires when the volume has been changed
  18854. *
  18855. * @event Player#volumechange
  18856. * @type {event}
  18857. */
  18858. /**
  18859. * Retrigger the `volumechange` event that was triggered by the {@link Tech}.
  18860. *
  18861. * @private
  18862. * @method Player#handleTechVolumechange_
  18863. * @fires Player#volumechange
  18864. * @listens Tech#volumechange
  18865. */
  18866. 'volumechange',
  18867. /**
  18868. * Fires when the text track has been changed
  18869. *
  18870. * @event Player#texttrackchange
  18871. * @type {event}
  18872. */
  18873. /**
  18874. * Retrigger the `texttrackchange` event that was triggered by the {@link Tech}.
  18875. *
  18876. * @private
  18877. * @method Player#handleTechTexttrackchange_
  18878. * @fires Player#texttrackchange
  18879. * @listens Tech#texttrackchange
  18880. */
  18881. 'texttrackchange']; // events to queue when playback rate is zero
  18882. // this is a hash for the sole purpose of mapping non-camel-cased event names
  18883. // to camel-cased function names
  18884. var TECH_EVENTS_QUEUE = {
  18885. canplay: 'CanPlay',
  18886. canplaythrough: 'CanPlayThrough',
  18887. playing: 'Playing',
  18888. seeked: 'Seeked'
  18889. };
  18890. var BREAKPOINT_ORDER = ['tiny', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'huge'];
  18891. var BREAKPOINT_CLASSES = {}; // grep: vjs-layout-tiny
  18892. // grep: vjs-layout-x-small
  18893. // grep: vjs-layout-small
  18894. // grep: vjs-layout-medium
  18895. // grep: vjs-layout-large
  18896. // grep: vjs-layout-x-large
  18897. // grep: vjs-layout-huge
  18898. BREAKPOINT_ORDER.forEach(function (k) {
  18899. var v = k.charAt(0) === 'x' ? "x-" + k.substring(1) : k;
  18900. BREAKPOINT_CLASSES[k] = "vjs-layout-" + v;
  18901. });
  18902. var DEFAULT_BREAKPOINTS = {
  18903. tiny: 210,
  18904. xsmall: 320,
  18905. small: 425,
  18906. medium: 768,
  18907. large: 1440,
  18908. xlarge: 2560,
  18909. huge: Infinity
  18910. };
  18911. /**
  18912. * An instance of the `Player` class is created when any of the Video.js setup methods
  18913. * are used to initialize a video.
  18914. *
  18915. * After an instance has been created it can be accessed globally in two ways:
  18916. * 1. By calling `videojs('example_video_1');`
  18917. * 2. By using it directly via `videojs.players.example_video_1;`
  18918. *
  18919. * @extends Component
  18920. */
  18921. var Player =
  18922. /*#__PURE__*/
  18923. function (_Component) {
  18924. _inheritsLoose(Player, _Component);
  18925. /**
  18926. * Create an instance of this class.
  18927. *
  18928. * @param {Element} tag
  18929. * The original video DOM element used for configuring options.
  18930. *
  18931. * @param {Object} [options]
  18932. * Object of option names and values.
  18933. *
  18934. * @param {Component~ReadyCallback} [ready]
  18935. * Ready callback function.
  18936. */
  18937. function Player(tag, options, ready) {
  18938. var _this;
  18939. // Make sure tag ID exists
  18940. tag.id = tag.id || options.id || "vjs_video_" + newGUID(); // Set Options
  18941. // The options argument overrides options set in the video tag
  18942. // which overrides globally set options.
  18943. // This latter part coincides with the load order
  18944. // (tag must exist before Player)
  18945. options = assign(Player.getTagSettings(tag), options); // Delay the initialization of children because we need to set up
  18946. // player properties first, and can't use `this` before `super()`
  18947. options.initChildren = false; // Same with creating the element
  18948. options.createEl = false; // don't auto mixin the evented mixin
  18949. options.evented = false; // we don't want the player to report touch activity on itself
  18950. // see enableTouchActivity in Component
  18951. options.reportTouchActivity = false; // If language is not set, get the closest lang attribute
  18952. if (!options.language) {
  18953. if (typeof tag.closest === 'function') {
  18954. var closest = tag.closest('[lang]');
  18955. if (closest && closest.getAttribute) {
  18956. options.language = closest.getAttribute('lang');
  18957. }
  18958. } else {
  18959. var element = tag;
  18960. while (element && element.nodeType === 1) {
  18961. if (getAttributes(element).hasOwnProperty('lang')) {
  18962. options.language = element.getAttribute('lang');
  18963. break;
  18964. }
  18965. element = element.parentNode;
  18966. }
  18967. }
  18968. } // Run base component initializing with new options
  18969. _this = _Component.call(this, null, options, ready) || this; // Create bound methods for document listeners.
  18970. _this.boundDocumentFullscreenChange_ = bind(_assertThisInitialized(_this), _this.documentFullscreenChange_);
  18971. _this.boundFullWindowOnEscKey_ = bind(_assertThisInitialized(_this), _this.fullWindowOnEscKey); // create logger
  18972. _this.log = createLogger$1(_this.id_); // Hold our own reference to fullscreen api so it can be mocked in tests
  18973. _this.fsApi_ = FullscreenApi; // Tracks when a tech changes the poster
  18974. _this.isPosterFromTech_ = false; // Holds callback info that gets queued when playback rate is zero
  18975. // and a seek is happening
  18976. _this.queuedCallbacks_ = []; // Turn off API access because we're loading a new tech that might load asynchronously
  18977. _this.isReady_ = false; // Init state hasStarted_
  18978. _this.hasStarted_ = false; // Init state userActive_
  18979. _this.userActive_ = false; // if the global option object was accidentally blown away by
  18980. // someone, bail early with an informative error
  18981. if (!_this.options_ || !_this.options_.techOrder || !_this.options_.techOrder.length) {
  18982. throw new Error('No techOrder specified. Did you overwrite ' + 'videojs.options instead of just changing the ' + 'properties you want to override?');
  18983. } // Store the original tag used to set options
  18984. _this.tag = tag; // Store the tag attributes used to restore html5 element
  18985. _this.tagAttributes = tag && getAttributes(tag); // Update current language
  18986. _this.language(_this.options_.language); // Update Supported Languages
  18987. if (options.languages) {
  18988. // Normalise player option languages to lowercase
  18989. var languagesToLower = {};
  18990. Object.getOwnPropertyNames(options.languages).forEach(function (name) {
  18991. languagesToLower[name.toLowerCase()] = options.languages[name];
  18992. });
  18993. _this.languages_ = languagesToLower;
  18994. } else {
  18995. _this.languages_ = Player.prototype.options_.languages;
  18996. }
  18997. _this.resetCache_(); // Set poster
  18998. _this.poster_ = options.poster || ''; // Set controls
  18999. _this.controls_ = !!options.controls; // Original tag settings stored in options
  19000. // now remove immediately so native controls don't flash.
  19001. // May be turned back on by HTML5 tech if nativeControlsForTouch is true
  19002. tag.controls = false;
  19003. tag.removeAttribute('controls');
  19004. _this.changingSrc_ = false;
  19005. _this.playCallbacks_ = [];
  19006. _this.playTerminatedQueue_ = []; // the attribute overrides the option
  19007. if (tag.hasAttribute('autoplay')) {
  19008. _this.autoplay(true);
  19009. } else {
  19010. // otherwise use the setter to validate and
  19011. // set the correct value.
  19012. _this.autoplay(_this.options_.autoplay);
  19013. } // check plugins
  19014. if (options.plugins) {
  19015. Object.keys(options.plugins).forEach(function (name) {
  19016. if (typeof _this[name] !== 'function') {
  19017. throw new Error("plugin \"" + name + "\" does not exist");
  19018. }
  19019. });
  19020. }
  19021. /*
  19022. * Store the internal state of scrubbing
  19023. *
  19024. * @private
  19025. * @return {Boolean} True if the user is scrubbing
  19026. */
  19027. _this.scrubbing_ = false;
  19028. _this.el_ = _this.createEl(); // Make this an evented object and use `el_` as its event bus.
  19029. evented(_assertThisInitialized(_this), {
  19030. eventBusKey: 'el_'
  19031. });
  19032. if (_this.fluid_) {
  19033. _this.on('playerreset', _this.updateStyleEl_);
  19034. } // We also want to pass the original player options to each component and plugin
  19035. // as well so they don't need to reach back into the player for options later.
  19036. // We also need to do another copy of this.options_ so we don't end up with
  19037. // an infinite loop.
  19038. var playerOptionsCopy = mergeOptions(_this.options_); // Load plugins
  19039. if (options.plugins) {
  19040. Object.keys(options.plugins).forEach(function (name) {
  19041. _this[name](options.plugins[name]);
  19042. });
  19043. }
  19044. _this.options_.playerOptions = playerOptionsCopy;
  19045. _this.middleware_ = [];
  19046. _this.initChildren(); // Set isAudio based on whether or not an audio tag was used
  19047. _this.isAudio(tag.nodeName.toLowerCase() === 'audio'); // Update controls className. Can't do this when the controls are initially
  19048. // set because the element doesn't exist yet.
  19049. if (_this.controls()) {
  19050. _this.addClass('vjs-controls-enabled');
  19051. } else {
  19052. _this.addClass('vjs-controls-disabled');
  19053. } // Set ARIA label and region role depending on player type
  19054. _this.el_.setAttribute('role', 'region');
  19055. if (_this.isAudio()) {
  19056. _this.el_.setAttribute('aria-label', _this.localize('Audio Player'));
  19057. } else {
  19058. _this.el_.setAttribute('aria-label', _this.localize('Video Player'));
  19059. }
  19060. if (_this.isAudio()) {
  19061. _this.addClass('vjs-audio');
  19062. }
  19063. if (_this.flexNotSupported_()) {
  19064. _this.addClass('vjs-no-flex');
  19065. } // TODO: Make this smarter. Toggle user state between touching/mousing
  19066. // using events, since devices can have both touch and mouse events.
  19067. // TODO: Make this check be performed again when the window switches between monitors
  19068. // (See https://github.com/videojs/video.js/issues/5683)
  19069. if (TOUCH_ENABLED) {
  19070. _this.addClass('vjs-touch-enabled');
  19071. } // iOS Safari has broken hover handling
  19072. if (!IS_IOS) {
  19073. _this.addClass('vjs-workinghover');
  19074. } // Make player easily findable by ID
  19075. Player.players[_this.id_] = _assertThisInitialized(_this); // Add a major version class to aid css in plugins
  19076. var majorVersion = version.split('.')[0];
  19077. _this.addClass("vjs-v" + majorVersion); // When the player is first initialized, trigger activity so components
  19078. // like the control bar show themselves if needed
  19079. _this.userActive(true);
  19080. _this.reportUserActivity();
  19081. _this.one('play', _this.listenForUserActivity_);
  19082. _this.on('stageclick', _this.handleStageClick_);
  19083. _this.on('keydown', _this.handleKeyDown);
  19084. _this.breakpoints(_this.options_.breakpoints);
  19085. _this.responsive(_this.options_.responsive);
  19086. return _this;
  19087. }
  19088. /**
  19089. * Destroys the video player and does any necessary cleanup.
  19090. *
  19091. * This is especially helpful if you are dynamically adding and removing videos
  19092. * to/from the DOM.
  19093. *
  19094. * @fires Player#dispose
  19095. */
  19096. var _proto = Player.prototype;
  19097. _proto.dispose = function dispose() {
  19098. var _this2 = this;
  19099. /**
  19100. * Called when the player is being disposed of.
  19101. *
  19102. * @event Player#dispose
  19103. * @type {EventTarget~Event}
  19104. */
  19105. this.trigger('dispose'); // prevent dispose from being called twice
  19106. this.off('dispose'); // Make sure all player-specific document listeners are unbound. This is
  19107. off(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_);
  19108. off(document, 'keydown', this.boundFullWindowOnEscKey_);
  19109. if (this.styleEl_ && this.styleEl_.parentNode) {
  19110. this.styleEl_.parentNode.removeChild(this.styleEl_);
  19111. this.styleEl_ = null;
  19112. } // Kill reference to this player
  19113. Player.players[this.id_] = null;
  19114. if (this.tag && this.tag.player) {
  19115. this.tag.player = null;
  19116. }
  19117. if (this.el_ && this.el_.player) {
  19118. this.el_.player = null;
  19119. }
  19120. if (this.tech_) {
  19121. this.tech_.dispose();
  19122. this.isPosterFromTech_ = false;
  19123. this.poster_ = '';
  19124. }
  19125. if (this.playerElIngest_) {
  19126. this.playerElIngest_ = null;
  19127. }
  19128. if (this.tag) {
  19129. this.tag = null;
  19130. }
  19131. clearCacheForPlayer(this); // remove all event handlers for track lists
  19132. // all tracks and track listeners are removed on
  19133. // tech dispose
  19134. ALL.names.forEach(function (name) {
  19135. var props = ALL[name];
  19136. var list = _this2[props.getterName](); // if it is not a native list
  19137. // we have to manually remove event listeners
  19138. if (list && list.off) {
  19139. list.off();
  19140. }
  19141. }); // the actual .el_ is removed here
  19142. _Component.prototype.dispose.call(this);
  19143. }
  19144. /**
  19145. * Create the `Player`'s DOM element.
  19146. *
  19147. * @return {Element}
  19148. * The DOM element that gets created.
  19149. */
  19150. ;
  19151. _proto.createEl = function createEl() {
  19152. var tag = this.tag;
  19153. var el;
  19154. var playerElIngest = this.playerElIngest_ = tag.parentNode && tag.parentNode.hasAttribute && tag.parentNode.hasAttribute('data-vjs-player');
  19155. var divEmbed = this.tag.tagName.toLowerCase() === 'video-js';
  19156. if (playerElIngest) {
  19157. el = this.el_ = tag.parentNode;
  19158. } else if (!divEmbed) {
  19159. el = this.el_ = _Component.prototype.createEl.call(this, 'div');
  19160. } // Copy over all the attributes from the tag, including ID and class
  19161. // ID will now reference player box, not the video tag
  19162. var attrs = getAttributes(tag);
  19163. if (divEmbed) {
  19164. el = this.el_ = tag;
  19165. tag = this.tag = document.createElement('video');
  19166. while (el.children.length) {
  19167. tag.appendChild(el.firstChild);
  19168. }
  19169. if (!hasClass(el, 'video-js')) {
  19170. addClass(el, 'video-js');
  19171. }
  19172. el.appendChild(tag);
  19173. playerElIngest = this.playerElIngest_ = el; // move properties over from our custom `video-js` element
  19174. // to our new `video` element. This will move things like
  19175. // `src` or `controls` that were set via js before the player
  19176. // was initialized.
  19177. Object.keys(el).forEach(function (k) {
  19178. tag[k] = el[k];
  19179. });
  19180. } // set tabindex to -1 to remove the video element from the focus order
  19181. tag.setAttribute('tabindex', '-1');
  19182. attrs.tabindex = '-1'; // Workaround for #4583 (JAWS+IE doesn't announce BPB or play button), and
  19183. // for the same issue with Chrome (on Windows) with JAWS.
  19184. // See https://github.com/FreedomScientific/VFO-standards-support/issues/78
  19185. // Note that we can't detect if JAWS is being used, but this ARIA attribute
  19186. // doesn't change behavior of IE11 or Chrome if JAWS is not being used
  19187. if (IE_VERSION || IS_CHROME && IS_WINDOWS) {
  19188. tag.setAttribute('role', 'application');
  19189. attrs.role = 'application';
  19190. } // Remove width/height attrs from tag so CSS can make it 100% width/height
  19191. tag.removeAttribute('width');
  19192. tag.removeAttribute('height');
  19193. if ('width' in attrs) {
  19194. delete attrs.width;
  19195. }
  19196. if ('height' in attrs) {
  19197. delete attrs.height;
  19198. }
  19199. Object.getOwnPropertyNames(attrs).forEach(function (attr) {
  19200. // don't copy over the class attribute to the player element when we're in a div embed
  19201. // the class is already set up properly in the divEmbed case
  19202. // and we want to make sure that the `video-js` class doesn't get lost
  19203. if (!(divEmbed && attr === 'class')) {
  19204. el.setAttribute(attr, attrs[attr]);
  19205. }
  19206. if (divEmbed) {
  19207. tag.setAttribute(attr, attrs[attr]);
  19208. }
  19209. }); // Update tag id/class for use as HTML5 playback tech
  19210. // Might think we should do this after embedding in container so .vjs-tech class
  19211. // doesn't flash 100% width/height, but class only applies with .video-js parent
  19212. tag.playerId = tag.id;
  19213. tag.id += '_html5_api';
  19214. tag.className = 'vjs-tech'; // Make player findable on elements
  19215. tag.player = el.player = this; // Default state of video is paused
  19216. this.addClass('vjs-paused'); // Add a style element in the player that we'll use to set the width/height
  19217. // of the player in a way that's still overrideable by CSS, just like the
  19218. // video element
  19219. if (window$1.VIDEOJS_NO_DYNAMIC_STYLE !== true) {
  19220. this.styleEl_ = createStyleElement('vjs-styles-dimensions');
  19221. var defaultsStyleEl = $('.vjs-styles-defaults');
  19222. var head = $('head');
  19223. head.insertBefore(this.styleEl_, defaultsStyleEl ? defaultsStyleEl.nextSibling : head.firstChild);
  19224. }
  19225. this.fill_ = false;
  19226. this.fluid_ = false; // Pass in the width/height/aspectRatio options which will update the style el
  19227. this.width(this.options_.width);
  19228. this.height(this.options_.height);
  19229. this.fill(this.options_.fill);
  19230. this.fluid(this.options_.fluid);
  19231. this.aspectRatio(this.options_.aspectRatio); // Hide any links within the video/audio tag,
  19232. // because IE doesn't hide them completely from screen readers.
  19233. var links = tag.getElementsByTagName('a');
  19234. for (var i = 0; i < links.length; i++) {
  19235. var linkEl = links.item(i);
  19236. addClass(linkEl, 'vjs-hidden');
  19237. linkEl.setAttribute('hidden', 'hidden');
  19238. } // insertElFirst seems to cause the networkState to flicker from 3 to 2, so
  19239. // keep track of the original for later so we can know if the source originally failed
  19240. tag.initNetworkState_ = tag.networkState; // Wrap video tag in div (el/box) container
  19241. if (tag.parentNode && !playerElIngest) {
  19242. tag.parentNode.insertBefore(el, tag);
  19243. } // insert the tag as the first child of the player element
  19244. // then manually add it to the children array so that this.addChild
  19245. // will work properly for other components
  19246. //
  19247. // Breaks iPhone, fixed in HTML5 setup.
  19248. prependTo(tag, el);
  19249. this.children_.unshift(tag); // Set lang attr on player to ensure CSS :lang() in consistent with player
  19250. // if it's been set to something different to the doc
  19251. this.el_.setAttribute('lang', this.language_);
  19252. this.el_ = el;
  19253. return el;
  19254. }
  19255. /**
  19256. * A getter/setter for the `Player`'s width. Returns the player's configured value.
  19257. * To get the current width use `currentWidth()`.
  19258. *
  19259. * @param {number} [value]
  19260. * The value to set the `Player`'s width to.
  19261. *
  19262. * @return {number}
  19263. * The current width of the `Player` when getting.
  19264. */
  19265. ;
  19266. _proto.width = function width(value) {
  19267. return this.dimension('width', value);
  19268. }
  19269. /**
  19270. * A getter/setter for the `Player`'s height. Returns the player's configured value.
  19271. * To get the current height use `currentheight()`.
  19272. *
  19273. * @param {number} [value]
  19274. * The value to set the `Player`'s heigth to.
  19275. *
  19276. * @return {number}
  19277. * The current height of the `Player` when getting.
  19278. */
  19279. ;
  19280. _proto.height = function height(value) {
  19281. return this.dimension('height', value);
  19282. }
  19283. /**
  19284. * A getter/setter for the `Player`'s width & height.
  19285. *
  19286. * @param {string} dimension
  19287. * This string can be:
  19288. * - 'width'
  19289. * - 'height'
  19290. *
  19291. * @param {number} [value]
  19292. * Value for dimension specified in the first argument.
  19293. *
  19294. * @return {number}
  19295. * The dimension arguments value when getting (width/height).
  19296. */
  19297. ;
  19298. _proto.dimension = function dimension(_dimension, value) {
  19299. var privDimension = _dimension + '_';
  19300. if (value === undefined) {
  19301. return this[privDimension] || 0;
  19302. }
  19303. if (value === '') {
  19304. // If an empty string is given, reset the dimension to be automatic
  19305. this[privDimension] = undefined;
  19306. this.updateStyleEl_();
  19307. return;
  19308. }
  19309. var parsedVal = parseFloat(value);
  19310. if (isNaN(parsedVal)) {
  19311. log.error("Improper value \"" + value + "\" supplied for for " + _dimension);
  19312. return;
  19313. }
  19314. this[privDimension] = parsedVal;
  19315. this.updateStyleEl_();
  19316. }
  19317. /**
  19318. * A getter/setter/toggler for the vjs-fluid `className` on the `Player`.
  19319. *
  19320. * Turning this on will turn off fill mode.
  19321. *
  19322. * @param {boolean} [bool]
  19323. * - A value of true adds the class.
  19324. * - A value of false removes the class.
  19325. * - No value will be a getter.
  19326. *
  19327. * @return {boolean|undefined}
  19328. * - The value of fluid when getting.
  19329. * - `undefined` when setting.
  19330. */
  19331. ;
  19332. _proto.fluid = function fluid(bool) {
  19333. if (bool === undefined) {
  19334. return !!this.fluid_;
  19335. }
  19336. this.fluid_ = !!bool;
  19337. if (isEvented(this)) {
  19338. this.off('playerreset', this.updateStyleEl_);
  19339. }
  19340. if (bool) {
  19341. this.addClass('vjs-fluid');
  19342. this.fill(false);
  19343. addEventedCallback(function () {
  19344. this.on('playerreset', this.updateStyleEl_);
  19345. });
  19346. } else {
  19347. this.removeClass('vjs-fluid');
  19348. }
  19349. this.updateStyleEl_();
  19350. }
  19351. /**
  19352. * A getter/setter/toggler for the vjs-fill `className` on the `Player`.
  19353. *
  19354. * Turning this on will turn off fluid mode.
  19355. *
  19356. * @param {boolean} [bool]
  19357. * - A value of true adds the class.
  19358. * - A value of false removes the class.
  19359. * - No value will be a getter.
  19360. *
  19361. * @return {boolean|undefined}
  19362. * - The value of fluid when getting.
  19363. * - `undefined` when setting.
  19364. */
  19365. ;
  19366. _proto.fill = function fill(bool) {
  19367. if (bool === undefined) {
  19368. return !!this.fill_;
  19369. }
  19370. this.fill_ = !!bool;
  19371. if (bool) {
  19372. this.addClass('vjs-fill');
  19373. this.fluid(false);
  19374. } else {
  19375. this.removeClass('vjs-fill');
  19376. }
  19377. }
  19378. /**
  19379. * Get/Set the aspect ratio
  19380. *
  19381. * @param {string} [ratio]
  19382. * Aspect ratio for player
  19383. *
  19384. * @return {string|undefined}
  19385. * returns the current aspect ratio when getting
  19386. */
  19387. /**
  19388. * A getter/setter for the `Player`'s aspect ratio.
  19389. *
  19390. * @param {string} [ratio]
  19391. * The value to set the `Player's aspect ratio to.
  19392. *
  19393. * @return {string|undefined}
  19394. * - The current aspect ratio of the `Player` when getting.
  19395. * - undefined when setting
  19396. */
  19397. ;
  19398. _proto.aspectRatio = function aspectRatio(ratio) {
  19399. if (ratio === undefined) {
  19400. return this.aspectRatio_;
  19401. } // Check for width:height format
  19402. if (!/^\d+\:\d+$/.test(ratio)) {
  19403. throw new Error('Improper value supplied for aspect ratio. The format should be width:height, for example 16:9.');
  19404. }
  19405. this.aspectRatio_ = ratio; // We're assuming if you set an aspect ratio you want fluid mode,
  19406. // because in fixed mode you could calculate width and height yourself.
  19407. this.fluid(true);
  19408. this.updateStyleEl_();
  19409. }
  19410. /**
  19411. * Update styles of the `Player` element (height, width and aspect ratio).
  19412. *
  19413. * @private
  19414. * @listens Tech#loadedmetadata
  19415. */
  19416. ;
  19417. _proto.updateStyleEl_ = function updateStyleEl_() {
  19418. if (window$1.VIDEOJS_NO_DYNAMIC_STYLE === true) {
  19419. var _width = typeof this.width_ === 'number' ? this.width_ : this.options_.width;
  19420. var _height = typeof this.height_ === 'number' ? this.height_ : this.options_.height;
  19421. var techEl = this.tech_ && this.tech_.el();
  19422. if (techEl) {
  19423. if (_width >= 0) {
  19424. techEl.width = _width;
  19425. }
  19426. if (_height >= 0) {
  19427. techEl.height = _height;
  19428. }
  19429. }
  19430. return;
  19431. }
  19432. var width;
  19433. var height;
  19434. var aspectRatio;
  19435. var idClass; // The aspect ratio is either used directly or to calculate width and height.
  19436. if (this.aspectRatio_ !== undefined && this.aspectRatio_ !== 'auto') {
  19437. // Use any aspectRatio that's been specifically set
  19438. aspectRatio = this.aspectRatio_;
  19439. } else if (this.videoWidth() > 0) {
  19440. // Otherwise try to get the aspect ratio from the video metadata
  19441. aspectRatio = this.videoWidth() + ':' + this.videoHeight();
  19442. } else {
  19443. // Or use a default. The video element's is 2:1, but 16:9 is more common.
  19444. aspectRatio = '16:9';
  19445. } // Get the ratio as a decimal we can use to calculate dimensions
  19446. var ratioParts = aspectRatio.split(':');
  19447. var ratioMultiplier = ratioParts[1] / ratioParts[0];
  19448. if (this.width_ !== undefined) {
  19449. // Use any width that's been specifically set
  19450. width = this.width_;
  19451. } else if (this.height_ !== undefined) {
  19452. // Or calulate the width from the aspect ratio if a height has been set
  19453. width = this.height_ / ratioMultiplier;
  19454. } else {
  19455. // Or use the video's metadata, or use the video el's default of 300
  19456. width = this.videoWidth() || 300;
  19457. }
  19458. if (this.height_ !== undefined) {
  19459. // Use any height that's been specifically set
  19460. height = this.height_;
  19461. } else {
  19462. // Otherwise calculate the height from the ratio and the width
  19463. height = width * ratioMultiplier;
  19464. } // Ensure the CSS class is valid by starting with an alpha character
  19465. if (/^[^a-zA-Z]/.test(this.id())) {
  19466. idClass = 'dimensions-' + this.id();
  19467. } else {
  19468. idClass = this.id() + '-dimensions';
  19469. } // Ensure the right class is still on the player for the style element
  19470. this.addClass(idClass);
  19471. setTextContent(this.styleEl_, "\n ." + idClass + " {\n width: " + width + "px;\n height: " + height + "px;\n }\n\n ." + idClass + ".vjs-fluid {\n padding-top: " + ratioMultiplier * 100 + "%;\n }\n ");
  19472. }
  19473. /**
  19474. * Load/Create an instance of playback {@link Tech} including element
  19475. * and API methods. Then append the `Tech` element in `Player` as a child.
  19476. *
  19477. * @param {string} techName
  19478. * name of the playback technology
  19479. *
  19480. * @param {string} source
  19481. * video source
  19482. *
  19483. * @private
  19484. */
  19485. ;
  19486. _proto.loadTech_ = function loadTech_(techName, source) {
  19487. var _this3 = this;
  19488. // Pause and remove current playback technology
  19489. if (this.tech_) {
  19490. this.unloadTech_();
  19491. }
  19492. var titleTechName = toTitleCase(techName);
  19493. var camelTechName = techName.charAt(0).toLowerCase() + techName.slice(1); // get rid of the HTML5 video tag as soon as we are using another tech
  19494. if (titleTechName !== 'Html5' && this.tag) {
  19495. Tech.getTech('Html5').disposeMediaElement(this.tag);
  19496. this.tag.player = null;
  19497. this.tag = null;
  19498. }
  19499. this.techName_ = titleTechName; // Turn off API access because we're loading a new tech that might load asynchronously
  19500. this.isReady_ = false; // if autoplay is a string we pass false to the tech
  19501. // because the player is going to handle autoplay on `loadstart`
  19502. var autoplay = typeof this.autoplay() === 'string' ? false : this.autoplay(); // Grab tech-specific options from player options and add source and parent element to use.
  19503. var techOptions = {
  19504. source: source,
  19505. autoplay: autoplay,
  19506. 'nativeControlsForTouch': this.options_.nativeControlsForTouch,
  19507. 'playerId': this.id(),
  19508. 'techId': this.id() + "_" + camelTechName + "_api",
  19509. 'playsinline': this.options_.playsinline,
  19510. 'preload': this.options_.preload,
  19511. 'loop': this.options_.loop,
  19512. 'muted': this.options_.muted,
  19513. 'poster': this.poster(),
  19514. 'language': this.language(),
  19515. 'playerElIngest': this.playerElIngest_ || false,
  19516. 'vtt.js': this.options_['vtt.js'],
  19517. 'canOverridePoster': !!this.options_.techCanOverridePoster,
  19518. 'enableSourceset': this.options_.enableSourceset,
  19519. 'Promise': this.options_.Promise
  19520. };
  19521. ALL.names.forEach(function (name) {
  19522. var props = ALL[name];
  19523. techOptions[props.getterName] = _this3[props.privateName];
  19524. });
  19525. assign(techOptions, this.options_[titleTechName]);
  19526. assign(techOptions, this.options_[camelTechName]);
  19527. assign(techOptions, this.options_[techName.toLowerCase()]);
  19528. if (this.tag) {
  19529. techOptions.tag = this.tag;
  19530. }
  19531. if (source && source.src === this.cache_.src && this.cache_.currentTime > 0) {
  19532. techOptions.startTime = this.cache_.currentTime;
  19533. } // Initialize tech instance
  19534. var TechClass = Tech.getTech(techName);
  19535. if (!TechClass) {
  19536. throw new Error("No Tech named '" + titleTechName + "' exists! '" + titleTechName + "' should be registered using videojs.registerTech()'");
  19537. }
  19538. this.tech_ = new TechClass(techOptions); // player.triggerReady is always async, so don't need this to be async
  19539. this.tech_.ready(bind(this, this.handleTechReady_), true);
  19540. textTrackConverter.jsonToTextTracks(this.textTracksJson_ || [], this.tech_); // Listen to all HTML5-defined events and trigger them on the player
  19541. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  19542. _this3.on(_this3.tech_, event, _this3["handleTech" + toTitleCase(event) + "_"]);
  19543. });
  19544. Object.keys(TECH_EVENTS_QUEUE).forEach(function (event) {
  19545. _this3.on(_this3.tech_, event, function (eventObj) {
  19546. if (_this3.tech_.playbackRate() === 0 && _this3.tech_.seeking()) {
  19547. _this3.queuedCallbacks_.push({
  19548. callback: _this3["handleTech" + TECH_EVENTS_QUEUE[event] + "_"].bind(_this3),
  19549. event: eventObj
  19550. });
  19551. return;
  19552. }
  19553. _this3["handleTech" + TECH_EVENTS_QUEUE[event] + "_"](eventObj);
  19554. });
  19555. });
  19556. this.on(this.tech_, 'loadstart', this.handleTechLoadStart_);
  19557. this.on(this.tech_, 'sourceset', this.handleTechSourceset_);
  19558. this.on(this.tech_, 'waiting', this.handleTechWaiting_);
  19559. this.on(this.tech_, 'ended', this.handleTechEnded_);
  19560. this.on(this.tech_, 'seeking', this.handleTechSeeking_);
  19561. this.on(this.tech_, 'play', this.handleTechPlay_);
  19562. this.on(this.tech_, 'firstplay', this.handleTechFirstPlay_);
  19563. this.on(this.tech_, 'pause', this.handleTechPause_);
  19564. this.on(this.tech_, 'durationchange', this.handleTechDurationChange_);
  19565. this.on(this.tech_, 'fullscreenchange', this.handleTechFullscreenChange_);
  19566. this.on(this.tech_, 'enterpictureinpicture', this.handleTechEnterPictureInPicture_);
  19567. this.on(this.tech_, 'leavepictureinpicture', this.handleTechLeavePictureInPicture_);
  19568. this.on(this.tech_, 'error', this.handleTechError_);
  19569. this.on(this.tech_, 'loadedmetadata', this.updateStyleEl_);
  19570. this.on(this.tech_, 'posterchange', this.handleTechPosterChange_);
  19571. this.on(this.tech_, 'textdata', this.handleTechTextData_);
  19572. this.on(this.tech_, 'ratechange', this.handleTechRateChange_);
  19573. this.usingNativeControls(this.techGet_('controls'));
  19574. if (this.controls() && !this.usingNativeControls()) {
  19575. this.addTechControlsListeners_();
  19576. } // Add the tech element in the DOM if it was not already there
  19577. // Make sure to not insert the original video element if using Html5
  19578. if (this.tech_.el().parentNode !== this.el() && (titleTechName !== 'Html5' || !this.tag)) {
  19579. prependTo(this.tech_.el(), this.el());
  19580. } // Get rid of the original video tag reference after the first tech is loaded
  19581. if (this.tag) {
  19582. this.tag.player = null;
  19583. this.tag = null;
  19584. }
  19585. }
  19586. /**
  19587. * Unload and dispose of the current playback {@link Tech}.
  19588. *
  19589. * @private
  19590. */
  19591. ;
  19592. _proto.unloadTech_ = function unloadTech_() {
  19593. var _this4 = this;
  19594. // Save the current text tracks so that we can reuse the same text tracks with the next tech
  19595. ALL.names.forEach(function (name) {
  19596. var props = ALL[name];
  19597. _this4[props.privateName] = _this4[props.getterName]();
  19598. });
  19599. this.textTracksJson_ = textTrackConverter.textTracksToJson(this.tech_);
  19600. this.isReady_ = false;
  19601. this.tech_.dispose();
  19602. this.tech_ = false;
  19603. if (this.isPosterFromTech_) {
  19604. this.poster_ = '';
  19605. this.trigger('posterchange');
  19606. }
  19607. this.isPosterFromTech_ = false;
  19608. }
  19609. /**
  19610. * Return a reference to the current {@link Tech}.
  19611. * It will print a warning by default about the danger of using the tech directly
  19612. * but any argument that is passed in will silence the warning.
  19613. *
  19614. * @param {*} [safety]
  19615. * Anything passed in to silence the warning
  19616. *
  19617. * @return {Tech}
  19618. * The Tech
  19619. */
  19620. ;
  19621. _proto.tech = function tech(safety) {
  19622. if (safety === undefined) {
  19623. log.warn('Using the tech directly can be dangerous. I hope you know what you\'re doing.\n' + 'See https://github.com/videojs/video.js/issues/2617 for more info.\n');
  19624. }
  19625. return this.tech_;
  19626. }
  19627. /**
  19628. * Set up click and touch listeners for the playback element
  19629. *
  19630. * - On desktops: a click on the video itself will toggle playback
  19631. * - On mobile devices: a click on the video toggles controls
  19632. * which is done by toggling the user state between active and
  19633. * inactive
  19634. * - A tap can signal that a user has become active or has become inactive
  19635. * e.g. a quick tap on an iPhone movie should reveal the controls. Another
  19636. * quick tap should hide them again (signaling the user is in an inactive
  19637. * viewing state)
  19638. * - In addition to this, we still want the user to be considered inactive after
  19639. * a few seconds of inactivity.
  19640. *
  19641. * > Note: the only part of iOS interaction we can't mimic with this setup
  19642. * is a touch and hold on the video element counting as activity in order to
  19643. * keep the controls showing, but that shouldn't be an issue. A touch and hold
  19644. * on any controls will still keep the user active
  19645. *
  19646. * @private
  19647. */
  19648. ;
  19649. _proto.addTechControlsListeners_ = function addTechControlsListeners_() {
  19650. // Make sure to remove all the previous listeners in case we are called multiple times.
  19651. this.removeTechControlsListeners_(); // Some browsers (Chrome & IE) don't trigger a click on a flash swf, but do
  19652. // trigger mousedown/up.
  19653. // http://stackoverflow.com/questions/1444562/javascript-onclick-event-over-flash-object
  19654. // Any touch events are set to block the mousedown event from happening
  19655. this.on(this.tech_, 'mouseup', this.handleTechClick_);
  19656. this.on(this.tech_, 'dblclick', this.handleTechDoubleClick_); // If the controls were hidden we don't want that to change without a tap event
  19657. // so we'll check if the controls were already showing before reporting user
  19658. // activity
  19659. this.on(this.tech_, 'touchstart', this.handleTechTouchStart_);
  19660. this.on(this.tech_, 'touchmove', this.handleTechTouchMove_);
  19661. this.on(this.tech_, 'touchend', this.handleTechTouchEnd_); // The tap listener needs to come after the touchend listener because the tap
  19662. // listener cancels out any reportedUserActivity when setting userActive(false)
  19663. this.on(this.tech_, 'tap', this.handleTechTap_);
  19664. }
  19665. /**
  19666. * Remove the listeners used for click and tap controls. This is needed for
  19667. * toggling to controls disabled, where a tap/touch should do nothing.
  19668. *
  19669. * @private
  19670. */
  19671. ;
  19672. _proto.removeTechControlsListeners_ = function removeTechControlsListeners_() {
  19673. // We don't want to just use `this.off()` because there might be other needed
  19674. // listeners added by techs that extend this.
  19675. this.off(this.tech_, 'tap', this.handleTechTap_);
  19676. this.off(this.tech_, 'touchstart', this.handleTechTouchStart_);
  19677. this.off(this.tech_, 'touchmove', this.handleTechTouchMove_);
  19678. this.off(this.tech_, 'touchend', this.handleTechTouchEnd_);
  19679. this.off(this.tech_, 'mouseup', this.handleTechClick_);
  19680. this.off(this.tech_, 'dblclick', this.handleTechDoubleClick_);
  19681. }
  19682. /**
  19683. * Player waits for the tech to be ready
  19684. *
  19685. * @private
  19686. */
  19687. ;
  19688. _proto.handleTechReady_ = function handleTechReady_() {
  19689. this.triggerReady(); // Keep the same volume as before
  19690. if (this.cache_.volume) {
  19691. this.techCall_('setVolume', this.cache_.volume);
  19692. } // Look if the tech found a higher resolution poster while loading
  19693. this.handleTechPosterChange_(); // Update the duration if available
  19694. this.handleTechDurationChange_();
  19695. }
  19696. /**
  19697. * Retrigger the `loadstart` event that was triggered by the {@link Tech}. This
  19698. * function will also trigger {@link Player#firstplay} if it is the first loadstart
  19699. * for a video.
  19700. *
  19701. * @fires Player#loadstart
  19702. * @fires Player#firstplay
  19703. * @listens Tech#loadstart
  19704. * @private
  19705. */
  19706. ;
  19707. _proto.handleTechLoadStart_ = function handleTechLoadStart_() {
  19708. // TODO: Update to use `emptied` event instead. See #1277.
  19709. this.removeClass('vjs-ended');
  19710. this.removeClass('vjs-seeking'); // reset the error state
  19711. this.error(null); // Update the duration
  19712. this.handleTechDurationChange_(); // If it's already playing we want to trigger a firstplay event now.
  19713. // The firstplay event relies on both the play and loadstart events
  19714. // which can happen in any order for a new source
  19715. if (!this.paused()) {
  19716. /**
  19717. * Fired when the user agent begins looking for media data
  19718. *
  19719. * @event Player#loadstart
  19720. * @type {EventTarget~Event}
  19721. */
  19722. this.trigger('loadstart');
  19723. this.trigger('firstplay');
  19724. } else {
  19725. // reset the hasStarted state
  19726. this.hasStarted(false);
  19727. this.trigger('loadstart');
  19728. } // autoplay happens after loadstart for the browser,
  19729. // so we mimic that behavior
  19730. this.manualAutoplay_(this.autoplay());
  19731. }
  19732. /**
  19733. * Handle autoplay string values, rather than the typical boolean
  19734. * values that should be handled by the tech. Note that this is not
  19735. * part of any specification. Valid values and what they do can be
  19736. * found on the autoplay getter at Player#autoplay()
  19737. */
  19738. ;
  19739. _proto.manualAutoplay_ = function manualAutoplay_(type) {
  19740. var _this5 = this;
  19741. if (!this.tech_ || typeof type !== 'string') {
  19742. return;
  19743. }
  19744. var muted = function muted() {
  19745. var previouslyMuted = _this5.muted();
  19746. _this5.muted(true);
  19747. var restoreMuted = function restoreMuted() {
  19748. _this5.muted(previouslyMuted);
  19749. }; // restore muted on play terminatation
  19750. _this5.playTerminatedQueue_.push(restoreMuted);
  19751. var mutedPromise = _this5.play();
  19752. if (!isPromise(mutedPromise)) {
  19753. return;
  19754. }
  19755. return mutedPromise["catch"](restoreMuted);
  19756. };
  19757. var promise; // if muted defaults to true
  19758. // the only thing we can do is call play
  19759. if (type === 'any' && this.muted() !== true) {
  19760. promise = this.play();
  19761. if (isPromise(promise)) {
  19762. promise = promise["catch"](muted);
  19763. }
  19764. } else if (type === 'muted' && this.muted() !== true) {
  19765. promise = muted();
  19766. } else {
  19767. promise = this.play();
  19768. }
  19769. if (!isPromise(promise)) {
  19770. return;
  19771. }
  19772. return promise.then(function () {
  19773. _this5.trigger({
  19774. type: 'autoplay-success',
  19775. autoplay: type
  19776. });
  19777. })["catch"](function (e) {
  19778. _this5.trigger({
  19779. type: 'autoplay-failure',
  19780. autoplay: type
  19781. });
  19782. });
  19783. }
  19784. /**
  19785. * Update the internal source caches so that we return the correct source from
  19786. * `src()`, `currentSource()`, and `currentSources()`.
  19787. *
  19788. * > Note: `currentSources` will not be updated if the source that is passed in exists
  19789. * in the current `currentSources` cache.
  19790. *
  19791. *
  19792. * @param {Tech~SourceObject} srcObj
  19793. * A string or object source to update our caches to.
  19794. */
  19795. ;
  19796. _proto.updateSourceCaches_ = function updateSourceCaches_(srcObj) {
  19797. if (srcObj === void 0) {
  19798. srcObj = '';
  19799. }
  19800. var src = srcObj;
  19801. var type = '';
  19802. if (typeof src !== 'string') {
  19803. src = srcObj.src;
  19804. type = srcObj.type;
  19805. } // make sure all the caches are set to default values
  19806. // to prevent null checking
  19807. this.cache_.source = this.cache_.source || {};
  19808. this.cache_.sources = this.cache_.sources || []; // try to get the type of the src that was passed in
  19809. if (src && !type) {
  19810. type = findMimetype(this, src);
  19811. } // update `currentSource` cache always
  19812. this.cache_.source = mergeOptions({}, srcObj, {
  19813. src: src,
  19814. type: type
  19815. });
  19816. var matchingSources = this.cache_.sources.filter(function (s) {
  19817. return s.src && s.src === src;
  19818. });
  19819. var sourceElSources = [];
  19820. var sourceEls = this.$$('source');
  19821. var matchingSourceEls = [];
  19822. for (var i = 0; i < sourceEls.length; i++) {
  19823. var sourceObj = getAttributes(sourceEls[i]);
  19824. sourceElSources.push(sourceObj);
  19825. if (sourceObj.src && sourceObj.src === src) {
  19826. matchingSourceEls.push(sourceObj.src);
  19827. }
  19828. } // if we have matching source els but not matching sources
  19829. // the current source cache is not up to date
  19830. if (matchingSourceEls.length && !matchingSources.length) {
  19831. this.cache_.sources = sourceElSources; // if we don't have matching source or source els set the
  19832. // sources cache to the `currentSource` cache
  19833. } else if (!matchingSources.length) {
  19834. this.cache_.sources = [this.cache_.source];
  19835. } // update the tech `src` cache
  19836. this.cache_.src = src;
  19837. }
  19838. /**
  19839. * *EXPERIMENTAL* Fired when the source is set or changed on the {@link Tech}
  19840. * causing the media element to reload.
  19841. *
  19842. * It will fire for the initial source and each subsequent source.
  19843. * This event is a custom event from Video.js and is triggered by the {@link Tech}.
  19844. *
  19845. * The event object for this event contains a `src` property that will contain the source
  19846. * that was available when the event was triggered. This is generally only necessary if Video.js
  19847. * is switching techs while the source was being changed.
  19848. *
  19849. * It is also fired when `load` is called on the player (or media element)
  19850. * because the {@link https://html.spec.whatwg.org/multipage/media.html#dom-media-load|specification for `load`}
  19851. * says that the resource selection algorithm needs to be aborted and restarted.
  19852. * In this case, it is very likely that the `src` property will be set to the
  19853. * empty string `""` to indicate we do not know what the source will be but
  19854. * that it is changing.
  19855. *
  19856. * *This event is currently still experimental and may change in minor releases.*
  19857. * __To use this, pass `enableSourceset` option to the player.__
  19858. *
  19859. * @event Player#sourceset
  19860. * @type {EventTarget~Event}
  19861. * @prop {string} src
  19862. * The source url available when the `sourceset` was triggered.
  19863. * It will be an empty string if we cannot know what the source is
  19864. * but know that the source will change.
  19865. */
  19866. /**
  19867. * Retrigger the `sourceset` event that was triggered by the {@link Tech}.
  19868. *
  19869. * @fires Player#sourceset
  19870. * @listens Tech#sourceset
  19871. * @private
  19872. */
  19873. ;
  19874. _proto.handleTechSourceset_ = function handleTechSourceset_(event) {
  19875. var _this6 = this;
  19876. // only update the source cache when the source
  19877. // was not updated using the player api
  19878. if (!this.changingSrc_) {
  19879. var updateSourceCaches = function updateSourceCaches(src) {
  19880. return _this6.updateSourceCaches_(src);
  19881. };
  19882. var playerSrc = this.currentSource().src;
  19883. var eventSrc = event.src; // if we have a playerSrc that is not a blob, and a tech src that is a blob
  19884. if (playerSrc && !/^blob:/.test(playerSrc) && /^blob:/.test(eventSrc)) {
  19885. // if both the tech source and the player source were updated we assume
  19886. // something like @videojs/http-streaming did the sourceset and skip updating the source cache.
  19887. if (!this.lastSource_ || this.lastSource_.tech !== eventSrc && this.lastSource_.player !== playerSrc) {
  19888. updateSourceCaches = function updateSourceCaches() {};
  19889. }
  19890. } // update the source to the intial source right away
  19891. // in some cases this will be empty string
  19892. updateSourceCaches(eventSrc); // if the `sourceset` `src` was an empty string
  19893. // wait for a `loadstart` to update the cache to `currentSrc`.
  19894. // If a sourceset happens before a `loadstart`, we reset the state
  19895. if (!event.src) {
  19896. this.tech_.any(['sourceset', 'loadstart'], function (e) {
  19897. // if a sourceset happens before a `loadstart` there
  19898. // is nothing to do as this `handleTechSourceset_`
  19899. // will be called again and this will be handled there.
  19900. if (e.type === 'sourceset') {
  19901. return;
  19902. }
  19903. var techSrc = _this6.techGet('currentSrc');
  19904. _this6.lastSource_.tech = techSrc;
  19905. _this6.updateSourceCaches_(techSrc);
  19906. });
  19907. }
  19908. }
  19909. this.lastSource_ = {
  19910. player: this.currentSource().src,
  19911. tech: event.src
  19912. };
  19913. this.trigger({
  19914. src: event.src,
  19915. type: 'sourceset'
  19916. });
  19917. }
  19918. /**
  19919. * Add/remove the vjs-has-started class
  19920. *
  19921. * @fires Player#firstplay
  19922. *
  19923. * @param {boolean} request
  19924. * - true: adds the class
  19925. * - false: remove the class
  19926. *
  19927. * @return {boolean}
  19928. * the boolean value of hasStarted_
  19929. */
  19930. ;
  19931. _proto.hasStarted = function hasStarted(request) {
  19932. if (request === undefined) {
  19933. // act as getter, if we have no request to change
  19934. return this.hasStarted_;
  19935. }
  19936. if (request === this.hasStarted_) {
  19937. return;
  19938. }
  19939. this.hasStarted_ = request;
  19940. if (this.hasStarted_) {
  19941. this.addClass('vjs-has-started');
  19942. this.trigger('firstplay');
  19943. } else {
  19944. this.removeClass('vjs-has-started');
  19945. }
  19946. }
  19947. /**
  19948. * Fired whenever the media begins or resumes playback
  19949. *
  19950. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play}
  19951. * @fires Player#play
  19952. * @listens Tech#play
  19953. * @private
  19954. */
  19955. ;
  19956. _proto.handleTechPlay_ = function handleTechPlay_() {
  19957. this.removeClass('vjs-ended');
  19958. this.removeClass('vjs-paused');
  19959. this.addClass('vjs-playing'); // hide the poster when the user hits play
  19960. this.hasStarted(true);
  19961. /**
  19962. * Triggered whenever an {@link Tech#play} event happens. Indicates that
  19963. * playback has started or resumed.
  19964. *
  19965. * @event Player#play
  19966. * @type {EventTarget~Event}
  19967. */
  19968. this.trigger('play');
  19969. }
  19970. /**
  19971. * Retrigger the `ratechange` event that was triggered by the {@link Tech}.
  19972. *
  19973. * If there were any events queued while the playback rate was zero, fire
  19974. * those events now.
  19975. *
  19976. * @private
  19977. * @method Player#handleTechRateChange_
  19978. * @fires Player#ratechange
  19979. * @listens Tech#ratechange
  19980. */
  19981. ;
  19982. _proto.handleTechRateChange_ = function handleTechRateChange_() {
  19983. if (this.tech_.playbackRate() > 0 && this.cache_.lastPlaybackRate === 0) {
  19984. this.queuedCallbacks_.forEach(function (queued) {
  19985. return queued.callback(queued.event);
  19986. });
  19987. this.queuedCallbacks_ = [];
  19988. }
  19989. this.cache_.lastPlaybackRate = this.tech_.playbackRate();
  19990. /**
  19991. * Fires when the playing speed of the audio/video is changed
  19992. *
  19993. * @event Player#ratechange
  19994. * @type {event}
  19995. */
  19996. this.trigger('ratechange');
  19997. }
  19998. /**
  19999. * Retrigger the `waiting` event that was triggered by the {@link Tech}.
  20000. *
  20001. * @fires Player#waiting
  20002. * @listens Tech#waiting
  20003. * @private
  20004. */
  20005. ;
  20006. _proto.handleTechWaiting_ = function handleTechWaiting_() {
  20007. var _this7 = this;
  20008. this.addClass('vjs-waiting');
  20009. /**
  20010. * A readyState change on the DOM element has caused playback to stop.
  20011. *
  20012. * @event Player#waiting
  20013. * @type {EventTarget~Event}
  20014. */
  20015. this.trigger('waiting'); // Browsers may emit a timeupdate event after a waiting event. In order to prevent
  20016. // premature removal of the waiting class, wait for the time to change.
  20017. var timeWhenWaiting = this.currentTime();
  20018. var timeUpdateListener = function timeUpdateListener() {
  20019. if (timeWhenWaiting !== _this7.currentTime()) {
  20020. _this7.removeClass('vjs-waiting');
  20021. _this7.off('timeupdate', timeUpdateListener);
  20022. }
  20023. };
  20024. this.on('timeupdate', timeUpdateListener);
  20025. }
  20026. /**
  20027. * Retrigger the `canplay` event that was triggered by the {@link Tech}.
  20028. * > Note: This is not consistent between browsers. See #1351
  20029. *
  20030. * @fires Player#canplay
  20031. * @listens Tech#canplay
  20032. * @private
  20033. */
  20034. ;
  20035. _proto.handleTechCanPlay_ = function handleTechCanPlay_() {
  20036. this.removeClass('vjs-waiting');
  20037. /**
  20038. * The media has a readyState of HAVE_FUTURE_DATA or greater.
  20039. *
  20040. * @event Player#canplay
  20041. * @type {EventTarget~Event}
  20042. */
  20043. this.trigger('canplay');
  20044. }
  20045. /**
  20046. * Retrigger the `canplaythrough` event that was triggered by the {@link Tech}.
  20047. *
  20048. * @fires Player#canplaythrough
  20049. * @listens Tech#canplaythrough
  20050. * @private
  20051. */
  20052. ;
  20053. _proto.handleTechCanPlayThrough_ = function handleTechCanPlayThrough_() {
  20054. this.removeClass('vjs-waiting');
  20055. /**
  20056. * The media has a readyState of HAVE_ENOUGH_DATA or greater. This means that the
  20057. * entire media file can be played without buffering.
  20058. *
  20059. * @event Player#canplaythrough
  20060. * @type {EventTarget~Event}
  20061. */
  20062. this.trigger('canplaythrough');
  20063. }
  20064. /**
  20065. * Retrigger the `playing` event that was triggered by the {@link Tech}.
  20066. *
  20067. * @fires Player#playing
  20068. * @listens Tech#playing
  20069. * @private
  20070. */
  20071. ;
  20072. _proto.handleTechPlaying_ = function handleTechPlaying_() {
  20073. this.removeClass('vjs-waiting');
  20074. /**
  20075. * The media is no longer blocked from playback, and has started playing.
  20076. *
  20077. * @event Player#playing
  20078. * @type {EventTarget~Event}
  20079. */
  20080. this.trigger('playing');
  20081. }
  20082. /**
  20083. * Retrigger the `seeking` event that was triggered by the {@link Tech}.
  20084. *
  20085. * @fires Player#seeking
  20086. * @listens Tech#seeking
  20087. * @private
  20088. */
  20089. ;
  20090. _proto.handleTechSeeking_ = function handleTechSeeking_() {
  20091. this.addClass('vjs-seeking');
  20092. /**
  20093. * Fired whenever the player is jumping to a new time
  20094. *
  20095. * @event Player#seeking
  20096. * @type {EventTarget~Event}
  20097. */
  20098. this.trigger('seeking');
  20099. }
  20100. /**
  20101. * Retrigger the `seeked` event that was triggered by the {@link Tech}.
  20102. *
  20103. * @fires Player#seeked
  20104. * @listens Tech#seeked
  20105. * @private
  20106. */
  20107. ;
  20108. _proto.handleTechSeeked_ = function handleTechSeeked_() {
  20109. this.removeClass('vjs-seeking');
  20110. this.removeClass('vjs-ended');
  20111. /**
  20112. * Fired when the player has finished jumping to a new time
  20113. *
  20114. * @event Player#seeked
  20115. * @type {EventTarget~Event}
  20116. */
  20117. this.trigger('seeked');
  20118. }
  20119. /**
  20120. * Retrigger the `firstplay` event that was triggered by the {@link Tech}.
  20121. *
  20122. * @fires Player#firstplay
  20123. * @listens Tech#firstplay
  20124. * @deprecated As of 6.0 firstplay event is deprecated.
  20125. * As of 6.0 passing the `starttime` option to the player and the firstplay event are deprecated.
  20126. * @private
  20127. */
  20128. ;
  20129. _proto.handleTechFirstPlay_ = function handleTechFirstPlay_() {
  20130. // If the first starttime attribute is specified
  20131. // then we will start at the given offset in seconds
  20132. if (this.options_.starttime) {
  20133. log.warn('Passing the `starttime` option to the player will be deprecated in 6.0');
  20134. this.currentTime(this.options_.starttime);
  20135. }
  20136. this.addClass('vjs-has-started');
  20137. /**
  20138. * Fired the first time a video is played. Not part of the HLS spec, and this is
  20139. * probably not the best implementation yet, so use sparingly. If you don't have a
  20140. * reason to prevent playback, use `myPlayer.one('play');` instead.
  20141. *
  20142. * @event Player#firstplay
  20143. * @deprecated As of 6.0 firstplay event is deprecated.
  20144. * @type {EventTarget~Event}
  20145. */
  20146. this.trigger('firstplay');
  20147. }
  20148. /**
  20149. * Retrigger the `pause` event that was triggered by the {@link Tech}.
  20150. *
  20151. * @fires Player#pause
  20152. * @listens Tech#pause
  20153. * @private
  20154. */
  20155. ;
  20156. _proto.handleTechPause_ = function handleTechPause_() {
  20157. this.removeClass('vjs-playing');
  20158. this.addClass('vjs-paused');
  20159. /**
  20160. * Fired whenever the media has been paused
  20161. *
  20162. * @event Player#pause
  20163. * @type {EventTarget~Event}
  20164. */
  20165. this.trigger('pause');
  20166. }
  20167. /**
  20168. * Retrigger the `ended` event that was triggered by the {@link Tech}.
  20169. *
  20170. * @fires Player#ended
  20171. * @listens Tech#ended
  20172. * @private
  20173. */
  20174. ;
  20175. _proto.handleTechEnded_ = function handleTechEnded_() {
  20176. this.addClass('vjs-ended');
  20177. if (this.options_.loop) {
  20178. this.currentTime(0);
  20179. this.play();
  20180. } else if (!this.paused()) {
  20181. this.pause();
  20182. }
  20183. /**
  20184. * Fired when the end of the media resource is reached (currentTime == duration)
  20185. *
  20186. * @event Player#ended
  20187. * @type {EventTarget~Event}
  20188. */
  20189. this.trigger('ended');
  20190. }
  20191. /**
  20192. * Fired when the duration of the media resource is first known or changed
  20193. *
  20194. * @listens Tech#durationchange
  20195. * @private
  20196. */
  20197. ;
  20198. _proto.handleTechDurationChange_ = function handleTechDurationChange_() {
  20199. this.duration(this.techGet_('duration'));
  20200. }
  20201. /**
  20202. * Handle a click on the media element to play/pause
  20203. *
  20204. * @param {EventTarget~Event} event
  20205. * the event that caused this function to trigger
  20206. *
  20207. * @listens Tech#mouseup
  20208. * @private
  20209. */
  20210. ;
  20211. _proto.handleTechClick_ = function handleTechClick_(event) {
  20212. if (!isSingleLeftClick(event)) {
  20213. return;
  20214. } // When controls are disabled a click should not toggle playback because
  20215. // the click is considered a control
  20216. if (!this.controls_) {
  20217. return;
  20218. }
  20219. if (this.paused()) {
  20220. silencePromise(this.play());
  20221. } else {
  20222. this.pause();
  20223. }
  20224. }
  20225. /**
  20226. * Handle a double-click on the media element to enter/exit fullscreen
  20227. *
  20228. * @param {EventTarget~Event} event
  20229. * the event that caused this function to trigger
  20230. *
  20231. * @listens Tech#dblclick
  20232. * @private
  20233. */
  20234. ;
  20235. _proto.handleTechDoubleClick_ = function handleTechDoubleClick_(event) {
  20236. if (!this.controls_) {
  20237. return;
  20238. } // we do not want to toggle fullscreen state
  20239. // when double-clicking inside a control bar or a modal
  20240. var inAllowedEls = Array.prototype.some.call(this.$$('.vjs-control-bar, .vjs-modal-dialog'), function (el) {
  20241. return el.contains(event.target);
  20242. });
  20243. if (!inAllowedEls) {
  20244. /*
  20245. * options.userActions.doubleClick
  20246. *
  20247. * If `undefined` or `true`, double-click toggles fullscreen if controls are present
  20248. * Set to `false` to disable double-click handling
  20249. * Set to a function to substitute an external double-click handler
  20250. */
  20251. if (this.options_ === undefined || this.options_.userActions === undefined || this.options_.userActions.doubleClick === undefined || this.options_.userActions.doubleClick !== false) {
  20252. if (this.options_ !== undefined && this.options_.userActions !== undefined && typeof this.options_.userActions.doubleClick === 'function') {
  20253. this.options_.userActions.doubleClick.call(this, event);
  20254. } else if (this.isFullscreen()) {
  20255. this.exitFullscreen();
  20256. } else {
  20257. this.requestFullscreen();
  20258. }
  20259. }
  20260. }
  20261. }
  20262. /**
  20263. * Handle a tap on the media element. It will toggle the user
  20264. * activity state, which hides and shows the controls.
  20265. *
  20266. * @listens Tech#tap
  20267. * @private
  20268. */
  20269. ;
  20270. _proto.handleTechTap_ = function handleTechTap_() {
  20271. this.userActive(!this.userActive());
  20272. }
  20273. /**
  20274. * Handle touch to start
  20275. *
  20276. * @listens Tech#touchstart
  20277. * @private
  20278. */
  20279. ;
  20280. _proto.handleTechTouchStart_ = function handleTechTouchStart_() {
  20281. this.userWasActive = this.userActive();
  20282. }
  20283. /**
  20284. * Handle touch to move
  20285. *
  20286. * @listens Tech#touchmove
  20287. * @private
  20288. */
  20289. ;
  20290. _proto.handleTechTouchMove_ = function handleTechTouchMove_() {
  20291. if (this.userWasActive) {
  20292. this.reportUserActivity();
  20293. }
  20294. }
  20295. /**
  20296. * Handle touch to end
  20297. *
  20298. * @param {EventTarget~Event} event
  20299. * the touchend event that triggered
  20300. * this function
  20301. *
  20302. * @listens Tech#touchend
  20303. * @private
  20304. */
  20305. ;
  20306. _proto.handleTechTouchEnd_ = function handleTechTouchEnd_(event) {
  20307. // Stop the mouse events from also happening
  20308. event.preventDefault();
  20309. }
  20310. /**
  20311. * native click events on the SWF aren't triggered on IE11, Win8.1RT
  20312. * use stageclick events triggered from inside the SWF instead
  20313. *
  20314. * @private
  20315. * @listens stageclick
  20316. */
  20317. ;
  20318. _proto.handleStageClick_ = function handleStageClick_() {
  20319. this.reportUserActivity();
  20320. }
  20321. /**
  20322. * @private
  20323. */
  20324. ;
  20325. _proto.toggleFullscreenClass_ = function toggleFullscreenClass_() {
  20326. if (this.isFullscreen()) {
  20327. this.addClass('vjs-fullscreen');
  20328. } else {
  20329. this.removeClass('vjs-fullscreen');
  20330. }
  20331. }
  20332. /**
  20333. * when the document fschange event triggers it calls this
  20334. */
  20335. ;
  20336. _proto.documentFullscreenChange_ = function documentFullscreenChange_(e) {
  20337. var el = this.el();
  20338. var isFs = document[this.fsApi_.fullscreenElement] === el;
  20339. if (!isFs && el.matches) {
  20340. isFs = el.matches(':' + this.fsApi_.fullscreen);
  20341. } else if (!isFs && el.msMatchesSelector) {
  20342. isFs = el.msMatchesSelector(':' + this.fsApi_.fullscreen);
  20343. }
  20344. this.isFullscreen(isFs); // If cancelling fullscreen, remove event listener.
  20345. if (this.isFullscreen() === false) {
  20346. off(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_);
  20347. }
  20348. if (this.fsApi_.prefixed) {
  20349. /**
  20350. * @event Player#fullscreenchange
  20351. * @type {EventTarget~Event}
  20352. */
  20353. this.trigger('fullscreenchange');
  20354. }
  20355. }
  20356. /**
  20357. * Handle Tech Fullscreen Change
  20358. *
  20359. * @param {EventTarget~Event} event
  20360. * the fullscreenchange event that triggered this function
  20361. *
  20362. * @param {Object} data
  20363. * the data that was sent with the event
  20364. *
  20365. * @private
  20366. * @listens Tech#fullscreenchange
  20367. * @fires Player#fullscreenchange
  20368. */
  20369. ;
  20370. _proto.handleTechFullscreenChange_ = function handleTechFullscreenChange_(event, data) {
  20371. if (data) {
  20372. this.isFullscreen(data.isFullscreen);
  20373. }
  20374. /**
  20375. * Fired when going in and out of fullscreen.
  20376. *
  20377. * @event Player#fullscreenchange
  20378. * @type {EventTarget~Event}
  20379. */
  20380. this.trigger('fullscreenchange');
  20381. }
  20382. /**
  20383. * @private
  20384. */
  20385. ;
  20386. _proto.togglePictureInPictureClass_ = function togglePictureInPictureClass_() {
  20387. if (this.isInPictureInPicture()) {
  20388. this.addClass('vjs-picture-in-picture');
  20389. } else {
  20390. this.removeClass('vjs-picture-in-picture');
  20391. }
  20392. }
  20393. /**
  20394. * Handle Tech Enter Picture-in-Picture.
  20395. *
  20396. * @param {EventTarget~Event} event
  20397. * the enterpictureinpicture event that triggered this function
  20398. *
  20399. * @private
  20400. * @listens Tech#enterpictureinpicture
  20401. */
  20402. ;
  20403. _proto.handleTechEnterPictureInPicture_ = function handleTechEnterPictureInPicture_(event) {
  20404. this.isInPictureInPicture(true);
  20405. }
  20406. /**
  20407. * Handle Tech Leave Picture-in-Picture.
  20408. *
  20409. * @param {EventTarget~Event} event
  20410. * the leavepictureinpicture event that triggered this function
  20411. *
  20412. * @private
  20413. * @listens Tech#leavepictureinpicture
  20414. */
  20415. ;
  20416. _proto.handleTechLeavePictureInPicture_ = function handleTechLeavePictureInPicture_(event) {
  20417. this.isInPictureInPicture(false);
  20418. }
  20419. /**
  20420. * Fires when an error occurred during the loading of an audio/video.
  20421. *
  20422. * @private
  20423. * @listens Tech#error
  20424. */
  20425. ;
  20426. _proto.handleTechError_ = function handleTechError_() {
  20427. var error = this.tech_.error();
  20428. this.error(error);
  20429. }
  20430. /**
  20431. * Retrigger the `textdata` event that was triggered by the {@link Tech}.
  20432. *
  20433. * @fires Player#textdata
  20434. * @listens Tech#textdata
  20435. * @private
  20436. */
  20437. ;
  20438. _proto.handleTechTextData_ = function handleTechTextData_() {
  20439. var data = null;
  20440. if (arguments.length > 1) {
  20441. data = arguments[1];
  20442. }
  20443. /**
  20444. * Fires when we get a textdata event from tech
  20445. *
  20446. * @event Player#textdata
  20447. * @type {EventTarget~Event}
  20448. */
  20449. this.trigger('textdata', data);
  20450. }
  20451. /**
  20452. * Get object for cached values.
  20453. *
  20454. * @return {Object}
  20455. * get the current object cache
  20456. */
  20457. ;
  20458. _proto.getCache = function getCache() {
  20459. return this.cache_;
  20460. }
  20461. /**
  20462. * Resets the internal cache object.
  20463. *
  20464. * Using this function outside the player constructor or reset method may
  20465. * have unintended side-effects.
  20466. *
  20467. * @private
  20468. */
  20469. ;
  20470. _proto.resetCache_ = function resetCache_() {
  20471. this.cache_ = {
  20472. // Right now, the currentTime is not _really_ cached because it is always
  20473. // retrieved from the tech (see: currentTime). However, for completeness,
  20474. // we set it to zero here to ensure that if we do start actually caching
  20475. // it, we reset it along with everything else.
  20476. currentTime: 0,
  20477. inactivityTimeout: this.options_.inactivityTimeout,
  20478. duration: NaN,
  20479. lastVolume: 1,
  20480. lastPlaybackRate: this.defaultPlaybackRate(),
  20481. media: null,
  20482. src: '',
  20483. source: {},
  20484. sources: [],
  20485. volume: 1
  20486. };
  20487. }
  20488. /**
  20489. * Pass values to the playback tech
  20490. *
  20491. * @param {string} [method]
  20492. * the method to call
  20493. *
  20494. * @param {Object} arg
  20495. * the argument to pass
  20496. *
  20497. * @private
  20498. */
  20499. ;
  20500. _proto.techCall_ = function techCall_(method, arg) {
  20501. // If it's not ready yet, call method when it is
  20502. this.ready(function () {
  20503. if (method in allowedSetters) {
  20504. return set(this.middleware_, this.tech_, method, arg);
  20505. } else if (method in allowedMediators) {
  20506. return mediate(this.middleware_, this.tech_, method, arg);
  20507. }
  20508. try {
  20509. if (this.tech_) {
  20510. this.tech_[method](arg);
  20511. }
  20512. } catch (e) {
  20513. log(e);
  20514. throw e;
  20515. }
  20516. }, true);
  20517. }
  20518. /**
  20519. * Get calls can't wait for the tech, and sometimes don't need to.
  20520. *
  20521. * @param {string} method
  20522. * Tech method
  20523. *
  20524. * @return {Function|undefined}
  20525. * the method or undefined
  20526. *
  20527. * @private
  20528. */
  20529. ;
  20530. _proto.techGet_ = function techGet_(method) {
  20531. if (!this.tech_ || !this.tech_.isReady_) {
  20532. return;
  20533. }
  20534. if (method in allowedGetters) {
  20535. return get(this.middleware_, this.tech_, method);
  20536. } else if (method in allowedMediators) {
  20537. return mediate(this.middleware_, this.tech_, method);
  20538. } // Flash likes to die and reload when you hide or reposition it.
  20539. // In these cases the object methods go away and we get errors.
  20540. // When that happens we'll catch the errors and inform tech that it's not ready any more.
  20541. try {
  20542. return this.tech_[method]();
  20543. } catch (e) {
  20544. // When building additional tech libs, an expected method may not be defined yet
  20545. if (this.tech_[method] === undefined) {
  20546. log("Video.js: " + method + " method not defined for " + this.techName_ + " playback technology.", e);
  20547. throw e;
  20548. } // When a method isn't available on the object it throws a TypeError
  20549. if (e.name === 'TypeError') {
  20550. log("Video.js: " + method + " unavailable on " + this.techName_ + " playback technology element.", e);
  20551. this.tech_.isReady_ = false;
  20552. throw e;
  20553. } // If error unknown, just log and throw
  20554. log(e);
  20555. throw e;
  20556. }
  20557. }
  20558. /**
  20559. * Attempt to begin playback at the first opportunity.
  20560. *
  20561. * @return {Promise|undefined}
  20562. * Returns a promise if the browser supports Promises (or one
  20563. * was passed in as an option). This promise will be resolved on
  20564. * the return value of play. If this is undefined it will fulfill the
  20565. * promise chain otherwise the promise chain will be fulfilled when
  20566. * the promise from play is fulfilled.
  20567. */
  20568. ;
  20569. _proto.play = function play() {
  20570. var _this8 = this;
  20571. var PromiseClass = this.options_.Promise || window$1.Promise;
  20572. if (PromiseClass) {
  20573. return new PromiseClass(function (resolve) {
  20574. _this8.play_(resolve);
  20575. });
  20576. }
  20577. return this.play_();
  20578. }
  20579. /**
  20580. * The actual logic for play, takes a callback that will be resolved on the
  20581. * return value of play. This allows us to resolve to the play promise if there
  20582. * is one on modern browsers.
  20583. *
  20584. * @private
  20585. * @param {Function} [callback]
  20586. * The callback that should be called when the techs play is actually called
  20587. */
  20588. ;
  20589. _proto.play_ = function play_(callback) {
  20590. var _this9 = this;
  20591. if (callback === void 0) {
  20592. callback = silencePromise;
  20593. }
  20594. this.playCallbacks_.push(callback);
  20595. var isSrcReady = Boolean(!this.changingSrc_ && (this.src() || this.currentSrc())); // treat calls to play_ somewhat like the `one` event function
  20596. if (this.waitToPlay_) {
  20597. this.off(['ready', 'loadstart'], this.waitToPlay_);
  20598. this.waitToPlay_ = null;
  20599. } // if the player/tech is not ready or the src itself is not ready
  20600. // queue up a call to play on `ready` or `loadstart`
  20601. if (!this.isReady_ || !isSrcReady) {
  20602. this.waitToPlay_ = function (e) {
  20603. _this9.play_();
  20604. };
  20605. this.one(['ready', 'loadstart'], this.waitToPlay_); // if we are in Safari, there is a high chance that loadstart will trigger after the gesture timeperiod
  20606. // in that case, we need to prime the video element by calling load so it'll be ready in time
  20607. if (!isSrcReady && (IS_ANY_SAFARI || IS_IOS)) {
  20608. this.load();
  20609. }
  20610. return;
  20611. } // If the player/tech is ready and we have a source, we can attempt playback.
  20612. var val = this.techGet_('play'); // play was terminated if the returned value is null
  20613. if (val === null) {
  20614. this.runPlayTerminatedQueue_();
  20615. } else {
  20616. this.runPlayCallbacks_(val);
  20617. }
  20618. }
  20619. /**
  20620. * These functions will be run when if play is terminated. If play
  20621. * runPlayCallbacks_ is run these function will not be run. This allows us
  20622. * to differenciate between a terminated play and an actual call to play.
  20623. */
  20624. ;
  20625. _proto.runPlayTerminatedQueue_ = function runPlayTerminatedQueue_() {
  20626. var queue = this.playTerminatedQueue_.slice(0);
  20627. this.playTerminatedQueue_ = [];
  20628. queue.forEach(function (q) {
  20629. q();
  20630. });
  20631. }
  20632. /**
  20633. * When a callback to play is delayed we have to run these
  20634. * callbacks when play is actually called on the tech. This function
  20635. * runs the callbacks that were delayed and accepts the return value
  20636. * from the tech.
  20637. *
  20638. * @param {undefined|Promise} val
  20639. * The return value from the tech.
  20640. */
  20641. ;
  20642. _proto.runPlayCallbacks_ = function runPlayCallbacks_(val) {
  20643. var callbacks = this.playCallbacks_.slice(0);
  20644. this.playCallbacks_ = []; // clear play terminatedQueue since we finished a real play
  20645. this.playTerminatedQueue_ = [];
  20646. callbacks.forEach(function (cb) {
  20647. cb(val);
  20648. });
  20649. }
  20650. /**
  20651. * Pause the video playback
  20652. *
  20653. * @return {Player}
  20654. * A reference to the player object this function was called on
  20655. */
  20656. ;
  20657. _proto.pause = function pause() {
  20658. this.techCall_('pause');
  20659. }
  20660. /**
  20661. * Check if the player is paused or has yet to play
  20662. *
  20663. * @return {boolean}
  20664. * - false: if the media is currently playing
  20665. * - true: if media is not currently playing
  20666. */
  20667. ;
  20668. _proto.paused = function paused() {
  20669. // The initial state of paused should be true (in Safari it's actually false)
  20670. return this.techGet_('paused') === false ? false : true;
  20671. }
  20672. /**
  20673. * Get a TimeRange object representing the current ranges of time that the user
  20674. * has played.
  20675. *
  20676. * @return {TimeRange}
  20677. * A time range object that represents all the increments of time that have
  20678. * been played.
  20679. */
  20680. ;
  20681. _proto.played = function played() {
  20682. return this.techGet_('played') || createTimeRanges(0, 0);
  20683. }
  20684. /**
  20685. * Returns whether or not the user is "scrubbing". Scrubbing is
  20686. * when the user has clicked the progress bar handle and is
  20687. * dragging it along the progress bar.
  20688. *
  20689. * @param {boolean} [isScrubbing]
  20690. * whether the user is or is not scrubbing
  20691. *
  20692. * @return {boolean}
  20693. * The value of scrubbing when getting
  20694. */
  20695. ;
  20696. _proto.scrubbing = function scrubbing(isScrubbing) {
  20697. if (typeof isScrubbing === 'undefined') {
  20698. return this.scrubbing_;
  20699. }
  20700. this.scrubbing_ = !!isScrubbing;
  20701. if (isScrubbing) {
  20702. this.addClass('vjs-scrubbing');
  20703. } else {
  20704. this.removeClass('vjs-scrubbing');
  20705. }
  20706. }
  20707. /**
  20708. * Get or set the current time (in seconds)
  20709. *
  20710. * @param {number|string} [seconds]
  20711. * The time to seek to in seconds
  20712. *
  20713. * @return {number}
  20714. * - the current time in seconds when getting
  20715. */
  20716. ;
  20717. _proto.currentTime = function currentTime(seconds) {
  20718. if (typeof seconds !== 'undefined') {
  20719. if (seconds < 0) {
  20720. seconds = 0;
  20721. }
  20722. this.techCall_('setCurrentTime', seconds);
  20723. return;
  20724. } // cache last currentTime and return. default to 0 seconds
  20725. //
  20726. // Caching the currentTime is meant to prevent a massive amount of reads on the tech's
  20727. // currentTime when scrubbing, but may not provide much performance benefit afterall.
  20728. // Should be tested. Also something has to read the actual current time or the cache will
  20729. // never get updated.
  20730. this.cache_.currentTime = this.techGet_('currentTime') || 0;
  20731. return this.cache_.currentTime;
  20732. }
  20733. /**
  20734. * Normally gets the length in time of the video in seconds;
  20735. * in all but the rarest use cases an argument will NOT be passed to the method
  20736. *
  20737. * > **NOTE**: The video must have started loading before the duration can be
  20738. * known, and in the case of Flash, may not be known until the video starts
  20739. * playing.
  20740. *
  20741. * @fires Player#durationchange
  20742. *
  20743. * @param {number} [seconds]
  20744. * The duration of the video to set in seconds
  20745. *
  20746. * @return {number}
  20747. * - The duration of the video in seconds when getting
  20748. */
  20749. ;
  20750. _proto.duration = function duration(seconds) {
  20751. if (seconds === undefined) {
  20752. // return NaN if the duration is not known
  20753. return this.cache_.duration !== undefined ? this.cache_.duration : NaN;
  20754. }
  20755. seconds = parseFloat(seconds); // Standardize on Infinity for signaling video is live
  20756. if (seconds < 0) {
  20757. seconds = Infinity;
  20758. }
  20759. if (seconds !== this.cache_.duration) {
  20760. // Cache the last set value for optimized scrubbing (esp. Flash)
  20761. this.cache_.duration = seconds;
  20762. if (seconds === Infinity) {
  20763. this.addClass('vjs-live');
  20764. if (this.options_.liveui && this.player_.liveTracker) {
  20765. this.addClass('vjs-liveui');
  20766. }
  20767. } else {
  20768. this.removeClass('vjs-live');
  20769. this.removeClass('vjs-liveui');
  20770. }
  20771. if (!isNaN(seconds)) {
  20772. // Do not fire durationchange unless the duration value is known.
  20773. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  20774. /**
  20775. * @event Player#durationchange
  20776. * @type {EventTarget~Event}
  20777. */
  20778. this.trigger('durationchange');
  20779. }
  20780. }
  20781. }
  20782. /**
  20783. * Calculates how much time is left in the video. Not part
  20784. * of the native video API.
  20785. *
  20786. * @return {number}
  20787. * The time remaining in seconds
  20788. */
  20789. ;
  20790. _proto.remainingTime = function remainingTime() {
  20791. return this.duration() - this.currentTime();
  20792. }
  20793. /**
  20794. * A remaining time function that is intented to be used when
  20795. * the time is to be displayed directly to the user.
  20796. *
  20797. * @return {number}
  20798. * The rounded time remaining in seconds
  20799. */
  20800. ;
  20801. _proto.remainingTimeDisplay = function remainingTimeDisplay() {
  20802. return Math.floor(this.duration()) - Math.floor(this.currentTime());
  20803. } //
  20804. // Kind of like an array of portions of the video that have been downloaded.
  20805. /**
  20806. * Get a TimeRange object with an array of the times of the video
  20807. * that have been downloaded. If you just want the percent of the
  20808. * video that's been downloaded, use bufferedPercent.
  20809. *
  20810. * @see [Buffered Spec]{@link http://dev.w3.org/html5/spec/video.html#dom-media-buffered}
  20811. *
  20812. * @return {TimeRange}
  20813. * A mock TimeRange object (following HTML spec)
  20814. */
  20815. ;
  20816. _proto.buffered = function buffered() {
  20817. var buffered = this.techGet_('buffered');
  20818. if (!buffered || !buffered.length) {
  20819. buffered = createTimeRanges(0, 0);
  20820. }
  20821. return buffered;
  20822. }
  20823. /**
  20824. * Get the percent (as a decimal) of the video that's been downloaded.
  20825. * This method is not a part of the native HTML video API.
  20826. *
  20827. * @return {number}
  20828. * A decimal between 0 and 1 representing the percent
  20829. * that is buffered 0 being 0% and 1 being 100%
  20830. */
  20831. ;
  20832. _proto.bufferedPercent = function bufferedPercent$1() {
  20833. return bufferedPercent(this.buffered(), this.duration());
  20834. }
  20835. /**
  20836. * Get the ending time of the last buffered time range
  20837. * This is used in the progress bar to encapsulate all time ranges.
  20838. *
  20839. * @return {number}
  20840. * The end of the last buffered time range
  20841. */
  20842. ;
  20843. _proto.bufferedEnd = function bufferedEnd() {
  20844. var buffered = this.buffered();
  20845. var duration = this.duration();
  20846. var end = buffered.end(buffered.length - 1);
  20847. if (end > duration) {
  20848. end = duration;
  20849. }
  20850. return end;
  20851. }
  20852. /**
  20853. * Get or set the current volume of the media
  20854. *
  20855. * @param {number} [percentAsDecimal]
  20856. * The new volume as a decimal percent:
  20857. * - 0 is muted/0%/off
  20858. * - 1.0 is 100%/full
  20859. * - 0.5 is half volume or 50%
  20860. *
  20861. * @return {number}
  20862. * The current volume as a percent when getting
  20863. */
  20864. ;
  20865. _proto.volume = function volume(percentAsDecimal) {
  20866. var vol;
  20867. if (percentAsDecimal !== undefined) {
  20868. // Force value to between 0 and 1
  20869. vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal)));
  20870. this.cache_.volume = vol;
  20871. this.techCall_('setVolume', vol);
  20872. if (vol > 0) {
  20873. this.lastVolume_(vol);
  20874. }
  20875. return;
  20876. } // Default to 1 when returning current volume.
  20877. vol = parseFloat(this.techGet_('volume'));
  20878. return isNaN(vol) ? 1 : vol;
  20879. }
  20880. /**
  20881. * Get the current muted state, or turn mute on or off
  20882. *
  20883. * @param {boolean} [muted]
  20884. * - true to mute
  20885. * - false to unmute
  20886. *
  20887. * @return {boolean}
  20888. * - true if mute is on and getting
  20889. * - false if mute is off and getting
  20890. */
  20891. ;
  20892. _proto.muted = function muted(_muted) {
  20893. if (_muted !== undefined) {
  20894. this.techCall_('setMuted', _muted);
  20895. return;
  20896. }
  20897. return this.techGet_('muted') || false;
  20898. }
  20899. /**
  20900. * Get the current defaultMuted state, or turn defaultMuted on or off. defaultMuted
  20901. * indicates the state of muted on initial playback.
  20902. *
  20903. * ```js
  20904. * var myPlayer = videojs('some-player-id');
  20905. *
  20906. * myPlayer.src("http://www.example.com/path/to/video.mp4");
  20907. *
  20908. * // get, should be false
  20909. * console.log(myPlayer.defaultMuted());
  20910. * // set to true
  20911. * myPlayer.defaultMuted(true);
  20912. * // get should be true
  20913. * console.log(myPlayer.defaultMuted());
  20914. * ```
  20915. *
  20916. * @param {boolean} [defaultMuted]
  20917. * - true to mute
  20918. * - false to unmute
  20919. *
  20920. * @return {boolean|Player}
  20921. * - true if defaultMuted is on and getting
  20922. * - false if defaultMuted is off and getting
  20923. * - A reference to the current player when setting
  20924. */
  20925. ;
  20926. _proto.defaultMuted = function defaultMuted(_defaultMuted) {
  20927. if (_defaultMuted !== undefined) {
  20928. return this.techCall_('setDefaultMuted', _defaultMuted);
  20929. }
  20930. return this.techGet_('defaultMuted') || false;
  20931. }
  20932. /**
  20933. * Get the last volume, or set it
  20934. *
  20935. * @param {number} [percentAsDecimal]
  20936. * The new last volume as a decimal percent:
  20937. * - 0 is muted/0%/off
  20938. * - 1.0 is 100%/full
  20939. * - 0.5 is half volume or 50%
  20940. *
  20941. * @return {number}
  20942. * the current value of lastVolume as a percent when getting
  20943. *
  20944. * @private
  20945. */
  20946. ;
  20947. _proto.lastVolume_ = function lastVolume_(percentAsDecimal) {
  20948. if (percentAsDecimal !== undefined && percentAsDecimal !== 0) {
  20949. this.cache_.lastVolume = percentAsDecimal;
  20950. return;
  20951. }
  20952. return this.cache_.lastVolume;
  20953. }
  20954. /**
  20955. * Check if current tech can support native fullscreen
  20956. * (e.g. with built in controls like iOS, so not our flash swf)
  20957. *
  20958. * @return {boolean}
  20959. * if native fullscreen is supported
  20960. */
  20961. ;
  20962. _proto.supportsFullScreen = function supportsFullScreen() {
  20963. return this.techGet_('supportsFullScreen') || false;
  20964. }
  20965. /**
  20966. * Check if the player is in fullscreen mode or tell the player that it
  20967. * is or is not in fullscreen mode.
  20968. *
  20969. * > NOTE: As of the latest HTML5 spec, isFullscreen is no longer an official
  20970. * property and instead document.fullscreenElement is used. But isFullscreen is
  20971. * still a valuable property for internal player workings.
  20972. *
  20973. * @param {boolean} [isFS]
  20974. * Set the players current fullscreen state
  20975. *
  20976. * @return {boolean}
  20977. * - true if fullscreen is on and getting
  20978. * - false if fullscreen is off and getting
  20979. */
  20980. ;
  20981. _proto.isFullscreen = function isFullscreen(isFS) {
  20982. if (isFS !== undefined) {
  20983. this.isFullscreen_ = !!isFS;
  20984. this.toggleFullscreenClass_();
  20985. return;
  20986. }
  20987. return !!this.isFullscreen_;
  20988. }
  20989. /**
  20990. * Increase the size of the video to full screen
  20991. * In some browsers, full screen is not supported natively, so it enters
  20992. * "full window mode", where the video fills the browser window.
  20993. * In browsers and devices that support native full screen, sometimes the
  20994. * browser's default controls will be shown, and not the Video.js custom skin.
  20995. * This includes most mobile devices (iOS, Android) and older versions of
  20996. * Safari.
  20997. *
  20998. * @param {Object} [fullscreenOptions]
  20999. * Override the player fullscreen options
  21000. *
  21001. * @fires Player#fullscreenchange
  21002. */
  21003. ;
  21004. _proto.requestFullscreen = function requestFullscreen(fullscreenOptions) {
  21005. var fsOptions;
  21006. this.isFullscreen(true);
  21007. if (this.fsApi_.requestFullscreen) {
  21008. // the browser supports going fullscreen at the element level so we can
  21009. // take the controls fullscreen as well as the video
  21010. // Trigger fullscreenchange event after change
  21011. // We have to specifically add this each time, and remove
  21012. // when canceling fullscreen. Otherwise if there's multiple
  21013. // players on a page, they would all be reacting to the same fullscreen
  21014. // events
  21015. on(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_); // only pass FullscreenOptions to requestFullscreen if it isn't prefixed
  21016. if (!this.fsApi_.prefixed) {
  21017. fsOptions = this.options_.fullscreen && this.options_.fullscreen.options || {};
  21018. if (fullscreenOptions !== undefined) {
  21019. fsOptions = fullscreenOptions;
  21020. }
  21021. }
  21022. silencePromise(this.el_[this.fsApi_.requestFullscreen](fsOptions));
  21023. } else if (this.tech_.supportsFullScreen()) {
  21024. // we can't take the video.js controls fullscreen but we can go fullscreen
  21025. // with native controls
  21026. this.techCall_('enterFullScreen');
  21027. } else {
  21028. // fullscreen isn't supported so we'll just stretch the video element to
  21029. // fill the viewport
  21030. this.enterFullWindow();
  21031. /**
  21032. * @event Player#fullscreenchange
  21033. * @type {EventTarget~Event}
  21034. */
  21035. this.trigger('fullscreenchange');
  21036. }
  21037. }
  21038. /**
  21039. * Return the video to its normal size after having been in full screen mode
  21040. *
  21041. * @fires Player#fullscreenchange
  21042. */
  21043. ;
  21044. _proto.exitFullscreen = function exitFullscreen() {
  21045. this.isFullscreen(false); // Check for browser element fullscreen support
  21046. if (this.fsApi_.requestFullscreen) {
  21047. silencePromise(document[this.fsApi_.exitFullscreen]());
  21048. } else if (this.tech_.supportsFullScreen()) {
  21049. this.techCall_('exitFullScreen');
  21050. } else {
  21051. this.exitFullWindow();
  21052. /**
  21053. * @event Player#fullscreenchange
  21054. * @type {EventTarget~Event}
  21055. */
  21056. this.trigger('fullscreenchange');
  21057. }
  21058. }
  21059. /**
  21060. * When fullscreen isn't supported we can stretch the
  21061. * video container to as wide as the browser will let us.
  21062. *
  21063. * @fires Player#enterFullWindow
  21064. */
  21065. ;
  21066. _proto.enterFullWindow = function enterFullWindow() {
  21067. this.isFullWindow = true; // Storing original doc overflow value to return to when fullscreen is off
  21068. this.docOrigOverflow = document.documentElement.style.overflow; // Add listener for esc key to exit fullscreen
  21069. on(document, 'keydown', this.boundFullWindowOnEscKey_); // Hide any scroll bars
  21070. document.documentElement.style.overflow = 'hidden'; // Apply fullscreen styles
  21071. addClass(document.body, 'vjs-full-window');
  21072. /**
  21073. * @event Player#enterFullWindow
  21074. * @type {EventTarget~Event}
  21075. */
  21076. this.trigger('enterFullWindow');
  21077. }
  21078. /**
  21079. * Check for call to either exit full window or
  21080. * full screen on ESC key
  21081. *
  21082. * @param {string} event
  21083. * Event to check for key press
  21084. */
  21085. ;
  21086. _proto.fullWindowOnEscKey = function fullWindowOnEscKey(event) {
  21087. if (keycode.isEventKey(event, 'Esc')) {
  21088. if (this.isFullscreen() === true) {
  21089. this.exitFullscreen();
  21090. } else {
  21091. this.exitFullWindow();
  21092. }
  21093. }
  21094. }
  21095. /**
  21096. * Exit full window
  21097. *
  21098. * @fires Player#exitFullWindow
  21099. */
  21100. ;
  21101. _proto.exitFullWindow = function exitFullWindow() {
  21102. this.isFullWindow = false;
  21103. off(document, 'keydown', this.boundFullWindowOnEscKey_); // Unhide scroll bars.
  21104. document.documentElement.style.overflow = this.docOrigOverflow; // Remove fullscreen styles
  21105. removeClass(document.body, 'vjs-full-window'); // Resize the box, controller, and poster to original sizes
  21106. // this.positionAll();
  21107. /**
  21108. * @event Player#exitFullWindow
  21109. * @type {EventTarget~Event}
  21110. */
  21111. this.trigger('exitFullWindow');
  21112. }
  21113. /**
  21114. * Check if the player is in Picture-in-Picture mode or tell the player that it
  21115. * is or is not in Picture-in-Picture mode.
  21116. *
  21117. * @param {boolean} [isPiP]
  21118. * Set the players current Picture-in-Picture state
  21119. *
  21120. * @return {boolean}
  21121. * - true if Picture-in-Picture is on and getting
  21122. * - false if Picture-in-Picture is off and getting
  21123. */
  21124. ;
  21125. _proto.isInPictureInPicture = function isInPictureInPicture(isPiP) {
  21126. if (isPiP !== undefined) {
  21127. this.isInPictureInPicture_ = !!isPiP;
  21128. this.togglePictureInPictureClass_();
  21129. return;
  21130. }
  21131. return !!this.isInPictureInPicture_;
  21132. }
  21133. /**
  21134. * Create a floating video window always on top of other windows so that users may
  21135. * continue consuming media while they interact with other content sites, or
  21136. * applications on their device.
  21137. *
  21138. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  21139. *
  21140. * @fires Player#enterpictureinpicture
  21141. *
  21142. * @return {Promise}
  21143. * A promise with a Picture-in-Picture window.
  21144. */
  21145. ;
  21146. _proto.requestPictureInPicture = function requestPictureInPicture() {
  21147. if ('pictureInPictureEnabled' in document) {
  21148. /**
  21149. * This event fires when the player enters picture in picture mode
  21150. *
  21151. * @event Player#enterpictureinpicture
  21152. * @type {EventTarget~Event}
  21153. */
  21154. return this.techGet_('requestPictureInPicture');
  21155. }
  21156. }
  21157. /**
  21158. * Exit Picture-in-Picture mode.
  21159. *
  21160. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  21161. *
  21162. * @fires Player#leavepictureinpicture
  21163. *
  21164. * @return {Promise}
  21165. * A promise.
  21166. */
  21167. ;
  21168. _proto.exitPictureInPicture = function exitPictureInPicture() {
  21169. if ('pictureInPictureEnabled' in document) {
  21170. /**
  21171. * This event fires when the player leaves picture in picture mode
  21172. *
  21173. * @event Player#leavepictureinpicture
  21174. * @type {EventTarget~Event}
  21175. */
  21176. return document.exitPictureInPicture();
  21177. }
  21178. }
  21179. /**
  21180. * Called when this Player has focus and a key gets pressed down, or when
  21181. * any Component of this player receives a key press that it doesn't handle.
  21182. * This allows player-wide hotkeys (either as defined below, or optionally
  21183. * by an external function).
  21184. *
  21185. * @param {EventTarget~Event} event
  21186. * The `keydown` event that caused this function to be called.
  21187. *
  21188. * @listens keydown
  21189. */
  21190. ;
  21191. _proto.handleKeyDown = function handleKeyDown(event) {
  21192. var userActions = this.options_.userActions; // Bail out if hotkeys are not configured.
  21193. if (!userActions || !userActions.hotkeys) {
  21194. return;
  21195. } // Function that determines whether or not to exclude an element from
  21196. // hotkeys handling.
  21197. var excludeElement = function excludeElement(el) {
  21198. var tagName = el.tagName.toLowerCase(); // The first and easiest test is for `contenteditable` elements.
  21199. if (el.isContentEditable) {
  21200. return true;
  21201. } // Inputs matching these types will still trigger hotkey handling as
  21202. // they are not text inputs.
  21203. var allowedInputTypes = ['button', 'checkbox', 'hidden', 'radio', 'reset', 'submit'];
  21204. if (tagName === 'input') {
  21205. return allowedInputTypes.indexOf(el.type) === -1;
  21206. } // The final test is by tag name. These tags will be excluded entirely.
  21207. var excludedTags = ['textarea'];
  21208. return excludedTags.indexOf(tagName) !== -1;
  21209. }; // Bail out if the user is focused on an interactive form element.
  21210. if (excludeElement(this.el_.ownerDocument.activeElement)) {
  21211. return;
  21212. }
  21213. if (typeof userActions.hotkeys === 'function') {
  21214. userActions.hotkeys.call(this, event);
  21215. } else {
  21216. this.handleHotkeys(event);
  21217. }
  21218. }
  21219. /**
  21220. * Called when this Player receives a hotkey keydown event.
  21221. * Supported player-wide hotkeys are:
  21222. *
  21223. * f - toggle fullscreen
  21224. * m - toggle mute
  21225. * k or Space - toggle play/pause
  21226. *
  21227. * @param {EventTarget~Event} event
  21228. * The `keydown` event that caused this function to be called.
  21229. */
  21230. ;
  21231. _proto.handleHotkeys = function handleHotkeys(event) {
  21232. var hotkeys = this.options_.userActions ? this.options_.userActions.hotkeys : {}; // set fullscreenKey, muteKey, playPauseKey from `hotkeys`, use defaults if not set
  21233. var _hotkeys$fullscreenKe = hotkeys.fullscreenKey,
  21234. fullscreenKey = _hotkeys$fullscreenKe === void 0 ? function (keydownEvent) {
  21235. return keycode.isEventKey(keydownEvent, 'f');
  21236. } : _hotkeys$fullscreenKe,
  21237. _hotkeys$muteKey = hotkeys.muteKey,
  21238. muteKey = _hotkeys$muteKey === void 0 ? function (keydownEvent) {
  21239. return keycode.isEventKey(keydownEvent, 'm');
  21240. } : _hotkeys$muteKey,
  21241. _hotkeys$playPauseKey = hotkeys.playPauseKey,
  21242. playPauseKey = _hotkeys$playPauseKey === void 0 ? function (keydownEvent) {
  21243. return keycode.isEventKey(keydownEvent, 'k') || keycode.isEventKey(keydownEvent, 'Space');
  21244. } : _hotkeys$playPauseKey;
  21245. if (fullscreenKey.call(this, event)) {
  21246. event.preventDefault();
  21247. event.stopPropagation();
  21248. var FSToggle = Component.getComponent('FullscreenToggle');
  21249. if (document[this.fsApi_.fullscreenEnabled] !== false) {
  21250. FSToggle.prototype.handleClick.call(this, event);
  21251. }
  21252. } else if (muteKey.call(this, event)) {
  21253. event.preventDefault();
  21254. event.stopPropagation();
  21255. var MuteToggle = Component.getComponent('MuteToggle');
  21256. MuteToggle.prototype.handleClick.call(this, event);
  21257. } else if (playPauseKey.call(this, event)) {
  21258. event.preventDefault();
  21259. event.stopPropagation();
  21260. var PlayToggle = Component.getComponent('PlayToggle');
  21261. PlayToggle.prototype.handleClick.call(this, event);
  21262. }
  21263. }
  21264. /**
  21265. * Check whether the player can play a given mimetype
  21266. *
  21267. * @see https://www.w3.org/TR/2011/WD-html5-20110113/video.html#dom-navigator-canplaytype
  21268. *
  21269. * @param {string} type
  21270. * The mimetype to check
  21271. *
  21272. * @return {string}
  21273. * 'probably', 'maybe', or '' (empty string)
  21274. */
  21275. ;
  21276. _proto.canPlayType = function canPlayType(type) {
  21277. var can; // Loop through each playback technology in the options order
  21278. for (var i = 0, j = this.options_.techOrder; i < j.length; i++) {
  21279. var techName = j[i];
  21280. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  21281. // Remove once that deprecated behavior is removed.
  21282. if (!tech) {
  21283. tech = Component.getComponent(techName);
  21284. } // Check if the current tech is defined before continuing
  21285. if (!tech) {
  21286. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  21287. continue;
  21288. } // Check if the browser supports this technology
  21289. if (tech.isSupported()) {
  21290. can = tech.canPlayType(type);
  21291. if (can) {
  21292. return can;
  21293. }
  21294. }
  21295. }
  21296. return '';
  21297. }
  21298. /**
  21299. * Select source based on tech-order or source-order
  21300. * Uses source-order selection if `options.sourceOrder` is truthy. Otherwise,
  21301. * defaults to tech-order selection
  21302. *
  21303. * @param {Array} sources
  21304. * The sources for a media asset
  21305. *
  21306. * @return {Object|boolean}
  21307. * Object of source and tech order or false
  21308. */
  21309. ;
  21310. _proto.selectSource = function selectSource(sources) {
  21311. var _this10 = this;
  21312. // Get only the techs specified in `techOrder` that exist and are supported by the
  21313. // current platform
  21314. var techs = this.options_.techOrder.map(function (techName) {
  21315. return [techName, Tech.getTech(techName)];
  21316. }).filter(function (_ref) {
  21317. var techName = _ref[0],
  21318. tech = _ref[1];
  21319. // Check if the current tech is defined before continuing
  21320. if (tech) {
  21321. // Check if the browser supports this technology
  21322. return tech.isSupported();
  21323. }
  21324. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  21325. return false;
  21326. }); // Iterate over each `innerArray` element once per `outerArray` element and execute
  21327. // `tester` with both. If `tester` returns a non-falsy value, exit early and return
  21328. // that value.
  21329. var findFirstPassingTechSourcePair = function findFirstPassingTechSourcePair(outerArray, innerArray, tester) {
  21330. var found;
  21331. outerArray.some(function (outerChoice) {
  21332. return innerArray.some(function (innerChoice) {
  21333. found = tester(outerChoice, innerChoice);
  21334. if (found) {
  21335. return true;
  21336. }
  21337. });
  21338. });
  21339. return found;
  21340. };
  21341. var foundSourceAndTech;
  21342. var flip = function flip(fn) {
  21343. return function (a, b) {
  21344. return fn(b, a);
  21345. };
  21346. };
  21347. var finder = function finder(_ref2, source) {
  21348. var techName = _ref2[0],
  21349. tech = _ref2[1];
  21350. if (tech.canPlaySource(source, _this10.options_[techName.toLowerCase()])) {
  21351. return {
  21352. source: source,
  21353. tech: techName
  21354. };
  21355. }
  21356. }; // Depending on the truthiness of `options.sourceOrder`, we swap the order of techs and sources
  21357. // to select from them based on their priority.
  21358. if (this.options_.sourceOrder) {
  21359. // Source-first ordering
  21360. foundSourceAndTech = findFirstPassingTechSourcePair(sources, techs, flip(finder));
  21361. } else {
  21362. // Tech-first ordering
  21363. foundSourceAndTech = findFirstPassingTechSourcePair(techs, sources, finder);
  21364. }
  21365. return foundSourceAndTech || false;
  21366. }
  21367. /**
  21368. * Get or set the video source.
  21369. *
  21370. * @param {Tech~SourceObject|Tech~SourceObject[]|string} [source]
  21371. * A SourceObject, an array of SourceObjects, or a string referencing
  21372. * a URL to a media source. It is _highly recommended_ that an object
  21373. * or array of objects is used here, so that source selection
  21374. * algorithms can take the `type` into account.
  21375. *
  21376. * If not provided, this method acts as a getter.
  21377. *
  21378. * @return {string|undefined}
  21379. * If the `source` argument is missing, returns the current source
  21380. * URL. Otherwise, returns nothing/undefined.
  21381. */
  21382. ;
  21383. _proto.src = function src(source) {
  21384. var _this11 = this;
  21385. // getter usage
  21386. if (typeof source === 'undefined') {
  21387. return this.cache_.src || '';
  21388. } // filter out invalid sources and turn our source into
  21389. // an array of source objects
  21390. var sources = filterSource(source); // if a source was passed in then it is invalid because
  21391. // it was filtered to a zero length Array. So we have to
  21392. // show an error
  21393. if (!sources.length) {
  21394. this.setTimeout(function () {
  21395. this.error({
  21396. code: 4,
  21397. message: this.localize(this.options_.notSupportedMessage)
  21398. });
  21399. }, 0);
  21400. return;
  21401. } // intial sources
  21402. this.changingSrc_ = true;
  21403. this.cache_.sources = sources;
  21404. this.updateSourceCaches_(sources[0]); // middlewareSource is the source after it has been changed by middleware
  21405. setSource(this, sources[0], function (middlewareSource, mws) {
  21406. _this11.middleware_ = mws; // since sourceSet is async we have to update the cache again after we select a source since
  21407. // the source that is selected could be out of order from the cache update above this callback.
  21408. _this11.cache_.sources = sources;
  21409. _this11.updateSourceCaches_(middlewareSource);
  21410. var err = _this11.src_(middlewareSource);
  21411. if (err) {
  21412. if (sources.length > 1) {
  21413. return _this11.src(sources.slice(1));
  21414. }
  21415. _this11.changingSrc_ = false; // We need to wrap this in a timeout to give folks a chance to add error event handlers
  21416. _this11.setTimeout(function () {
  21417. this.error({
  21418. code: 4,
  21419. message: this.localize(this.options_.notSupportedMessage)
  21420. });
  21421. }, 0); // we could not find an appropriate tech, but let's still notify the delegate that this is it
  21422. // this needs a better comment about why this is needed
  21423. _this11.triggerReady();
  21424. return;
  21425. }
  21426. setTech(mws, _this11.tech_);
  21427. });
  21428. }
  21429. /**
  21430. * Set the source object on the tech, returns a boolean that indicates whether
  21431. * there is a tech that can play the source or not
  21432. *
  21433. * @param {Tech~SourceObject} source
  21434. * The source object to set on the Tech
  21435. *
  21436. * @return {boolean}
  21437. * - True if there is no Tech to playback this source
  21438. * - False otherwise
  21439. *
  21440. * @private
  21441. */
  21442. ;
  21443. _proto.src_ = function src_(source) {
  21444. var _this12 = this;
  21445. var sourceTech = this.selectSource([source]);
  21446. if (!sourceTech) {
  21447. return true;
  21448. }
  21449. if (!titleCaseEquals(sourceTech.tech, this.techName_)) {
  21450. this.changingSrc_ = true; // load this technology with the chosen source
  21451. this.loadTech_(sourceTech.tech, sourceTech.source);
  21452. this.tech_.ready(function () {
  21453. _this12.changingSrc_ = false;
  21454. });
  21455. return false;
  21456. } // wait until the tech is ready to set the source
  21457. // and set it synchronously if possible (#2326)
  21458. this.ready(function () {
  21459. // The setSource tech method was added with source handlers
  21460. // so older techs won't support it
  21461. // We need to check the direct prototype for the case where subclasses
  21462. // of the tech do not support source handlers
  21463. if (this.tech_.constructor.prototype.hasOwnProperty('setSource')) {
  21464. this.techCall_('setSource', source);
  21465. } else {
  21466. this.techCall_('src', source.src);
  21467. }
  21468. this.changingSrc_ = false;
  21469. }, true);
  21470. return false;
  21471. }
  21472. /**
  21473. * Begin loading the src data.
  21474. */
  21475. ;
  21476. _proto.load = function load() {
  21477. this.techCall_('load');
  21478. }
  21479. /**
  21480. * Reset the player. Loads the first tech in the techOrder,
  21481. * removes all the text tracks in the existing `tech`,
  21482. * and calls `reset` on the `tech`.
  21483. */
  21484. ;
  21485. _proto.reset = function reset() {
  21486. var _this13 = this;
  21487. var PromiseClass = this.options_.Promise || window$1.Promise;
  21488. if (this.paused() || !PromiseClass) {
  21489. this.doReset_();
  21490. } else {
  21491. var playPromise = this.play();
  21492. silencePromise(playPromise.then(function () {
  21493. return _this13.doReset_();
  21494. }));
  21495. }
  21496. };
  21497. _proto.doReset_ = function doReset_() {
  21498. if (this.tech_) {
  21499. this.tech_.clearTracks('text');
  21500. }
  21501. this.resetCache_();
  21502. this.poster('');
  21503. this.loadTech_(this.options_.techOrder[0], null);
  21504. this.techCall_('reset');
  21505. this.resetControlBarUI_();
  21506. if (isEvented(this)) {
  21507. this.trigger('playerreset');
  21508. }
  21509. }
  21510. /**
  21511. * Reset Control Bar's UI by calling sub-methods that reset
  21512. * all of Control Bar's components
  21513. */
  21514. ;
  21515. _proto.resetControlBarUI_ = function resetControlBarUI_() {
  21516. this.resetProgressBar_();
  21517. this.resetPlaybackRate_();
  21518. this.resetVolumeBar_();
  21519. }
  21520. /**
  21521. * Reset tech's progress so progress bar is reset in the UI
  21522. */
  21523. ;
  21524. _proto.resetProgressBar_ = function resetProgressBar_() {
  21525. this.currentTime(0);
  21526. var _this$controlBar = this.controlBar,
  21527. durationDisplay = _this$controlBar.durationDisplay,
  21528. remainingTimeDisplay = _this$controlBar.remainingTimeDisplay;
  21529. if (durationDisplay) {
  21530. durationDisplay.updateContent();
  21531. }
  21532. if (remainingTimeDisplay) {
  21533. remainingTimeDisplay.updateContent();
  21534. }
  21535. }
  21536. /**
  21537. * Reset Playback ratio
  21538. */
  21539. ;
  21540. _proto.resetPlaybackRate_ = function resetPlaybackRate_() {
  21541. this.playbackRate(this.defaultPlaybackRate());
  21542. this.handleTechRateChange_();
  21543. }
  21544. /**
  21545. * Reset Volume bar
  21546. */
  21547. ;
  21548. _proto.resetVolumeBar_ = function resetVolumeBar_() {
  21549. this.volume(1.0);
  21550. this.trigger('volumechange');
  21551. }
  21552. /**
  21553. * Returns all of the current source objects.
  21554. *
  21555. * @return {Tech~SourceObject[]}
  21556. * The current source objects
  21557. */
  21558. ;
  21559. _proto.currentSources = function currentSources() {
  21560. var source = this.currentSource();
  21561. var sources = []; // assume `{}` or `{ src }`
  21562. if (Object.keys(source).length !== 0) {
  21563. sources.push(source);
  21564. }
  21565. return this.cache_.sources || sources;
  21566. }
  21567. /**
  21568. * Returns the current source object.
  21569. *
  21570. * @return {Tech~SourceObject}
  21571. * The current source object
  21572. */
  21573. ;
  21574. _proto.currentSource = function currentSource() {
  21575. return this.cache_.source || {};
  21576. }
  21577. /**
  21578. * Returns the fully qualified URL of the current source value e.g. http://mysite.com/video.mp4
  21579. * Can be used in conjunction with `currentType` to assist in rebuilding the current source object.
  21580. *
  21581. * @return {string}
  21582. * The current source
  21583. */
  21584. ;
  21585. _proto.currentSrc = function currentSrc() {
  21586. return this.currentSource() && this.currentSource().src || '';
  21587. }
  21588. /**
  21589. * Get the current source type e.g. video/mp4
  21590. * This can allow you rebuild the current source object so that you could load the same
  21591. * source and tech later
  21592. *
  21593. * @return {string}
  21594. * The source MIME type
  21595. */
  21596. ;
  21597. _proto.currentType = function currentType() {
  21598. return this.currentSource() && this.currentSource().type || '';
  21599. }
  21600. /**
  21601. * Get or set the preload attribute
  21602. *
  21603. * @param {boolean} [value]
  21604. * - true means that we should preload
  21605. * - false means that we should not preload
  21606. *
  21607. * @return {string}
  21608. * The preload attribute value when getting
  21609. */
  21610. ;
  21611. _proto.preload = function preload(value) {
  21612. if (value !== undefined) {
  21613. this.techCall_('setPreload', value);
  21614. this.options_.preload = value;
  21615. return;
  21616. }
  21617. return this.techGet_('preload');
  21618. }
  21619. /**
  21620. * Get or set the autoplay option. When this is a boolean it will
  21621. * modify the attribute on the tech. When this is a string the attribute on
  21622. * the tech will be removed and `Player` will handle autoplay on loadstarts.
  21623. *
  21624. * @param {boolean|string} [value]
  21625. * - true: autoplay using the browser behavior
  21626. * - false: do not autoplay
  21627. * - 'play': call play() on every loadstart
  21628. * - 'muted': call muted() then play() on every loadstart
  21629. * - 'any': call play() on every loadstart. if that fails call muted() then play().
  21630. * - *: values other than those listed here will be set `autoplay` to true
  21631. *
  21632. * @return {boolean|string}
  21633. * The current value of autoplay when getting
  21634. */
  21635. ;
  21636. _proto.autoplay = function autoplay(value) {
  21637. // getter usage
  21638. if (value === undefined) {
  21639. return this.options_.autoplay || false;
  21640. }
  21641. var techAutoplay; // if the value is a valid string set it to that
  21642. if (typeof value === 'string' && /(any|play|muted)/.test(value)) {
  21643. this.options_.autoplay = value;
  21644. this.manualAutoplay_(value);
  21645. techAutoplay = false; // any falsy value sets autoplay to false in the browser,
  21646. // lets do the same
  21647. } else if (!value) {
  21648. this.options_.autoplay = false; // any other value (ie truthy) sets autoplay to true
  21649. } else {
  21650. this.options_.autoplay = true;
  21651. }
  21652. techAutoplay = typeof techAutoplay === 'undefined' ? this.options_.autoplay : techAutoplay; // if we don't have a tech then we do not queue up
  21653. // a setAutoplay call on tech ready. We do this because the
  21654. // autoplay option will be passed in the constructor and we
  21655. // do not need to set it twice
  21656. if (this.tech_) {
  21657. this.techCall_('setAutoplay', techAutoplay);
  21658. }
  21659. }
  21660. /**
  21661. * Set or unset the playsinline attribute.
  21662. * Playsinline tells the browser that non-fullscreen playback is preferred.
  21663. *
  21664. * @param {boolean} [value]
  21665. * - true means that we should try to play inline by default
  21666. * - false means that we should use the browser's default playback mode,
  21667. * which in most cases is inline. iOS Safari is a notable exception
  21668. * and plays fullscreen by default.
  21669. *
  21670. * @return {string|Player}
  21671. * - the current value of playsinline
  21672. * - the player when setting
  21673. *
  21674. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  21675. */
  21676. ;
  21677. _proto.playsinline = function playsinline(value) {
  21678. if (value !== undefined) {
  21679. this.techCall_('setPlaysinline', value);
  21680. this.options_.playsinline = value;
  21681. return this;
  21682. }
  21683. return this.techGet_('playsinline');
  21684. }
  21685. /**
  21686. * Get or set the loop attribute on the video element.
  21687. *
  21688. * @param {boolean} [value]
  21689. * - true means that we should loop the video
  21690. * - false means that we should not loop the video
  21691. *
  21692. * @return {boolean}
  21693. * The current value of loop when getting
  21694. */
  21695. ;
  21696. _proto.loop = function loop(value) {
  21697. if (value !== undefined) {
  21698. this.techCall_('setLoop', value);
  21699. this.options_.loop = value;
  21700. return;
  21701. }
  21702. return this.techGet_('loop');
  21703. }
  21704. /**
  21705. * Get or set the poster image source url
  21706. *
  21707. * @fires Player#posterchange
  21708. *
  21709. * @param {string} [src]
  21710. * Poster image source URL
  21711. *
  21712. * @return {string}
  21713. * The current value of poster when getting
  21714. */
  21715. ;
  21716. _proto.poster = function poster(src) {
  21717. if (src === undefined) {
  21718. return this.poster_;
  21719. } // The correct way to remove a poster is to set as an empty string
  21720. // other falsey values will throw errors
  21721. if (!src) {
  21722. src = '';
  21723. }
  21724. if (src === this.poster_) {
  21725. return;
  21726. } // update the internal poster variable
  21727. this.poster_ = src; // update the tech's poster
  21728. this.techCall_('setPoster', src);
  21729. this.isPosterFromTech_ = false; // alert components that the poster has been set
  21730. /**
  21731. * This event fires when the poster image is changed on the player.
  21732. *
  21733. * @event Player#posterchange
  21734. * @type {EventTarget~Event}
  21735. */
  21736. this.trigger('posterchange');
  21737. }
  21738. /**
  21739. * Some techs (e.g. YouTube) can provide a poster source in an
  21740. * asynchronous way. We want the poster component to use this
  21741. * poster source so that it covers up the tech's controls.
  21742. * (YouTube's play button). However we only want to use this
  21743. * source if the player user hasn't set a poster through
  21744. * the normal APIs.
  21745. *
  21746. * @fires Player#posterchange
  21747. * @listens Tech#posterchange
  21748. * @private
  21749. */
  21750. ;
  21751. _proto.handleTechPosterChange_ = function handleTechPosterChange_() {
  21752. if ((!this.poster_ || this.options_.techCanOverridePoster) && this.tech_ && this.tech_.poster) {
  21753. var newPoster = this.tech_.poster() || '';
  21754. if (newPoster !== this.poster_) {
  21755. this.poster_ = newPoster;
  21756. this.isPosterFromTech_ = true; // Let components know the poster has changed
  21757. this.trigger('posterchange');
  21758. }
  21759. }
  21760. }
  21761. /**
  21762. * Get or set whether or not the controls are showing.
  21763. *
  21764. * @fires Player#controlsenabled
  21765. *
  21766. * @param {boolean} [bool]
  21767. * - true to turn controls on
  21768. * - false to turn controls off
  21769. *
  21770. * @return {boolean}
  21771. * The current value of controls when getting
  21772. */
  21773. ;
  21774. _proto.controls = function controls(bool) {
  21775. if (bool === undefined) {
  21776. return !!this.controls_;
  21777. }
  21778. bool = !!bool; // Don't trigger a change event unless it actually changed
  21779. if (this.controls_ === bool) {
  21780. return;
  21781. }
  21782. this.controls_ = bool;
  21783. if (this.usingNativeControls()) {
  21784. this.techCall_('setControls', bool);
  21785. }
  21786. if (this.controls_) {
  21787. this.removeClass('vjs-controls-disabled');
  21788. this.addClass('vjs-controls-enabled');
  21789. /**
  21790. * @event Player#controlsenabled
  21791. * @type {EventTarget~Event}
  21792. */
  21793. this.trigger('controlsenabled');
  21794. if (!this.usingNativeControls()) {
  21795. this.addTechControlsListeners_();
  21796. }
  21797. } else {
  21798. this.removeClass('vjs-controls-enabled');
  21799. this.addClass('vjs-controls-disabled');
  21800. /**
  21801. * @event Player#controlsdisabled
  21802. * @type {EventTarget~Event}
  21803. */
  21804. this.trigger('controlsdisabled');
  21805. if (!this.usingNativeControls()) {
  21806. this.removeTechControlsListeners_();
  21807. }
  21808. }
  21809. }
  21810. /**
  21811. * Toggle native controls on/off. Native controls are the controls built into
  21812. * devices (e.g. default iPhone controls), Flash, or other techs
  21813. * (e.g. Vimeo Controls)
  21814. * **This should only be set by the current tech, because only the tech knows
  21815. * if it can support native controls**
  21816. *
  21817. * @fires Player#usingnativecontrols
  21818. * @fires Player#usingcustomcontrols
  21819. *
  21820. * @param {boolean} [bool]
  21821. * - true to turn native controls on
  21822. * - false to turn native controls off
  21823. *
  21824. * @return {boolean}
  21825. * The current value of native controls when getting
  21826. */
  21827. ;
  21828. _proto.usingNativeControls = function usingNativeControls(bool) {
  21829. if (bool === undefined) {
  21830. return !!this.usingNativeControls_;
  21831. }
  21832. bool = !!bool; // Don't trigger a change event unless it actually changed
  21833. if (this.usingNativeControls_ === bool) {
  21834. return;
  21835. }
  21836. this.usingNativeControls_ = bool;
  21837. if (this.usingNativeControls_) {
  21838. this.addClass('vjs-using-native-controls');
  21839. /**
  21840. * player is using the native device controls
  21841. *
  21842. * @event Player#usingnativecontrols
  21843. * @type {EventTarget~Event}
  21844. */
  21845. this.trigger('usingnativecontrols');
  21846. } else {
  21847. this.removeClass('vjs-using-native-controls');
  21848. /**
  21849. * player is using the custom HTML controls
  21850. *
  21851. * @event Player#usingcustomcontrols
  21852. * @type {EventTarget~Event}
  21853. */
  21854. this.trigger('usingcustomcontrols');
  21855. }
  21856. }
  21857. /**
  21858. * Set or get the current MediaError
  21859. *
  21860. * @fires Player#error
  21861. *
  21862. * @param {MediaError|string|number} [err]
  21863. * A MediaError or a string/number to be turned
  21864. * into a MediaError
  21865. *
  21866. * @return {MediaError|null}
  21867. * The current MediaError when getting (or null)
  21868. */
  21869. ;
  21870. _proto.error = function error(err) {
  21871. if (err === undefined) {
  21872. return this.error_ || null;
  21873. } // Suppress the first error message for no compatible source until
  21874. // user interaction
  21875. if (this.options_.suppressNotSupportedError && err && err.message && err.message === this.localize(this.options_.notSupportedMessage)) {
  21876. var triggerSuppressedError = function triggerSuppressedError() {
  21877. this.error(err);
  21878. };
  21879. this.options_.suppressNotSupportedError = false;
  21880. this.any(['click', 'touchstart'], triggerSuppressedError);
  21881. this.one('loadstart', function () {
  21882. this.off(['click', 'touchstart'], triggerSuppressedError);
  21883. });
  21884. return;
  21885. } // restoring to default
  21886. if (err === null) {
  21887. this.error_ = err;
  21888. this.removeClass('vjs-error');
  21889. if (this.errorDisplay) {
  21890. this.errorDisplay.close();
  21891. }
  21892. return;
  21893. }
  21894. this.error_ = new MediaError(err); // add the vjs-error classname to the player
  21895. this.addClass('vjs-error'); // log the name of the error type and any message
  21896. // IE11 logs "[object object]" and required you to expand message to see error object
  21897. log.error("(CODE:" + this.error_.code + " " + MediaError.errorTypes[this.error_.code] + ")", this.error_.message, this.error_);
  21898. /**
  21899. * @event Player#error
  21900. * @type {EventTarget~Event}
  21901. */
  21902. this.trigger('error');
  21903. return;
  21904. }
  21905. /**
  21906. * Report user activity
  21907. *
  21908. * @param {Object} event
  21909. * Event object
  21910. */
  21911. ;
  21912. _proto.reportUserActivity = function reportUserActivity(event) {
  21913. this.userActivity_ = true;
  21914. }
  21915. /**
  21916. * Get/set if user is active
  21917. *
  21918. * @fires Player#useractive
  21919. * @fires Player#userinactive
  21920. *
  21921. * @param {boolean} [bool]
  21922. * - true if the user is active
  21923. * - false if the user is inactive
  21924. *
  21925. * @return {boolean}
  21926. * The current value of userActive when getting
  21927. */
  21928. ;
  21929. _proto.userActive = function userActive(bool) {
  21930. if (bool === undefined) {
  21931. return this.userActive_;
  21932. }
  21933. bool = !!bool;
  21934. if (bool === this.userActive_) {
  21935. return;
  21936. }
  21937. this.userActive_ = bool;
  21938. if (this.userActive_) {
  21939. this.userActivity_ = true;
  21940. this.removeClass('vjs-user-inactive');
  21941. this.addClass('vjs-user-active');
  21942. /**
  21943. * @event Player#useractive
  21944. * @type {EventTarget~Event}
  21945. */
  21946. this.trigger('useractive');
  21947. return;
  21948. } // Chrome/Safari/IE have bugs where when you change the cursor it can
  21949. // trigger a mousemove event. This causes an issue when you're hiding
  21950. // the cursor when the user is inactive, and a mousemove signals user
  21951. // activity. Making it impossible to go into inactive mode. Specifically
  21952. // this happens in fullscreen when we really need to hide the cursor.
  21953. //
  21954. // When this gets resolved in ALL browsers it can be removed
  21955. // https://code.google.com/p/chromium/issues/detail?id=103041
  21956. if (this.tech_) {
  21957. this.tech_.one('mousemove', function (e) {
  21958. e.stopPropagation();
  21959. e.preventDefault();
  21960. });
  21961. }
  21962. this.userActivity_ = false;
  21963. this.removeClass('vjs-user-active');
  21964. this.addClass('vjs-user-inactive');
  21965. /**
  21966. * @event Player#userinactive
  21967. * @type {EventTarget~Event}
  21968. */
  21969. this.trigger('userinactive');
  21970. }
  21971. /**
  21972. * Listen for user activity based on timeout value
  21973. *
  21974. * @private
  21975. */
  21976. ;
  21977. _proto.listenForUserActivity_ = function listenForUserActivity_() {
  21978. var mouseInProgress;
  21979. var lastMoveX;
  21980. var lastMoveY;
  21981. var handleActivity = bind(this, this.reportUserActivity);
  21982. var handleMouseMove = function handleMouseMove(e) {
  21983. // #1068 - Prevent mousemove spamming
  21984. // Chrome Bug: https://code.google.com/p/chromium/issues/detail?id=366970
  21985. if (e.screenX !== lastMoveX || e.screenY !== lastMoveY) {
  21986. lastMoveX = e.screenX;
  21987. lastMoveY = e.screenY;
  21988. handleActivity();
  21989. }
  21990. };
  21991. var handleMouseDown = function handleMouseDown() {
  21992. handleActivity(); // For as long as the they are touching the device or have their mouse down,
  21993. // we consider them active even if they're not moving their finger or mouse.
  21994. // So we want to continue to update that they are active
  21995. this.clearInterval(mouseInProgress); // Setting userActivity=true now and setting the interval to the same time
  21996. // as the activityCheck interval (250) should ensure we never miss the
  21997. // next activityCheck
  21998. mouseInProgress = this.setInterval(handleActivity, 250);
  21999. };
  22000. var handleMouseUp = function handleMouseUp(event) {
  22001. handleActivity(); // Stop the interval that maintains activity if the mouse/touch is down
  22002. this.clearInterval(mouseInProgress);
  22003. }; // Any mouse movement will be considered user activity
  22004. this.on('mousedown', handleMouseDown);
  22005. this.on('mousemove', handleMouseMove);
  22006. this.on('mouseup', handleMouseUp);
  22007. var controlBar = this.getChild('controlBar'); // Fixes bug on Android & iOS where when tapping progressBar (when control bar is displayed)
  22008. // controlBar would no longer be hidden by default timeout.
  22009. if (controlBar && !IS_IOS && !IS_ANDROID) {
  22010. controlBar.on('mouseenter', function (event) {
  22011. this.player().cache_.inactivityTimeout = this.player().options_.inactivityTimeout;
  22012. this.player().options_.inactivityTimeout = 0;
  22013. });
  22014. controlBar.on('mouseleave', function (event) {
  22015. this.player().options_.inactivityTimeout = this.player().cache_.inactivityTimeout;
  22016. });
  22017. } // Listen for keyboard navigation
  22018. // Shouldn't need to use inProgress interval because of key repeat
  22019. this.on('keydown', handleActivity);
  22020. this.on('keyup', handleActivity); // Run an interval every 250 milliseconds instead of stuffing everything into
  22021. // the mousemove/touchmove function itself, to prevent performance degradation.
  22022. // `this.reportUserActivity` simply sets this.userActivity_ to true, which
  22023. // then gets picked up by this loop
  22024. // http://ejohn.org/blog/learning-from-twitter/
  22025. var inactivityTimeout;
  22026. this.setInterval(function () {
  22027. // Check to see if mouse/touch activity has happened
  22028. if (!this.userActivity_) {
  22029. return;
  22030. } // Reset the activity tracker
  22031. this.userActivity_ = false; // If the user state was inactive, set the state to active
  22032. this.userActive(true); // Clear any existing inactivity timeout to start the timer over
  22033. this.clearTimeout(inactivityTimeout);
  22034. var timeout = this.options_.inactivityTimeout;
  22035. if (timeout <= 0) {
  22036. return;
  22037. } // In <timeout> milliseconds, if no more activity has occurred the
  22038. // user will be considered inactive
  22039. inactivityTimeout = this.setTimeout(function () {
  22040. // Protect against the case where the inactivityTimeout can trigger just
  22041. // before the next user activity is picked up by the activity check loop
  22042. // causing a flicker
  22043. if (!this.userActivity_) {
  22044. this.userActive(false);
  22045. }
  22046. }, timeout);
  22047. }, 250);
  22048. }
  22049. /**
  22050. * Gets or sets the current playback rate. A playback rate of
  22051. * 1.0 represents normal speed and 0.5 would indicate half-speed
  22052. * playback, for instance.
  22053. *
  22054. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-playbackrate
  22055. *
  22056. * @param {number} [rate]
  22057. * New playback rate to set.
  22058. *
  22059. * @return {number}
  22060. * The current playback rate when getting or 1.0
  22061. */
  22062. ;
  22063. _proto.playbackRate = function playbackRate(rate) {
  22064. if (rate !== undefined) {
  22065. // NOTE: this.cache_.lastPlaybackRate is set from the tech handler
  22066. // that is registered above
  22067. this.techCall_('setPlaybackRate', rate);
  22068. return;
  22069. }
  22070. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  22071. return this.cache_.lastPlaybackRate || this.techGet_('playbackRate');
  22072. }
  22073. return 1.0;
  22074. }
  22075. /**
  22076. * Gets or sets the current default playback rate. A default playback rate of
  22077. * 1.0 represents normal speed and 0.5 would indicate half-speed playback, for instance.
  22078. * defaultPlaybackRate will only represent what the initial playbackRate of a video was, not
  22079. * not the current playbackRate.
  22080. *
  22081. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-defaultplaybackrate
  22082. *
  22083. * @param {number} [rate]
  22084. * New default playback rate to set.
  22085. *
  22086. * @return {number|Player}
  22087. * - The default playback rate when getting or 1.0
  22088. * - the player when setting
  22089. */
  22090. ;
  22091. _proto.defaultPlaybackRate = function defaultPlaybackRate(rate) {
  22092. if (rate !== undefined) {
  22093. return this.techCall_('setDefaultPlaybackRate', rate);
  22094. }
  22095. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  22096. return this.techGet_('defaultPlaybackRate');
  22097. }
  22098. return 1.0;
  22099. }
  22100. /**
  22101. * Gets or sets the audio flag
  22102. *
  22103. * @param {boolean} bool
  22104. * - true signals that this is an audio player
  22105. * - false signals that this is not an audio player
  22106. *
  22107. * @return {boolean}
  22108. * The current value of isAudio when getting
  22109. */
  22110. ;
  22111. _proto.isAudio = function isAudio(bool) {
  22112. if (bool !== undefined) {
  22113. this.isAudio_ = !!bool;
  22114. return;
  22115. }
  22116. return !!this.isAudio_;
  22117. }
  22118. /**
  22119. * A helper method for adding a {@link TextTrack} to our
  22120. * {@link TextTrackList}.
  22121. *
  22122. * In addition to the W3C settings we allow adding additional info through options.
  22123. *
  22124. * @see http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-addtexttrack
  22125. *
  22126. * @param {string} [kind]
  22127. * the kind of TextTrack you are adding
  22128. *
  22129. * @param {string} [label]
  22130. * the label to give the TextTrack label
  22131. *
  22132. * @param {string} [language]
  22133. * the language to set on the TextTrack
  22134. *
  22135. * @return {TextTrack|undefined}
  22136. * the TextTrack that was added or undefined
  22137. * if there is no tech
  22138. */
  22139. ;
  22140. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  22141. if (this.tech_) {
  22142. return this.tech_.addTextTrack(kind, label, language);
  22143. }
  22144. }
  22145. /**
  22146. * Create a remote {@link TextTrack} and an {@link HTMLTrackElement}. It will
  22147. * automatically removed from the video element whenever the source changes, unless
  22148. * manualCleanup is set to false.
  22149. *
  22150. * @param {Object} options
  22151. * Options to pass to {@link HTMLTrackElement} during creation. See
  22152. * {@link HTMLTrackElement} for object properties that you should use.
  22153. *
  22154. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  22155. *
  22156. * @return {HtmlTrackElement}
  22157. * the HTMLTrackElement that was created and added
  22158. * to the HtmlTrackElementList and the remote
  22159. * TextTrackList
  22160. *
  22161. * @deprecated The default value of the "manualCleanup" parameter will default
  22162. * to "false" in upcoming versions of Video.js
  22163. */
  22164. ;
  22165. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  22166. if (this.tech_) {
  22167. return this.tech_.addRemoteTextTrack(options, manualCleanup);
  22168. }
  22169. }
  22170. /**
  22171. * Remove a remote {@link TextTrack} from the respective
  22172. * {@link TextTrackList} and {@link HtmlTrackElementList}.
  22173. *
  22174. * @param {Object} track
  22175. * Remote {@link TextTrack} to remove
  22176. *
  22177. * @return {undefined}
  22178. * does not return anything
  22179. */
  22180. ;
  22181. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(obj) {
  22182. if (obj === void 0) {
  22183. obj = {};
  22184. }
  22185. var _obj = obj,
  22186. track = _obj.track;
  22187. if (!track) {
  22188. track = obj;
  22189. } // destructure the input into an object with a track argument, defaulting to arguments[0]
  22190. // default the whole argument to an empty object if nothing was passed in
  22191. if (this.tech_) {
  22192. return this.tech_.removeRemoteTextTrack(track);
  22193. }
  22194. }
  22195. /**
  22196. * Gets available media playback quality metrics as specified by the W3C's Media
  22197. * Playback Quality API.
  22198. *
  22199. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  22200. *
  22201. * @return {Object|undefined}
  22202. * An object with supported media playback quality metrics or undefined if there
  22203. * is no tech or the tech does not support it.
  22204. */
  22205. ;
  22206. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  22207. return this.techGet_('getVideoPlaybackQuality');
  22208. }
  22209. /**
  22210. * Get video width
  22211. *
  22212. * @return {number}
  22213. * current video width
  22214. */
  22215. ;
  22216. _proto.videoWidth = function videoWidth() {
  22217. return this.tech_ && this.tech_.videoWidth && this.tech_.videoWidth() || 0;
  22218. }
  22219. /**
  22220. * Get video height
  22221. *
  22222. * @return {number}
  22223. * current video height
  22224. */
  22225. ;
  22226. _proto.videoHeight = function videoHeight() {
  22227. return this.tech_ && this.tech_.videoHeight && this.tech_.videoHeight() || 0;
  22228. }
  22229. /**
  22230. * The player's language code
  22231. * NOTE: The language should be set in the player options if you want the
  22232. * the controls to be built with a specific language. Changing the language
  22233. * later will not update controls text.
  22234. *
  22235. * @param {string} [code]
  22236. * the language code to set the player to
  22237. *
  22238. * @return {string}
  22239. * The current language code when getting
  22240. */
  22241. ;
  22242. _proto.language = function language(code) {
  22243. if (code === undefined) {
  22244. return this.language_;
  22245. }
  22246. this.language_ = String(code).toLowerCase();
  22247. }
  22248. /**
  22249. * Get the player's language dictionary
  22250. * Merge every time, because a newly added plugin might call videojs.addLanguage() at any time
  22251. * Languages specified directly in the player options have precedence
  22252. *
  22253. * @return {Array}
  22254. * An array of of supported languages
  22255. */
  22256. ;
  22257. _proto.languages = function languages() {
  22258. return mergeOptions(Player.prototype.options_.languages, this.languages_);
  22259. }
  22260. /**
  22261. * returns a JavaScript object reperesenting the current track
  22262. * information. **DOES not return it as JSON**
  22263. *
  22264. * @return {Object}
  22265. * Object representing the current of track info
  22266. */
  22267. ;
  22268. _proto.toJSON = function toJSON() {
  22269. var options = mergeOptions(this.options_);
  22270. var tracks = options.tracks;
  22271. options.tracks = [];
  22272. for (var i = 0; i < tracks.length; i++) {
  22273. var track = tracks[i]; // deep merge tracks and null out player so no circular references
  22274. track = mergeOptions(track);
  22275. track.player = undefined;
  22276. options.tracks[i] = track;
  22277. }
  22278. return options;
  22279. }
  22280. /**
  22281. * Creates a simple modal dialog (an instance of the {@link ModalDialog}
  22282. * component) that immediately overlays the player with arbitrary
  22283. * content and removes itself when closed.
  22284. *
  22285. * @param {string|Function|Element|Array|null} content
  22286. * Same as {@link ModalDialog#content}'s param of the same name.
  22287. * The most straight-forward usage is to provide a string or DOM
  22288. * element.
  22289. *
  22290. * @param {Object} [options]
  22291. * Extra options which will be passed on to the {@link ModalDialog}.
  22292. *
  22293. * @return {ModalDialog}
  22294. * the {@link ModalDialog} that was created
  22295. */
  22296. ;
  22297. _proto.createModal = function createModal(content, options) {
  22298. var _this14 = this;
  22299. options = options || {};
  22300. options.content = content || '';
  22301. var modal = new ModalDialog(this, options);
  22302. this.addChild(modal);
  22303. modal.on('dispose', function () {
  22304. _this14.removeChild(modal);
  22305. });
  22306. modal.open();
  22307. return modal;
  22308. }
  22309. /**
  22310. * Change breakpoint classes when the player resizes.
  22311. *
  22312. * @private
  22313. */
  22314. ;
  22315. _proto.updateCurrentBreakpoint_ = function updateCurrentBreakpoint_() {
  22316. if (!this.responsive()) {
  22317. return;
  22318. }
  22319. var currentBreakpoint = this.currentBreakpoint();
  22320. var currentWidth = this.currentWidth();
  22321. for (var i = 0; i < BREAKPOINT_ORDER.length; i++) {
  22322. var candidateBreakpoint = BREAKPOINT_ORDER[i];
  22323. var maxWidth = this.breakpoints_[candidateBreakpoint];
  22324. if (currentWidth <= maxWidth) {
  22325. // The current breakpoint did not change, nothing to do.
  22326. if (currentBreakpoint === candidateBreakpoint) {
  22327. return;
  22328. } // Only remove a class if there is a current breakpoint.
  22329. if (currentBreakpoint) {
  22330. this.removeClass(BREAKPOINT_CLASSES[currentBreakpoint]);
  22331. }
  22332. this.addClass(BREAKPOINT_CLASSES[candidateBreakpoint]);
  22333. this.breakpoint_ = candidateBreakpoint;
  22334. break;
  22335. }
  22336. }
  22337. }
  22338. /**
  22339. * Removes the current breakpoint.
  22340. *
  22341. * @private
  22342. */
  22343. ;
  22344. _proto.removeCurrentBreakpoint_ = function removeCurrentBreakpoint_() {
  22345. var className = this.currentBreakpointClass();
  22346. this.breakpoint_ = '';
  22347. if (className) {
  22348. this.removeClass(className);
  22349. }
  22350. }
  22351. /**
  22352. * Get or set breakpoints on the player.
  22353. *
  22354. * Calling this method with an object or `true` will remove any previous
  22355. * custom breakpoints and start from the defaults again.
  22356. *
  22357. * @param {Object|boolean} [breakpoints]
  22358. * If an object is given, it can be used to provide custom
  22359. * breakpoints. If `true` is given, will set default breakpoints.
  22360. * If this argument is not given, will simply return the current
  22361. * breakpoints.
  22362. *
  22363. * @param {number} [breakpoints.tiny]
  22364. * The maximum width for the "vjs-layout-tiny" class.
  22365. *
  22366. * @param {number} [breakpoints.xsmall]
  22367. * The maximum width for the "vjs-layout-x-small" class.
  22368. *
  22369. * @param {number} [breakpoints.small]
  22370. * The maximum width for the "vjs-layout-small" class.
  22371. *
  22372. * @param {number} [breakpoints.medium]
  22373. * The maximum width for the "vjs-layout-medium" class.
  22374. *
  22375. * @param {number} [breakpoints.large]
  22376. * The maximum width for the "vjs-layout-large" class.
  22377. *
  22378. * @param {number} [breakpoints.xlarge]
  22379. * The maximum width for the "vjs-layout-x-large" class.
  22380. *
  22381. * @param {number} [breakpoints.huge]
  22382. * The maximum width for the "vjs-layout-huge" class.
  22383. *
  22384. * @return {Object}
  22385. * An object mapping breakpoint names to maximum width values.
  22386. */
  22387. ;
  22388. _proto.breakpoints = function breakpoints(_breakpoints) {
  22389. // Used as a getter.
  22390. if (_breakpoints === undefined) {
  22391. return assign(this.breakpoints_);
  22392. }
  22393. this.breakpoint_ = '';
  22394. this.breakpoints_ = assign({}, DEFAULT_BREAKPOINTS, _breakpoints); // When breakpoint definitions change, we need to update the currently
  22395. // selected breakpoint.
  22396. this.updateCurrentBreakpoint_(); // Clone the breakpoints before returning.
  22397. return assign(this.breakpoints_);
  22398. }
  22399. /**
  22400. * Get or set a flag indicating whether or not this player should adjust
  22401. * its UI based on its dimensions.
  22402. *
  22403. * @param {boolean} value
  22404. * Should be `true` if the player should adjust its UI based on its
  22405. * dimensions; otherwise, should be `false`.
  22406. *
  22407. * @return {boolean}
  22408. * Will be `true` if this player should adjust its UI based on its
  22409. * dimensions; otherwise, will be `false`.
  22410. */
  22411. ;
  22412. _proto.responsive = function responsive(value) {
  22413. // Used as a getter.
  22414. if (value === undefined) {
  22415. return this.responsive_;
  22416. }
  22417. value = Boolean(value);
  22418. var current = this.responsive_; // Nothing changed.
  22419. if (value === current) {
  22420. return;
  22421. } // The value actually changed, set it.
  22422. this.responsive_ = value; // Start listening for breakpoints and set the initial breakpoint if the
  22423. // player is now responsive.
  22424. if (value) {
  22425. this.on('playerresize', this.updateCurrentBreakpoint_);
  22426. this.updateCurrentBreakpoint_(); // Stop listening for breakpoints if the player is no longer responsive.
  22427. } else {
  22428. this.off('playerresize', this.updateCurrentBreakpoint_);
  22429. this.removeCurrentBreakpoint_();
  22430. }
  22431. return value;
  22432. }
  22433. /**
  22434. * Get current breakpoint name, if any.
  22435. *
  22436. * @return {string}
  22437. * If there is currently a breakpoint set, returns a the key from the
  22438. * breakpoints object matching it. Otherwise, returns an empty string.
  22439. */
  22440. ;
  22441. _proto.currentBreakpoint = function currentBreakpoint() {
  22442. return this.breakpoint_;
  22443. }
  22444. /**
  22445. * Get the current breakpoint class name.
  22446. *
  22447. * @return {string}
  22448. * The matching class name (e.g. `"vjs-layout-tiny"` or
  22449. * `"vjs-layout-large"`) for the current breakpoint. Empty string if
  22450. * there is no current breakpoint.
  22451. */
  22452. ;
  22453. _proto.currentBreakpointClass = function currentBreakpointClass() {
  22454. return BREAKPOINT_CLASSES[this.breakpoint_] || '';
  22455. }
  22456. /**
  22457. * An object that describes a single piece of media.
  22458. *
  22459. * Properties that are not part of this type description will be retained; so,
  22460. * this can be viewed as a generic metadata storage mechanism as well.
  22461. *
  22462. * @see {@link https://wicg.github.io/mediasession/#the-mediametadata-interface}
  22463. * @typedef {Object} Player~MediaObject
  22464. *
  22465. * @property {string} [album]
  22466. * Unused, except if this object is passed to the `MediaSession`
  22467. * API.
  22468. *
  22469. * @property {string} [artist]
  22470. * Unused, except if this object is passed to the `MediaSession`
  22471. * API.
  22472. *
  22473. * @property {Object[]} [artwork]
  22474. * Unused, except if this object is passed to the `MediaSession`
  22475. * API. If not specified, will be populated via the `poster`, if
  22476. * available.
  22477. *
  22478. * @property {string} [poster]
  22479. * URL to an image that will display before playback.
  22480. *
  22481. * @property {Tech~SourceObject|Tech~SourceObject[]|string} [src]
  22482. * A single source object, an array of source objects, or a string
  22483. * referencing a URL to a media source. It is _highly recommended_
  22484. * that an object or array of objects is used here, so that source
  22485. * selection algorithms can take the `type` into account.
  22486. *
  22487. * @property {string} [title]
  22488. * Unused, except if this object is passed to the `MediaSession`
  22489. * API.
  22490. *
  22491. * @property {Object[]} [textTracks]
  22492. * An array of objects to be used to create text tracks, following
  22493. * the {@link https://www.w3.org/TR/html50/embedded-content-0.html#the-track-element|native track element format}.
  22494. * For ease of removal, these will be created as "remote" text
  22495. * tracks and set to automatically clean up on source changes.
  22496. *
  22497. * These objects may have properties like `src`, `kind`, `label`,
  22498. * and `language`, see {@link Tech#createRemoteTextTrack}.
  22499. */
  22500. /**
  22501. * Populate the player using a {@link Player~MediaObject|MediaObject}.
  22502. *
  22503. * @param {Player~MediaObject} media
  22504. * A media object.
  22505. *
  22506. * @param {Function} ready
  22507. * A callback to be called when the player is ready.
  22508. */
  22509. ;
  22510. _proto.loadMedia = function loadMedia(media, ready) {
  22511. var _this15 = this;
  22512. if (!media || typeof media !== 'object') {
  22513. return;
  22514. }
  22515. this.reset(); // Clone the media object so it cannot be mutated from outside.
  22516. this.cache_.media = mergeOptions(media);
  22517. var _this$cache_$media = this.cache_.media,
  22518. artwork = _this$cache_$media.artwork,
  22519. poster = _this$cache_$media.poster,
  22520. src = _this$cache_$media.src,
  22521. textTracks = _this$cache_$media.textTracks; // If `artwork` is not given, create it using `poster`.
  22522. if (!artwork && poster) {
  22523. this.cache_.media.artwork = [{
  22524. src: poster,
  22525. type: getMimetype(poster)
  22526. }];
  22527. }
  22528. if (src) {
  22529. this.src(src);
  22530. }
  22531. if (poster) {
  22532. this.poster(poster);
  22533. }
  22534. if (Array.isArray(textTracks)) {
  22535. textTracks.forEach(function (tt) {
  22536. return _this15.addRemoteTextTrack(tt, false);
  22537. });
  22538. }
  22539. this.ready(ready);
  22540. }
  22541. /**
  22542. * Get a clone of the current {@link Player~MediaObject} for this player.
  22543. *
  22544. * If the `loadMedia` method has not been used, will attempt to return a
  22545. * {@link Player~MediaObject} based on the current state of the player.
  22546. *
  22547. * @return {Player~MediaObject}
  22548. */
  22549. ;
  22550. _proto.getMedia = function getMedia() {
  22551. if (!this.cache_.media) {
  22552. var poster = this.poster();
  22553. var src = this.currentSources();
  22554. var textTracks = Array.prototype.map.call(this.remoteTextTracks(), function (tt) {
  22555. return {
  22556. kind: tt.kind,
  22557. label: tt.label,
  22558. language: tt.language,
  22559. src: tt.src
  22560. };
  22561. });
  22562. var media = {
  22563. src: src,
  22564. textTracks: textTracks
  22565. };
  22566. if (poster) {
  22567. media.poster = poster;
  22568. media.artwork = [{
  22569. src: media.poster,
  22570. type: getMimetype(media.poster)
  22571. }];
  22572. }
  22573. return media;
  22574. }
  22575. return mergeOptions(this.cache_.media);
  22576. }
  22577. /**
  22578. * Gets tag settings
  22579. *
  22580. * @param {Element} tag
  22581. * The player tag
  22582. *
  22583. * @return {Object}
  22584. * An object containing all of the settings
  22585. * for a player tag
  22586. */
  22587. ;
  22588. Player.getTagSettings = function getTagSettings(tag) {
  22589. var baseOptions = {
  22590. sources: [],
  22591. tracks: []
  22592. };
  22593. var tagOptions = getAttributes(tag);
  22594. var dataSetup = tagOptions['data-setup'];
  22595. if (hasClass(tag, 'vjs-fill')) {
  22596. tagOptions.fill = true;
  22597. }
  22598. if (hasClass(tag, 'vjs-fluid')) {
  22599. tagOptions.fluid = true;
  22600. } // Check if data-setup attr exists.
  22601. if (dataSetup !== null) {
  22602. // Parse options JSON
  22603. // If empty string, make it a parsable json object.
  22604. var _safeParseTuple = tuple(dataSetup || '{}'),
  22605. err = _safeParseTuple[0],
  22606. data = _safeParseTuple[1];
  22607. if (err) {
  22608. log.error(err);
  22609. }
  22610. assign(tagOptions, data);
  22611. }
  22612. assign(baseOptions, tagOptions); // Get tag children settings
  22613. if (tag.hasChildNodes()) {
  22614. var children = tag.childNodes;
  22615. for (var i = 0, j = children.length; i < j; i++) {
  22616. var child = children[i]; // Change case needed: http://ejohn.org/blog/nodename-case-sensitivity/
  22617. var childName = child.nodeName.toLowerCase();
  22618. if (childName === 'source') {
  22619. baseOptions.sources.push(getAttributes(child));
  22620. } else if (childName === 'track') {
  22621. baseOptions.tracks.push(getAttributes(child));
  22622. }
  22623. }
  22624. }
  22625. return baseOptions;
  22626. }
  22627. /**
  22628. * Determine whether or not flexbox is supported
  22629. *
  22630. * @return {boolean}
  22631. * - true if flexbox is supported
  22632. * - false if flexbox is not supported
  22633. */
  22634. ;
  22635. _proto.flexNotSupported_ = function flexNotSupported_() {
  22636. var elem = document.createElement('i'); // Note: We don't actually use flexBasis (or flexOrder), but it's one of the more
  22637. // common flex features that we can rely on when checking for flex support.
  22638. return !('flexBasis' in elem.style || 'webkitFlexBasis' in elem.style || 'mozFlexBasis' in elem.style || 'msFlexBasis' in elem.style || // IE10-specific (2012 flex spec), available for completeness
  22639. 'msFlexOrder' in elem.style);
  22640. };
  22641. return Player;
  22642. }(Component);
  22643. /**
  22644. * Get the {@link VideoTrackList}
  22645. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist
  22646. *
  22647. * @return {VideoTrackList}
  22648. * the current video track list
  22649. *
  22650. * @method Player.prototype.videoTracks
  22651. */
  22652. /**
  22653. * Get the {@link AudioTrackList}
  22654. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist
  22655. *
  22656. * @return {AudioTrackList}
  22657. * the current audio track list
  22658. *
  22659. * @method Player.prototype.audioTracks
  22660. */
  22661. /**
  22662. * Get the {@link TextTrackList}
  22663. *
  22664. * @link http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-texttracks
  22665. *
  22666. * @return {TextTrackList}
  22667. * the current text track list
  22668. *
  22669. * @method Player.prototype.textTracks
  22670. */
  22671. /**
  22672. * Get the remote {@link TextTrackList}
  22673. *
  22674. * @return {TextTrackList}
  22675. * The current remote text track list
  22676. *
  22677. * @method Player.prototype.remoteTextTracks
  22678. */
  22679. /**
  22680. * Get the remote {@link HtmlTrackElementList} tracks.
  22681. *
  22682. * @return {HtmlTrackElementList}
  22683. * The current remote text track element list
  22684. *
  22685. * @method Player.prototype.remoteTextTrackEls
  22686. */
  22687. ALL.names.forEach(function (name) {
  22688. var props = ALL[name];
  22689. Player.prototype[props.getterName] = function () {
  22690. if (this.tech_) {
  22691. return this.tech_[props.getterName]();
  22692. } // if we have not yet loadTech_, we create {video,audio,text}Tracks_
  22693. // these will be passed to the tech during loading
  22694. this[props.privateName] = this[props.privateName] || new props.ListClass();
  22695. return this[props.privateName];
  22696. };
  22697. });
  22698. /**
  22699. * Global enumeration of players.
  22700. *
  22701. * The keys are the player IDs and the values are either the {@link Player}
  22702. * instance or `null` for disposed players.
  22703. *
  22704. * @type {Object}
  22705. */
  22706. Player.players = {};
  22707. var navigator = window$1.navigator;
  22708. /*
  22709. * Player instance options, surfaced using options
  22710. * options = Player.prototype.options_
  22711. * Make changes in options, not here.
  22712. *
  22713. * @type {Object}
  22714. * @private
  22715. */
  22716. Player.prototype.options_ = {
  22717. // Default order of fallback technology
  22718. techOrder: Tech.defaultTechOrder_,
  22719. html5: {},
  22720. flash: {},
  22721. // default inactivity timeout
  22722. inactivityTimeout: 2000,
  22723. // default playback rates
  22724. playbackRates: [],
  22725. // Add playback rate selection by adding rates
  22726. // 'playbackRates': [0.5, 1, 1.5, 2],
  22727. liveui: false,
  22728. // Included control sets
  22729. children: ['mediaLoader', 'posterImage', 'textTrackDisplay', 'loadingSpinner', 'bigPlayButton', 'liveTracker', 'controlBar', 'errorDisplay', 'textTrackSettings', 'resizeManager'],
  22730. language: navigator && (navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language) || 'en',
  22731. // locales and their language translations
  22732. languages: {},
  22733. // Default message to show when a video cannot be played.
  22734. notSupportedMessage: 'No compatible source was found for this media.',
  22735. fullscreen: {
  22736. options: {
  22737. navigationUI: 'hide'
  22738. }
  22739. },
  22740. breakpoints: {},
  22741. responsive: false
  22742. };
  22743. [
  22744. /**
  22745. * Returns whether or not the player is in the "ended" state.
  22746. *
  22747. * @return {Boolean} True if the player is in the ended state, false if not.
  22748. * @method Player#ended
  22749. */
  22750. 'ended',
  22751. /**
  22752. * Returns whether or not the player is in the "seeking" state.
  22753. *
  22754. * @return {Boolean} True if the player is in the seeking state, false if not.
  22755. * @method Player#seeking
  22756. */
  22757. 'seeking',
  22758. /**
  22759. * Returns the TimeRanges of the media that are currently available
  22760. * for seeking to.
  22761. *
  22762. * @return {TimeRanges} the seekable intervals of the media timeline
  22763. * @method Player#seekable
  22764. */
  22765. 'seekable',
  22766. /**
  22767. * Returns the current state of network activity for the element, from
  22768. * the codes in the list below.
  22769. * - NETWORK_EMPTY (numeric value 0)
  22770. * The element has not yet been initialised. All attributes are in
  22771. * their initial states.
  22772. * - NETWORK_IDLE (numeric value 1)
  22773. * The element's resource selection algorithm is active and has
  22774. * selected a resource, but it is not actually using the network at
  22775. * this time.
  22776. * - NETWORK_LOADING (numeric value 2)
  22777. * The user agent is actively trying to download data.
  22778. * - NETWORK_NO_SOURCE (numeric value 3)
  22779. * The element's resource selection algorithm is active, but it has
  22780. * not yet found a resource to use.
  22781. *
  22782. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
  22783. * @return {number} the current network activity state
  22784. * @method Player#networkState
  22785. */
  22786. 'networkState',
  22787. /**
  22788. * Returns a value that expresses the current state of the element
  22789. * with respect to rendering the current playback position, from the
  22790. * codes in the list below.
  22791. * - HAVE_NOTHING (numeric value 0)
  22792. * No information regarding the media resource is available.
  22793. * - HAVE_METADATA (numeric value 1)
  22794. * Enough of the resource has been obtained that the duration of the
  22795. * resource is available.
  22796. * - HAVE_CURRENT_DATA (numeric value 2)
  22797. * Data for the immediate current playback position is available.
  22798. * - HAVE_FUTURE_DATA (numeric value 3)
  22799. * Data for the immediate current playback position is available, as
  22800. * well as enough data for the user agent to advance the current
  22801. * playback position in the direction of playback.
  22802. * - HAVE_ENOUGH_DATA (numeric value 4)
  22803. * The user agent estimates that enough data is available for
  22804. * playback to proceed uninterrupted.
  22805. *
  22806. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
  22807. * @return {number} the current playback rendering state
  22808. * @method Player#readyState
  22809. */
  22810. 'readyState'].forEach(function (fn) {
  22811. Player.prototype[fn] = function () {
  22812. return this.techGet_(fn);
  22813. };
  22814. });
  22815. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  22816. Player.prototype["handleTech" + toTitleCase(event) + "_"] = function () {
  22817. return this.trigger(event);
  22818. };
  22819. });
  22820. /**
  22821. * Fired when the player has initial duration and dimension information
  22822. *
  22823. * @event Player#loadedmetadata
  22824. * @type {EventTarget~Event}
  22825. */
  22826. /**
  22827. * Fired when the player has downloaded data at the current playback position
  22828. *
  22829. * @event Player#loadeddata
  22830. * @type {EventTarget~Event}
  22831. */
  22832. /**
  22833. * Fired when the current playback position has changed *
  22834. * During playback this is fired every 15-250 milliseconds, depending on the
  22835. * playback technology in use.
  22836. *
  22837. * @event Player#timeupdate
  22838. * @type {EventTarget~Event}
  22839. */
  22840. /**
  22841. * Fired when the volume changes
  22842. *
  22843. * @event Player#volumechange
  22844. * @type {EventTarget~Event}
  22845. */
  22846. /**
  22847. * Reports whether or not a player has a plugin available.
  22848. *
  22849. * This does not report whether or not the plugin has ever been initialized
  22850. * on this player. For that, [usingPlugin]{@link Player#usingPlugin}.
  22851. *
  22852. * @method Player#hasPlugin
  22853. * @param {string} name
  22854. * The name of a plugin.
  22855. *
  22856. * @return {boolean}
  22857. * Whether or not this player has the requested plugin available.
  22858. */
  22859. /**
  22860. * Reports whether or not a player is using a plugin by name.
  22861. *
  22862. * For basic plugins, this only reports whether the plugin has _ever_ been
  22863. * initialized on this player.
  22864. *
  22865. * @method Player#usingPlugin
  22866. * @param {string} name
  22867. * The name of a plugin.
  22868. *
  22869. * @return {boolean}
  22870. * Whether or not this player is using the requested plugin.
  22871. */
  22872. Component.registerComponent('Player', Player);
  22873. /**
  22874. * The base plugin name.
  22875. *
  22876. * @private
  22877. * @constant
  22878. * @type {string}
  22879. */
  22880. var BASE_PLUGIN_NAME = 'plugin';
  22881. /**
  22882. * The key on which a player's active plugins cache is stored.
  22883. *
  22884. * @private
  22885. * @constant
  22886. * @type {string}
  22887. */
  22888. var PLUGIN_CACHE_KEY = 'activePlugins_';
  22889. /**
  22890. * Stores registered plugins in a private space.
  22891. *
  22892. * @private
  22893. * @type {Object}
  22894. */
  22895. var pluginStorage = {};
  22896. /**
  22897. * Reports whether or not a plugin has been registered.
  22898. *
  22899. * @private
  22900. * @param {string} name
  22901. * The name of a plugin.
  22902. *
  22903. * @return {boolean}
  22904. * Whether or not the plugin has been registered.
  22905. */
  22906. var pluginExists = function pluginExists(name) {
  22907. return pluginStorage.hasOwnProperty(name);
  22908. };
  22909. /**
  22910. * Get a single registered plugin by name.
  22911. *
  22912. * @private
  22913. * @param {string} name
  22914. * The name of a plugin.
  22915. *
  22916. * @return {Function|undefined}
  22917. * The plugin (or undefined).
  22918. */
  22919. var getPlugin = function getPlugin(name) {
  22920. return pluginExists(name) ? pluginStorage[name] : undefined;
  22921. };
  22922. /**
  22923. * Marks a plugin as "active" on a player.
  22924. *
  22925. * Also, ensures that the player has an object for tracking active plugins.
  22926. *
  22927. * @private
  22928. * @param {Player} player
  22929. * A Video.js player instance.
  22930. *
  22931. * @param {string} name
  22932. * The name of a plugin.
  22933. */
  22934. var markPluginAsActive = function markPluginAsActive(player, name) {
  22935. player[PLUGIN_CACHE_KEY] = player[PLUGIN_CACHE_KEY] || {};
  22936. player[PLUGIN_CACHE_KEY][name] = true;
  22937. };
  22938. /**
  22939. * Triggers a pair of plugin setup events.
  22940. *
  22941. * @private
  22942. * @param {Player} player
  22943. * A Video.js player instance.
  22944. *
  22945. * @param {Plugin~PluginEventHash} hash
  22946. * A plugin event hash.
  22947. *
  22948. * @param {boolean} [before]
  22949. * If true, prefixes the event name with "before". In other words,
  22950. * use this to trigger "beforepluginsetup" instead of "pluginsetup".
  22951. */
  22952. var triggerSetupEvent = function triggerSetupEvent(player, hash, before) {
  22953. var eventName = (before ? 'before' : '') + 'pluginsetup';
  22954. player.trigger(eventName, hash);
  22955. player.trigger(eventName + ':' + hash.name, hash);
  22956. };
  22957. /**
  22958. * Takes a basic plugin function and returns a wrapper function which marks
  22959. * on the player that the plugin has been activated.
  22960. *
  22961. * @private
  22962. * @param {string} name
  22963. * The name of the plugin.
  22964. *
  22965. * @param {Function} plugin
  22966. * The basic plugin.
  22967. *
  22968. * @return {Function}
  22969. * A wrapper function for the given plugin.
  22970. */
  22971. var createBasicPlugin = function createBasicPlugin(name, plugin) {
  22972. var basicPluginWrapper = function basicPluginWrapper() {
  22973. // We trigger the "beforepluginsetup" and "pluginsetup" events on the player
  22974. // regardless, but we want the hash to be consistent with the hash provided
  22975. // for advanced plugins.
  22976. //
  22977. // The only potentially counter-intuitive thing here is the `instance` in
  22978. // the "pluginsetup" event is the value returned by the `plugin` function.
  22979. triggerSetupEvent(this, {
  22980. name: name,
  22981. plugin: plugin,
  22982. instance: null
  22983. }, true);
  22984. var instance = plugin.apply(this, arguments);
  22985. markPluginAsActive(this, name);
  22986. triggerSetupEvent(this, {
  22987. name: name,
  22988. plugin: plugin,
  22989. instance: instance
  22990. });
  22991. return instance;
  22992. };
  22993. Object.keys(plugin).forEach(function (prop) {
  22994. basicPluginWrapper[prop] = plugin[prop];
  22995. });
  22996. return basicPluginWrapper;
  22997. };
  22998. /**
  22999. * Takes a plugin sub-class and returns a factory function for generating
  23000. * instances of it.
  23001. *
  23002. * This factory function will replace itself with an instance of the requested
  23003. * sub-class of Plugin.
  23004. *
  23005. * @private
  23006. * @param {string} name
  23007. * The name of the plugin.
  23008. *
  23009. * @param {Plugin} PluginSubClass
  23010. * The advanced plugin.
  23011. *
  23012. * @return {Function}
  23013. */
  23014. var createPluginFactory = function createPluginFactory(name, PluginSubClass) {
  23015. // Add a `name` property to the plugin prototype so that each plugin can
  23016. // refer to itself by name.
  23017. PluginSubClass.prototype.name = name;
  23018. return function () {
  23019. triggerSetupEvent(this, {
  23020. name: name,
  23021. plugin: PluginSubClass,
  23022. instance: null
  23023. }, true);
  23024. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  23025. args[_key] = arguments[_key];
  23026. }
  23027. var instance = _construct(PluginSubClass, [this].concat(args)); // The plugin is replaced by a function that returns the current instance.
  23028. this[name] = function () {
  23029. return instance;
  23030. };
  23031. triggerSetupEvent(this, instance.getEventHash());
  23032. return instance;
  23033. };
  23034. };
  23035. /**
  23036. * Parent class for all advanced plugins.
  23037. *
  23038. * @mixes module:evented~EventedMixin
  23039. * @mixes module:stateful~StatefulMixin
  23040. * @fires Player#beforepluginsetup
  23041. * @fires Player#beforepluginsetup:$name
  23042. * @fires Player#pluginsetup
  23043. * @fires Player#pluginsetup:$name
  23044. * @listens Player#dispose
  23045. * @throws {Error}
  23046. * If attempting to instantiate the base {@link Plugin} class
  23047. * directly instead of via a sub-class.
  23048. */
  23049. var Plugin =
  23050. /*#__PURE__*/
  23051. function () {
  23052. /**
  23053. * Creates an instance of this class.
  23054. *
  23055. * Sub-classes should call `super` to ensure plugins are properly initialized.
  23056. *
  23057. * @param {Player} player
  23058. * A Video.js player instance.
  23059. */
  23060. function Plugin(player) {
  23061. if (this.constructor === Plugin) {
  23062. throw new Error('Plugin must be sub-classed; not directly instantiated.');
  23063. }
  23064. this.player = player; // Make this object evented, but remove the added `trigger` method so we
  23065. // use the prototype version instead.
  23066. evented(this);
  23067. delete this.trigger;
  23068. stateful(this, this.constructor.defaultState);
  23069. markPluginAsActive(player, this.name); // Auto-bind the dispose method so we can use it as a listener and unbind
  23070. // it later easily.
  23071. this.dispose = bind(this, this.dispose); // If the player is disposed, dispose the plugin.
  23072. player.on('dispose', this.dispose);
  23073. }
  23074. /**
  23075. * Get the version of the plugin that was set on <pluginName>.VERSION
  23076. */
  23077. var _proto = Plugin.prototype;
  23078. _proto.version = function version() {
  23079. return this.constructor.VERSION;
  23080. }
  23081. /**
  23082. * Each event triggered by plugins includes a hash of additional data with
  23083. * conventional properties.
  23084. *
  23085. * This returns that object or mutates an existing hash.
  23086. *
  23087. * @param {Object} [hash={}]
  23088. * An object to be used as event an event hash.
  23089. *
  23090. * @return {Plugin~PluginEventHash}
  23091. * An event hash object with provided properties mixed-in.
  23092. */
  23093. ;
  23094. _proto.getEventHash = function getEventHash(hash) {
  23095. if (hash === void 0) {
  23096. hash = {};
  23097. }
  23098. hash.name = this.name;
  23099. hash.plugin = this.constructor;
  23100. hash.instance = this;
  23101. return hash;
  23102. }
  23103. /**
  23104. * Triggers an event on the plugin object and overrides
  23105. * {@link module:evented~EventedMixin.trigger|EventedMixin.trigger}.
  23106. *
  23107. * @param {string|Object} event
  23108. * An event type or an object with a type property.
  23109. *
  23110. * @param {Object} [hash={}]
  23111. * Additional data hash to merge with a
  23112. * {@link Plugin~PluginEventHash|PluginEventHash}.
  23113. *
  23114. * @return {boolean}
  23115. * Whether or not default was prevented.
  23116. */
  23117. ;
  23118. _proto.trigger = function trigger$1(event, hash) {
  23119. if (hash === void 0) {
  23120. hash = {};
  23121. }
  23122. return trigger(this.eventBusEl_, event, this.getEventHash(hash));
  23123. }
  23124. /**
  23125. * Handles "statechanged" events on the plugin. No-op by default, override by
  23126. * subclassing.
  23127. *
  23128. * @abstract
  23129. * @param {Event} e
  23130. * An event object provided by a "statechanged" event.
  23131. *
  23132. * @param {Object} e.changes
  23133. * An object describing changes that occurred with the "statechanged"
  23134. * event.
  23135. */
  23136. ;
  23137. _proto.handleStateChanged = function handleStateChanged(e) {}
  23138. /**
  23139. * Disposes a plugin.
  23140. *
  23141. * Subclasses can override this if they want, but for the sake of safety,
  23142. * it's probably best to subscribe the "dispose" event.
  23143. *
  23144. * @fires Plugin#dispose
  23145. */
  23146. ;
  23147. _proto.dispose = function dispose() {
  23148. var name = this.name,
  23149. player = this.player;
  23150. /**
  23151. * Signals that a advanced plugin is about to be disposed.
  23152. *
  23153. * @event Plugin#dispose
  23154. * @type {EventTarget~Event}
  23155. */
  23156. this.trigger('dispose');
  23157. this.off();
  23158. player.off('dispose', this.dispose); // Eliminate any possible sources of leaking memory by clearing up
  23159. // references between the player and the plugin instance and nulling out
  23160. // the plugin's state and replacing methods with a function that throws.
  23161. player[PLUGIN_CACHE_KEY][name] = false;
  23162. this.player = this.state = null; // Finally, replace the plugin name on the player with a new factory
  23163. // function, so that the plugin is ready to be set up again.
  23164. player[name] = createPluginFactory(name, pluginStorage[name]);
  23165. }
  23166. /**
  23167. * Determines if a plugin is a basic plugin (i.e. not a sub-class of `Plugin`).
  23168. *
  23169. * @param {string|Function} plugin
  23170. * If a string, matches the name of a plugin. If a function, will be
  23171. * tested directly.
  23172. *
  23173. * @return {boolean}
  23174. * Whether or not a plugin is a basic plugin.
  23175. */
  23176. ;
  23177. Plugin.isBasic = function isBasic(plugin) {
  23178. var p = typeof plugin === 'string' ? getPlugin(plugin) : plugin;
  23179. return typeof p === 'function' && !Plugin.prototype.isPrototypeOf(p.prototype);
  23180. }
  23181. /**
  23182. * Register a Video.js plugin.
  23183. *
  23184. * @param {string} name
  23185. * The name of the plugin to be registered. Must be a string and
  23186. * must not match an existing plugin or a method on the `Player`
  23187. * prototype.
  23188. *
  23189. * @param {Function} plugin
  23190. * A sub-class of `Plugin` or a function for basic plugins.
  23191. *
  23192. * @return {Function}
  23193. * For advanced plugins, a factory function for that plugin. For
  23194. * basic plugins, a wrapper function that initializes the plugin.
  23195. */
  23196. ;
  23197. Plugin.registerPlugin = function registerPlugin(name, plugin) {
  23198. if (typeof name !== 'string') {
  23199. throw new Error("Illegal plugin name, \"" + name + "\", must be a string, was " + typeof name + ".");
  23200. }
  23201. if (pluginExists(name)) {
  23202. log.warn("A plugin named \"" + name + "\" already exists. You may want to avoid re-registering plugins!");
  23203. } else if (Player.prototype.hasOwnProperty(name)) {
  23204. throw new Error("Illegal plugin name, \"" + name + "\", cannot share a name with an existing player method!");
  23205. }
  23206. if (typeof plugin !== 'function') {
  23207. throw new Error("Illegal plugin for \"" + name + "\", must be a function, was " + typeof plugin + ".");
  23208. }
  23209. pluginStorage[name] = plugin; // Add a player prototype method for all sub-classed plugins (but not for
  23210. // the base Plugin class).
  23211. if (name !== BASE_PLUGIN_NAME) {
  23212. if (Plugin.isBasic(plugin)) {
  23213. Player.prototype[name] = createBasicPlugin(name, plugin);
  23214. } else {
  23215. Player.prototype[name] = createPluginFactory(name, plugin);
  23216. }
  23217. }
  23218. return plugin;
  23219. }
  23220. /**
  23221. * De-register a Video.js plugin.
  23222. *
  23223. * @param {string} name
  23224. * The name of the plugin to be de-registered. Must be a string that
  23225. * matches an existing plugin.
  23226. *
  23227. * @throws {Error}
  23228. * If an attempt is made to de-register the base plugin.
  23229. */
  23230. ;
  23231. Plugin.deregisterPlugin = function deregisterPlugin(name) {
  23232. if (name === BASE_PLUGIN_NAME) {
  23233. throw new Error('Cannot de-register base plugin.');
  23234. }
  23235. if (pluginExists(name)) {
  23236. delete pluginStorage[name];
  23237. delete Player.prototype[name];
  23238. }
  23239. }
  23240. /**
  23241. * Gets an object containing multiple Video.js plugins.
  23242. *
  23243. * @param {Array} [names]
  23244. * If provided, should be an array of plugin names. Defaults to _all_
  23245. * plugin names.
  23246. *
  23247. * @return {Object|undefined}
  23248. * An object containing plugin(s) associated with their name(s) or
  23249. * `undefined` if no matching plugins exist).
  23250. */
  23251. ;
  23252. Plugin.getPlugins = function getPlugins(names) {
  23253. if (names === void 0) {
  23254. names = Object.keys(pluginStorage);
  23255. }
  23256. var result;
  23257. names.forEach(function (name) {
  23258. var plugin = getPlugin(name);
  23259. if (plugin) {
  23260. result = result || {};
  23261. result[name] = plugin;
  23262. }
  23263. });
  23264. return result;
  23265. }
  23266. /**
  23267. * Gets a plugin's version, if available
  23268. *
  23269. * @param {string} name
  23270. * The name of a plugin.
  23271. *
  23272. * @return {string}
  23273. * The plugin's version or an empty string.
  23274. */
  23275. ;
  23276. Plugin.getPluginVersion = function getPluginVersion(name) {
  23277. var plugin = getPlugin(name);
  23278. return plugin && plugin.VERSION || '';
  23279. };
  23280. return Plugin;
  23281. }();
  23282. /**
  23283. * Gets a plugin by name if it exists.
  23284. *
  23285. * @static
  23286. * @method getPlugin
  23287. * @memberOf Plugin
  23288. * @param {string} name
  23289. * The name of a plugin.
  23290. *
  23291. * @returns {Function|undefined}
  23292. * The plugin (or `undefined`).
  23293. */
  23294. Plugin.getPlugin = getPlugin;
  23295. /**
  23296. * The name of the base plugin class as it is registered.
  23297. *
  23298. * @type {string}
  23299. */
  23300. Plugin.BASE_PLUGIN_NAME = BASE_PLUGIN_NAME;
  23301. Plugin.registerPlugin(BASE_PLUGIN_NAME, Plugin);
  23302. /**
  23303. * Documented in player.js
  23304. *
  23305. * @ignore
  23306. */
  23307. Player.prototype.usingPlugin = function (name) {
  23308. return !!this[PLUGIN_CACHE_KEY] && this[PLUGIN_CACHE_KEY][name] === true;
  23309. };
  23310. /**
  23311. * Documented in player.js
  23312. *
  23313. * @ignore
  23314. */
  23315. Player.prototype.hasPlugin = function (name) {
  23316. return !!pluginExists(name);
  23317. };
  23318. /**
  23319. * Signals that a plugin is about to be set up on a player.
  23320. *
  23321. * @event Player#beforepluginsetup
  23322. * @type {Plugin~PluginEventHash}
  23323. */
  23324. /**
  23325. * Signals that a plugin is about to be set up on a player - by name. The name
  23326. * is the name of the plugin.
  23327. *
  23328. * @event Player#beforepluginsetup:$name
  23329. * @type {Plugin~PluginEventHash}
  23330. */
  23331. /**
  23332. * Signals that a plugin has just been set up on a player.
  23333. *
  23334. * @event Player#pluginsetup
  23335. * @type {Plugin~PluginEventHash}
  23336. */
  23337. /**
  23338. * Signals that a plugin has just been set up on a player - by name. The name
  23339. * is the name of the plugin.
  23340. *
  23341. * @event Player#pluginsetup:$name
  23342. * @type {Plugin~PluginEventHash}
  23343. */
  23344. /**
  23345. * @typedef {Object} Plugin~PluginEventHash
  23346. *
  23347. * @property {string} instance
  23348. * For basic plugins, the return value of the plugin function. For
  23349. * advanced plugins, the plugin instance on which the event is fired.
  23350. *
  23351. * @property {string} name
  23352. * The name of the plugin.
  23353. *
  23354. * @property {string} plugin
  23355. * For basic plugins, the plugin function. For advanced plugins, the
  23356. * plugin class/constructor.
  23357. */
  23358. /**
  23359. * @file extend.js
  23360. * @module extend
  23361. */
  23362. /**
  23363. * A combination of node inherits and babel's inherits (after transpile).
  23364. * Both work the same but node adds `super_` to the subClass
  23365. * and Bable adds the superClass as __proto__. Both seem useful.
  23366. *
  23367. * @param {Object} subClass
  23368. * The class to inherit to
  23369. *
  23370. * @param {Object} superClass
  23371. * The class to inherit from
  23372. *
  23373. * @private
  23374. */
  23375. var _inherits = function _inherits(subClass, superClass) {
  23376. if (typeof superClass !== 'function' && superClass !== null) {
  23377. throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
  23378. }
  23379. subClass.prototype = Object.create(superClass && superClass.prototype, {
  23380. constructor: {
  23381. value: subClass,
  23382. enumerable: false,
  23383. writable: true,
  23384. configurable: true
  23385. }
  23386. });
  23387. if (superClass) {
  23388. // node
  23389. subClass.super_ = superClass;
  23390. }
  23391. };
  23392. /**
  23393. * Used to subclass an existing class by emulating ES subclassing using the
  23394. * `extends` keyword.
  23395. *
  23396. * @function
  23397. * @example
  23398. * var MyComponent = videojs.extend(videojs.getComponent('Component'), {
  23399. * myCustomMethod: function() {
  23400. * // Do things in my method.
  23401. * }
  23402. * });
  23403. *
  23404. * @param {Function} superClass
  23405. * The class to inherit from
  23406. *
  23407. * @param {Object} [subClassMethods={}]
  23408. * Methods of the new class
  23409. *
  23410. * @return {Function}
  23411. * The new class with subClassMethods that inherited superClass.
  23412. */
  23413. var extend$1 = function extend(superClass, subClassMethods) {
  23414. if (subClassMethods === void 0) {
  23415. subClassMethods = {};
  23416. }
  23417. var subClass = function subClass() {
  23418. superClass.apply(this, arguments);
  23419. };
  23420. var methods = {};
  23421. if (typeof subClassMethods === 'object') {
  23422. if (subClassMethods.constructor !== Object.prototype.constructor) {
  23423. subClass = subClassMethods.constructor;
  23424. }
  23425. methods = subClassMethods;
  23426. } else if (typeof subClassMethods === 'function') {
  23427. subClass = subClassMethods;
  23428. }
  23429. _inherits(subClass, superClass); // Extend subObj's prototype with functions and other properties from props
  23430. for (var name in methods) {
  23431. if (methods.hasOwnProperty(name)) {
  23432. subClass.prototype[name] = methods[name];
  23433. }
  23434. }
  23435. return subClass;
  23436. };
  23437. /**
  23438. * @file video.js
  23439. * @module videojs
  23440. */
  23441. /**
  23442. * Normalize an `id` value by trimming off a leading `#`
  23443. *
  23444. * @private
  23445. * @param {string} id
  23446. * A string, maybe with a leading `#`.
  23447. *
  23448. * @return {string}
  23449. * The string, without any leading `#`.
  23450. */
  23451. var normalizeId = function normalizeId(id) {
  23452. return id.indexOf('#') === 0 ? id.slice(1) : id;
  23453. };
  23454. /**
  23455. * The `videojs()` function doubles as the main function for users to create a
  23456. * {@link Player} instance as well as the main library namespace.
  23457. *
  23458. * It can also be used as a getter for a pre-existing {@link Player} instance.
  23459. * However, we _strongly_ recommend using `videojs.getPlayer()` for this
  23460. * purpose because it avoids any potential for unintended initialization.
  23461. *
  23462. * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149)
  23463. * of our JSDoc template, we cannot properly document this as both a function
  23464. * and a namespace, so its function signature is documented here.
  23465. *
  23466. * #### Arguments
  23467. * ##### id
  23468. * string|Element, **required**
  23469. *
  23470. * Video element or video element ID.
  23471. *
  23472. * ##### options
  23473. * Object, optional
  23474. *
  23475. * Options object for providing settings.
  23476. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  23477. *
  23478. * ##### ready
  23479. * {@link Component~ReadyCallback}, optional
  23480. *
  23481. * A function to be called when the {@link Player} and {@link Tech} are ready.
  23482. *
  23483. * #### Return Value
  23484. *
  23485. * The `videojs()` function returns a {@link Player} instance.
  23486. *
  23487. * @namespace
  23488. *
  23489. * @borrows AudioTrack as AudioTrack
  23490. * @borrows Component.getComponent as getComponent
  23491. * @borrows module:computed-style~computedStyle as computedStyle
  23492. * @borrows module:events.on as on
  23493. * @borrows module:events.one as one
  23494. * @borrows module:events.off as off
  23495. * @borrows module:events.trigger as trigger
  23496. * @borrows EventTarget as EventTarget
  23497. * @borrows module:extend~extend as extend
  23498. * @borrows module:fn.bind as bind
  23499. * @borrows module:format-time.formatTime as formatTime
  23500. * @borrows module:format-time.resetFormatTime as resetFormatTime
  23501. * @borrows module:format-time.setFormatTime as setFormatTime
  23502. * @borrows module:merge-options.mergeOptions as mergeOptions
  23503. * @borrows module:middleware.use as use
  23504. * @borrows Player.players as players
  23505. * @borrows Plugin.registerPlugin as registerPlugin
  23506. * @borrows Plugin.deregisterPlugin as deregisterPlugin
  23507. * @borrows Plugin.getPlugins as getPlugins
  23508. * @borrows Plugin.getPlugin as getPlugin
  23509. * @borrows Plugin.getPluginVersion as getPluginVersion
  23510. * @borrows Tech.getTech as getTech
  23511. * @borrows Tech.registerTech as registerTech
  23512. * @borrows TextTrack as TextTrack
  23513. * @borrows module:time-ranges.createTimeRanges as createTimeRange
  23514. * @borrows module:time-ranges.createTimeRanges as createTimeRanges
  23515. * @borrows module:url.isCrossOrigin as isCrossOrigin
  23516. * @borrows module:url.parseUrl as parseUrl
  23517. * @borrows VideoTrack as VideoTrack
  23518. *
  23519. * @param {string|Element} id
  23520. * Video element or video element ID.
  23521. *
  23522. * @param {Object} [options]
  23523. * Options object for providing settings.
  23524. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  23525. *
  23526. * @param {Component~ReadyCallback} [ready]
  23527. * A function to be called when the {@link Player} and {@link Tech} are
  23528. * ready.
  23529. *
  23530. * @return {Player}
  23531. * The `videojs()` function returns a {@link Player|Player} instance.
  23532. */
  23533. function videojs$1(id, options, ready) {
  23534. var player = videojs$1.getPlayer(id);
  23535. if (player) {
  23536. if (options) {
  23537. log.warn("Player \"" + id + "\" is already initialised. Options will not be applied.");
  23538. }
  23539. if (ready) {
  23540. player.ready(ready);
  23541. }
  23542. return player;
  23543. }
  23544. var el = typeof id === 'string' ? $('#' + normalizeId(id)) : id;
  23545. if (!isEl(el)) {
  23546. throw new TypeError('The element or ID supplied is not valid. (videojs)');
  23547. } // document.body.contains(el) will only check if el is contained within that one document.
  23548. // This causes problems for elements in iframes.
  23549. // Instead, use the element's ownerDocument instead of the global document.
  23550. // This will make sure that the element is indeed in the dom of that document.
  23551. // Additionally, check that the document in question has a default view.
  23552. // If the document is no longer attached to the dom, the defaultView of the document will be null.
  23553. if (!el.ownerDocument.defaultView || !el.ownerDocument.body.contains(el)) {
  23554. log.warn('The element supplied is not included in the DOM');
  23555. }
  23556. options = options || {};
  23557. videojs$1.hooks('beforesetup').forEach(function (hookFunction) {
  23558. var opts = hookFunction(el, mergeOptions(options));
  23559. if (!isObject(opts) || Array.isArray(opts)) {
  23560. log.error('please return an object in beforesetup hooks');
  23561. return;
  23562. }
  23563. options = mergeOptions(options, opts);
  23564. }); // We get the current "Player" component here in case an integration has
  23565. // replaced it with a custom player.
  23566. var PlayerComponent = Component.getComponent('Player');
  23567. player = new PlayerComponent(el, options, ready);
  23568. videojs$1.hooks('setup').forEach(function (hookFunction) {
  23569. return hookFunction(player);
  23570. });
  23571. return player;
  23572. }
  23573. /**
  23574. * An Object that contains lifecycle hooks as keys which point to an array
  23575. * of functions that are run when a lifecycle is triggered
  23576. *
  23577. * @private
  23578. */
  23579. videojs$1.hooks_ = {};
  23580. /**
  23581. * Get a list of hooks for a specific lifecycle
  23582. *
  23583. * @param {string} type
  23584. * the lifecyle to get hooks from
  23585. *
  23586. * @param {Function|Function[]} [fn]
  23587. * Optionally add a hook (or hooks) to the lifecycle that your are getting.
  23588. *
  23589. * @return {Array}
  23590. * an array of hooks, or an empty array if there are none.
  23591. */
  23592. videojs$1.hooks = function (type, fn) {
  23593. videojs$1.hooks_[type] = videojs$1.hooks_[type] || [];
  23594. if (fn) {
  23595. videojs$1.hooks_[type] = videojs$1.hooks_[type].concat(fn);
  23596. }
  23597. return videojs$1.hooks_[type];
  23598. };
  23599. /**
  23600. * Add a function hook to a specific videojs lifecycle.
  23601. *
  23602. * @param {string} type
  23603. * the lifecycle to hook the function to.
  23604. *
  23605. * @param {Function|Function[]}
  23606. * The function or array of functions to attach.
  23607. */
  23608. videojs$1.hook = function (type, fn) {
  23609. videojs$1.hooks(type, fn);
  23610. };
  23611. /**
  23612. * Add a function hook that will only run once to a specific videojs lifecycle.
  23613. *
  23614. * @param {string} type
  23615. * the lifecycle to hook the function to.
  23616. *
  23617. * @param {Function|Function[]}
  23618. * The function or array of functions to attach.
  23619. */
  23620. videojs$1.hookOnce = function (type, fn) {
  23621. videojs$1.hooks(type, [].concat(fn).map(function (original) {
  23622. var wrapper = function wrapper() {
  23623. videojs$1.removeHook(type, wrapper);
  23624. return original.apply(void 0, arguments);
  23625. };
  23626. return wrapper;
  23627. }));
  23628. };
  23629. /**
  23630. * Remove a hook from a specific videojs lifecycle.
  23631. *
  23632. * @param {string} type
  23633. * the lifecycle that the function hooked to
  23634. *
  23635. * @param {Function} fn
  23636. * The hooked function to remove
  23637. *
  23638. * @return {boolean}
  23639. * The function that was removed or undef
  23640. */
  23641. videojs$1.removeHook = function (type, fn) {
  23642. var index = videojs$1.hooks(type).indexOf(fn);
  23643. if (index <= -1) {
  23644. return false;
  23645. }
  23646. videojs$1.hooks_[type] = videojs$1.hooks_[type].slice();
  23647. videojs$1.hooks_[type].splice(index, 1);
  23648. return true;
  23649. }; // Add default styles
  23650. if (window$1.VIDEOJS_NO_DYNAMIC_STYLE !== true && isReal()) {
  23651. var style = $('.vjs-styles-defaults');
  23652. if (!style) {
  23653. style = createStyleElement('vjs-styles-defaults');
  23654. var head = $('head');
  23655. if (head) {
  23656. head.insertBefore(style, head.firstChild);
  23657. }
  23658. setTextContent(style, "\n .video-js {\n width: 300px;\n height: 150px;\n }\n\n .vjs-fluid {\n padding-top: 56.25%\n }\n ");
  23659. }
  23660. } // Run Auto-load players
  23661. // You have to wait at least once in case this script is loaded after your
  23662. // video in the DOM (weird behavior only with minified version)
  23663. autoSetupTimeout(1, videojs$1);
  23664. /**
  23665. * Current Video.js version. Follows [semantic versioning](https://semver.org/).
  23666. *
  23667. * @type {string}
  23668. */
  23669. videojs$1.VERSION = version;
  23670. /**
  23671. * The global options object. These are the settings that take effect
  23672. * if no overrides are specified when the player is created.
  23673. *
  23674. * @type {Object}
  23675. */
  23676. videojs$1.options = Player.prototype.options_;
  23677. /**
  23678. * Get an object with the currently created players, keyed by player ID
  23679. *
  23680. * @return {Object}
  23681. * The created players
  23682. */
  23683. videojs$1.getPlayers = function () {
  23684. return Player.players;
  23685. };
  23686. /**
  23687. * Get a single player based on an ID or DOM element.
  23688. *
  23689. * This is useful if you want to check if an element or ID has an associated
  23690. * Video.js player, but not create one if it doesn't.
  23691. *
  23692. * @param {string|Element} id
  23693. * An HTML element - `<video>`, `<audio>`, or `<video-js>` -
  23694. * or a string matching the `id` of such an element.
  23695. *
  23696. * @return {Player|undefined}
  23697. * A player instance or `undefined` if there is no player instance
  23698. * matching the argument.
  23699. */
  23700. videojs$1.getPlayer = function (id) {
  23701. var players = Player.players;
  23702. var tag;
  23703. if (typeof id === 'string') {
  23704. var nId = normalizeId(id);
  23705. var player = players[nId];
  23706. if (player) {
  23707. return player;
  23708. }
  23709. tag = $('#' + nId);
  23710. } else {
  23711. tag = id;
  23712. }
  23713. if (isEl(tag)) {
  23714. var _tag = tag,
  23715. _player = _tag.player,
  23716. playerId = _tag.playerId; // Element may have a `player` property referring to an already created
  23717. // player instance. If so, return that.
  23718. if (_player || players[playerId]) {
  23719. return _player || players[playerId];
  23720. }
  23721. }
  23722. };
  23723. /**
  23724. * Returns an array of all current players.
  23725. *
  23726. * @return {Array}
  23727. * An array of all players. The array will be in the order that
  23728. * `Object.keys` provides, which could potentially vary between
  23729. * JavaScript engines.
  23730. *
  23731. */
  23732. videojs$1.getAllPlayers = function () {
  23733. return (// Disposed players leave a key with a `null` value, so we need to make sure
  23734. // we filter those out.
  23735. Object.keys(Player.players).map(function (k) {
  23736. return Player.players[k];
  23737. }).filter(Boolean)
  23738. );
  23739. };
  23740. videojs$1.players = Player.players;
  23741. videojs$1.getComponent = Component.getComponent;
  23742. /**
  23743. * Register a component so it can referred to by name. Used when adding to other
  23744. * components, either through addChild `component.addChild('myComponent')` or through
  23745. * default children options `{ children: ['myComponent'] }`.
  23746. *
  23747. * > NOTE: You could also just initialize the component before adding.
  23748. * `component.addChild(new MyComponent());`
  23749. *
  23750. * @param {string} name
  23751. * The class name of the component
  23752. *
  23753. * @param {Component} comp
  23754. * The component class
  23755. *
  23756. * @return {Component}
  23757. * The newly registered component
  23758. */
  23759. videojs$1.registerComponent = function (name, comp) {
  23760. if (Tech.isTech(comp)) {
  23761. log.warn("The " + name + " tech was registered as a component. It should instead be registered using videojs.registerTech(name, tech)");
  23762. }
  23763. Component.registerComponent.call(Component, name, comp);
  23764. };
  23765. videojs$1.getTech = Tech.getTech;
  23766. videojs$1.registerTech = Tech.registerTech;
  23767. videojs$1.use = use;
  23768. /**
  23769. * An object that can be returned by a middleware to signify
  23770. * that the middleware is being terminated.
  23771. *
  23772. * @type {object}
  23773. * @property {object} middleware.TERMINATOR
  23774. */
  23775. Object.defineProperty(videojs$1, 'middleware', {
  23776. value: {},
  23777. writeable: false,
  23778. enumerable: true
  23779. });
  23780. Object.defineProperty(videojs$1.middleware, 'TERMINATOR', {
  23781. value: TERMINATOR,
  23782. writeable: false,
  23783. enumerable: true
  23784. });
  23785. /**
  23786. * A reference to the {@link module:browser|browser utility module} as an object.
  23787. *
  23788. * @type {Object}
  23789. * @see {@link module:browser|browser}
  23790. */
  23791. videojs$1.browser = browser;
  23792. /**
  23793. * Use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED} instead; only
  23794. * included for backward-compatibility with 4.x.
  23795. *
  23796. * @deprecated Since version 5.0, use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED instead.
  23797. * @type {boolean}
  23798. */
  23799. videojs$1.TOUCH_ENABLED = TOUCH_ENABLED;
  23800. videojs$1.extend = extend$1;
  23801. videojs$1.mergeOptions = mergeOptions;
  23802. videojs$1.bind = bind;
  23803. videojs$1.registerPlugin = Plugin.registerPlugin;
  23804. videojs$1.deregisterPlugin = Plugin.deregisterPlugin;
  23805. /**
  23806. * Deprecated method to register a plugin with Video.js
  23807. *
  23808. * @deprecated videojs.plugin() is deprecated; use videojs.registerPlugin() instead
  23809. *
  23810. * @param {string} name
  23811. * The plugin name
  23812. *
  23813. * @param {Plugin|Function} plugin
  23814. * The plugin sub-class or function
  23815. */
  23816. videojs$1.plugin = function (name, plugin) {
  23817. log.warn('videojs.plugin() is deprecated; use videojs.registerPlugin() instead');
  23818. return Plugin.registerPlugin(name, plugin);
  23819. };
  23820. videojs$1.getPlugins = Plugin.getPlugins;
  23821. videojs$1.getPlugin = Plugin.getPlugin;
  23822. videojs$1.getPluginVersion = Plugin.getPluginVersion;
  23823. /**
  23824. * Adding languages so that they're available to all players.
  23825. * Example: `videojs.addLanguage('es', { 'Hello': 'Hola' });`
  23826. *
  23827. * @param {string} code
  23828. * The language code or dictionary property
  23829. *
  23830. * @param {Object} data
  23831. * The data values to be translated
  23832. *
  23833. * @return {Object}
  23834. * The resulting language dictionary object
  23835. */
  23836. videojs$1.addLanguage = function (code, data) {
  23837. var _mergeOptions;
  23838. code = ('' + code).toLowerCase();
  23839. videojs$1.options.languages = mergeOptions(videojs$1.options.languages, (_mergeOptions = {}, _mergeOptions[code] = data, _mergeOptions));
  23840. return videojs$1.options.languages[code];
  23841. };
  23842. /**
  23843. * A reference to the {@link module:log|log utility module} as an object.
  23844. *
  23845. * @type {Function}
  23846. * @see {@link module:log|log}
  23847. */
  23848. videojs$1.log = log;
  23849. videojs$1.createLogger = createLogger$1;
  23850. videojs$1.createTimeRange = videojs$1.createTimeRanges = createTimeRanges;
  23851. videojs$1.formatTime = formatTime;
  23852. videojs$1.setFormatTime = setFormatTime;
  23853. videojs$1.resetFormatTime = resetFormatTime;
  23854. videojs$1.parseUrl = parseUrl;
  23855. videojs$1.isCrossOrigin = isCrossOrigin;
  23856. videojs$1.EventTarget = EventTarget;
  23857. videojs$1.on = on;
  23858. videojs$1.one = one;
  23859. videojs$1.off = off;
  23860. videojs$1.trigger = trigger;
  23861. /**
  23862. * A cross-browser XMLHttpRequest wrapper.
  23863. *
  23864. * @function
  23865. * @param {Object} options
  23866. * Settings for the request.
  23867. *
  23868. * @return {XMLHttpRequest|XDomainRequest}
  23869. * The request object.
  23870. *
  23871. * @see https://github.com/Raynos/xhr
  23872. */
  23873. videojs$1.xhr = xhr;
  23874. videojs$1.TextTrack = TextTrack;
  23875. videojs$1.AudioTrack = AudioTrack;
  23876. videojs$1.VideoTrack = VideoTrack;
  23877. ['isEl', 'isTextNode', 'createEl', 'hasClass', 'addClass', 'removeClass', 'toggleClass', 'setAttributes', 'getAttributes', 'emptyEl', 'appendContent', 'insertContent'].forEach(function (k) {
  23878. videojs$1[k] = function () {
  23879. log.warn("videojs." + k + "() is deprecated; use videojs.dom." + k + "() instead");
  23880. return Dom[k].apply(null, arguments);
  23881. };
  23882. });
  23883. videojs$1.computedStyle = computedStyle;
  23884. /**
  23885. * A reference to the {@link module:dom|DOM utility module} as an object.
  23886. *
  23887. * @type {Object}
  23888. * @see {@link module:dom|dom}
  23889. */
  23890. videojs$1.dom = Dom;
  23891. /**
  23892. * A reference to the {@link module:url|URL utility module} as an object.
  23893. *
  23894. * @type {Object}
  23895. * @see {@link module:url|url}
  23896. */
  23897. videojs$1.url = Url;
  23898. return videojs$1;
  23899. }));