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.

29844 lines
869 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. /**
  8056. * Copyright 2013 vtt.js Contributors
  8057. *
  8058. * Licensed under the Apache License, Version 2.0 (the "License");
  8059. * you may not use this file except in compliance with the License.
  8060. * You may obtain a copy of the License at
  8061. *
  8062. * http://www.apache.org/licenses/LICENSE-2.0
  8063. *
  8064. * Unless required by applicable law or agreed to in writing, software
  8065. * distributed under the License is distributed on an "AS IS" BASIS,
  8066. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  8067. * See the License for the specific language governing permissions and
  8068. * limitations under the License.
  8069. */
  8070. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  8071. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  8072. var _objCreate = Object.create || function () {
  8073. function F() {}
  8074. return function (o) {
  8075. if (arguments.length !== 1) {
  8076. throw new Error('Object.create shim only accepts one parameter.');
  8077. }
  8078. F.prototype = o;
  8079. return new F();
  8080. };
  8081. }(); // Creates a new ParserError object from an errorData object. The errorData
  8082. // object should have default code and message properties. The default message
  8083. // property can be overriden by passing in a message parameter.
  8084. // See ParsingError.Errors below for acceptable errors.
  8085. function ParsingError(errorData, message) {
  8086. this.name = "ParsingError";
  8087. this.code = errorData.code;
  8088. this.message = message || errorData.message;
  8089. }
  8090. ParsingError.prototype = _objCreate(Error.prototype);
  8091. ParsingError.prototype.constructor = ParsingError; // ParsingError metadata for acceptable ParsingErrors.
  8092. ParsingError.Errors = {
  8093. BadSignature: {
  8094. code: 0,
  8095. message: "Malformed WebVTT signature."
  8096. },
  8097. BadTimeStamp: {
  8098. code: 1,
  8099. message: "Malformed time stamp."
  8100. }
  8101. }; // Try to parse input as a time stamp.
  8102. function parseTimeStamp(input) {
  8103. function computeSeconds(h, m, s, f) {
  8104. return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;
  8105. }
  8106. var m = input.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);
  8107. if (!m) {
  8108. return null;
  8109. }
  8110. if (m[3]) {
  8111. // Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
  8112. return computeSeconds(m[1], m[2], m[3].replace(":", ""), m[4]);
  8113. } else if (m[1] > 59) {
  8114. // Timestamp takes the form of [hours]:[minutes].[milliseconds]
  8115. // First position is hours as it's over 59.
  8116. return computeSeconds(m[1], m[2], 0, m[4]);
  8117. } else {
  8118. // Timestamp takes the form of [minutes]:[seconds].[milliseconds]
  8119. return computeSeconds(0, m[1], m[2], m[4]);
  8120. }
  8121. } // A settings object holds key/value pairs and will ignore anything but the first
  8122. // assignment to a specific key.
  8123. function Settings() {
  8124. this.values = _objCreate(null);
  8125. }
  8126. Settings.prototype = {
  8127. // Only accept the first assignment to any key.
  8128. set: function set(k, v) {
  8129. if (!this.get(k) && v !== "") {
  8130. this.values[k] = v;
  8131. }
  8132. },
  8133. // Return the value for a key, or a default value.
  8134. // If 'defaultKey' is passed then 'dflt' is assumed to be an object with
  8135. // a number of possible default values as properties where 'defaultKey' is
  8136. // the key of the property that will be chosen; otherwise it's assumed to be
  8137. // a single value.
  8138. get: function get(k, dflt, defaultKey) {
  8139. if (defaultKey) {
  8140. return this.has(k) ? this.values[k] : dflt[defaultKey];
  8141. }
  8142. return this.has(k) ? this.values[k] : dflt;
  8143. },
  8144. // Check whether we have a value for a key.
  8145. has: function has(k) {
  8146. return k in this.values;
  8147. },
  8148. // Accept a setting if its one of the given alternatives.
  8149. alt: function alt(k, v, a) {
  8150. for (var n = 0; n < a.length; ++n) {
  8151. if (v === a[n]) {
  8152. this.set(k, v);
  8153. break;
  8154. }
  8155. }
  8156. },
  8157. // Accept a setting if its a valid (signed) integer.
  8158. integer: function integer(k, v) {
  8159. if (/^-?\d+$/.test(v)) {
  8160. // integer
  8161. this.set(k, parseInt(v, 10));
  8162. }
  8163. },
  8164. // Accept a setting if its a valid percentage.
  8165. percent: function percent(k, v) {
  8166. var m;
  8167. if (m = v.match(/^([\d]{1,3})(\.[\d]*)?%$/)) {
  8168. v = parseFloat(v);
  8169. if (v >= 0 && v <= 100) {
  8170. this.set(k, v);
  8171. return true;
  8172. }
  8173. }
  8174. return false;
  8175. }
  8176. }; // Helper function to parse input into groups separated by 'groupDelim', and
  8177. // interprete each group as a key/value pair separated by 'keyValueDelim'.
  8178. function parseOptions(input, callback, keyValueDelim, groupDelim) {
  8179. var groups = groupDelim ? input.split(groupDelim) : [input];
  8180. for (var i in groups) {
  8181. if (typeof groups[i] !== "string") {
  8182. continue;
  8183. }
  8184. var kv = groups[i].split(keyValueDelim);
  8185. if (kv.length !== 2) {
  8186. continue;
  8187. }
  8188. var k = kv[0];
  8189. var v = kv[1];
  8190. callback(k, v);
  8191. }
  8192. }
  8193. function parseCue(input, cue, regionList) {
  8194. // Remember the original input if we need to throw an error.
  8195. var oInput = input; // 4.1 WebVTT timestamp
  8196. function consumeTimeStamp() {
  8197. var ts = parseTimeStamp(input);
  8198. if (ts === null) {
  8199. throw new ParsingError(ParsingError.Errors.BadTimeStamp, "Malformed timestamp: " + oInput);
  8200. } // Remove time stamp from input.
  8201. input = input.replace(/^[^\sa-zA-Z-]+/, "");
  8202. return ts;
  8203. } // 4.4.2 WebVTT cue settings
  8204. function consumeCueSettings(input, cue) {
  8205. var settings = new Settings();
  8206. parseOptions(input, function (k, v) {
  8207. switch (k) {
  8208. case "region":
  8209. // Find the last region we parsed with the same region id.
  8210. for (var i = regionList.length - 1; i >= 0; i--) {
  8211. if (regionList[i].id === v) {
  8212. settings.set(k, regionList[i].region);
  8213. break;
  8214. }
  8215. }
  8216. break;
  8217. case "vertical":
  8218. settings.alt(k, v, ["rl", "lr"]);
  8219. break;
  8220. case "line":
  8221. var vals = v.split(","),
  8222. vals0 = vals[0];
  8223. settings.integer(k, vals0);
  8224. settings.percent(k, vals0) ? settings.set("snapToLines", false) : null;
  8225. settings.alt(k, vals0, ["auto"]);
  8226. if (vals.length === 2) {
  8227. settings.alt("lineAlign", vals[1], ["start", "middle", "end"]);
  8228. }
  8229. break;
  8230. case "position":
  8231. vals = v.split(",");
  8232. settings.percent(k, vals[0]);
  8233. if (vals.length === 2) {
  8234. settings.alt("positionAlign", vals[1], ["start", "middle", "end"]);
  8235. }
  8236. break;
  8237. case "size":
  8238. settings.percent(k, v);
  8239. break;
  8240. case "align":
  8241. settings.alt(k, v, ["start", "middle", "end", "left", "right"]);
  8242. break;
  8243. }
  8244. }, /:/, /\s/); // Apply default values for any missing fields.
  8245. cue.region = settings.get("region", null);
  8246. cue.vertical = settings.get("vertical", "");
  8247. cue.line = settings.get("line", "auto");
  8248. cue.lineAlign = settings.get("lineAlign", "start");
  8249. cue.snapToLines = settings.get("snapToLines", true);
  8250. cue.size = settings.get("size", 100);
  8251. cue.align = settings.get("align", "middle");
  8252. cue.position = settings.get("position", {
  8253. start: 0,
  8254. left: 0,
  8255. middle: 50,
  8256. end: 100,
  8257. right: 100
  8258. }, cue.align);
  8259. cue.positionAlign = settings.get("positionAlign", {
  8260. start: "start",
  8261. left: "start",
  8262. middle: "middle",
  8263. end: "end",
  8264. right: "end"
  8265. }, cue.align);
  8266. }
  8267. function skipWhitespace() {
  8268. input = input.replace(/^\s+/, "");
  8269. } // 4.1 WebVTT cue timings.
  8270. skipWhitespace();
  8271. cue.startTime = consumeTimeStamp(); // (1) collect cue start time
  8272. skipWhitespace();
  8273. if (input.substr(0, 3) !== "-->") {
  8274. // (3) next characters must match "-->"
  8275. throw new ParsingError(ParsingError.Errors.BadTimeStamp, "Malformed time stamp (time stamps must be separated by '-->'): " + oInput);
  8276. }
  8277. input = input.substr(3);
  8278. skipWhitespace();
  8279. cue.endTime = consumeTimeStamp(); // (5) collect cue end time
  8280. // 4.1 WebVTT cue settings list.
  8281. skipWhitespace();
  8282. consumeCueSettings(input, cue);
  8283. }
  8284. var ESCAPE = {
  8285. "&amp;": "&",
  8286. "&lt;": "<",
  8287. "&gt;": ">",
  8288. "&lrm;": "\u200E",
  8289. "&rlm;": "\u200F",
  8290. "&nbsp;": "\xA0"
  8291. };
  8292. var TAG_NAME = {
  8293. c: "span",
  8294. i: "i",
  8295. b: "b",
  8296. u: "u",
  8297. ruby: "ruby",
  8298. rt: "rt",
  8299. v: "span",
  8300. lang: "span"
  8301. };
  8302. var TAG_ANNOTATION = {
  8303. v: "title",
  8304. lang: "lang"
  8305. };
  8306. var NEEDS_PARENT = {
  8307. rt: "ruby"
  8308. }; // Parse content into a document fragment.
  8309. function parseContent(window, input) {
  8310. function nextToken() {
  8311. // Check for end-of-string.
  8312. if (!input) {
  8313. return null;
  8314. } // Consume 'n' characters from the input.
  8315. function consume(result) {
  8316. input = input.substr(result.length);
  8317. return result;
  8318. }
  8319. var m = input.match(/^([^<]*)(<[^>]*>?)?/); // If there is some text before the next tag, return it, otherwise return
  8320. // the tag.
  8321. return consume(m[1] ? m[1] : m[2]);
  8322. } // Unescape a string 's'.
  8323. function unescape1(e) {
  8324. return ESCAPE[e];
  8325. }
  8326. function unescape(s) {
  8327. while (m = s.match(/&(amp|lt|gt|lrm|rlm|nbsp);/)) {
  8328. s = s.replace(m[0], unescape1);
  8329. }
  8330. return s;
  8331. }
  8332. function shouldAdd(current, element) {
  8333. return !NEEDS_PARENT[element.localName] || NEEDS_PARENT[element.localName] === current.localName;
  8334. } // Create an element for this tag.
  8335. function createElement(type, annotation) {
  8336. var tagName = TAG_NAME[type];
  8337. if (!tagName) {
  8338. return null;
  8339. }
  8340. var element = window.document.createElement(tagName);
  8341. element.localName = tagName;
  8342. var name = TAG_ANNOTATION[type];
  8343. if (name && annotation) {
  8344. element[name] = annotation.trim();
  8345. }
  8346. return element;
  8347. }
  8348. var rootDiv = window.document.createElement("div"),
  8349. current = rootDiv,
  8350. t,
  8351. tagStack = [];
  8352. while ((t = nextToken()) !== null) {
  8353. if (t[0] === '<') {
  8354. if (t[1] === "/") {
  8355. // If the closing tag matches, move back up to the parent node.
  8356. if (tagStack.length && tagStack[tagStack.length - 1] === t.substr(2).replace(">", "")) {
  8357. tagStack.pop();
  8358. current = current.parentNode;
  8359. } // Otherwise just ignore the end tag.
  8360. continue;
  8361. }
  8362. var ts = parseTimeStamp(t.substr(1, t.length - 2));
  8363. var node;
  8364. if (ts) {
  8365. // Timestamps are lead nodes as well.
  8366. node = window.document.createProcessingInstruction("timestamp", ts);
  8367. current.appendChild(node);
  8368. continue;
  8369. }
  8370. var m = t.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/); // If we can't parse the tag, skip to the next tag.
  8371. if (!m) {
  8372. continue;
  8373. } // Try to construct an element, and ignore the tag if we couldn't.
  8374. node = createElement(m[1], m[3]);
  8375. if (!node) {
  8376. continue;
  8377. } // Determine if the tag should be added based on the context of where it
  8378. // is placed in the cuetext.
  8379. if (!shouldAdd(current, node)) {
  8380. continue;
  8381. } // Set the class list (as a list of classes, separated by space).
  8382. if (m[2]) {
  8383. node.className = m[2].substr(1).replace('.', ' ');
  8384. } // Append the node to the current node, and enter the scope of the new
  8385. // node.
  8386. tagStack.push(m[1]);
  8387. current.appendChild(node);
  8388. current = node;
  8389. continue;
  8390. } // Text nodes are leaf nodes.
  8391. current.appendChild(window.document.createTextNode(unescape(t)));
  8392. }
  8393. return rootDiv;
  8394. } // This is a list of all the Unicode characters that have a strong
  8395. // right-to-left category. What this means is that these characters are
  8396. // written right-to-left for sure. It was generated by pulling all the strong
  8397. // right-to-left characters out of the Unicode data table. That table can
  8398. // found at: http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
  8399. var strongRTLRanges = [[0x5be, 0x5be], [0x5c0, 0x5c0], [0x5c3, 0x5c3], [0x5c6, 0x5c6], [0x5d0, 0x5ea], [0x5f0, 0x5f4], [0x608, 0x608], [0x60b, 0x60b], [0x60d, 0x60d], [0x61b, 0x61b], [0x61e, 0x64a], [0x66d, 0x66f], [0x671, 0x6d5], [0x6e5, 0x6e6], [0x6ee, 0x6ef], [0x6fa, 0x70d], [0x70f, 0x710], [0x712, 0x72f], [0x74d, 0x7a5], [0x7b1, 0x7b1], [0x7c0, 0x7ea], [0x7f4, 0x7f5], [0x7fa, 0x7fa], [0x800, 0x815], [0x81a, 0x81a], [0x824, 0x824], [0x828, 0x828], [0x830, 0x83e], [0x840, 0x858], [0x85e, 0x85e], [0x8a0, 0x8a0], [0x8a2, 0x8ac], [0x200f, 0x200f], [0xfb1d, 0xfb1d], [0xfb1f, 0xfb28], [0xfb2a, 0xfb36], [0xfb38, 0xfb3c], [0xfb3e, 0xfb3e], [0xfb40, 0xfb41], [0xfb43, 0xfb44], [0xfb46, 0xfbc1], [0xfbd3, 0xfd3d], [0xfd50, 0xfd8f], [0xfd92, 0xfdc7], [0xfdf0, 0xfdfc], [0xfe70, 0xfe74], [0xfe76, 0xfefc], [0x10800, 0x10805], [0x10808, 0x10808], [0x1080a, 0x10835], [0x10837, 0x10838], [0x1083c, 0x1083c], [0x1083f, 0x10855], [0x10857, 0x1085f], [0x10900, 0x1091b], [0x10920, 0x10939], [0x1093f, 0x1093f], [0x10980, 0x109b7], [0x109be, 0x109bf], [0x10a00, 0x10a00], [0x10a10, 0x10a13], [0x10a15, 0x10a17], [0x10a19, 0x10a33], [0x10a40, 0x10a47], [0x10a50, 0x10a58], [0x10a60, 0x10a7f], [0x10b00, 0x10b35], [0x10b40, 0x10b55], [0x10b58, 0x10b72], [0x10b78, 0x10b7f], [0x10c00, 0x10c48], [0x1ee00, 0x1ee03], [0x1ee05, 0x1ee1f], [0x1ee21, 0x1ee22], [0x1ee24, 0x1ee24], [0x1ee27, 0x1ee27], [0x1ee29, 0x1ee32], [0x1ee34, 0x1ee37], [0x1ee39, 0x1ee39], [0x1ee3b, 0x1ee3b], [0x1ee42, 0x1ee42], [0x1ee47, 0x1ee47], [0x1ee49, 0x1ee49], [0x1ee4b, 0x1ee4b], [0x1ee4d, 0x1ee4f], [0x1ee51, 0x1ee52], [0x1ee54, 0x1ee54], [0x1ee57, 0x1ee57], [0x1ee59, 0x1ee59], [0x1ee5b, 0x1ee5b], [0x1ee5d, 0x1ee5d], [0x1ee5f, 0x1ee5f], [0x1ee61, 0x1ee62], [0x1ee64, 0x1ee64], [0x1ee67, 0x1ee6a], [0x1ee6c, 0x1ee72], [0x1ee74, 0x1ee77], [0x1ee79, 0x1ee7c], [0x1ee7e, 0x1ee7e], [0x1ee80, 0x1ee89], [0x1ee8b, 0x1ee9b], [0x1eea1, 0x1eea3], [0x1eea5, 0x1eea9], [0x1eeab, 0x1eebb], [0x10fffd, 0x10fffd]];
  8400. function isStrongRTLChar(charCode) {
  8401. for (var i = 0; i < strongRTLRanges.length; i++) {
  8402. var currentRange = strongRTLRanges[i];
  8403. if (charCode >= currentRange[0] && charCode <= currentRange[1]) {
  8404. return true;
  8405. }
  8406. }
  8407. return false;
  8408. }
  8409. function determineBidi(cueDiv) {
  8410. var nodeStack = [],
  8411. text = "",
  8412. charCode;
  8413. if (!cueDiv || !cueDiv.childNodes) {
  8414. return "ltr";
  8415. }
  8416. function pushNodes(nodeStack, node) {
  8417. for (var i = node.childNodes.length - 1; i >= 0; i--) {
  8418. nodeStack.push(node.childNodes[i]);
  8419. }
  8420. }
  8421. function nextTextNode(nodeStack) {
  8422. if (!nodeStack || !nodeStack.length) {
  8423. return null;
  8424. }
  8425. var node = nodeStack.pop(),
  8426. text = node.textContent || node.innerText;
  8427. if (text) {
  8428. // TODO: This should match all unicode type B characters (paragraph
  8429. // separator characters). See issue #115.
  8430. var m = text.match(/^.*(\n|\r)/);
  8431. if (m) {
  8432. nodeStack.length = 0;
  8433. return m[0];
  8434. }
  8435. return text;
  8436. }
  8437. if (node.tagName === "ruby") {
  8438. return nextTextNode(nodeStack);
  8439. }
  8440. if (node.childNodes) {
  8441. pushNodes(nodeStack, node);
  8442. return nextTextNode(nodeStack);
  8443. }
  8444. }
  8445. pushNodes(nodeStack, cueDiv);
  8446. while (text = nextTextNode(nodeStack)) {
  8447. for (var i = 0; i < text.length; i++) {
  8448. charCode = text.charCodeAt(i);
  8449. if (isStrongRTLChar(charCode)) {
  8450. return "rtl";
  8451. }
  8452. }
  8453. }
  8454. return "ltr";
  8455. }
  8456. function computeLinePos(cue) {
  8457. if (typeof cue.line === "number" && (cue.snapToLines || cue.line >= 0 && cue.line <= 100)) {
  8458. return cue.line;
  8459. }
  8460. if (!cue.track || !cue.track.textTrackList || !cue.track.textTrackList.mediaElement) {
  8461. return -1;
  8462. }
  8463. var track = cue.track,
  8464. trackList = track.textTrackList,
  8465. count = 0;
  8466. for (var i = 0; i < trackList.length && trackList[i] !== track; i++) {
  8467. if (trackList[i].mode === "showing") {
  8468. count++;
  8469. }
  8470. }
  8471. return ++count * -1;
  8472. }
  8473. function StyleBox() {} // Apply styles to a div. If there is no div passed then it defaults to the
  8474. // div on 'this'.
  8475. StyleBox.prototype.applyStyles = function (styles, div) {
  8476. div = div || this.div;
  8477. for (var prop in styles) {
  8478. if (styles.hasOwnProperty(prop)) {
  8479. div.style[prop] = styles[prop];
  8480. }
  8481. }
  8482. };
  8483. StyleBox.prototype.formatStyle = function (val, unit) {
  8484. return val === 0 ? 0 : val + unit;
  8485. }; // Constructs the computed display state of the cue (a div). Places the div
  8486. // into the overlay which should be a block level element (usually a div).
  8487. function CueStyleBox(window, cue, styleOptions) {
  8488. StyleBox.call(this);
  8489. this.cue = cue; // Parse our cue's text into a DOM tree rooted at 'cueDiv'. This div will
  8490. // have inline positioning and will function as the cue background box.
  8491. this.cueDiv = parseContent(window, cue.text);
  8492. var styles = {
  8493. color: "rgba(255, 255, 255, 1)",
  8494. backgroundColor: "rgba(0, 0, 0, 0.8)",
  8495. position: "relative",
  8496. left: 0,
  8497. right: 0,
  8498. top: 0,
  8499. bottom: 0,
  8500. display: "inline",
  8501. writingMode: cue.vertical === "" ? "horizontal-tb" : cue.vertical === "lr" ? "vertical-lr" : "vertical-rl",
  8502. unicodeBidi: "plaintext"
  8503. };
  8504. this.applyStyles(styles, this.cueDiv); // Create an absolutely positioned div that will be used to position the cue
  8505. // div. Note, all WebVTT cue-setting alignments are equivalent to the CSS
  8506. // mirrors of them except "middle" which is "center" in CSS.
  8507. this.div = window.document.createElement("div");
  8508. styles = {
  8509. direction: determineBidi(this.cueDiv),
  8510. writingMode: cue.vertical === "" ? "horizontal-tb" : cue.vertical === "lr" ? "vertical-lr" : "vertical-rl",
  8511. unicodeBidi: "plaintext",
  8512. textAlign: cue.align === "middle" ? "center" : cue.align,
  8513. font: styleOptions.font,
  8514. whiteSpace: "pre-line",
  8515. position: "absolute"
  8516. };
  8517. this.applyStyles(styles);
  8518. this.div.appendChild(this.cueDiv); // Calculate the distance from the reference edge of the viewport to the text
  8519. // position of the cue box. The reference edge will be resolved later when
  8520. // the box orientation styles are applied.
  8521. var textPos = 0;
  8522. switch (cue.positionAlign) {
  8523. case "start":
  8524. textPos = cue.position;
  8525. break;
  8526. case "middle":
  8527. textPos = cue.position - cue.size / 2;
  8528. break;
  8529. case "end":
  8530. textPos = cue.position - cue.size;
  8531. break;
  8532. } // Horizontal box orientation; textPos is the distance from the left edge of the
  8533. // area to the left edge of the box and cue.size is the distance extending to
  8534. // the right from there.
  8535. if (cue.vertical === "") {
  8536. this.applyStyles({
  8537. left: this.formatStyle(textPos, "%"),
  8538. width: this.formatStyle(cue.size, "%")
  8539. }); // Vertical box orientation; textPos is the distance from the top edge of the
  8540. // area to the top edge of the box and cue.size is the height extending
  8541. // downwards from there.
  8542. } else {
  8543. this.applyStyles({
  8544. top: this.formatStyle(textPos, "%"),
  8545. height: this.formatStyle(cue.size, "%")
  8546. });
  8547. }
  8548. this.move = function (box) {
  8549. this.applyStyles({
  8550. top: this.formatStyle(box.top, "px"),
  8551. bottom: this.formatStyle(box.bottom, "px"),
  8552. left: this.formatStyle(box.left, "px"),
  8553. right: this.formatStyle(box.right, "px"),
  8554. height: this.formatStyle(box.height, "px"),
  8555. width: this.formatStyle(box.width, "px")
  8556. });
  8557. };
  8558. }
  8559. CueStyleBox.prototype = _objCreate(StyleBox.prototype);
  8560. CueStyleBox.prototype.constructor = CueStyleBox; // Represents the co-ordinates of an Element in a way that we can easily
  8561. // compute things with such as if it overlaps or intersects with another Element.
  8562. // Can initialize it with either a StyleBox or another BoxPosition.
  8563. function BoxPosition(obj) {
  8564. // Either a BoxPosition was passed in and we need to copy it, or a StyleBox
  8565. // was passed in and we need to copy the results of 'getBoundingClientRect'
  8566. // as the object returned is readonly. All co-ordinate values are in reference
  8567. // to the viewport origin (top left).
  8568. var lh, height, width, top;
  8569. if (obj.div) {
  8570. height = obj.div.offsetHeight;
  8571. width = obj.div.offsetWidth;
  8572. top = obj.div.offsetTop;
  8573. var rects = (rects = obj.div.childNodes) && (rects = rects[0]) && rects.getClientRects && rects.getClientRects();
  8574. obj = obj.div.getBoundingClientRect(); // In certain cases the outter div will be slightly larger then the sum of
  8575. // the inner div's lines. This could be due to bold text, etc, on some platforms.
  8576. // In this case we should get the average line height and use that. This will
  8577. // result in the desired behaviour.
  8578. lh = rects ? Math.max(rects[0] && rects[0].height || 0, obj.height / rects.length) : 0;
  8579. }
  8580. this.left = obj.left;
  8581. this.right = obj.right;
  8582. this.top = obj.top || top;
  8583. this.height = obj.height || height;
  8584. this.bottom = obj.bottom || top + (obj.height || height);
  8585. this.width = obj.width || width;
  8586. this.lineHeight = lh !== undefined ? lh : obj.lineHeight;
  8587. } // Move the box along a particular axis. Optionally pass in an amount to move
  8588. // the box. If no amount is passed then the default is the line height of the
  8589. // box.
  8590. BoxPosition.prototype.move = function (axis, toMove) {
  8591. toMove = toMove !== undefined ? toMove : this.lineHeight;
  8592. switch (axis) {
  8593. case "+x":
  8594. this.left += toMove;
  8595. this.right += toMove;
  8596. break;
  8597. case "-x":
  8598. this.left -= toMove;
  8599. this.right -= toMove;
  8600. break;
  8601. case "+y":
  8602. this.top += toMove;
  8603. this.bottom += toMove;
  8604. break;
  8605. case "-y":
  8606. this.top -= toMove;
  8607. this.bottom -= toMove;
  8608. break;
  8609. }
  8610. }; // Check if this box overlaps another box, b2.
  8611. BoxPosition.prototype.overlaps = function (b2) {
  8612. return this.left < b2.right && this.right > b2.left && this.top < b2.bottom && this.bottom > b2.top;
  8613. }; // Check if this box overlaps any other boxes in boxes.
  8614. BoxPosition.prototype.overlapsAny = function (boxes) {
  8615. for (var i = 0; i < boxes.length; i++) {
  8616. if (this.overlaps(boxes[i])) {
  8617. return true;
  8618. }
  8619. }
  8620. return false;
  8621. }; // Check if this box is within another box.
  8622. BoxPosition.prototype.within = function (container) {
  8623. return this.top >= container.top && this.bottom <= container.bottom && this.left >= container.left && this.right <= container.right;
  8624. }; // Check if this box is entirely within the container or it is overlapping
  8625. // on the edge opposite of the axis direction passed. For example, if "+x" is
  8626. // passed and the box is overlapping on the left edge of the container, then
  8627. // return true.
  8628. BoxPosition.prototype.overlapsOppositeAxis = function (container, axis) {
  8629. switch (axis) {
  8630. case "+x":
  8631. return this.left < container.left;
  8632. case "-x":
  8633. return this.right > container.right;
  8634. case "+y":
  8635. return this.top < container.top;
  8636. case "-y":
  8637. return this.bottom > container.bottom;
  8638. }
  8639. }; // Find the percentage of the area that this box is overlapping with another
  8640. // box.
  8641. BoxPosition.prototype.intersectPercentage = function (b2) {
  8642. var x = Math.max(0, Math.min(this.right, b2.right) - Math.max(this.left, b2.left)),
  8643. y = Math.max(0, Math.min(this.bottom, b2.bottom) - Math.max(this.top, b2.top)),
  8644. intersectArea = x * y;
  8645. return intersectArea / (this.height * this.width);
  8646. }; // Convert the positions from this box to CSS compatible positions using
  8647. // the reference container's positions. This has to be done because this
  8648. // box's positions are in reference to the viewport origin, whereas, CSS
  8649. // values are in referecne to their respective edges.
  8650. BoxPosition.prototype.toCSSCompatValues = function (reference) {
  8651. return {
  8652. top: this.top - reference.top,
  8653. bottom: reference.bottom - this.bottom,
  8654. left: this.left - reference.left,
  8655. right: reference.right - this.right,
  8656. height: this.height,
  8657. width: this.width
  8658. };
  8659. }; // Get an object that represents the box's position without anything extra.
  8660. // Can pass a StyleBox, HTMLElement, or another BoxPositon.
  8661. BoxPosition.getSimpleBoxPosition = function (obj) {
  8662. var height = obj.div ? obj.div.offsetHeight : obj.tagName ? obj.offsetHeight : 0;
  8663. var width = obj.div ? obj.div.offsetWidth : obj.tagName ? obj.offsetWidth : 0;
  8664. var top = obj.div ? obj.div.offsetTop : obj.tagName ? obj.offsetTop : 0;
  8665. obj = obj.div ? obj.div.getBoundingClientRect() : obj.tagName ? obj.getBoundingClientRect() : obj;
  8666. var ret = {
  8667. left: obj.left,
  8668. right: obj.right,
  8669. top: obj.top || top,
  8670. height: obj.height || height,
  8671. bottom: obj.bottom || top + (obj.height || height),
  8672. width: obj.width || width
  8673. };
  8674. return ret;
  8675. }; // Move a StyleBox to its specified, or next best, position. The containerBox
  8676. // is the box that contains the StyleBox, such as a div. boxPositions are
  8677. // a list of other boxes that the styleBox can't overlap with.
  8678. function moveBoxToLinePosition(window, styleBox, containerBox, boxPositions) {
  8679. // Find the best position for a cue box, b, on the video. The axis parameter
  8680. // is a list of axis, the order of which, it will move the box along. For example:
  8681. // Passing ["+x", "-x"] will move the box first along the x axis in the positive
  8682. // direction. If it doesn't find a good position for it there it will then move
  8683. // it along the x axis in the negative direction.
  8684. function findBestPosition(b, axis) {
  8685. var bestPosition,
  8686. specifiedPosition = new BoxPosition(b),
  8687. percentage = 1; // Highest possible so the first thing we get is better.
  8688. for (var i = 0; i < axis.length; i++) {
  8689. while (b.overlapsOppositeAxis(containerBox, axis[i]) || b.within(containerBox) && b.overlapsAny(boxPositions)) {
  8690. b.move(axis[i]);
  8691. } // We found a spot where we aren't overlapping anything. This is our
  8692. // best position.
  8693. if (b.within(containerBox)) {
  8694. return b;
  8695. }
  8696. var p = b.intersectPercentage(containerBox); // If we're outside the container box less then we were on our last try
  8697. // then remember this position as the best position.
  8698. if (percentage > p) {
  8699. bestPosition = new BoxPosition(b);
  8700. percentage = p;
  8701. } // Reset the box position to the specified position.
  8702. b = new BoxPosition(specifiedPosition);
  8703. }
  8704. return bestPosition || specifiedPosition;
  8705. }
  8706. var boxPosition = new BoxPosition(styleBox),
  8707. cue = styleBox.cue,
  8708. linePos = computeLinePos(cue),
  8709. axis = []; // If we have a line number to align the cue to.
  8710. if (cue.snapToLines) {
  8711. var size;
  8712. switch (cue.vertical) {
  8713. case "":
  8714. axis = ["+y", "-y"];
  8715. size = "height";
  8716. break;
  8717. case "rl":
  8718. axis = ["+x", "-x"];
  8719. size = "width";
  8720. break;
  8721. case "lr":
  8722. axis = ["-x", "+x"];
  8723. size = "width";
  8724. break;
  8725. }
  8726. var step = boxPosition.lineHeight,
  8727. position = step * Math.round(linePos),
  8728. maxPosition = containerBox[size] + step,
  8729. initialAxis = axis[0]; // If the specified intial position is greater then the max position then
  8730. // clamp the box to the amount of steps it would take for the box to
  8731. // reach the max position.
  8732. if (Math.abs(position) > maxPosition) {
  8733. position = position < 0 ? -1 : 1;
  8734. position *= Math.ceil(maxPosition / step) * step;
  8735. } // If computed line position returns negative then line numbers are
  8736. // relative to the bottom of the video instead of the top. Therefore, we
  8737. // need to increase our initial position by the length or width of the
  8738. // video, depending on the writing direction, and reverse our axis directions.
  8739. if (linePos < 0) {
  8740. position += cue.vertical === "" ? containerBox.height : containerBox.width;
  8741. axis = axis.reverse();
  8742. } // Move the box to the specified position. This may not be its best
  8743. // position.
  8744. boxPosition.move(initialAxis, position);
  8745. } else {
  8746. // If we have a percentage line value for the cue.
  8747. var calculatedPercentage = boxPosition.lineHeight / containerBox.height * 100;
  8748. switch (cue.lineAlign) {
  8749. case "middle":
  8750. linePos -= calculatedPercentage / 2;
  8751. break;
  8752. case "end":
  8753. linePos -= calculatedPercentage;
  8754. break;
  8755. } // Apply initial line position to the cue box.
  8756. switch (cue.vertical) {
  8757. case "":
  8758. styleBox.applyStyles({
  8759. top: styleBox.formatStyle(linePos, "%")
  8760. });
  8761. break;
  8762. case "rl":
  8763. styleBox.applyStyles({
  8764. left: styleBox.formatStyle(linePos, "%")
  8765. });
  8766. break;
  8767. case "lr":
  8768. styleBox.applyStyles({
  8769. right: styleBox.formatStyle(linePos, "%")
  8770. });
  8771. break;
  8772. }
  8773. axis = ["+y", "-x", "+x", "-y"]; // Get the box position again after we've applied the specified positioning
  8774. // to it.
  8775. boxPosition = new BoxPosition(styleBox);
  8776. }
  8777. var bestPosition = findBestPosition(boxPosition, axis);
  8778. styleBox.move(bestPosition.toCSSCompatValues(containerBox));
  8779. }
  8780. function WebVTT$1() {} // Nothing
  8781. // Helper to allow strings to be decoded instead of the default binary utf8 data.
  8782. WebVTT$1.StringDecoder = function () {
  8783. return {
  8784. decode: function decode(data) {
  8785. if (!data) {
  8786. return "";
  8787. }
  8788. if (typeof data !== "string") {
  8789. throw new Error("Error - expected string data.");
  8790. }
  8791. return decodeURIComponent(encodeURIComponent(data));
  8792. }
  8793. };
  8794. };
  8795. WebVTT$1.convertCueToDOMTree = function (window, cuetext) {
  8796. if (!window || !cuetext) {
  8797. return null;
  8798. }
  8799. return parseContent(window, cuetext);
  8800. };
  8801. var FONT_SIZE_PERCENT = 0.05;
  8802. var FONT_STYLE = "sans-serif";
  8803. var CUE_BACKGROUND_PADDING = "1.5%"; // Runs the processing model over the cues and regions passed to it.
  8804. // @param overlay A block level element (usually a div) that the computed cues
  8805. // and regions will be placed into.
  8806. WebVTT$1.processCues = function (window, cues, overlay) {
  8807. if (!window || !cues || !overlay) {
  8808. return null;
  8809. } // Remove all previous children.
  8810. while (overlay.firstChild) {
  8811. overlay.removeChild(overlay.firstChild);
  8812. }
  8813. var paddedOverlay = window.document.createElement("div");
  8814. paddedOverlay.style.position = "absolute";
  8815. paddedOverlay.style.left = "0";
  8816. paddedOverlay.style.right = "0";
  8817. paddedOverlay.style.top = "0";
  8818. paddedOverlay.style.bottom = "0";
  8819. paddedOverlay.style.margin = CUE_BACKGROUND_PADDING;
  8820. overlay.appendChild(paddedOverlay); // Determine if we need to compute the display states of the cues. This could
  8821. // be the case if a cue's state has been changed since the last computation or
  8822. // if it has not been computed yet.
  8823. function shouldCompute(cues) {
  8824. for (var i = 0; i < cues.length; i++) {
  8825. if (cues[i].hasBeenReset || !cues[i].displayState) {
  8826. return true;
  8827. }
  8828. }
  8829. return false;
  8830. } // We don't need to recompute the cues' display states. Just reuse them.
  8831. if (!shouldCompute(cues)) {
  8832. for (var i = 0; i < cues.length; i++) {
  8833. paddedOverlay.appendChild(cues[i].displayState);
  8834. }
  8835. return;
  8836. }
  8837. var boxPositions = [],
  8838. containerBox = BoxPosition.getSimpleBoxPosition(paddedOverlay),
  8839. fontSize = Math.round(containerBox.height * FONT_SIZE_PERCENT * 100) / 100;
  8840. var styleOptions = {
  8841. font: fontSize + "px " + FONT_STYLE
  8842. };
  8843. (function () {
  8844. var styleBox, cue;
  8845. for (var i = 0; i < cues.length; i++) {
  8846. cue = cues[i]; // Compute the intial position and styles of the cue div.
  8847. styleBox = new CueStyleBox(window, cue, styleOptions);
  8848. paddedOverlay.appendChild(styleBox.div); // Move the cue div to it's correct line position.
  8849. moveBoxToLinePosition(window, styleBox, containerBox, boxPositions); // Remember the computed div so that we don't have to recompute it later
  8850. // if we don't have too.
  8851. cue.displayState = styleBox.div;
  8852. boxPositions.push(BoxPosition.getSimpleBoxPosition(styleBox));
  8853. }
  8854. })();
  8855. };
  8856. WebVTT$1.Parser = function (window, vttjs, decoder) {
  8857. if (!decoder) {
  8858. decoder = vttjs;
  8859. vttjs = {};
  8860. }
  8861. if (!vttjs) {
  8862. vttjs = {};
  8863. }
  8864. this.window = window;
  8865. this.vttjs = vttjs;
  8866. this.state = "INITIAL";
  8867. this.buffer = "";
  8868. this.decoder = decoder || new TextDecoder("utf8");
  8869. this.regionList = [];
  8870. };
  8871. WebVTT$1.Parser.prototype = {
  8872. // If the error is a ParsingError then report it to the consumer if
  8873. // possible. If it's not a ParsingError then throw it like normal.
  8874. reportOrThrowError: function reportOrThrowError(e) {
  8875. if (e instanceof ParsingError) {
  8876. this.onparsingerror && this.onparsingerror(e);
  8877. } else {
  8878. throw e;
  8879. }
  8880. },
  8881. parse: function parse(data) {
  8882. var self = this; // If there is no data then we won't decode it, but will just try to parse
  8883. // whatever is in buffer already. This may occur in circumstances, for
  8884. // example when flush() is called.
  8885. if (data) {
  8886. // Try to decode the data that we received.
  8887. self.buffer += self.decoder.decode(data, {
  8888. stream: true
  8889. });
  8890. }
  8891. function collectNextLine() {
  8892. var buffer = self.buffer;
  8893. var pos = 0;
  8894. while (pos < buffer.length && buffer[pos] !== '\r' && buffer[pos] !== '\n') {
  8895. ++pos;
  8896. }
  8897. var line = buffer.substr(0, pos); // Advance the buffer early in case we fail below.
  8898. if (buffer[pos] === '\r') {
  8899. ++pos;
  8900. }
  8901. if (buffer[pos] === '\n') {
  8902. ++pos;
  8903. }
  8904. self.buffer = buffer.substr(pos);
  8905. return line;
  8906. } // 3.4 WebVTT region and WebVTT region settings syntax
  8907. function parseRegion(input) {
  8908. var settings = new Settings();
  8909. parseOptions(input, function (k, v) {
  8910. switch (k) {
  8911. case "id":
  8912. settings.set(k, v);
  8913. break;
  8914. case "width":
  8915. settings.percent(k, v);
  8916. break;
  8917. case "lines":
  8918. settings.integer(k, v);
  8919. break;
  8920. case "regionanchor":
  8921. case "viewportanchor":
  8922. var xy = v.split(',');
  8923. if (xy.length !== 2) {
  8924. break;
  8925. } // We have to make sure both x and y parse, so use a temporary
  8926. // settings object here.
  8927. var anchor = new Settings();
  8928. anchor.percent("x", xy[0]);
  8929. anchor.percent("y", xy[1]);
  8930. if (!anchor.has("x") || !anchor.has("y")) {
  8931. break;
  8932. }
  8933. settings.set(k + "X", anchor.get("x"));
  8934. settings.set(k + "Y", anchor.get("y"));
  8935. break;
  8936. case "scroll":
  8937. settings.alt(k, v, ["up"]);
  8938. break;
  8939. }
  8940. }, /=/, /\s/); // Create the region, using default values for any values that were not
  8941. // specified.
  8942. if (settings.has("id")) {
  8943. var region = new (self.vttjs.VTTRegion || self.window.VTTRegion)();
  8944. region.width = settings.get("width", 100);
  8945. region.lines = settings.get("lines", 3);
  8946. region.regionAnchorX = settings.get("regionanchorX", 0);
  8947. region.regionAnchorY = settings.get("regionanchorY", 100);
  8948. region.viewportAnchorX = settings.get("viewportanchorX", 0);
  8949. region.viewportAnchorY = settings.get("viewportanchorY", 100);
  8950. region.scroll = settings.get("scroll", ""); // Register the region.
  8951. self.onregion && self.onregion(region); // Remember the VTTRegion for later in case we parse any VTTCues that
  8952. // reference it.
  8953. self.regionList.push({
  8954. id: settings.get("id"),
  8955. region: region
  8956. });
  8957. }
  8958. } // draft-pantos-http-live-streaming-20
  8959. // https://tools.ietf.org/html/draft-pantos-http-live-streaming-20#section-3.5
  8960. // 3.5 WebVTT
  8961. function parseTimestampMap(input) {
  8962. var settings = new Settings();
  8963. parseOptions(input, function (k, v) {
  8964. switch (k) {
  8965. case "MPEGT":
  8966. settings.integer(k + 'S', v);
  8967. break;
  8968. case "LOCA":
  8969. settings.set(k + 'L', parseTimeStamp(v));
  8970. break;
  8971. }
  8972. }, /[^\d]:/, /,/);
  8973. self.ontimestampmap && self.ontimestampmap({
  8974. "MPEGTS": settings.get("MPEGTS"),
  8975. "LOCAL": settings.get("LOCAL")
  8976. });
  8977. } // 3.2 WebVTT metadata header syntax
  8978. function parseHeader(input) {
  8979. if (input.match(/X-TIMESTAMP-MAP/)) {
  8980. // This line contains HLS X-TIMESTAMP-MAP metadata
  8981. parseOptions(input, function (k, v) {
  8982. switch (k) {
  8983. case "X-TIMESTAMP-MAP":
  8984. parseTimestampMap(v);
  8985. break;
  8986. }
  8987. }, /=/);
  8988. } else {
  8989. parseOptions(input, function (k, v) {
  8990. switch (k) {
  8991. case "Region":
  8992. // 3.3 WebVTT region metadata header syntax
  8993. parseRegion(v);
  8994. break;
  8995. }
  8996. }, /:/);
  8997. }
  8998. } // 5.1 WebVTT file parsing.
  8999. try {
  9000. var line;
  9001. if (self.state === "INITIAL") {
  9002. // We can't start parsing until we have the first line.
  9003. if (!/\r\n|\n/.test(self.buffer)) {
  9004. return this;
  9005. }
  9006. line = collectNextLine();
  9007. var m = line.match(/^WEBVTT([ \t].*)?$/);
  9008. if (!m || !m[0]) {
  9009. throw new ParsingError(ParsingError.Errors.BadSignature);
  9010. }
  9011. self.state = "HEADER";
  9012. }
  9013. var alreadyCollectedLine = false;
  9014. while (self.buffer) {
  9015. // We can't parse a line until we have the full line.
  9016. if (!/\r\n|\n/.test(self.buffer)) {
  9017. return this;
  9018. }
  9019. if (!alreadyCollectedLine) {
  9020. line = collectNextLine();
  9021. } else {
  9022. alreadyCollectedLine = false;
  9023. }
  9024. switch (self.state) {
  9025. case "HEADER":
  9026. // 13-18 - Allow a header (metadata) under the WEBVTT line.
  9027. if (/:/.test(line)) {
  9028. parseHeader(line);
  9029. } else if (!line) {
  9030. // An empty line terminates the header and starts the body (cues).
  9031. self.state = "ID";
  9032. }
  9033. continue;
  9034. case "NOTE":
  9035. // Ignore NOTE blocks.
  9036. if (!line) {
  9037. self.state = "ID";
  9038. }
  9039. continue;
  9040. case "ID":
  9041. // Check for the start of NOTE blocks.
  9042. if (/^NOTE($|[ \t])/.test(line)) {
  9043. self.state = "NOTE";
  9044. break;
  9045. } // 19-29 - Allow any number of line terminators, then initialize new cue values.
  9046. if (!line) {
  9047. continue;
  9048. }
  9049. self.cue = new (self.vttjs.VTTCue || self.window.VTTCue)(0, 0, "");
  9050. self.state = "CUE"; // 30-39 - Check if self line contains an optional identifier or timing data.
  9051. if (line.indexOf("-->") === -1) {
  9052. self.cue.id = line;
  9053. continue;
  9054. }
  9055. // Process line as start of a cue.
  9056. /*falls through*/
  9057. case "CUE":
  9058. // 40 - Collect cue timings and settings.
  9059. try {
  9060. parseCue(line, self.cue, self.regionList);
  9061. } catch (e) {
  9062. self.reportOrThrowError(e); // In case of an error ignore rest of the cue.
  9063. self.cue = null;
  9064. self.state = "BADCUE";
  9065. continue;
  9066. }
  9067. self.state = "CUETEXT";
  9068. continue;
  9069. case "CUETEXT":
  9070. var hasSubstring = line.indexOf("-->") !== -1; // 34 - If we have an empty line then report the cue.
  9071. // 35 - If we have the special substring '-->' then report the cue,
  9072. // but do not collect the line as we need to process the current
  9073. // one as a new cue.
  9074. if (!line || hasSubstring && (alreadyCollectedLine = true)) {
  9075. // We are done parsing self cue.
  9076. self.oncue && self.oncue(self.cue);
  9077. self.cue = null;
  9078. self.state = "ID";
  9079. continue;
  9080. }
  9081. if (self.cue.text) {
  9082. self.cue.text += "\n";
  9083. }
  9084. self.cue.text += line;
  9085. continue;
  9086. case "BADCUE":
  9087. // BADCUE
  9088. // 54-62 - Collect and discard the remaining cue.
  9089. if (!line) {
  9090. self.state = "ID";
  9091. }
  9092. continue;
  9093. }
  9094. }
  9095. } catch (e) {
  9096. self.reportOrThrowError(e); // If we are currently parsing a cue, report what we have.
  9097. if (self.state === "CUETEXT" && self.cue && self.oncue) {
  9098. self.oncue(self.cue);
  9099. }
  9100. self.cue = null; // Enter BADWEBVTT state if header was not parsed correctly otherwise
  9101. // another exception occurred so enter BADCUE state.
  9102. self.state = self.state === "INITIAL" ? "BADWEBVTT" : "BADCUE";
  9103. }
  9104. return this;
  9105. },
  9106. flush: function flush() {
  9107. var self = this;
  9108. try {
  9109. // Finish decoding the stream.
  9110. self.buffer += self.decoder.decode(); // Synthesize the end of the current cue or region.
  9111. if (self.cue || self.state === "HEADER") {
  9112. self.buffer += "\n\n";
  9113. self.parse();
  9114. } // If we've flushed, parsed, and we're still on the INITIAL state then
  9115. // that means we don't have enough of the stream to parse the first
  9116. // line.
  9117. if (self.state === "INITIAL") {
  9118. throw new ParsingError(ParsingError.Errors.BadSignature);
  9119. }
  9120. } catch (e) {
  9121. self.reportOrThrowError(e);
  9122. }
  9123. self.onflush && self.onflush();
  9124. return this;
  9125. }
  9126. };
  9127. var vtt = WebVTT$1;
  9128. /**
  9129. * Copyright 2013 vtt.js Contributors
  9130. *
  9131. * Licensed under the Apache License, Version 2.0 (the "License");
  9132. * you may not use this file except in compliance with the License.
  9133. * You may obtain a copy of the License at
  9134. *
  9135. * http://www.apache.org/licenses/LICENSE-2.0
  9136. *
  9137. * Unless required by applicable law or agreed to in writing, software
  9138. * distributed under the License is distributed on an "AS IS" BASIS,
  9139. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9140. * See the License for the specific language governing permissions and
  9141. * limitations under the License.
  9142. */
  9143. var autoKeyword = "auto";
  9144. var directionSetting = {
  9145. "": 1,
  9146. "lr": 1,
  9147. "rl": 1
  9148. };
  9149. var alignSetting = {
  9150. "start": 1,
  9151. "middle": 1,
  9152. "end": 1,
  9153. "left": 1,
  9154. "right": 1
  9155. };
  9156. function findDirectionSetting(value) {
  9157. if (typeof value !== "string") {
  9158. return false;
  9159. }
  9160. var dir = directionSetting[value.toLowerCase()];
  9161. return dir ? value.toLowerCase() : false;
  9162. }
  9163. function findAlignSetting(value) {
  9164. if (typeof value !== "string") {
  9165. return false;
  9166. }
  9167. var align = alignSetting[value.toLowerCase()];
  9168. return align ? value.toLowerCase() : false;
  9169. }
  9170. function VTTCue(startTime, endTime, text) {
  9171. /**
  9172. * Shim implementation specific properties. These properties are not in
  9173. * the spec.
  9174. */
  9175. // Lets us know when the VTTCue's data has changed in such a way that we need
  9176. // to recompute its display state. This lets us compute its display state
  9177. // lazily.
  9178. this.hasBeenReset = false;
  9179. /**
  9180. * VTTCue and TextTrackCue properties
  9181. * http://dev.w3.org/html5/webvtt/#vttcue-interface
  9182. */
  9183. var _id = "";
  9184. var _pauseOnExit = false;
  9185. var _startTime = startTime;
  9186. var _endTime = endTime;
  9187. var _text = text;
  9188. var _region = null;
  9189. var _vertical = "";
  9190. var _snapToLines = true;
  9191. var _line = "auto";
  9192. var _lineAlign = "start";
  9193. var _position = 50;
  9194. var _positionAlign = "middle";
  9195. var _size = 50;
  9196. var _align = "middle";
  9197. Object.defineProperties(this, {
  9198. "id": {
  9199. enumerable: true,
  9200. get: function get() {
  9201. return _id;
  9202. },
  9203. set: function set(value) {
  9204. _id = "" + value;
  9205. }
  9206. },
  9207. "pauseOnExit": {
  9208. enumerable: true,
  9209. get: function get() {
  9210. return _pauseOnExit;
  9211. },
  9212. set: function set(value) {
  9213. _pauseOnExit = !!value;
  9214. }
  9215. },
  9216. "startTime": {
  9217. enumerable: true,
  9218. get: function get() {
  9219. return _startTime;
  9220. },
  9221. set: function set(value) {
  9222. if (typeof value !== "number") {
  9223. throw new TypeError("Start time must be set to a number.");
  9224. }
  9225. _startTime = value;
  9226. this.hasBeenReset = true;
  9227. }
  9228. },
  9229. "endTime": {
  9230. enumerable: true,
  9231. get: function get() {
  9232. return _endTime;
  9233. },
  9234. set: function set(value) {
  9235. if (typeof value !== "number") {
  9236. throw new TypeError("End time must be set to a number.");
  9237. }
  9238. _endTime = value;
  9239. this.hasBeenReset = true;
  9240. }
  9241. },
  9242. "text": {
  9243. enumerable: true,
  9244. get: function get() {
  9245. return _text;
  9246. },
  9247. set: function set(value) {
  9248. _text = "" + value;
  9249. this.hasBeenReset = true;
  9250. }
  9251. },
  9252. "region": {
  9253. enumerable: true,
  9254. get: function get() {
  9255. return _region;
  9256. },
  9257. set: function set(value) {
  9258. _region = value;
  9259. this.hasBeenReset = true;
  9260. }
  9261. },
  9262. "vertical": {
  9263. enumerable: true,
  9264. get: function get() {
  9265. return _vertical;
  9266. },
  9267. set: function set(value) {
  9268. var setting = findDirectionSetting(value); // Have to check for false because the setting an be an empty string.
  9269. if (setting === false) {
  9270. throw new SyntaxError("An invalid or illegal string was specified.");
  9271. }
  9272. _vertical = setting;
  9273. this.hasBeenReset = true;
  9274. }
  9275. },
  9276. "snapToLines": {
  9277. enumerable: true,
  9278. get: function get() {
  9279. return _snapToLines;
  9280. },
  9281. set: function set(value) {
  9282. _snapToLines = !!value;
  9283. this.hasBeenReset = true;
  9284. }
  9285. },
  9286. "line": {
  9287. enumerable: true,
  9288. get: function get() {
  9289. return _line;
  9290. },
  9291. set: function set(value) {
  9292. if (typeof value !== "number" && value !== autoKeyword) {
  9293. throw new SyntaxError("An invalid number or illegal string was specified.");
  9294. }
  9295. _line = value;
  9296. this.hasBeenReset = true;
  9297. }
  9298. },
  9299. "lineAlign": {
  9300. enumerable: true,
  9301. get: function get() {
  9302. return _lineAlign;
  9303. },
  9304. set: function set(value) {
  9305. var setting = findAlignSetting(value);
  9306. if (!setting) {
  9307. throw new SyntaxError("An invalid or illegal string was specified.");
  9308. }
  9309. _lineAlign = setting;
  9310. this.hasBeenReset = true;
  9311. }
  9312. },
  9313. "position": {
  9314. enumerable: true,
  9315. get: function get() {
  9316. return _position;
  9317. },
  9318. set: function set(value) {
  9319. if (value < 0 || value > 100) {
  9320. throw new Error("Position must be between 0 and 100.");
  9321. }
  9322. _position = value;
  9323. this.hasBeenReset = true;
  9324. }
  9325. },
  9326. "positionAlign": {
  9327. enumerable: true,
  9328. get: function get() {
  9329. return _positionAlign;
  9330. },
  9331. set: function set(value) {
  9332. var setting = findAlignSetting(value);
  9333. if (!setting) {
  9334. throw new SyntaxError("An invalid or illegal string was specified.");
  9335. }
  9336. _positionAlign = setting;
  9337. this.hasBeenReset = true;
  9338. }
  9339. },
  9340. "size": {
  9341. enumerable: true,
  9342. get: function get() {
  9343. return _size;
  9344. },
  9345. set: function set(value) {
  9346. if (value < 0 || value > 100) {
  9347. throw new Error("Size must be between 0 and 100.");
  9348. }
  9349. _size = value;
  9350. this.hasBeenReset = true;
  9351. }
  9352. },
  9353. "align": {
  9354. enumerable: true,
  9355. get: function get() {
  9356. return _align;
  9357. },
  9358. set: function set(value) {
  9359. var setting = findAlignSetting(value);
  9360. if (!setting) {
  9361. throw new SyntaxError("An invalid or illegal string was specified.");
  9362. }
  9363. _align = setting;
  9364. this.hasBeenReset = true;
  9365. }
  9366. }
  9367. });
  9368. /**
  9369. * Other <track> spec defined properties
  9370. */
  9371. // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#text-track-cue-display-state
  9372. this.displayState = undefined;
  9373. }
  9374. /**
  9375. * VTTCue methods
  9376. */
  9377. VTTCue.prototype.getCueAsHTML = function () {
  9378. // Assume WebVTT.convertCueToDOMTree is on the global.
  9379. return WebVTT.convertCueToDOMTree(window, this.text);
  9380. };
  9381. var vttcue = VTTCue;
  9382. /**
  9383. * Copyright 2013 vtt.js Contributors
  9384. *
  9385. * Licensed under the Apache License, Version 2.0 (the "License");
  9386. * you may not use this file except in compliance with the License.
  9387. * You may obtain a copy of the License at
  9388. *
  9389. * http://www.apache.org/licenses/LICENSE-2.0
  9390. *
  9391. * Unless required by applicable law or agreed to in writing, software
  9392. * distributed under the License is distributed on an "AS IS" BASIS,
  9393. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9394. * See the License for the specific language governing permissions and
  9395. * limitations under the License.
  9396. */
  9397. var scrollSetting = {
  9398. "": true,
  9399. "up": true
  9400. };
  9401. function findScrollSetting(value) {
  9402. if (typeof value !== "string") {
  9403. return false;
  9404. }
  9405. var scroll = scrollSetting[value.toLowerCase()];
  9406. return scroll ? value.toLowerCase() : false;
  9407. }
  9408. function isValidPercentValue(value) {
  9409. return typeof value === "number" && value >= 0 && value <= 100;
  9410. } // VTTRegion shim http://dev.w3.org/html5/webvtt/#vttregion-interface
  9411. function VTTRegion() {
  9412. var _width = 100;
  9413. var _lines = 3;
  9414. var _regionAnchorX = 0;
  9415. var _regionAnchorY = 100;
  9416. var _viewportAnchorX = 0;
  9417. var _viewportAnchorY = 100;
  9418. var _scroll = "";
  9419. Object.defineProperties(this, {
  9420. "width": {
  9421. enumerable: true,
  9422. get: function get() {
  9423. return _width;
  9424. },
  9425. set: function set(value) {
  9426. if (!isValidPercentValue(value)) {
  9427. throw new Error("Width must be between 0 and 100.");
  9428. }
  9429. _width = value;
  9430. }
  9431. },
  9432. "lines": {
  9433. enumerable: true,
  9434. get: function get() {
  9435. return _lines;
  9436. },
  9437. set: function set(value) {
  9438. if (typeof value !== "number") {
  9439. throw new TypeError("Lines must be set to a number.");
  9440. }
  9441. _lines = value;
  9442. }
  9443. },
  9444. "regionAnchorY": {
  9445. enumerable: true,
  9446. get: function get() {
  9447. return _regionAnchorY;
  9448. },
  9449. set: function set(value) {
  9450. if (!isValidPercentValue(value)) {
  9451. throw new Error("RegionAnchorX must be between 0 and 100.");
  9452. }
  9453. _regionAnchorY = value;
  9454. }
  9455. },
  9456. "regionAnchorX": {
  9457. enumerable: true,
  9458. get: function get() {
  9459. return _regionAnchorX;
  9460. },
  9461. set: function set(value) {
  9462. if (!isValidPercentValue(value)) {
  9463. throw new Error("RegionAnchorY must be between 0 and 100.");
  9464. }
  9465. _regionAnchorX = value;
  9466. }
  9467. },
  9468. "viewportAnchorY": {
  9469. enumerable: true,
  9470. get: function get() {
  9471. return _viewportAnchorY;
  9472. },
  9473. set: function set(value) {
  9474. if (!isValidPercentValue(value)) {
  9475. throw new Error("ViewportAnchorY must be between 0 and 100.");
  9476. }
  9477. _viewportAnchorY = value;
  9478. }
  9479. },
  9480. "viewportAnchorX": {
  9481. enumerable: true,
  9482. get: function get() {
  9483. return _viewportAnchorX;
  9484. },
  9485. set: function set(value) {
  9486. if (!isValidPercentValue(value)) {
  9487. throw new Error("ViewportAnchorX must be between 0 and 100.");
  9488. }
  9489. _viewportAnchorX = value;
  9490. }
  9491. },
  9492. "scroll": {
  9493. enumerable: true,
  9494. get: function get() {
  9495. return _scroll;
  9496. },
  9497. set: function set(value) {
  9498. var setting = findScrollSetting(value); // Have to check for false as an empty string is a legal value.
  9499. if (setting === false) {
  9500. throw new SyntaxError("An invalid or illegal string was specified.");
  9501. }
  9502. _scroll = setting;
  9503. }
  9504. }
  9505. });
  9506. }
  9507. var vttregion = VTTRegion;
  9508. var browserIndex = createCommonjsModule(function (module) {
  9509. /**
  9510. * Copyright 2013 vtt.js Contributors
  9511. *
  9512. * Licensed under the Apache License, Version 2.0 (the "License");
  9513. * you may not use this file except in compliance with the License.
  9514. * You may obtain a copy of the License at
  9515. *
  9516. * http://www.apache.org/licenses/LICENSE-2.0
  9517. *
  9518. * Unless required by applicable law or agreed to in writing, software
  9519. * distributed under the License is distributed on an "AS IS" BASIS,
  9520. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9521. * See the License for the specific language governing permissions and
  9522. * limitations under the License.
  9523. */
  9524. // Default exports for Node. Export the extended versions of VTTCue and
  9525. // VTTRegion in Node since we likely want the capability to convert back and
  9526. // forth between JSON. If we don't then it's not that big of a deal since we're
  9527. // off browser.
  9528. var vttjs = module.exports = {
  9529. WebVTT: vtt,
  9530. VTTCue: vttcue,
  9531. VTTRegion: vttregion
  9532. };
  9533. window$1.vttjs = vttjs;
  9534. window$1.WebVTT = vttjs.WebVTT;
  9535. var cueShim = vttjs.VTTCue;
  9536. var regionShim = vttjs.VTTRegion;
  9537. var nativeVTTCue = window$1.VTTCue;
  9538. var nativeVTTRegion = window$1.VTTRegion;
  9539. vttjs.shim = function () {
  9540. window$1.VTTCue = cueShim;
  9541. window$1.VTTRegion = regionShim;
  9542. };
  9543. vttjs.restore = function () {
  9544. window$1.VTTCue = nativeVTTCue;
  9545. window$1.VTTRegion = nativeVTTRegion;
  9546. };
  9547. if (!window$1.VTTCue) {
  9548. vttjs.shim();
  9549. }
  9550. });
  9551. var browserIndex_1 = browserIndex.WebVTT;
  9552. var browserIndex_2 = browserIndex.VTTCue;
  9553. var browserIndex_3 = browserIndex.VTTRegion;
  9554. /**
  9555. * An Object containing a structure like: `{src: 'url', type: 'mimetype'}` or string
  9556. * that just contains the src url alone.
  9557. * * `var SourceObject = {src: 'http://ex.com/video.mp4', type: 'video/mp4'};`
  9558. * `var SourceString = 'http://example.com/some-video.mp4';`
  9559. *
  9560. * @typedef {Object|string} Tech~SourceObject
  9561. *
  9562. * @property {string} src
  9563. * The url to the source
  9564. *
  9565. * @property {string} type
  9566. * The mime type of the source
  9567. */
  9568. /**
  9569. * A function used by {@link Tech} to create a new {@link TextTrack}.
  9570. *
  9571. * @private
  9572. *
  9573. * @param {Tech} self
  9574. * An instance of the Tech class.
  9575. *
  9576. * @param {string} kind
  9577. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  9578. *
  9579. * @param {string} [label]
  9580. * Label to identify the text track
  9581. *
  9582. * @param {string} [language]
  9583. * Two letter language abbreviation
  9584. *
  9585. * @param {Object} [options={}]
  9586. * An object with additional text track options
  9587. *
  9588. * @return {TextTrack}
  9589. * The text track that was created.
  9590. */
  9591. function createTrackHelper(self, kind, label, language, options) {
  9592. if (options === void 0) {
  9593. options = {};
  9594. }
  9595. var tracks = self.textTracks();
  9596. options.kind = kind;
  9597. if (label) {
  9598. options.label = label;
  9599. }
  9600. if (language) {
  9601. options.language = language;
  9602. }
  9603. options.tech = self;
  9604. var track = new ALL.text.TrackClass(options);
  9605. tracks.addTrack(track);
  9606. return track;
  9607. }
  9608. /**
  9609. * This is the base class for media playback technology controllers, such as
  9610. * {@link Flash} and {@link HTML5}
  9611. *
  9612. * @extends Component
  9613. */
  9614. var Tech =
  9615. /*#__PURE__*/
  9616. function (_Component) {
  9617. _inheritsLoose(Tech, _Component);
  9618. /**
  9619. * Create an instance of this Tech.
  9620. *
  9621. * @param {Object} [options]
  9622. * The key/value store of player options.
  9623. *
  9624. * @param {Component~ReadyCallback} ready
  9625. * Callback function to call when the `HTML5` Tech is ready.
  9626. */
  9627. function Tech(options, ready) {
  9628. var _this;
  9629. if (options === void 0) {
  9630. options = {};
  9631. }
  9632. if (ready === void 0) {
  9633. ready = function ready() {};
  9634. }
  9635. // we don't want the tech to report user activity automatically.
  9636. // This is done manually in addControlsListeners
  9637. options.reportTouchActivity = false;
  9638. _this = _Component.call(this, null, options, ready) || this; // keep track of whether the current source has played at all to
  9639. // implement a very limited played()
  9640. _this.hasStarted_ = false;
  9641. _this.on('playing', function () {
  9642. this.hasStarted_ = true;
  9643. });
  9644. _this.on('loadstart', function () {
  9645. this.hasStarted_ = false;
  9646. });
  9647. ALL.names.forEach(function (name) {
  9648. var props = ALL[name];
  9649. if (options && options[props.getterName]) {
  9650. _this[props.privateName] = options[props.getterName];
  9651. }
  9652. }); // Manually track progress in cases where the browser/flash player doesn't report it.
  9653. if (!_this.featuresProgressEvents) {
  9654. _this.manualProgressOn();
  9655. } // Manually track timeupdates in cases where the browser/flash player doesn't report it.
  9656. if (!_this.featuresTimeupdateEvents) {
  9657. _this.manualTimeUpdatesOn();
  9658. }
  9659. ['Text', 'Audio', 'Video'].forEach(function (track) {
  9660. if (options["native" + track + "Tracks"] === false) {
  9661. _this["featuresNative" + track + "Tracks"] = false;
  9662. }
  9663. });
  9664. if (options.nativeCaptions === false || options.nativeTextTracks === false) {
  9665. _this.featuresNativeTextTracks = false;
  9666. } else if (options.nativeCaptions === true || options.nativeTextTracks === true) {
  9667. _this.featuresNativeTextTracks = true;
  9668. }
  9669. if (!_this.featuresNativeTextTracks) {
  9670. _this.emulateTextTracks();
  9671. }
  9672. _this.autoRemoteTextTracks_ = new ALL.text.ListClass();
  9673. _this.initTrackListeners(); // Turn on component tap events only if not using native controls
  9674. if (!options.nativeControlsForTouch) {
  9675. _this.emitTapEvents();
  9676. }
  9677. if (_this.constructor) {
  9678. _this.name_ = _this.constructor.name || 'Unknown Tech';
  9679. }
  9680. return _this;
  9681. }
  9682. /**
  9683. * A special function to trigger source set in a way that will allow player
  9684. * to re-trigger if the player or tech are not ready yet.
  9685. *
  9686. * @fires Tech#sourceset
  9687. * @param {string} src The source string at the time of the source changing.
  9688. */
  9689. var _proto = Tech.prototype;
  9690. _proto.triggerSourceset = function triggerSourceset(src) {
  9691. var _this2 = this;
  9692. if (!this.isReady_) {
  9693. // on initial ready we have to trigger source set
  9694. // 1ms after ready so that player can watch for it.
  9695. this.one('ready', function () {
  9696. return _this2.setTimeout(function () {
  9697. return _this2.triggerSourceset(src);
  9698. }, 1);
  9699. });
  9700. }
  9701. /**
  9702. * Fired when the source is set on the tech causing the media element
  9703. * to reload.
  9704. *
  9705. * @see {@link Player#event:sourceset}
  9706. * @event Tech#sourceset
  9707. * @type {EventTarget~Event}
  9708. */
  9709. this.trigger({
  9710. src: src,
  9711. type: 'sourceset'
  9712. });
  9713. }
  9714. /* Fallbacks for unsupported event types
  9715. ================================================================================ */
  9716. /**
  9717. * Polyfill the `progress` event for browsers that don't support it natively.
  9718. *
  9719. * @see {@link Tech#trackProgress}
  9720. */
  9721. ;
  9722. _proto.manualProgressOn = function manualProgressOn() {
  9723. this.on('durationchange', this.onDurationChange);
  9724. this.manualProgress = true; // Trigger progress watching when a source begins loading
  9725. this.one('ready', this.trackProgress);
  9726. }
  9727. /**
  9728. * Turn off the polyfill for `progress` events that was created in
  9729. * {@link Tech#manualProgressOn}
  9730. */
  9731. ;
  9732. _proto.manualProgressOff = function manualProgressOff() {
  9733. this.manualProgress = false;
  9734. this.stopTrackingProgress();
  9735. this.off('durationchange', this.onDurationChange);
  9736. }
  9737. /**
  9738. * This is used to trigger a `progress` event when the buffered percent changes. It
  9739. * sets an interval function that will be called every 500 milliseconds to check if the
  9740. * buffer end percent has changed.
  9741. *
  9742. * > This function is called by {@link Tech#manualProgressOn}
  9743. *
  9744. * @param {EventTarget~Event} event
  9745. * The `ready` event that caused this to run.
  9746. *
  9747. * @listens Tech#ready
  9748. * @fires Tech#progress
  9749. */
  9750. ;
  9751. _proto.trackProgress = function trackProgress(event) {
  9752. this.stopTrackingProgress();
  9753. this.progressInterval = this.setInterval(bind(this, function () {
  9754. // Don't trigger unless buffered amount is greater than last time
  9755. var numBufferedPercent = this.bufferedPercent();
  9756. if (this.bufferedPercent_ !== numBufferedPercent) {
  9757. /**
  9758. * See {@link Player#progress}
  9759. *
  9760. * @event Tech#progress
  9761. * @type {EventTarget~Event}
  9762. */
  9763. this.trigger('progress');
  9764. }
  9765. this.bufferedPercent_ = numBufferedPercent;
  9766. if (numBufferedPercent === 1) {
  9767. this.stopTrackingProgress();
  9768. }
  9769. }), 500);
  9770. }
  9771. /**
  9772. * Update our internal duration on a `durationchange` event by calling
  9773. * {@link Tech#duration}.
  9774. *
  9775. * @param {EventTarget~Event} event
  9776. * The `durationchange` event that caused this to run.
  9777. *
  9778. * @listens Tech#durationchange
  9779. */
  9780. ;
  9781. _proto.onDurationChange = function onDurationChange(event) {
  9782. this.duration_ = this.duration();
  9783. }
  9784. /**
  9785. * Get and create a `TimeRange` object for buffering.
  9786. *
  9787. * @return {TimeRange}
  9788. * The time range object that was created.
  9789. */
  9790. ;
  9791. _proto.buffered = function buffered() {
  9792. return createTimeRanges(0, 0);
  9793. }
  9794. /**
  9795. * Get the percentage of the current video that is currently buffered.
  9796. *
  9797. * @return {number}
  9798. * A number from 0 to 1 that represents the decimal percentage of the
  9799. * video that is buffered.
  9800. *
  9801. */
  9802. ;
  9803. _proto.bufferedPercent = function bufferedPercent$1() {
  9804. return bufferedPercent(this.buffered(), this.duration_);
  9805. }
  9806. /**
  9807. * Turn off the polyfill for `progress` events that was created in
  9808. * {@link Tech#manualProgressOn}
  9809. * Stop manually tracking progress events by clearing the interval that was set in
  9810. * {@link Tech#trackProgress}.
  9811. */
  9812. ;
  9813. _proto.stopTrackingProgress = function stopTrackingProgress() {
  9814. this.clearInterval(this.progressInterval);
  9815. }
  9816. /**
  9817. * Polyfill the `timeupdate` event for browsers that don't support it.
  9818. *
  9819. * @see {@link Tech#trackCurrentTime}
  9820. */
  9821. ;
  9822. _proto.manualTimeUpdatesOn = function manualTimeUpdatesOn() {
  9823. this.manualTimeUpdates = true;
  9824. this.on('play', this.trackCurrentTime);
  9825. this.on('pause', this.stopTrackingCurrentTime);
  9826. }
  9827. /**
  9828. * Turn off the polyfill for `timeupdate` events that was created in
  9829. * {@link Tech#manualTimeUpdatesOn}
  9830. */
  9831. ;
  9832. _proto.manualTimeUpdatesOff = function manualTimeUpdatesOff() {
  9833. this.manualTimeUpdates = false;
  9834. this.stopTrackingCurrentTime();
  9835. this.off('play', this.trackCurrentTime);
  9836. this.off('pause', this.stopTrackingCurrentTime);
  9837. }
  9838. /**
  9839. * Sets up an interval function to track current time and trigger `timeupdate` every
  9840. * 250 milliseconds.
  9841. *
  9842. * @listens Tech#play
  9843. * @triggers Tech#timeupdate
  9844. */
  9845. ;
  9846. _proto.trackCurrentTime = function trackCurrentTime() {
  9847. if (this.currentTimeInterval) {
  9848. this.stopTrackingCurrentTime();
  9849. }
  9850. this.currentTimeInterval = this.setInterval(function () {
  9851. /**
  9852. * Triggered at an interval of 250ms to indicated that time is passing in the video.
  9853. *
  9854. * @event Tech#timeupdate
  9855. * @type {EventTarget~Event}
  9856. */
  9857. this.trigger({
  9858. type: 'timeupdate',
  9859. target: this,
  9860. manuallyTriggered: true
  9861. }); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
  9862. }, 250);
  9863. }
  9864. /**
  9865. * Stop the interval function created in {@link Tech#trackCurrentTime} so that the
  9866. * `timeupdate` event is no longer triggered.
  9867. *
  9868. * @listens {Tech#pause}
  9869. */
  9870. ;
  9871. _proto.stopTrackingCurrentTime = function stopTrackingCurrentTime() {
  9872. this.clearInterval(this.currentTimeInterval); // #1002 - if the video ends right before the next timeupdate would happen,
  9873. // the progress bar won't make it all the way to the end
  9874. this.trigger({
  9875. type: 'timeupdate',
  9876. target: this,
  9877. manuallyTriggered: true
  9878. });
  9879. }
  9880. /**
  9881. * Turn off all event polyfills, clear the `Tech`s {@link AudioTrackList},
  9882. * {@link VideoTrackList}, and {@link TextTrackList}, and dispose of this Tech.
  9883. *
  9884. * @fires Component#dispose
  9885. */
  9886. ;
  9887. _proto.dispose = function dispose() {
  9888. // clear out all tracks because we can't reuse them between techs
  9889. this.clearTracks(NORMAL.names); // Turn off any manual progress or timeupdate tracking
  9890. if (this.manualProgress) {
  9891. this.manualProgressOff();
  9892. }
  9893. if (this.manualTimeUpdates) {
  9894. this.manualTimeUpdatesOff();
  9895. }
  9896. _Component.prototype.dispose.call(this);
  9897. }
  9898. /**
  9899. * Clear out a single `TrackList` or an array of `TrackLists` given their names.
  9900. *
  9901. * > Note: Techs without source handlers should call this between sources for `video`
  9902. * & `audio` tracks. You don't want to use them between tracks!
  9903. *
  9904. * @param {string[]|string} types
  9905. * TrackList names to clear, valid names are `video`, `audio`, and
  9906. * `text`.
  9907. */
  9908. ;
  9909. _proto.clearTracks = function clearTracks(types) {
  9910. var _this3 = this;
  9911. types = [].concat(types); // clear out all tracks because we can't reuse them between techs
  9912. types.forEach(function (type) {
  9913. var list = _this3[type + "Tracks"]() || [];
  9914. var i = list.length;
  9915. while (i--) {
  9916. var track = list[i];
  9917. if (type === 'text') {
  9918. _this3.removeRemoteTextTrack(track);
  9919. }
  9920. list.removeTrack(track);
  9921. }
  9922. });
  9923. }
  9924. /**
  9925. * Remove any TextTracks added via addRemoteTextTrack that are
  9926. * flagged for automatic garbage collection
  9927. */
  9928. ;
  9929. _proto.cleanupAutoTextTracks = function cleanupAutoTextTracks() {
  9930. var list = this.autoRemoteTextTracks_ || [];
  9931. var i = list.length;
  9932. while (i--) {
  9933. var track = list[i];
  9934. this.removeRemoteTextTrack(track);
  9935. }
  9936. }
  9937. /**
  9938. * Reset the tech, which will removes all sources and reset the internal readyState.
  9939. *
  9940. * @abstract
  9941. */
  9942. ;
  9943. _proto.reset = function reset() {}
  9944. /**
  9945. * Get or set an error on the Tech.
  9946. *
  9947. * @param {MediaError} [err]
  9948. * Error to set on the Tech
  9949. *
  9950. * @return {MediaError|null}
  9951. * The current error object on the tech, or null if there isn't one.
  9952. */
  9953. ;
  9954. _proto.error = function error(err) {
  9955. if (err !== undefined) {
  9956. this.error_ = new MediaError(err);
  9957. this.trigger('error');
  9958. }
  9959. return this.error_;
  9960. }
  9961. /**
  9962. * Returns the `TimeRange`s that have been played through for the current source.
  9963. *
  9964. * > NOTE: This implementation is incomplete. It does not track the played `TimeRange`.
  9965. * It only checks whether the source has played at all or not.
  9966. *
  9967. * @return {TimeRange}
  9968. * - A single time range if this video has played
  9969. * - An empty set of ranges if not.
  9970. */
  9971. ;
  9972. _proto.played = function played() {
  9973. if (this.hasStarted_) {
  9974. return createTimeRanges(0, 0);
  9975. }
  9976. return createTimeRanges();
  9977. }
  9978. /**
  9979. * Causes a manual time update to occur if {@link Tech#manualTimeUpdatesOn} was
  9980. * previously called.
  9981. *
  9982. * @fires Tech#timeupdate
  9983. */
  9984. ;
  9985. _proto.setCurrentTime = function setCurrentTime() {
  9986. // improve the accuracy of manual timeupdates
  9987. if (this.manualTimeUpdates) {
  9988. /**
  9989. * A manual `timeupdate` event.
  9990. *
  9991. * @event Tech#timeupdate
  9992. * @type {EventTarget~Event}
  9993. */
  9994. this.trigger({
  9995. type: 'timeupdate',
  9996. target: this,
  9997. manuallyTriggered: true
  9998. });
  9999. }
  10000. }
  10001. /**
  10002. * Turn on listeners for {@link VideoTrackList}, {@link {AudioTrackList}, and
  10003. * {@link TextTrackList} events.
  10004. *
  10005. * This adds {@link EventTarget~EventListeners} for `addtrack`, and `removetrack`.
  10006. *
  10007. * @fires Tech#audiotrackchange
  10008. * @fires Tech#videotrackchange
  10009. * @fires Tech#texttrackchange
  10010. */
  10011. ;
  10012. _proto.initTrackListeners = function initTrackListeners() {
  10013. var _this4 = this;
  10014. /**
  10015. * Triggered when tracks are added or removed on the Tech {@link AudioTrackList}
  10016. *
  10017. * @event Tech#audiotrackchange
  10018. * @type {EventTarget~Event}
  10019. */
  10020. /**
  10021. * Triggered when tracks are added or removed on the Tech {@link VideoTrackList}
  10022. *
  10023. * @event Tech#videotrackchange
  10024. * @type {EventTarget~Event}
  10025. */
  10026. /**
  10027. * Triggered when tracks are added or removed on the Tech {@link TextTrackList}
  10028. *
  10029. * @event Tech#texttrackchange
  10030. * @type {EventTarget~Event}
  10031. */
  10032. NORMAL.names.forEach(function (name) {
  10033. var props = NORMAL[name];
  10034. var trackListChanges = function trackListChanges() {
  10035. _this4.trigger(name + "trackchange");
  10036. };
  10037. var tracks = _this4[props.getterName]();
  10038. tracks.addEventListener('removetrack', trackListChanges);
  10039. tracks.addEventListener('addtrack', trackListChanges);
  10040. _this4.on('dispose', function () {
  10041. tracks.removeEventListener('removetrack', trackListChanges);
  10042. tracks.removeEventListener('addtrack', trackListChanges);
  10043. });
  10044. });
  10045. }
  10046. /**
  10047. * Emulate TextTracks using vtt.js if necessary
  10048. *
  10049. * @fires Tech#vttjsloaded
  10050. * @fires Tech#vttjserror
  10051. */
  10052. ;
  10053. _proto.addWebVttScript_ = function addWebVttScript_() {
  10054. var _this5 = this;
  10055. if (window$1.WebVTT) {
  10056. return;
  10057. } // Initially, Tech.el_ is a child of a dummy-div wait until the Component system
  10058. // signals that the Tech is ready at which point Tech.el_ is part of the DOM
  10059. // before inserting the WebVTT script
  10060. if (document.body.contains(this.el())) {
  10061. // load via require if available and vtt.js script location was not passed in
  10062. // as an option. novtt builds will turn the above require call into an empty object
  10063. // which will cause this if check to always fail.
  10064. if (!this.options_['vtt.js'] && isPlain(browserIndex) && Object.keys(browserIndex).length > 0) {
  10065. this.trigger('vttjsloaded');
  10066. return;
  10067. } // load vtt.js via the script location option or the cdn of no location was
  10068. // passed in
  10069. var script = document.createElement('script');
  10070. script.src = this.options_['vtt.js'] || 'https://vjs.zencdn.net/vttjs/0.14.1/vtt.min.js';
  10071. script.onload = function () {
  10072. /**
  10073. * Fired when vtt.js is loaded.
  10074. *
  10075. * @event Tech#vttjsloaded
  10076. * @type {EventTarget~Event}
  10077. */
  10078. _this5.trigger('vttjsloaded');
  10079. };
  10080. script.onerror = function () {
  10081. /**
  10082. * Fired when vtt.js was not loaded due to an error
  10083. *
  10084. * @event Tech#vttjsloaded
  10085. * @type {EventTarget~Event}
  10086. */
  10087. _this5.trigger('vttjserror');
  10088. };
  10089. this.on('dispose', function () {
  10090. script.onload = null;
  10091. script.onerror = null;
  10092. }); // but have not loaded yet and we set it to true before the inject so that
  10093. // we don't overwrite the injected window.WebVTT if it loads right away
  10094. window$1.WebVTT = true;
  10095. this.el().parentNode.appendChild(script);
  10096. } else {
  10097. this.ready(this.addWebVttScript_);
  10098. }
  10099. }
  10100. /**
  10101. * Emulate texttracks
  10102. *
  10103. */
  10104. ;
  10105. _proto.emulateTextTracks = function emulateTextTracks() {
  10106. var _this6 = this;
  10107. var tracks = this.textTracks();
  10108. var remoteTracks = this.remoteTextTracks();
  10109. var handleAddTrack = function handleAddTrack(e) {
  10110. return tracks.addTrack(e.track);
  10111. };
  10112. var handleRemoveTrack = function handleRemoveTrack(e) {
  10113. return tracks.removeTrack(e.track);
  10114. };
  10115. remoteTracks.on('addtrack', handleAddTrack);
  10116. remoteTracks.on('removetrack', handleRemoveTrack);
  10117. this.addWebVttScript_();
  10118. var updateDisplay = function updateDisplay() {
  10119. return _this6.trigger('texttrackchange');
  10120. };
  10121. var textTracksChanges = function textTracksChanges() {
  10122. updateDisplay();
  10123. for (var i = 0; i < tracks.length; i++) {
  10124. var track = tracks[i];
  10125. track.removeEventListener('cuechange', updateDisplay);
  10126. if (track.mode === 'showing') {
  10127. track.addEventListener('cuechange', updateDisplay);
  10128. }
  10129. }
  10130. };
  10131. textTracksChanges();
  10132. tracks.addEventListener('change', textTracksChanges);
  10133. tracks.addEventListener('addtrack', textTracksChanges);
  10134. tracks.addEventListener('removetrack', textTracksChanges);
  10135. this.on('dispose', function () {
  10136. remoteTracks.off('addtrack', handleAddTrack);
  10137. remoteTracks.off('removetrack', handleRemoveTrack);
  10138. tracks.removeEventListener('change', textTracksChanges);
  10139. tracks.removeEventListener('addtrack', textTracksChanges);
  10140. tracks.removeEventListener('removetrack', textTracksChanges);
  10141. for (var i = 0; i < tracks.length; i++) {
  10142. var track = tracks[i];
  10143. track.removeEventListener('cuechange', updateDisplay);
  10144. }
  10145. });
  10146. }
  10147. /**
  10148. * Create and returns a remote {@link TextTrack} object.
  10149. *
  10150. * @param {string} kind
  10151. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  10152. *
  10153. * @param {string} [label]
  10154. * Label to identify the text track
  10155. *
  10156. * @param {string} [language]
  10157. * Two letter language abbreviation
  10158. *
  10159. * @return {TextTrack}
  10160. * The TextTrack that gets created.
  10161. */
  10162. ;
  10163. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  10164. if (!kind) {
  10165. throw new Error('TextTrack kind is required but was not provided');
  10166. }
  10167. return createTrackHelper(this, kind, label, language);
  10168. }
  10169. /**
  10170. * Create an emulated TextTrack for use by addRemoteTextTrack
  10171. *
  10172. * This is intended to be overridden by classes that inherit from
  10173. * Tech in order to create native or custom TextTracks.
  10174. *
  10175. * @param {Object} options
  10176. * The object should contain the options to initialize the TextTrack with.
  10177. *
  10178. * @param {string} [options.kind]
  10179. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  10180. *
  10181. * @param {string} [options.label].
  10182. * Label to identify the text track
  10183. *
  10184. * @param {string} [options.language]
  10185. * Two letter language abbreviation.
  10186. *
  10187. * @return {HTMLTrackElement}
  10188. * The track element that gets created.
  10189. */
  10190. ;
  10191. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  10192. var track = mergeOptions(options, {
  10193. tech: this
  10194. });
  10195. return new REMOTE.remoteTextEl.TrackClass(track);
  10196. }
  10197. /**
  10198. * Creates a remote text track object and returns an html track element.
  10199. *
  10200. * > Note: This can be an emulated {@link HTMLTrackElement} or a native one.
  10201. *
  10202. * @param {Object} options
  10203. * See {@link Tech#createRemoteTextTrack} for more detailed properties.
  10204. *
  10205. * @param {boolean} [manualCleanup=true]
  10206. * - When false: the TextTrack will be automatically removed from the video
  10207. * element whenever the source changes
  10208. * - When True: The TextTrack will have to be cleaned up manually
  10209. *
  10210. * @return {HTMLTrackElement}
  10211. * An Html Track Element.
  10212. *
  10213. * @deprecated The default functionality for this function will be equivalent
  10214. * to "manualCleanup=false" in the future. The manualCleanup parameter will
  10215. * also be removed.
  10216. */
  10217. ;
  10218. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  10219. var _this7 = this;
  10220. if (options === void 0) {
  10221. options = {};
  10222. }
  10223. var htmlTrackElement = this.createRemoteTextTrack(options);
  10224. if (manualCleanup !== true && manualCleanup !== false) {
  10225. // deprecation warning
  10226. log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js');
  10227. manualCleanup = true;
  10228. } // store HTMLTrackElement and TextTrack to remote list
  10229. this.remoteTextTrackEls().addTrackElement_(htmlTrackElement);
  10230. this.remoteTextTracks().addTrack(htmlTrackElement.track);
  10231. if (manualCleanup !== true) {
  10232. // create the TextTrackList if it doesn't exist
  10233. this.ready(function () {
  10234. return _this7.autoRemoteTextTracks_.addTrack(htmlTrackElement.track);
  10235. });
  10236. }
  10237. return htmlTrackElement;
  10238. }
  10239. /**
  10240. * Remove a remote text track from the remote `TextTrackList`.
  10241. *
  10242. * @param {TextTrack} track
  10243. * `TextTrack` to remove from the `TextTrackList`
  10244. */
  10245. ;
  10246. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  10247. var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track); // remove HTMLTrackElement and TextTrack from remote list
  10248. this.remoteTextTrackEls().removeTrackElement_(trackElement);
  10249. this.remoteTextTracks().removeTrack(track);
  10250. this.autoRemoteTextTracks_.removeTrack(track);
  10251. }
  10252. /**
  10253. * Gets available media playback quality metrics as specified by the W3C's Media
  10254. * Playback Quality API.
  10255. *
  10256. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  10257. *
  10258. * @return {Object}
  10259. * An object with supported media playback quality metrics
  10260. *
  10261. * @abstract
  10262. */
  10263. ;
  10264. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  10265. return {};
  10266. }
  10267. /**
  10268. * Attempt to create a floating video window always on top of other windows
  10269. * so that users may continue consuming media while they interact with other
  10270. * content sites, or applications on their device.
  10271. *
  10272. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  10273. *
  10274. * @return {Promise|undefined}
  10275. * A promise with a Picture-in-Picture window if the browser supports
  10276. * Promises (or one was passed in as an option). It returns undefined
  10277. * otherwise.
  10278. *
  10279. * @abstract
  10280. */
  10281. ;
  10282. _proto.requestPictureInPicture = function requestPictureInPicture() {
  10283. var PromiseClass = this.options_.Promise || window$1.Promise;
  10284. if (PromiseClass) {
  10285. return PromiseClass.reject();
  10286. }
  10287. }
  10288. /**
  10289. * A method to set a poster from a `Tech`.
  10290. *
  10291. * @abstract
  10292. */
  10293. ;
  10294. _proto.setPoster = function setPoster() {}
  10295. /**
  10296. * A method to check for the presence of the 'playsinline' <video> attribute.
  10297. *
  10298. * @abstract
  10299. */
  10300. ;
  10301. _proto.playsinline = function playsinline() {}
  10302. /**
  10303. * A method to set or unset the 'playsinline' <video> attribute.
  10304. *
  10305. * @abstract
  10306. */
  10307. ;
  10308. _proto.setPlaysinline = function setPlaysinline() {}
  10309. /**
  10310. * Attempt to force override of native audio tracks.
  10311. *
  10312. * @param {boolean} override - If set to true native audio will be overridden,
  10313. * otherwise native audio will potentially be used.
  10314. *
  10315. * @abstract
  10316. */
  10317. ;
  10318. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks() {}
  10319. /**
  10320. * Attempt to force override of native video tracks.
  10321. *
  10322. * @param {boolean} override - If set to true native video will be overridden,
  10323. * otherwise native video will potentially be used.
  10324. *
  10325. * @abstract
  10326. */
  10327. ;
  10328. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks() {}
  10329. /*
  10330. * Check if the tech can support the given mime-type.
  10331. *
  10332. * The base tech does not support any type, but source handlers might
  10333. * overwrite this.
  10334. *
  10335. * @param {string} type
  10336. * The mimetype to check for support
  10337. *
  10338. * @return {string}
  10339. * 'probably', 'maybe', or empty string
  10340. *
  10341. * @see [Spec]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canPlayType}
  10342. *
  10343. * @abstract
  10344. */
  10345. ;
  10346. _proto.canPlayType = function canPlayType() {
  10347. return '';
  10348. }
  10349. /**
  10350. * Check if the type is supported by this tech.
  10351. *
  10352. * The base tech does not support any type, but source handlers might
  10353. * overwrite this.
  10354. *
  10355. * @param {string} type
  10356. * The media type to check
  10357. * @return {string} Returns the native video element's response
  10358. */
  10359. ;
  10360. Tech.canPlayType = function canPlayType() {
  10361. return '';
  10362. }
  10363. /**
  10364. * Check if the tech can support the given source
  10365. *
  10366. * @param {Object} srcObj
  10367. * The source object
  10368. * @param {Object} options
  10369. * The options passed to the tech
  10370. * @return {string} 'probably', 'maybe', or '' (empty string)
  10371. */
  10372. ;
  10373. Tech.canPlaySource = function canPlaySource(srcObj, options) {
  10374. return Tech.canPlayType(srcObj.type);
  10375. }
  10376. /*
  10377. * Return whether the argument is a Tech or not.
  10378. * Can be passed either a Class like `Html5` or a instance like `player.tech_`
  10379. *
  10380. * @param {Object} component
  10381. * The item to check
  10382. *
  10383. * @return {boolean}
  10384. * Whether it is a tech or not
  10385. * - True if it is a tech
  10386. * - False if it is not
  10387. */
  10388. ;
  10389. Tech.isTech = function isTech(component) {
  10390. return component.prototype instanceof Tech || component instanceof Tech || component === Tech;
  10391. }
  10392. /**
  10393. * Registers a `Tech` into a shared list for videojs.
  10394. *
  10395. * @param {string} name
  10396. * Name of the `Tech` to register.
  10397. *
  10398. * @param {Object} tech
  10399. * The `Tech` class to register.
  10400. */
  10401. ;
  10402. Tech.registerTech = function registerTech(name, tech) {
  10403. if (!Tech.techs_) {
  10404. Tech.techs_ = {};
  10405. }
  10406. if (!Tech.isTech(tech)) {
  10407. throw new Error("Tech " + name + " must be a Tech");
  10408. }
  10409. if (!Tech.canPlayType) {
  10410. throw new Error('Techs must have a static canPlayType method on them');
  10411. }
  10412. if (!Tech.canPlaySource) {
  10413. throw new Error('Techs must have a static canPlaySource method on them');
  10414. }
  10415. name = toTitleCase(name);
  10416. Tech.techs_[name] = tech;
  10417. Tech.techs_[toLowerCase(name)] = tech;
  10418. if (name !== 'Tech') {
  10419. // camel case the techName for use in techOrder
  10420. Tech.defaultTechOrder_.push(name);
  10421. }
  10422. return tech;
  10423. }
  10424. /**
  10425. * Get a `Tech` from the shared list by name.
  10426. *
  10427. * @param {string} name
  10428. * `camelCase` or `TitleCase` name of the Tech to get
  10429. *
  10430. * @return {Tech|undefined}
  10431. * The `Tech` or undefined if there was no tech with the name requested.
  10432. */
  10433. ;
  10434. Tech.getTech = function getTech(name) {
  10435. if (!name) {
  10436. return;
  10437. }
  10438. if (Tech.techs_ && Tech.techs_[name]) {
  10439. return Tech.techs_[name];
  10440. }
  10441. name = toTitleCase(name);
  10442. if (window$1 && window$1.videojs && window$1.videojs[name]) {
  10443. log.warn("The " + name + " tech was added to the videojs object when it should be registered using videojs.registerTech(name, tech)");
  10444. return window$1.videojs[name];
  10445. }
  10446. };
  10447. return Tech;
  10448. }(Component);
  10449. /**
  10450. * Get the {@link VideoTrackList}
  10451. *
  10452. * @returns {VideoTrackList}
  10453. * @method Tech.prototype.videoTracks
  10454. */
  10455. /**
  10456. * Get the {@link AudioTrackList}
  10457. *
  10458. * @returns {AudioTrackList}
  10459. * @method Tech.prototype.audioTracks
  10460. */
  10461. /**
  10462. * Get the {@link TextTrackList}
  10463. *
  10464. * @returns {TextTrackList}
  10465. * @method Tech.prototype.textTracks
  10466. */
  10467. /**
  10468. * Get the remote element {@link TextTrackList}
  10469. *
  10470. * @returns {TextTrackList}
  10471. * @method Tech.prototype.remoteTextTracks
  10472. */
  10473. /**
  10474. * Get the remote element {@link HtmlTrackElementList}
  10475. *
  10476. * @returns {HtmlTrackElementList}
  10477. * @method Tech.prototype.remoteTextTrackEls
  10478. */
  10479. ALL.names.forEach(function (name) {
  10480. var props = ALL[name];
  10481. Tech.prototype[props.getterName] = function () {
  10482. this[props.privateName] = this[props.privateName] || new props.ListClass();
  10483. return this[props.privateName];
  10484. };
  10485. });
  10486. /**
  10487. * List of associated text tracks
  10488. *
  10489. * @type {TextTrackList}
  10490. * @private
  10491. * @property Tech#textTracks_
  10492. */
  10493. /**
  10494. * List of associated audio tracks.
  10495. *
  10496. * @type {AudioTrackList}
  10497. * @private
  10498. * @property Tech#audioTracks_
  10499. */
  10500. /**
  10501. * List of associated video tracks.
  10502. *
  10503. * @type {VideoTrackList}
  10504. * @private
  10505. * @property Tech#videoTracks_
  10506. */
  10507. /**
  10508. * Boolean indicating whether the `Tech` supports volume control.
  10509. *
  10510. * @type {boolean}
  10511. * @default
  10512. */
  10513. Tech.prototype.featuresVolumeControl = true;
  10514. /**
  10515. * Boolean indicating whether the `Tech` supports muting volume.
  10516. *
  10517. * @type {bolean}
  10518. * @default
  10519. */
  10520. Tech.prototype.featuresMuteControl = true;
  10521. /**
  10522. * Boolean indicating whether the `Tech` supports fullscreen resize control.
  10523. * Resizing plugins using request fullscreen reloads the plugin
  10524. *
  10525. * @type {boolean}
  10526. * @default
  10527. */
  10528. Tech.prototype.featuresFullscreenResize = false;
  10529. /**
  10530. * Boolean indicating whether the `Tech` supports changing the speed at which the video
  10531. * plays. Examples:
  10532. * - Set player to play 2x (twice) as fast
  10533. * - Set player to play 0.5x (half) as fast
  10534. *
  10535. * @type {boolean}
  10536. * @default
  10537. */
  10538. Tech.prototype.featuresPlaybackRate = false;
  10539. /**
  10540. * Boolean indicating whether the `Tech` supports the `progress` event. This is currently
  10541. * not triggered by video-js-swf. This will be used to determine if
  10542. * {@link Tech#manualProgressOn} should be called.
  10543. *
  10544. * @type {boolean}
  10545. * @default
  10546. */
  10547. Tech.prototype.featuresProgressEvents = false;
  10548. /**
  10549. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  10550. *
  10551. * A tech should set this to `true` and then use {@link Tech#triggerSourceset}
  10552. * to trigger a {@link Tech#event:sourceset} at the earliest time after getting
  10553. * a new source.
  10554. *
  10555. * @type {boolean}
  10556. * @default
  10557. */
  10558. Tech.prototype.featuresSourceset = false;
  10559. /**
  10560. * Boolean indicating whether the `Tech` supports the `timeupdate` event. This is currently
  10561. * not triggered by video-js-swf. This will be used to determine if
  10562. * {@link Tech#manualTimeUpdates} should be called.
  10563. *
  10564. * @type {boolean}
  10565. * @default
  10566. */
  10567. Tech.prototype.featuresTimeupdateEvents = false;
  10568. /**
  10569. * Boolean indicating whether the `Tech` supports the native `TextTrack`s.
  10570. * This will help us integrate with native `TextTrack`s if the browser supports them.
  10571. *
  10572. * @type {boolean}
  10573. * @default
  10574. */
  10575. Tech.prototype.featuresNativeTextTracks = false;
  10576. /**
  10577. * A functional mixin for techs that want to use the Source Handler pattern.
  10578. * Source handlers are scripts for handling specific formats.
  10579. * The source handler pattern is used for adaptive formats (HLS, DASH) that
  10580. * manually load video data and feed it into a Source Buffer (Media Source Extensions)
  10581. * Example: `Tech.withSourceHandlers.call(MyTech);`
  10582. *
  10583. * @param {Tech} _Tech
  10584. * The tech to add source handler functions to.
  10585. *
  10586. * @mixes Tech~SourceHandlerAdditions
  10587. */
  10588. Tech.withSourceHandlers = function (_Tech) {
  10589. /**
  10590. * Register a source handler
  10591. *
  10592. * @param {Function} handler
  10593. * The source handler class
  10594. *
  10595. * @param {number} [index]
  10596. * Register it at the following index
  10597. */
  10598. _Tech.registerSourceHandler = function (handler, index) {
  10599. var handlers = _Tech.sourceHandlers;
  10600. if (!handlers) {
  10601. handlers = _Tech.sourceHandlers = [];
  10602. }
  10603. if (index === undefined) {
  10604. // add to the end of the list
  10605. index = handlers.length;
  10606. }
  10607. handlers.splice(index, 0, handler);
  10608. };
  10609. /**
  10610. * Check if the tech can support the given type. Also checks the
  10611. * Techs sourceHandlers.
  10612. *
  10613. * @param {string} type
  10614. * The mimetype to check.
  10615. *
  10616. * @return {string}
  10617. * 'probably', 'maybe', or '' (empty string)
  10618. */
  10619. _Tech.canPlayType = function (type) {
  10620. var handlers = _Tech.sourceHandlers || [];
  10621. var can;
  10622. for (var i = 0; i < handlers.length; i++) {
  10623. can = handlers[i].canPlayType(type);
  10624. if (can) {
  10625. return can;
  10626. }
  10627. }
  10628. return '';
  10629. };
  10630. /**
  10631. * Returns the first source handler that supports the source.
  10632. *
  10633. * TODO: Answer question: should 'probably' be prioritized over 'maybe'
  10634. *
  10635. * @param {Tech~SourceObject} source
  10636. * The source object
  10637. *
  10638. * @param {Object} options
  10639. * The options passed to the tech
  10640. *
  10641. * @return {SourceHandler|null}
  10642. * The first source handler that supports the source or null if
  10643. * no SourceHandler supports the source
  10644. */
  10645. _Tech.selectSourceHandler = function (source, options) {
  10646. var handlers = _Tech.sourceHandlers || [];
  10647. var can;
  10648. for (var i = 0; i < handlers.length; i++) {
  10649. can = handlers[i].canHandleSource(source, options);
  10650. if (can) {
  10651. return handlers[i];
  10652. }
  10653. }
  10654. return null;
  10655. };
  10656. /**
  10657. * Check if the tech can support the given source.
  10658. *
  10659. * @param {Tech~SourceObject} srcObj
  10660. * The source object
  10661. *
  10662. * @param {Object} options
  10663. * The options passed to the tech
  10664. *
  10665. * @return {string}
  10666. * 'probably', 'maybe', or '' (empty string)
  10667. */
  10668. _Tech.canPlaySource = function (srcObj, options) {
  10669. var sh = _Tech.selectSourceHandler(srcObj, options);
  10670. if (sh) {
  10671. return sh.canHandleSource(srcObj, options);
  10672. }
  10673. return '';
  10674. };
  10675. /**
  10676. * When using a source handler, prefer its implementation of
  10677. * any function normally provided by the tech.
  10678. */
  10679. var deferrable = ['seekable', 'seeking', 'duration'];
  10680. /**
  10681. * A wrapper around {@link Tech#seekable} that will call a `SourceHandler`s seekable
  10682. * function if it exists, with a fallback to the Techs seekable function.
  10683. *
  10684. * @method _Tech.seekable
  10685. */
  10686. /**
  10687. * A wrapper around {@link Tech#duration} that will call a `SourceHandler`s duration
  10688. * function if it exists, otherwise it will fallback to the techs duration function.
  10689. *
  10690. * @method _Tech.duration
  10691. */
  10692. deferrable.forEach(function (fnName) {
  10693. var originalFn = this[fnName];
  10694. if (typeof originalFn !== 'function') {
  10695. return;
  10696. }
  10697. this[fnName] = function () {
  10698. if (this.sourceHandler_ && this.sourceHandler_[fnName]) {
  10699. return this.sourceHandler_[fnName].apply(this.sourceHandler_, arguments);
  10700. }
  10701. return originalFn.apply(this, arguments);
  10702. };
  10703. }, _Tech.prototype);
  10704. /**
  10705. * Create a function for setting the source using a source object
  10706. * and source handlers.
  10707. * Should never be called unless a source handler was found.
  10708. *
  10709. * @param {Tech~SourceObject} source
  10710. * A source object with src and type keys
  10711. */
  10712. _Tech.prototype.setSource = function (source) {
  10713. var sh = _Tech.selectSourceHandler(source, this.options_);
  10714. if (!sh) {
  10715. // Fall back to a native source hander when unsupported sources are
  10716. // deliberately set
  10717. if (_Tech.nativeSourceHandler) {
  10718. sh = _Tech.nativeSourceHandler;
  10719. } else {
  10720. log.error('No source handler found for the current source.');
  10721. }
  10722. } // Dispose any existing source handler
  10723. this.disposeSourceHandler();
  10724. this.off('dispose', this.disposeSourceHandler);
  10725. if (sh !== _Tech.nativeSourceHandler) {
  10726. this.currentSource_ = source;
  10727. }
  10728. this.sourceHandler_ = sh.handleSource(source, this, this.options_);
  10729. this.one('dispose', this.disposeSourceHandler);
  10730. };
  10731. /**
  10732. * Clean up any existing SourceHandlers and listeners when the Tech is disposed.
  10733. *
  10734. * @listens Tech#dispose
  10735. */
  10736. _Tech.prototype.disposeSourceHandler = function () {
  10737. // if we have a source and get another one
  10738. // then we are loading something new
  10739. // than clear all of our current tracks
  10740. if (this.currentSource_) {
  10741. this.clearTracks(['audio', 'video']);
  10742. this.currentSource_ = null;
  10743. } // always clean up auto-text tracks
  10744. this.cleanupAutoTextTracks();
  10745. if (this.sourceHandler_) {
  10746. if (this.sourceHandler_.dispose) {
  10747. this.sourceHandler_.dispose();
  10748. }
  10749. this.sourceHandler_ = null;
  10750. }
  10751. };
  10752. }; // The base Tech class needs to be registered as a Component. It is the only
  10753. // Tech that can be registered as a Component.
  10754. Component.registerComponent('Tech', Tech);
  10755. Tech.registerTech('Tech', Tech);
  10756. /**
  10757. * A list of techs that should be added to techOrder on Players
  10758. *
  10759. * @private
  10760. */
  10761. Tech.defaultTechOrder_ = [];
  10762. /**
  10763. * @file middleware.js
  10764. * @module middleware
  10765. */
  10766. var middlewares = {};
  10767. var middlewareInstances = {};
  10768. var TERMINATOR = {};
  10769. /**
  10770. * A middleware object is a plain JavaScript object that has methods that
  10771. * match the {@link Tech} methods found in the lists of allowed
  10772. * {@link module:middleware.allowedGetters|getters},
  10773. * {@link module:middleware.allowedSetters|setters}, and
  10774. * {@link module:middleware.allowedMediators|mediators}.
  10775. *
  10776. * @typedef {Object} MiddlewareObject
  10777. */
  10778. /**
  10779. * A middleware factory function that should return a
  10780. * {@link module:middleware~MiddlewareObject|MiddlewareObject}.
  10781. *
  10782. * This factory will be called for each player when needed, with the player
  10783. * passed in as an argument.
  10784. *
  10785. * @callback MiddlewareFactory
  10786. * @param {Player} player
  10787. * A Video.js player.
  10788. */
  10789. /**
  10790. * Define a middleware that the player should use by way of a factory function
  10791. * that returns a middleware object.
  10792. *
  10793. * @param {string} type
  10794. * The MIME type to match or `"*"` for all MIME types.
  10795. *
  10796. * @param {MiddlewareFactory} middleware
  10797. * A middleware factory function that will be executed for
  10798. * matching types.
  10799. */
  10800. function use(type, middleware) {
  10801. middlewares[type] = middlewares[type] || [];
  10802. middlewares[type].push(middleware);
  10803. }
  10804. /**
  10805. * Asynchronously sets a source using middleware by recursing through any
  10806. * matching middlewares and calling `setSource` on each, passing along the
  10807. * previous returned value each time.
  10808. *
  10809. * @param {Player} player
  10810. * A {@link Player} instance.
  10811. *
  10812. * @param {Tech~SourceObject} src
  10813. * A source object.
  10814. *
  10815. * @param {Function}
  10816. * The next middleware to run.
  10817. */
  10818. function setSource(player, src, next) {
  10819. player.setTimeout(function () {
  10820. return setSourceHelper(src, middlewares[src.type], next, player);
  10821. }, 1);
  10822. }
  10823. /**
  10824. * When the tech is set, passes the tech to each middleware's `setTech` method.
  10825. *
  10826. * @param {Object[]} middleware
  10827. * An array of middleware instances.
  10828. *
  10829. * @param {Tech} tech
  10830. * A Video.js tech.
  10831. */
  10832. function setTech(middleware, tech) {
  10833. middleware.forEach(function (mw) {
  10834. return mw.setTech && mw.setTech(tech);
  10835. });
  10836. }
  10837. /**
  10838. * Calls a getter on the tech first, through each middleware
  10839. * from right to left to the player.
  10840. *
  10841. * @param {Object[]} middleware
  10842. * An array of middleware instances.
  10843. *
  10844. * @param {Tech} tech
  10845. * The current tech.
  10846. *
  10847. * @param {string} method
  10848. * A method name.
  10849. *
  10850. * @return {Mixed}
  10851. * The final value from the tech after middleware has intercepted it.
  10852. */
  10853. function get(middleware, tech, method) {
  10854. return middleware.reduceRight(middlewareIterator(method), tech[method]());
  10855. }
  10856. /**
  10857. * Takes the argument given to the player and calls the setter method on each
  10858. * middleware from left to right to the tech.
  10859. *
  10860. * @param {Object[]} middleware
  10861. * An array of middleware instances.
  10862. *
  10863. * @param {Tech} tech
  10864. * The current tech.
  10865. *
  10866. * @param {string} method
  10867. * A method name.
  10868. *
  10869. * @param {Mixed} arg
  10870. * The value to set on the tech.
  10871. *
  10872. * @return {Mixed}
  10873. * The return value of the `method` of the `tech`.
  10874. */
  10875. function set(middleware, tech, method, arg) {
  10876. return tech[method](middleware.reduce(middlewareIterator(method), arg));
  10877. }
  10878. /**
  10879. * Takes the argument given to the player and calls the `call` version of the
  10880. * method on each middleware from left to right.
  10881. *
  10882. * Then, call the passed in method on the tech and return the result unchanged
  10883. * back to the player, through middleware, this time from right to left.
  10884. *
  10885. * @param {Object[]} middleware
  10886. * An array of middleware instances.
  10887. *
  10888. * @param {Tech} tech
  10889. * The current tech.
  10890. *
  10891. * @param {string} method
  10892. * A method name.
  10893. *
  10894. * @param {Mixed} arg
  10895. * The value to set on the tech.
  10896. *
  10897. * @return {Mixed}
  10898. * The return value of the `method` of the `tech`, regardless of the
  10899. * return values of middlewares.
  10900. */
  10901. function mediate(middleware, tech, method, arg) {
  10902. if (arg === void 0) {
  10903. arg = null;
  10904. }
  10905. var callMethod = 'call' + toTitleCase(method);
  10906. var middlewareValue = middleware.reduce(middlewareIterator(callMethod), arg);
  10907. var terminated = middlewareValue === TERMINATOR; // deprecated. The `null` return value should instead return TERMINATOR to
  10908. // prevent confusion if a techs method actually returns null.
  10909. var returnValue = terminated ? null : tech[method](middlewareValue);
  10910. executeRight(middleware, method, returnValue, terminated);
  10911. return returnValue;
  10912. }
  10913. /**
  10914. * Enumeration of allowed getters where the keys are method names.
  10915. *
  10916. * @type {Object}
  10917. */
  10918. var allowedGetters = {
  10919. buffered: 1,
  10920. currentTime: 1,
  10921. duration: 1,
  10922. seekable: 1,
  10923. played: 1,
  10924. paused: 1,
  10925. volume: 1
  10926. };
  10927. /**
  10928. * Enumeration of allowed setters where the keys are method names.
  10929. *
  10930. * @type {Object}
  10931. */
  10932. var allowedSetters = {
  10933. setCurrentTime: 1,
  10934. setVolume: 1
  10935. };
  10936. /**
  10937. * Enumeration of allowed mediators where the keys are method names.
  10938. *
  10939. * @type {Object}
  10940. */
  10941. var allowedMediators = {
  10942. play: 1,
  10943. pause: 1
  10944. };
  10945. function middlewareIterator(method) {
  10946. return function (value, mw) {
  10947. // if the previous middleware terminated, pass along the termination
  10948. if (value === TERMINATOR) {
  10949. return TERMINATOR;
  10950. }
  10951. if (mw[method]) {
  10952. return mw[method](value);
  10953. }
  10954. return value;
  10955. };
  10956. }
  10957. function executeRight(mws, method, value, terminated) {
  10958. for (var i = mws.length - 1; i >= 0; i--) {
  10959. var mw = mws[i];
  10960. if (mw[method]) {
  10961. mw[method](terminated, value);
  10962. }
  10963. }
  10964. }
  10965. /**
  10966. * Clear the middleware cache for a player.
  10967. *
  10968. * @param {Player} player
  10969. * A {@link Player} instance.
  10970. */
  10971. function clearCacheForPlayer(player) {
  10972. middlewareInstances[player.id()] = null;
  10973. }
  10974. /**
  10975. * {
  10976. * [playerId]: [[mwFactory, mwInstance], ...]
  10977. * }
  10978. *
  10979. * @private
  10980. */
  10981. function getOrCreateFactory(player, mwFactory) {
  10982. var mws = middlewareInstances[player.id()];
  10983. var mw = null;
  10984. if (mws === undefined || mws === null) {
  10985. mw = mwFactory(player);
  10986. middlewareInstances[player.id()] = [[mwFactory, mw]];
  10987. return mw;
  10988. }
  10989. for (var i = 0; i < mws.length; i++) {
  10990. var _mws$i = mws[i],
  10991. mwf = _mws$i[0],
  10992. mwi = _mws$i[1];
  10993. if (mwf !== mwFactory) {
  10994. continue;
  10995. }
  10996. mw = mwi;
  10997. }
  10998. if (mw === null) {
  10999. mw = mwFactory(player);
  11000. mws.push([mwFactory, mw]);
  11001. }
  11002. return mw;
  11003. }
  11004. function setSourceHelper(src, middleware, next, player, acc, lastRun) {
  11005. if (src === void 0) {
  11006. src = {};
  11007. }
  11008. if (middleware === void 0) {
  11009. middleware = [];
  11010. }
  11011. if (acc === void 0) {
  11012. acc = [];
  11013. }
  11014. if (lastRun === void 0) {
  11015. lastRun = false;
  11016. }
  11017. var _middleware = middleware,
  11018. mwFactory = _middleware[0],
  11019. mwrest = _middleware.slice(1); // if mwFactory is a string, then we're at a fork in the road
  11020. if (typeof mwFactory === 'string') {
  11021. setSourceHelper(src, middlewares[mwFactory], next, player, acc, lastRun); // if we have an mwFactory, call it with the player to get the mw,
  11022. // then call the mw's setSource method
  11023. } else if (mwFactory) {
  11024. var mw = getOrCreateFactory(player, mwFactory); // if setSource isn't present, implicitly select this middleware
  11025. if (!mw.setSource) {
  11026. acc.push(mw);
  11027. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  11028. }
  11029. mw.setSource(assign({}, src), function (err, _src) {
  11030. // something happened, try the next middleware on the current level
  11031. // make sure to use the old src
  11032. if (err) {
  11033. return setSourceHelper(src, mwrest, next, player, acc, lastRun);
  11034. } // we've succeeded, now we need to go deeper
  11035. acc.push(mw); // if it's the same type, continue down the current chain
  11036. // otherwise, we want to go down the new chain
  11037. setSourceHelper(_src, src.type === _src.type ? mwrest : middlewares[_src.type], next, player, acc, lastRun);
  11038. });
  11039. } else if (mwrest.length) {
  11040. setSourceHelper(src, mwrest, next, player, acc, lastRun);
  11041. } else if (lastRun) {
  11042. next(src, acc);
  11043. } else {
  11044. setSourceHelper(src, middlewares['*'], next, player, acc, true);
  11045. }
  11046. }
  11047. /**
  11048. * Mimetypes
  11049. *
  11050. * @see http://hul.harvard.edu/ois/////systems/wax/wax-public-help/mimetypes.htm
  11051. * @typedef Mimetypes~Kind
  11052. * @enum
  11053. */
  11054. var MimetypesKind = {
  11055. opus: 'video/ogg',
  11056. ogv: 'video/ogg',
  11057. mp4: 'video/mp4',
  11058. mov: 'video/mp4',
  11059. m4v: 'video/mp4',
  11060. mkv: 'video/x-matroska',
  11061. m4a: 'audio/mp4',
  11062. mp3: 'audio/mpeg',
  11063. aac: 'audio/aac',
  11064. oga: 'audio/ogg',
  11065. m3u8: 'application/x-mpegURL',
  11066. jpg: 'image/jpeg',
  11067. jpeg: 'image/jpeg',
  11068. gif: 'image/gif',
  11069. png: 'image/png',
  11070. svg: 'image/svg+xml',
  11071. webp: 'image/webp'
  11072. };
  11073. /**
  11074. * Get the mimetype of a given src url if possible
  11075. *
  11076. * @param {string} src
  11077. * The url to the src
  11078. *
  11079. * @return {string}
  11080. * return the mimetype if it was known or empty string otherwise
  11081. */
  11082. var getMimetype = function getMimetype(src) {
  11083. if (src === void 0) {
  11084. src = '';
  11085. }
  11086. var ext = getFileExtension(src);
  11087. var mimetype = MimetypesKind[ext.toLowerCase()];
  11088. return mimetype || '';
  11089. };
  11090. /**
  11091. * Find the mime type of a given source string if possible. Uses the player
  11092. * source cache.
  11093. *
  11094. * @param {Player} player
  11095. * The player object
  11096. *
  11097. * @param {string} src
  11098. * The source string
  11099. *
  11100. * @return {string}
  11101. * The type that was found
  11102. */
  11103. var findMimetype = function findMimetype(player, src) {
  11104. if (!src) {
  11105. return '';
  11106. } // 1. check for the type in the `source` cache
  11107. if (player.cache_.source.src === src && player.cache_.source.type) {
  11108. return player.cache_.source.type;
  11109. } // 2. see if we have this source in our `currentSources` cache
  11110. var matchingSources = player.cache_.sources.filter(function (s) {
  11111. return s.src === src;
  11112. });
  11113. if (matchingSources.length) {
  11114. return matchingSources[0].type;
  11115. } // 3. look for the src url in source elements and use the type there
  11116. var sources = player.$$('source');
  11117. for (var i = 0; i < sources.length; i++) {
  11118. var s = sources[i];
  11119. if (s.type && s.src && s.src === src) {
  11120. return s.type;
  11121. }
  11122. } // 4. finally fallback to our list of mime types based on src url extension
  11123. return getMimetype(src);
  11124. };
  11125. /**
  11126. * @module filter-source
  11127. */
  11128. /**
  11129. * Filter out single bad source objects or multiple source objects in an
  11130. * array. Also flattens nested source object arrays into a 1 dimensional
  11131. * array of source objects.
  11132. *
  11133. * @param {Tech~SourceObject|Tech~SourceObject[]} src
  11134. * The src object to filter
  11135. *
  11136. * @return {Tech~SourceObject[]}
  11137. * An array of sourceobjects containing only valid sources
  11138. *
  11139. * @private
  11140. */
  11141. var filterSource = function filterSource(src) {
  11142. // traverse array
  11143. if (Array.isArray(src)) {
  11144. var newsrc = [];
  11145. src.forEach(function (srcobj) {
  11146. srcobj = filterSource(srcobj);
  11147. if (Array.isArray(srcobj)) {
  11148. newsrc = newsrc.concat(srcobj);
  11149. } else if (isObject(srcobj)) {
  11150. newsrc.push(srcobj);
  11151. }
  11152. });
  11153. src = newsrc;
  11154. } else if (typeof src === 'string' && src.trim()) {
  11155. // convert string into object
  11156. src = [fixSource({
  11157. src: src
  11158. })];
  11159. } else if (isObject(src) && typeof src.src === 'string' && src.src && src.src.trim()) {
  11160. // src is already valid
  11161. src = [fixSource(src)];
  11162. } else {
  11163. // invalid source, turn it into an empty array
  11164. src = [];
  11165. }
  11166. return src;
  11167. };
  11168. /**
  11169. * Checks src mimetype, adding it when possible
  11170. *
  11171. * @param {Tech~SourceObject} src
  11172. * The src object to check
  11173. * @return {Tech~SourceObject}
  11174. * src Object with known type
  11175. */
  11176. function fixSource(src) {
  11177. if (!src.type) {
  11178. var mimetype = getMimetype(src.src);
  11179. if (mimetype) {
  11180. src.type = mimetype;
  11181. }
  11182. }
  11183. return src;
  11184. }
  11185. /**
  11186. * The `MediaLoader` is the `Component` that decides which playback technology to load
  11187. * when a player is initialized.
  11188. *
  11189. * @extends Component
  11190. */
  11191. var MediaLoader =
  11192. /*#__PURE__*/
  11193. function (_Component) {
  11194. _inheritsLoose(MediaLoader, _Component);
  11195. /**
  11196. * Create an instance of this class.
  11197. *
  11198. * @param {Player} player
  11199. * The `Player` that this class should attach to.
  11200. *
  11201. * @param {Object} [options]
  11202. * The key/value store of player options.
  11203. *
  11204. * @param {Component~ReadyCallback} [ready]
  11205. * The function that is run when this component is ready.
  11206. */
  11207. function MediaLoader(player, options, ready) {
  11208. var _this;
  11209. // MediaLoader has no element
  11210. var options_ = mergeOptions({
  11211. createEl: false
  11212. }, options);
  11213. _this = _Component.call(this, player, options_, ready) || this; // If there are no sources when the player is initialized,
  11214. // load the first supported playback technology.
  11215. if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
  11216. for (var i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
  11217. var techName = toTitleCase(j[i]);
  11218. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  11219. // Remove once that deprecated behavior is removed.
  11220. if (!techName) {
  11221. tech = Component.getComponent(techName);
  11222. } // Check if the browser supports this technology
  11223. if (tech && tech.isSupported()) {
  11224. player.loadTech_(techName);
  11225. break;
  11226. }
  11227. }
  11228. } else {
  11229. // Loop through playback technologies (HTML5, Flash) and check for support.
  11230. // Then load the best source.
  11231. // A few assumptions here:
  11232. // All playback technologies respect preload false.
  11233. player.src(options.playerOptions.sources);
  11234. }
  11235. return _this;
  11236. }
  11237. return MediaLoader;
  11238. }(Component);
  11239. Component.registerComponent('MediaLoader', MediaLoader);
  11240. /**
  11241. * Component which is clickable or keyboard actionable, but is not a
  11242. * native HTML button.
  11243. *
  11244. * @extends Component
  11245. */
  11246. var ClickableComponent =
  11247. /*#__PURE__*/
  11248. function (_Component) {
  11249. _inheritsLoose(ClickableComponent, _Component);
  11250. /**
  11251. * Creates an instance of this class.
  11252. *
  11253. * @param {Player} player
  11254. * The `Player` that this class should be attached to.
  11255. *
  11256. * @param {Object} [options]
  11257. * The key/value store of player options.
  11258. */
  11259. function ClickableComponent(player, options) {
  11260. var _this;
  11261. _this = _Component.call(this, player, options) || this;
  11262. _this.emitTapEvents();
  11263. _this.enable();
  11264. return _this;
  11265. }
  11266. /**
  11267. * Create the `ClickableComponent`s DOM element.
  11268. *
  11269. * @param {string} [tag=div]
  11270. * The element's node type.
  11271. *
  11272. * @param {Object} [props={}]
  11273. * An object of properties that should be set on the element.
  11274. *
  11275. * @param {Object} [attributes={}]
  11276. * An object of attributes that should be set on the element.
  11277. *
  11278. * @return {Element}
  11279. * The element that gets created.
  11280. */
  11281. var _proto = ClickableComponent.prototype;
  11282. _proto.createEl = function createEl(tag, props, attributes) {
  11283. if (tag === void 0) {
  11284. tag = 'div';
  11285. }
  11286. if (props === void 0) {
  11287. props = {};
  11288. }
  11289. if (attributes === void 0) {
  11290. attributes = {};
  11291. }
  11292. props = assign({
  11293. innerHTML: '<span aria-hidden="true" class="vjs-icon-placeholder"></span>',
  11294. className: this.buildCSSClass(),
  11295. tabIndex: 0
  11296. }, props);
  11297. if (tag === 'button') {
  11298. log.error("Creating a ClickableComponent with an HTML element of " + tag + " is not supported; use a Button instead.");
  11299. } // Add ARIA attributes for clickable element which is not a native HTML button
  11300. attributes = assign({
  11301. role: 'button'
  11302. }, attributes);
  11303. this.tabIndex_ = props.tabIndex;
  11304. var el = _Component.prototype.createEl.call(this, tag, props, attributes);
  11305. this.createControlTextEl(el);
  11306. return el;
  11307. };
  11308. _proto.dispose = function dispose() {
  11309. // remove controlTextEl_ on dispose
  11310. this.controlTextEl_ = null;
  11311. _Component.prototype.dispose.call(this);
  11312. }
  11313. /**
  11314. * Create a control text element on this `ClickableComponent`
  11315. *
  11316. * @param {Element} [el]
  11317. * Parent element for the control text.
  11318. *
  11319. * @return {Element}
  11320. * The control text element that gets created.
  11321. */
  11322. ;
  11323. _proto.createControlTextEl = function createControlTextEl(el) {
  11324. this.controlTextEl_ = createEl('span', {
  11325. className: 'vjs-control-text'
  11326. }, {
  11327. // let the screen reader user know that the text of the element may change
  11328. 'aria-live': 'polite'
  11329. });
  11330. if (el) {
  11331. el.appendChild(this.controlTextEl_);
  11332. }
  11333. this.controlText(this.controlText_, el);
  11334. return this.controlTextEl_;
  11335. }
  11336. /**
  11337. * Get or set the localize text to use for the controls on the `ClickableComponent`.
  11338. *
  11339. * @param {string} [text]
  11340. * Control text for element.
  11341. *
  11342. * @param {Element} [el=this.el()]
  11343. * Element to set the title on.
  11344. *
  11345. * @return {string}
  11346. * - The control text when getting
  11347. */
  11348. ;
  11349. _proto.controlText = function controlText(text, el) {
  11350. if (el === void 0) {
  11351. el = this.el();
  11352. }
  11353. if (text === undefined) {
  11354. return this.controlText_ || 'Need Text';
  11355. }
  11356. var localizedText = this.localize(text);
  11357. this.controlText_ = text;
  11358. textContent(this.controlTextEl_, localizedText);
  11359. if (!this.nonIconControl) {
  11360. // Set title attribute if only an icon is shown
  11361. el.setAttribute('title', localizedText);
  11362. }
  11363. }
  11364. /**
  11365. * Builds the default DOM `className`.
  11366. *
  11367. * @return {string}
  11368. * The DOM `className` for this object.
  11369. */
  11370. ;
  11371. _proto.buildCSSClass = function buildCSSClass() {
  11372. return "vjs-control vjs-button " + _Component.prototype.buildCSSClass.call(this);
  11373. }
  11374. /**
  11375. * Enable this `ClickableComponent`
  11376. */
  11377. ;
  11378. _proto.enable = function enable() {
  11379. if (!this.enabled_) {
  11380. this.enabled_ = true;
  11381. this.removeClass('vjs-disabled');
  11382. this.el_.setAttribute('aria-disabled', 'false');
  11383. if (typeof this.tabIndex_ !== 'undefined') {
  11384. this.el_.setAttribute('tabIndex', this.tabIndex_);
  11385. }
  11386. this.on(['tap', 'click'], this.handleClick);
  11387. this.on('keydown', this.handleKeyDown);
  11388. }
  11389. }
  11390. /**
  11391. * Disable this `ClickableComponent`
  11392. */
  11393. ;
  11394. _proto.disable = function disable() {
  11395. this.enabled_ = false;
  11396. this.addClass('vjs-disabled');
  11397. this.el_.setAttribute('aria-disabled', 'true');
  11398. if (typeof this.tabIndex_ !== 'undefined') {
  11399. this.el_.removeAttribute('tabIndex');
  11400. }
  11401. this.off('mouseover', this.handleMouseOver);
  11402. this.off('mouseout', this.handleMouseOut);
  11403. this.off(['tap', 'click'], this.handleClick);
  11404. this.off('keydown', this.handleKeyDown);
  11405. }
  11406. /**
  11407. * Event handler that is called when a `ClickableComponent` receives a
  11408. * `click` or `tap` event.
  11409. *
  11410. * @param {EventTarget~Event} event
  11411. * The `tap` or `click` event that caused this function to be called.
  11412. *
  11413. * @listens tap
  11414. * @listens click
  11415. * @abstract
  11416. */
  11417. ;
  11418. _proto.handleClick = function handleClick(event) {}
  11419. /**
  11420. * Event handler that is called when a `ClickableComponent` receives a
  11421. * `keydown` event.
  11422. *
  11423. * By default, if the key is Space or Enter, it will trigger a `click` event.
  11424. *
  11425. * @param {EventTarget~Event} event
  11426. * The `keydown` event that caused this function to be called.
  11427. *
  11428. * @listens keydown
  11429. */
  11430. ;
  11431. _proto.handleKeyDown = function handleKeyDown(event) {
  11432. // Support Space or Enter key operation to fire a click event. Also,
  11433. // prevent the event from propagating through the DOM and triggering
  11434. // Player hotkeys.
  11435. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  11436. event.preventDefault();
  11437. event.stopPropagation();
  11438. this.trigger('click');
  11439. } else {
  11440. // Pass keypress handling up for unsupported keys
  11441. _Component.prototype.handleKeyDown.call(this, event);
  11442. }
  11443. };
  11444. return ClickableComponent;
  11445. }(Component);
  11446. Component.registerComponent('ClickableComponent', ClickableComponent);
  11447. /**
  11448. * A `ClickableComponent` that handles showing the poster image for the player.
  11449. *
  11450. * @extends ClickableComponent
  11451. */
  11452. var PosterImage =
  11453. /*#__PURE__*/
  11454. function (_ClickableComponent) {
  11455. _inheritsLoose(PosterImage, _ClickableComponent);
  11456. /**
  11457. * Create an instance of this class.
  11458. *
  11459. * @param {Player} player
  11460. * The `Player` that this class should attach to.
  11461. *
  11462. * @param {Object} [options]
  11463. * The key/value store of player options.
  11464. */
  11465. function PosterImage(player, options) {
  11466. var _this;
  11467. _this = _ClickableComponent.call(this, player, options) || this;
  11468. _this.update();
  11469. player.on('posterchange', bind(_assertThisInitialized(_this), _this.update));
  11470. return _this;
  11471. }
  11472. /**
  11473. * Clean up and dispose of the `PosterImage`.
  11474. */
  11475. var _proto = PosterImage.prototype;
  11476. _proto.dispose = function dispose() {
  11477. this.player().off('posterchange', this.update);
  11478. _ClickableComponent.prototype.dispose.call(this);
  11479. }
  11480. /**
  11481. * Create the `PosterImage`s DOM element.
  11482. *
  11483. * @return {Element}
  11484. * The element that gets created.
  11485. */
  11486. ;
  11487. _proto.createEl = function createEl$1() {
  11488. var el = createEl('div', {
  11489. className: 'vjs-poster',
  11490. // Don't want poster to be tabbable.
  11491. tabIndex: -1
  11492. });
  11493. return el;
  11494. }
  11495. /**
  11496. * An {@link EventTarget~EventListener} for {@link Player#posterchange} events.
  11497. *
  11498. * @listens Player#posterchange
  11499. *
  11500. * @param {EventTarget~Event} [event]
  11501. * The `Player#posterchange` event that triggered this function.
  11502. */
  11503. ;
  11504. _proto.update = function update(event) {
  11505. var url = this.player().poster();
  11506. this.setSrc(url); // If there's no poster source we should display:none on this component
  11507. // so it's not still clickable or right-clickable
  11508. if (url) {
  11509. this.show();
  11510. } else {
  11511. this.hide();
  11512. }
  11513. }
  11514. /**
  11515. * Set the source of the `PosterImage` depending on the display method.
  11516. *
  11517. * @param {string} url
  11518. * The URL to the source for the `PosterImage`.
  11519. */
  11520. ;
  11521. _proto.setSrc = function setSrc(url) {
  11522. var backgroundImage = ''; // Any falsy value should stay as an empty string, otherwise
  11523. // this will throw an extra error
  11524. if (url) {
  11525. backgroundImage = "url(\"" + url + "\")";
  11526. }
  11527. this.el_.style.backgroundImage = backgroundImage;
  11528. }
  11529. /**
  11530. * An {@link EventTarget~EventListener} for clicks on the `PosterImage`. See
  11531. * {@link ClickableComponent#handleClick} for instances where this will be triggered.
  11532. *
  11533. * @listens tap
  11534. * @listens click
  11535. * @listens keydown
  11536. *
  11537. * @param {EventTarget~Event} event
  11538. + The `click`, `tap` or `keydown` event that caused this function to be called.
  11539. */
  11540. ;
  11541. _proto.handleClick = function handleClick(event) {
  11542. // We don't want a click to trigger playback when controls are disabled
  11543. if (!this.player_.controls()) {
  11544. return;
  11545. }
  11546. if (this.player_.tech(true)) {
  11547. this.player_.tech(true).focus();
  11548. }
  11549. if (this.player_.paused()) {
  11550. silencePromise(this.player_.play());
  11551. } else {
  11552. this.player_.pause();
  11553. }
  11554. };
  11555. return PosterImage;
  11556. }(ClickableComponent);
  11557. Component.registerComponent('PosterImage', PosterImage);
  11558. var darkGray = '#222';
  11559. var lightGray = '#ccc';
  11560. var fontMap = {
  11561. monospace: 'monospace',
  11562. sansSerif: 'sans-serif',
  11563. serif: 'serif',
  11564. monospaceSansSerif: '"Andale Mono", "Lucida Console", monospace',
  11565. monospaceSerif: '"Courier New", monospace',
  11566. proportionalSansSerif: 'sans-serif',
  11567. proportionalSerif: 'serif',
  11568. casual: '"Comic Sans MS", Impact, fantasy',
  11569. script: '"Monotype Corsiva", cursive',
  11570. smallcaps: '"Andale Mono", "Lucida Console", monospace, sans-serif'
  11571. };
  11572. /**
  11573. * Construct an rgba color from a given hex color code.
  11574. *
  11575. * @param {number} color
  11576. * Hex number for color, like #f0e or #f604e2.
  11577. *
  11578. * @param {number} opacity
  11579. * Value for opacity, 0.0 - 1.0.
  11580. *
  11581. * @return {string}
  11582. * The rgba color that was created, like 'rgba(255, 0, 0, 0.3)'.
  11583. */
  11584. function constructColor(color, opacity) {
  11585. var hex;
  11586. if (color.length === 4) {
  11587. // color looks like "#f0e"
  11588. hex = color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
  11589. } else if (color.length === 7) {
  11590. // color looks like "#f604e2"
  11591. hex = color.slice(1);
  11592. } else {
  11593. throw new Error('Invalid color code provided, ' + color + '; must be formatted as e.g. #f0e or #f604e2.');
  11594. }
  11595. return 'rgba(' + parseInt(hex.slice(0, 2), 16) + ',' + parseInt(hex.slice(2, 4), 16) + ',' + parseInt(hex.slice(4, 6), 16) + ',' + opacity + ')';
  11596. }
  11597. /**
  11598. * Try to update the style of a DOM element. Some style changes will throw an error,
  11599. * particularly in IE8. Those should be noops.
  11600. *
  11601. * @param {Element} el
  11602. * The DOM element to be styled.
  11603. *
  11604. * @param {string} style
  11605. * The CSS property on the element that should be styled.
  11606. *
  11607. * @param {string} rule
  11608. * The style rule that should be applied to the property.
  11609. *
  11610. * @private
  11611. */
  11612. function tryUpdateStyle(el, style, rule) {
  11613. try {
  11614. el.style[style] = rule;
  11615. } catch (e) {
  11616. // Satisfies linter.
  11617. return;
  11618. }
  11619. }
  11620. /**
  11621. * The component for displaying text track cues.
  11622. *
  11623. * @extends Component
  11624. */
  11625. var TextTrackDisplay =
  11626. /*#__PURE__*/
  11627. function (_Component) {
  11628. _inheritsLoose(TextTrackDisplay, _Component);
  11629. /**
  11630. * Creates an instance of this class.
  11631. *
  11632. * @param {Player} player
  11633. * The `Player` that this class should be attached to.
  11634. *
  11635. * @param {Object} [options]
  11636. * The key/value store of player options.
  11637. *
  11638. * @param {Component~ReadyCallback} [ready]
  11639. * The function to call when `TextTrackDisplay` is ready.
  11640. */
  11641. function TextTrackDisplay(player, options, ready) {
  11642. var _this;
  11643. _this = _Component.call(this, player, options, ready) || this;
  11644. var updateDisplayHandler = bind(_assertThisInitialized(_this), _this.updateDisplay);
  11645. player.on('loadstart', bind(_assertThisInitialized(_this), _this.toggleDisplay));
  11646. player.on('texttrackchange', updateDisplayHandler);
  11647. player.on('loadedmetadata', bind(_assertThisInitialized(_this), _this.preselectTrack)); // This used to be called during player init, but was causing an error
  11648. // if a track should show by default and the display hadn't loaded yet.
  11649. // Should probably be moved to an external track loader when we support
  11650. // tracks that don't need a display.
  11651. player.ready(bind(_assertThisInitialized(_this), function () {
  11652. if (player.tech_ && player.tech_.featuresNativeTextTracks) {
  11653. this.hide();
  11654. return;
  11655. }
  11656. player.on('fullscreenchange', updateDisplayHandler);
  11657. player.on('playerresize', updateDisplayHandler);
  11658. window$1.addEventListener('orientationchange', updateDisplayHandler);
  11659. player.on('dispose', function () {
  11660. return window$1.removeEventListener('orientationchange', updateDisplayHandler);
  11661. });
  11662. var tracks = this.options_.playerOptions.tracks || [];
  11663. for (var i = 0; i < tracks.length; i++) {
  11664. this.player_.addRemoteTextTrack(tracks[i], true);
  11665. }
  11666. this.preselectTrack();
  11667. }));
  11668. return _this;
  11669. }
  11670. /**
  11671. * Preselect a track following this precedence:
  11672. * - matches the previously selected {@link TextTrack}'s language and kind
  11673. * - matches the previously selected {@link TextTrack}'s language only
  11674. * - is the first default captions track
  11675. * - is the first default descriptions track
  11676. *
  11677. * @listens Player#loadstart
  11678. */
  11679. var _proto = TextTrackDisplay.prototype;
  11680. _proto.preselectTrack = function preselectTrack() {
  11681. var modes = {
  11682. captions: 1,
  11683. subtitles: 1
  11684. };
  11685. var trackList = this.player_.textTracks();
  11686. var userPref = this.player_.cache_.selectedLanguage;
  11687. var firstDesc;
  11688. var firstCaptions;
  11689. var preferredTrack;
  11690. for (var i = 0; i < trackList.length; i++) {
  11691. var track = trackList[i];
  11692. if (userPref && userPref.enabled && userPref.language && userPref.language === track.language && track.kind in modes) {
  11693. // Always choose the track that matches both language and kind
  11694. if (track.kind === userPref.kind) {
  11695. preferredTrack = track; // or choose the first track that matches language
  11696. } else if (!preferredTrack) {
  11697. preferredTrack = track;
  11698. } // clear everything if offTextTrackMenuItem was clicked
  11699. } else if (userPref && !userPref.enabled) {
  11700. preferredTrack = null;
  11701. firstDesc = null;
  11702. firstCaptions = null;
  11703. } else if (track["default"]) {
  11704. if (track.kind === 'descriptions' && !firstDesc) {
  11705. firstDesc = track;
  11706. } else if (track.kind in modes && !firstCaptions) {
  11707. firstCaptions = track;
  11708. }
  11709. }
  11710. } // The preferredTrack matches the user preference and takes
  11711. // precedence over all the other tracks.
  11712. // So, display the preferredTrack before the first default track
  11713. // and the subtitles/captions track before the descriptions track
  11714. if (preferredTrack) {
  11715. preferredTrack.mode = 'showing';
  11716. } else if (firstCaptions) {
  11717. firstCaptions.mode = 'showing';
  11718. } else if (firstDesc) {
  11719. firstDesc.mode = 'showing';
  11720. }
  11721. }
  11722. /**
  11723. * Turn display of {@link TextTrack}'s from the current state into the other state.
  11724. * There are only two states:
  11725. * - 'shown'
  11726. * - 'hidden'
  11727. *
  11728. * @listens Player#loadstart
  11729. */
  11730. ;
  11731. _proto.toggleDisplay = function toggleDisplay() {
  11732. if (this.player_.tech_ && this.player_.tech_.featuresNativeTextTracks) {
  11733. this.hide();
  11734. } else {
  11735. this.show();
  11736. }
  11737. }
  11738. /**
  11739. * Create the {@link Component}'s DOM element.
  11740. *
  11741. * @return {Element}
  11742. * The element that was created.
  11743. */
  11744. ;
  11745. _proto.createEl = function createEl() {
  11746. return _Component.prototype.createEl.call(this, 'div', {
  11747. className: 'vjs-text-track-display'
  11748. }, {
  11749. 'aria-live': 'off',
  11750. 'aria-atomic': 'true'
  11751. });
  11752. }
  11753. /**
  11754. * Clear all displayed {@link TextTrack}s.
  11755. */
  11756. ;
  11757. _proto.clearDisplay = function clearDisplay() {
  11758. if (typeof window$1.WebVTT === 'function') {
  11759. window$1.WebVTT.processCues(window$1, [], this.el_);
  11760. }
  11761. }
  11762. /**
  11763. * Update the displayed TextTrack when a either a {@link Player#texttrackchange} or
  11764. * a {@link Player#fullscreenchange} is fired.
  11765. *
  11766. * @listens Player#texttrackchange
  11767. * @listens Player#fullscreenchange
  11768. */
  11769. ;
  11770. _proto.updateDisplay = function updateDisplay() {
  11771. var tracks = this.player_.textTracks();
  11772. var allowMultipleShowingTracks = this.options_.allowMultipleShowingTracks;
  11773. this.clearDisplay();
  11774. if (allowMultipleShowingTracks) {
  11775. var showingTracks = [];
  11776. for (var _i = 0; _i < tracks.length; ++_i) {
  11777. var track = tracks[_i];
  11778. if (track.mode !== 'showing') {
  11779. continue;
  11780. }
  11781. showingTracks.push(track);
  11782. }
  11783. this.updateForTrack(showingTracks);
  11784. return;
  11785. } // Track display prioritization model: if multiple tracks are 'showing',
  11786. // display the first 'subtitles' or 'captions' track which is 'showing',
  11787. // otherwise display the first 'descriptions' track which is 'showing'
  11788. var descriptionsTrack = null;
  11789. var captionsSubtitlesTrack = null;
  11790. var i = tracks.length;
  11791. while (i--) {
  11792. var _track = tracks[i];
  11793. if (_track.mode === 'showing') {
  11794. if (_track.kind === 'descriptions') {
  11795. descriptionsTrack = _track;
  11796. } else {
  11797. captionsSubtitlesTrack = _track;
  11798. }
  11799. }
  11800. }
  11801. if (captionsSubtitlesTrack) {
  11802. if (this.getAttribute('aria-live') !== 'off') {
  11803. this.setAttribute('aria-live', 'off');
  11804. }
  11805. this.updateForTrack(captionsSubtitlesTrack);
  11806. } else if (descriptionsTrack) {
  11807. if (this.getAttribute('aria-live') !== 'assertive') {
  11808. this.setAttribute('aria-live', 'assertive');
  11809. }
  11810. this.updateForTrack(descriptionsTrack);
  11811. }
  11812. }
  11813. /**
  11814. * Style {@Link TextTrack} activeCues according to {@Link TextTrackSettings}.
  11815. *
  11816. * @param {TextTrack} track
  11817. * Text track object containing active cues to style.
  11818. */
  11819. ;
  11820. _proto.updateDisplayState = function updateDisplayState(track) {
  11821. var overrides = this.player_.textTrackSettings.getValues();
  11822. var cues = track.activeCues;
  11823. var i = cues.length;
  11824. while (i--) {
  11825. var cue = cues[i];
  11826. if (!cue) {
  11827. continue;
  11828. }
  11829. var cueDiv = cue.displayState;
  11830. if (overrides.color) {
  11831. cueDiv.firstChild.style.color = overrides.color;
  11832. }
  11833. if (overrides.textOpacity) {
  11834. tryUpdateStyle(cueDiv.firstChild, 'color', constructColor(overrides.color || '#fff', overrides.textOpacity));
  11835. }
  11836. if (overrides.backgroundColor) {
  11837. cueDiv.firstChild.style.backgroundColor = overrides.backgroundColor;
  11838. }
  11839. if (overrides.backgroundOpacity) {
  11840. tryUpdateStyle(cueDiv.firstChild, 'backgroundColor', constructColor(overrides.backgroundColor || '#000', overrides.backgroundOpacity));
  11841. }
  11842. if (overrides.windowColor) {
  11843. if (overrides.windowOpacity) {
  11844. tryUpdateStyle(cueDiv, 'backgroundColor', constructColor(overrides.windowColor, overrides.windowOpacity));
  11845. } else {
  11846. cueDiv.style.backgroundColor = overrides.windowColor;
  11847. }
  11848. }
  11849. if (overrides.edgeStyle) {
  11850. if (overrides.edgeStyle === 'dropshadow') {
  11851. cueDiv.firstChild.style.textShadow = "2px 2px 3px " + darkGray + ", 2px 2px 4px " + darkGray + ", 2px 2px 5px " + darkGray;
  11852. } else if (overrides.edgeStyle === 'raised') {
  11853. cueDiv.firstChild.style.textShadow = "1px 1px " + darkGray + ", 2px 2px " + darkGray + ", 3px 3px " + darkGray;
  11854. } else if (overrides.edgeStyle === 'depressed') {
  11855. cueDiv.firstChild.style.textShadow = "1px 1px " + lightGray + ", 0 1px " + lightGray + ", -1px -1px " + darkGray + ", 0 -1px " + darkGray;
  11856. } else if (overrides.edgeStyle === 'uniform') {
  11857. cueDiv.firstChild.style.textShadow = "0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray + ", 0 0 4px " + darkGray;
  11858. }
  11859. }
  11860. if (overrides.fontPercent && overrides.fontPercent !== 1) {
  11861. var fontSize = window$1.parseFloat(cueDiv.style.fontSize);
  11862. cueDiv.style.fontSize = fontSize * overrides.fontPercent + 'px';
  11863. cueDiv.style.height = 'auto';
  11864. cueDiv.style.top = 'auto';
  11865. cueDiv.style.bottom = '2px';
  11866. }
  11867. if (overrides.fontFamily && overrides.fontFamily !== 'default') {
  11868. if (overrides.fontFamily === 'small-caps') {
  11869. cueDiv.firstChild.style.fontVariant = 'small-caps';
  11870. } else {
  11871. cueDiv.firstChild.style.fontFamily = fontMap[overrides.fontFamily];
  11872. }
  11873. }
  11874. }
  11875. }
  11876. /**
  11877. * Add an {@link TextTrack} to to the {@link Tech}s {@link TextTrackList}.
  11878. *
  11879. * @param {TextTrack|TextTrack[]} tracks
  11880. * Text track object or text track array to be added to the list.
  11881. */
  11882. ;
  11883. _proto.updateForTrack = function updateForTrack(tracks) {
  11884. if (!Array.isArray(tracks)) {
  11885. tracks = [tracks];
  11886. }
  11887. if (typeof window$1.WebVTT !== 'function' || tracks.every(function (track) {
  11888. return !track.activeCues;
  11889. })) {
  11890. return;
  11891. }
  11892. var cues = []; // push all active track cues
  11893. for (var i = 0; i < tracks.length; ++i) {
  11894. var track = tracks[i];
  11895. for (var j = 0; j < track.activeCues.length; ++j) {
  11896. cues.push(track.activeCues[j]);
  11897. }
  11898. } // removes all cues before it processes new ones
  11899. window$1.WebVTT.processCues(window$1, cues, this.el_); // add unique class to each language text track & add settings styling if necessary
  11900. for (var _i2 = 0; _i2 < tracks.length; ++_i2) {
  11901. var _track2 = tracks[_i2];
  11902. for (var _j = 0; _j < _track2.activeCues.length; ++_j) {
  11903. var cueEl = _track2.activeCues[_j].displayState;
  11904. addClass(cueEl, 'vjs-text-track-cue');
  11905. addClass(cueEl, 'vjs-text-track-cue-' + (_track2.language ? _track2.language : _i2));
  11906. }
  11907. if (this.player_.textTrackSettings) {
  11908. this.updateDisplayState(_track2);
  11909. }
  11910. }
  11911. };
  11912. return TextTrackDisplay;
  11913. }(Component);
  11914. Component.registerComponent('TextTrackDisplay', TextTrackDisplay);
  11915. /**
  11916. * A loading spinner for use during waiting/loading events.
  11917. *
  11918. * @extends Component
  11919. */
  11920. var LoadingSpinner =
  11921. /*#__PURE__*/
  11922. function (_Component) {
  11923. _inheritsLoose(LoadingSpinner, _Component);
  11924. function LoadingSpinner() {
  11925. return _Component.apply(this, arguments) || this;
  11926. }
  11927. var _proto = LoadingSpinner.prototype;
  11928. /**
  11929. * Create the `LoadingSpinner`s DOM element.
  11930. *
  11931. * @return {Element}
  11932. * The dom element that gets created.
  11933. */
  11934. _proto.createEl = function createEl$1() {
  11935. var isAudio = this.player_.isAudio();
  11936. var playerType = this.localize(isAudio ? 'Audio Player' : 'Video Player');
  11937. var controlText = createEl('span', {
  11938. className: 'vjs-control-text',
  11939. innerHTML: this.localize('{1} is loading.', [playerType])
  11940. });
  11941. var el = _Component.prototype.createEl.call(this, 'div', {
  11942. className: 'vjs-loading-spinner',
  11943. dir: 'ltr'
  11944. });
  11945. el.appendChild(controlText);
  11946. return el;
  11947. };
  11948. return LoadingSpinner;
  11949. }(Component);
  11950. Component.registerComponent('LoadingSpinner', LoadingSpinner);
  11951. /**
  11952. * Base class for all buttons.
  11953. *
  11954. * @extends ClickableComponent
  11955. */
  11956. var Button =
  11957. /*#__PURE__*/
  11958. function (_ClickableComponent) {
  11959. _inheritsLoose(Button, _ClickableComponent);
  11960. function Button() {
  11961. return _ClickableComponent.apply(this, arguments) || this;
  11962. }
  11963. var _proto = Button.prototype;
  11964. /**
  11965. * Create the `Button`s DOM element.
  11966. *
  11967. * @param {string} [tag="button"]
  11968. * The element's node type. This argument is IGNORED: no matter what
  11969. * is passed, it will always create a `button` element.
  11970. *
  11971. * @param {Object} [props={}]
  11972. * An object of properties that should be set on the element.
  11973. *
  11974. * @param {Object} [attributes={}]
  11975. * An object of attributes that should be set on the element.
  11976. *
  11977. * @return {Element}
  11978. * The element that gets created.
  11979. */
  11980. _proto.createEl = function createEl(tag, props, attributes) {
  11981. if (props === void 0) {
  11982. props = {};
  11983. }
  11984. if (attributes === void 0) {
  11985. attributes = {};
  11986. }
  11987. tag = 'button';
  11988. props = assign({
  11989. innerHTML: '<span aria-hidden="true" class="vjs-icon-placeholder"></span>',
  11990. className: this.buildCSSClass()
  11991. }, props); // Add attributes for button element
  11992. attributes = assign({
  11993. // Necessary since the default button type is "submit"
  11994. type: 'button'
  11995. }, attributes);
  11996. var el = Component.prototype.createEl.call(this, tag, props, attributes);
  11997. this.createControlTextEl(el);
  11998. return el;
  11999. }
  12000. /**
  12001. * Add a child `Component` inside of this `Button`.
  12002. *
  12003. * @param {string|Component} child
  12004. * The name or instance of a child to add.
  12005. *
  12006. * @param {Object} [options={}]
  12007. * The key/value store of options that will get passed to children of
  12008. * the child.
  12009. *
  12010. * @return {Component}
  12011. * The `Component` that gets added as a child. When using a string the
  12012. * `Component` will get created by this process.
  12013. *
  12014. * @deprecated since version 5
  12015. */
  12016. ;
  12017. _proto.addChild = function addChild(child, options) {
  12018. if (options === void 0) {
  12019. options = {};
  12020. }
  12021. var className = this.constructor.name;
  12022. 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
  12023. return Component.prototype.addChild.call(this, child, options);
  12024. }
  12025. /**
  12026. * Enable the `Button` element so that it can be activated or clicked. Use this with
  12027. * {@link Button#disable}.
  12028. */
  12029. ;
  12030. _proto.enable = function enable() {
  12031. _ClickableComponent.prototype.enable.call(this);
  12032. this.el_.removeAttribute('disabled');
  12033. }
  12034. /**
  12035. * Disable the `Button` element so that it cannot be activated or clicked. Use this with
  12036. * {@link Button#enable}.
  12037. */
  12038. ;
  12039. _proto.disable = function disable() {
  12040. _ClickableComponent.prototype.disable.call(this);
  12041. this.el_.setAttribute('disabled', 'disabled');
  12042. }
  12043. /**
  12044. * This gets called when a `Button` has focus and `keydown` is triggered via a key
  12045. * press.
  12046. *
  12047. * @param {EventTarget~Event} event
  12048. * The event that caused this function to get called.
  12049. *
  12050. * @listens keydown
  12051. */
  12052. ;
  12053. _proto.handleKeyDown = function handleKeyDown(event) {
  12054. // Ignore Space or Enter key operation, which is handled by the browser for
  12055. // a button - though not for its super class, ClickableComponent. Also,
  12056. // prevent the event from propagating through the DOM and triggering Player
  12057. // hotkeys. We do not preventDefault here because we _want_ the browser to
  12058. // handle it.
  12059. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  12060. event.stopPropagation();
  12061. return;
  12062. } // Pass keypress handling up for unsupported keys
  12063. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  12064. };
  12065. return Button;
  12066. }(ClickableComponent);
  12067. Component.registerComponent('Button', Button);
  12068. /**
  12069. * The initial play button that shows before the video has played. The hiding of the
  12070. * `BigPlayButton` get done via CSS and `Player` states.
  12071. *
  12072. * @extends Button
  12073. */
  12074. var BigPlayButton =
  12075. /*#__PURE__*/
  12076. function (_Button) {
  12077. _inheritsLoose(BigPlayButton, _Button);
  12078. function BigPlayButton(player, options) {
  12079. var _this;
  12080. _this = _Button.call(this, player, options) || this;
  12081. _this.mouseused_ = false;
  12082. _this.on('mousedown', _this.handleMouseDown);
  12083. return _this;
  12084. }
  12085. /**
  12086. * Builds the default DOM `className`.
  12087. *
  12088. * @return {string}
  12089. * The DOM `className` for this object. Always returns 'vjs-big-play-button'.
  12090. */
  12091. var _proto = BigPlayButton.prototype;
  12092. _proto.buildCSSClass = function buildCSSClass() {
  12093. return 'vjs-big-play-button';
  12094. }
  12095. /**
  12096. * This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
  12097. * for more detailed information on what a click can be.
  12098. *
  12099. * @param {EventTarget~Event} event
  12100. * The `keydown`, `tap`, or `click` event that caused this function to be
  12101. * called.
  12102. *
  12103. * @listens tap
  12104. * @listens click
  12105. */
  12106. ;
  12107. _proto.handleClick = function handleClick(event) {
  12108. var playPromise = this.player_.play(); // exit early if clicked via the mouse
  12109. if (this.mouseused_ && event.clientX && event.clientY) {
  12110. silencePromise(playPromise);
  12111. if (this.player_.tech(true)) {
  12112. this.player_.tech(true).focus();
  12113. }
  12114. return;
  12115. }
  12116. var cb = this.player_.getChild('controlBar');
  12117. var playToggle = cb && cb.getChild('playToggle');
  12118. if (!playToggle) {
  12119. this.player_.tech(true).focus();
  12120. return;
  12121. }
  12122. var playFocus = function playFocus() {
  12123. return playToggle.focus();
  12124. };
  12125. if (isPromise(playPromise)) {
  12126. playPromise.then(playFocus, function () {});
  12127. } else {
  12128. this.setTimeout(playFocus, 1);
  12129. }
  12130. };
  12131. _proto.handleKeyDown = function handleKeyDown(event) {
  12132. this.mouseused_ = false;
  12133. _Button.prototype.handleKeyDown.call(this, event);
  12134. };
  12135. _proto.handleMouseDown = function handleMouseDown(event) {
  12136. this.mouseused_ = true;
  12137. };
  12138. return BigPlayButton;
  12139. }(Button);
  12140. /**
  12141. * The text that should display over the `BigPlayButton`s controls. Added to for localization.
  12142. *
  12143. * @type {string}
  12144. * @private
  12145. */
  12146. BigPlayButton.prototype.controlText_ = 'Play Video';
  12147. Component.registerComponent('BigPlayButton', BigPlayButton);
  12148. /**
  12149. * The `CloseButton` is a `{@link Button}` that fires a `close` event when
  12150. * it gets clicked.
  12151. *
  12152. * @extends Button
  12153. */
  12154. var CloseButton =
  12155. /*#__PURE__*/
  12156. function (_Button) {
  12157. _inheritsLoose(CloseButton, _Button);
  12158. /**
  12159. * Creates an instance of the this class.
  12160. *
  12161. * @param {Player} player
  12162. * The `Player` that this class should be attached to.
  12163. *
  12164. * @param {Object} [options]
  12165. * The key/value store of player options.
  12166. */
  12167. function CloseButton(player, options) {
  12168. var _this;
  12169. _this = _Button.call(this, player, options) || this;
  12170. _this.controlText(options && options.controlText || _this.localize('Close'));
  12171. return _this;
  12172. }
  12173. /**
  12174. * Builds the default DOM `className`.
  12175. *
  12176. * @return {string}
  12177. * The DOM `className` for this object.
  12178. */
  12179. var _proto = CloseButton.prototype;
  12180. _proto.buildCSSClass = function buildCSSClass() {
  12181. return "vjs-close-button " + _Button.prototype.buildCSSClass.call(this);
  12182. }
  12183. /**
  12184. * This gets called when a `CloseButton` gets clicked. See
  12185. * {@link ClickableComponent#handleClick} for more information on when
  12186. * this will be triggered
  12187. *
  12188. * @param {EventTarget~Event} event
  12189. * The `keydown`, `tap`, or `click` event that caused this function to be
  12190. * called.
  12191. *
  12192. * @listens tap
  12193. * @listens click
  12194. * @fires CloseButton#close
  12195. */
  12196. ;
  12197. _proto.handleClick = function handleClick(event) {
  12198. /**
  12199. * Triggered when the a `CloseButton` is clicked.
  12200. *
  12201. * @event CloseButton#close
  12202. * @type {EventTarget~Event}
  12203. *
  12204. * @property {boolean} [bubbles=false]
  12205. * set to false so that the close event does not
  12206. * bubble up to parents if there is no listener
  12207. */
  12208. this.trigger({
  12209. type: 'close',
  12210. bubbles: false
  12211. });
  12212. }
  12213. /**
  12214. * Event handler that is called when a `CloseButton` receives a
  12215. * `keydown` event.
  12216. *
  12217. * By default, if the key is Esc, it will trigger a `click` event.
  12218. *
  12219. * @param {EventTarget~Event} event
  12220. * The `keydown` event that caused this function to be called.
  12221. *
  12222. * @listens keydown
  12223. */
  12224. ;
  12225. _proto.handleKeyDown = function handleKeyDown(event) {
  12226. // Esc button will trigger `click` event
  12227. if (keycode.isEventKey(event, 'Esc')) {
  12228. event.preventDefault();
  12229. event.stopPropagation();
  12230. this.trigger('click');
  12231. } else {
  12232. // Pass keypress handling up for unsupported keys
  12233. _Button.prototype.handleKeyDown.call(this, event);
  12234. }
  12235. };
  12236. return CloseButton;
  12237. }(Button);
  12238. Component.registerComponent('CloseButton', CloseButton);
  12239. /**
  12240. * Button to toggle between play and pause.
  12241. *
  12242. * @extends Button
  12243. */
  12244. var PlayToggle =
  12245. /*#__PURE__*/
  12246. function (_Button) {
  12247. _inheritsLoose(PlayToggle, _Button);
  12248. /**
  12249. * Creates an instance of this class.
  12250. *
  12251. * @param {Player} player
  12252. * The `Player` that this class should be attached to.
  12253. *
  12254. * @param {Object} [options={}]
  12255. * The key/value store of player options.
  12256. */
  12257. function PlayToggle(player, options) {
  12258. var _this;
  12259. if (options === void 0) {
  12260. options = {};
  12261. }
  12262. _this = _Button.call(this, player, options) || this; // show or hide replay icon
  12263. options.replay = options.replay === undefined || options.replay;
  12264. _this.on(player, 'play', _this.handlePlay);
  12265. _this.on(player, 'pause', _this.handlePause);
  12266. if (options.replay) {
  12267. _this.on(player, 'ended', _this.handleEnded);
  12268. }
  12269. return _this;
  12270. }
  12271. /**
  12272. * Builds the default DOM `className`.
  12273. *
  12274. * @return {string}
  12275. * The DOM `className` for this object.
  12276. */
  12277. var _proto = PlayToggle.prototype;
  12278. _proto.buildCSSClass = function buildCSSClass() {
  12279. return "vjs-play-control " + _Button.prototype.buildCSSClass.call(this);
  12280. }
  12281. /**
  12282. * This gets called when an `PlayToggle` is "clicked". See
  12283. * {@link ClickableComponent} for more detailed information on what a click can be.
  12284. *
  12285. * @param {EventTarget~Event} [event]
  12286. * The `keydown`, `tap`, or `click` event that caused this function to be
  12287. * called.
  12288. *
  12289. * @listens tap
  12290. * @listens click
  12291. */
  12292. ;
  12293. _proto.handleClick = function handleClick(event) {
  12294. if (this.player_.paused()) {
  12295. this.player_.play();
  12296. } else {
  12297. this.player_.pause();
  12298. }
  12299. }
  12300. /**
  12301. * This gets called once after the video has ended and the user seeks so that
  12302. * we can change the replay button back to a play button.
  12303. *
  12304. * @param {EventTarget~Event} [event]
  12305. * The event that caused this function to run.
  12306. *
  12307. * @listens Player#seeked
  12308. */
  12309. ;
  12310. _proto.handleSeeked = function handleSeeked(event) {
  12311. this.removeClass('vjs-ended');
  12312. if (this.player_.paused()) {
  12313. this.handlePause(event);
  12314. } else {
  12315. this.handlePlay(event);
  12316. }
  12317. }
  12318. /**
  12319. * Add the vjs-playing class to the element so it can change appearance.
  12320. *
  12321. * @param {EventTarget~Event} [event]
  12322. * The event that caused this function to run.
  12323. *
  12324. * @listens Player#play
  12325. */
  12326. ;
  12327. _proto.handlePlay = function handlePlay(event) {
  12328. this.removeClass('vjs-ended');
  12329. this.removeClass('vjs-paused');
  12330. this.addClass('vjs-playing'); // change the button text to "Pause"
  12331. this.controlText('Pause');
  12332. }
  12333. /**
  12334. * Add the vjs-paused class to the element so it can change appearance.
  12335. *
  12336. * @param {EventTarget~Event} [event]
  12337. * The event that caused this function to run.
  12338. *
  12339. * @listens Player#pause
  12340. */
  12341. ;
  12342. _proto.handlePause = function handlePause(event) {
  12343. this.removeClass('vjs-playing');
  12344. this.addClass('vjs-paused'); // change the button text to "Play"
  12345. this.controlText('Play');
  12346. }
  12347. /**
  12348. * Add the vjs-ended class to the element so it can change appearance
  12349. *
  12350. * @param {EventTarget~Event} [event]
  12351. * The event that caused this function to run.
  12352. *
  12353. * @listens Player#ended
  12354. */
  12355. ;
  12356. _proto.handleEnded = function handleEnded(event) {
  12357. this.removeClass('vjs-playing');
  12358. this.addClass('vjs-ended'); // change the button text to "Replay"
  12359. this.controlText('Replay'); // on the next seek remove the replay button
  12360. this.one(this.player_, 'seeked', this.handleSeeked);
  12361. };
  12362. return PlayToggle;
  12363. }(Button);
  12364. /**
  12365. * The text that should display over the `PlayToggle`s controls. Added for localization.
  12366. *
  12367. * @type {string}
  12368. * @private
  12369. */
  12370. PlayToggle.prototype.controlText_ = 'Play';
  12371. Component.registerComponent('PlayToggle', PlayToggle);
  12372. /**
  12373. * @file format-time.js
  12374. * @module format-time
  12375. */
  12376. /**
  12377. * Format seconds as a time string, H:MM:SS or M:SS. Supplying a guide (in
  12378. * seconds) will force a number of leading zeros to cover the length of the
  12379. * guide.
  12380. *
  12381. * @private
  12382. * @param {number} seconds
  12383. * Number of seconds to be turned into a string
  12384. *
  12385. * @param {number} guide
  12386. * Number (in seconds) to model the string after
  12387. *
  12388. * @return {string}
  12389. * Time formatted as H:MM:SS or M:SS
  12390. */
  12391. var defaultImplementation = function defaultImplementation(seconds, guide) {
  12392. seconds = seconds < 0 ? 0 : seconds;
  12393. var s = Math.floor(seconds % 60);
  12394. var m = Math.floor(seconds / 60 % 60);
  12395. var h = Math.floor(seconds / 3600);
  12396. var gm = Math.floor(guide / 60 % 60);
  12397. var gh = Math.floor(guide / 3600); // handle invalid times
  12398. if (isNaN(seconds) || seconds === Infinity) {
  12399. // '-' is false for all relational operators (e.g. <, >=) so this setting
  12400. // will add the minimum number of fields specified by the guide
  12401. h = m = s = '-';
  12402. } // Check if we need to show hours
  12403. h = h > 0 || gh > 0 ? h + ':' : ''; // If hours are showing, we may need to add a leading zero.
  12404. // Always show at least one digit of minutes.
  12405. m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':'; // Check if leading zero is need for seconds
  12406. s = s < 10 ? '0' + s : s;
  12407. return h + m + s;
  12408. }; // Internal pointer to the current implementation.
  12409. var implementation$3 = defaultImplementation;
  12410. /**
  12411. * Replaces the default formatTime implementation with a custom implementation.
  12412. *
  12413. * @param {Function} customImplementation
  12414. * A function which will be used in place of the default formatTime
  12415. * implementation. Will receive the current time in seconds and the
  12416. * guide (in seconds) as arguments.
  12417. */
  12418. function setFormatTime(customImplementation) {
  12419. implementation$3 = customImplementation;
  12420. }
  12421. /**
  12422. * Resets formatTime to the default implementation.
  12423. */
  12424. function resetFormatTime() {
  12425. implementation$3 = defaultImplementation;
  12426. }
  12427. /**
  12428. * Delegates to either the default time formatting function or a custom
  12429. * function supplied via `setFormatTime`.
  12430. *
  12431. * Formats seconds as a time string (H:MM:SS or M:SS). Supplying a
  12432. * guide (in seconds) will force a number of leading zeros to cover the
  12433. * length of the guide.
  12434. *
  12435. * @static
  12436. * @example formatTime(125, 600) === "02:05"
  12437. * @param {number} seconds
  12438. * Number of seconds to be turned into a string
  12439. *
  12440. * @param {number} guide
  12441. * Number (in seconds) to model the string after
  12442. *
  12443. * @return {string}
  12444. * Time formatted as H:MM:SS or M:SS
  12445. */
  12446. function formatTime(seconds, guide) {
  12447. if (guide === void 0) {
  12448. guide = seconds;
  12449. }
  12450. return implementation$3(seconds, guide);
  12451. }
  12452. /**
  12453. * Displays time information about the video
  12454. *
  12455. * @extends Component
  12456. */
  12457. var TimeDisplay =
  12458. /*#__PURE__*/
  12459. function (_Component) {
  12460. _inheritsLoose(TimeDisplay, _Component);
  12461. /**
  12462. * Creates an instance of this class.
  12463. *
  12464. * @param {Player} player
  12465. * The `Player` that this class should be attached to.
  12466. *
  12467. * @param {Object} [options]
  12468. * The key/value store of player options.
  12469. */
  12470. function TimeDisplay(player, options) {
  12471. var _this;
  12472. _this = _Component.call(this, player, options) || this;
  12473. _this.throttledUpdateContent = throttle(bind(_assertThisInitialized(_this), _this.updateContent), UPDATE_REFRESH_INTERVAL);
  12474. _this.on(player, 'timeupdate', _this.throttledUpdateContent);
  12475. return _this;
  12476. }
  12477. /**
  12478. * Create the `Component`'s DOM element
  12479. *
  12480. * @return {Element}
  12481. * The element that was created.
  12482. */
  12483. var _proto = TimeDisplay.prototype;
  12484. _proto.createEl = function createEl$1() {
  12485. var className = this.buildCSSClass();
  12486. var el = _Component.prototype.createEl.call(this, 'div', {
  12487. className: className + " vjs-time-control vjs-control",
  12488. innerHTML: "<span class=\"vjs-control-text\" role=\"presentation\">" + this.localize(this.labelText_) + "\xA0</span>"
  12489. });
  12490. this.contentEl_ = createEl('span', {
  12491. className: className + "-display"
  12492. }, {
  12493. // tell screen readers not to automatically read the time as it changes
  12494. 'aria-live': 'off',
  12495. // span elements have no implicit role, but some screen readers (notably VoiceOver)
  12496. // treat them as a break between items in the DOM when using arrow keys
  12497. // (or left-to-right swipes on iOS) to read contents of a page. Using
  12498. // role='presentation' causes VoiceOver to NOT treat this span as a break.
  12499. 'role': 'presentation'
  12500. });
  12501. this.updateTextNode_();
  12502. el.appendChild(this.contentEl_);
  12503. return el;
  12504. };
  12505. _proto.dispose = function dispose() {
  12506. this.contentEl_ = null;
  12507. this.textNode_ = null;
  12508. _Component.prototype.dispose.call(this);
  12509. }
  12510. /**
  12511. * Updates the "remaining time" text node with new content using the
  12512. * contents of the `formattedTime_` property.
  12513. *
  12514. * @private
  12515. */
  12516. ;
  12517. _proto.updateTextNode_ = function updateTextNode_() {
  12518. if (!this.contentEl_) {
  12519. return;
  12520. }
  12521. while (this.contentEl_.firstChild) {
  12522. this.contentEl_.removeChild(this.contentEl_.firstChild);
  12523. }
  12524. this.textNode_ = document.createTextNode(this.formattedTime_ || this.formatTime_(0));
  12525. this.contentEl_.appendChild(this.textNode_);
  12526. }
  12527. /**
  12528. * Generates a formatted time for this component to use in display.
  12529. *
  12530. * @param {number} time
  12531. * A numeric time, in seconds.
  12532. *
  12533. * @return {string}
  12534. * A formatted time
  12535. *
  12536. * @private
  12537. */
  12538. ;
  12539. _proto.formatTime_ = function formatTime_(time) {
  12540. return formatTime(time);
  12541. }
  12542. /**
  12543. * Updates the time display text node if it has what was passed in changed
  12544. * the formatted time.
  12545. *
  12546. * @param {number} time
  12547. * The time to update to
  12548. *
  12549. * @private
  12550. */
  12551. ;
  12552. _proto.updateFormattedTime_ = function updateFormattedTime_(time) {
  12553. var formattedTime = this.formatTime_(time);
  12554. if (formattedTime === this.formattedTime_) {
  12555. return;
  12556. }
  12557. this.formattedTime_ = formattedTime;
  12558. this.requestAnimationFrame(this.updateTextNode_);
  12559. }
  12560. /**
  12561. * To be filled out in the child class, should update the displayed time
  12562. * in accordance with the fact that the current time has changed.
  12563. *
  12564. * @param {EventTarget~Event} [event]
  12565. * The `timeupdate` event that caused this to run.
  12566. *
  12567. * @listens Player#timeupdate
  12568. */
  12569. ;
  12570. _proto.updateContent = function updateContent(event) {};
  12571. return TimeDisplay;
  12572. }(Component);
  12573. /**
  12574. * The text that is added to the `TimeDisplay` for screen reader users.
  12575. *
  12576. * @type {string}
  12577. * @private
  12578. */
  12579. TimeDisplay.prototype.labelText_ = 'Time';
  12580. /**
  12581. * The text that should display over the `TimeDisplay`s controls. Added to for localization.
  12582. *
  12583. * @type {string}
  12584. * @private
  12585. *
  12586. * @deprecated in v7; controlText_ is not used in non-active display Components
  12587. */
  12588. TimeDisplay.prototype.controlText_ = 'Time';
  12589. Component.registerComponent('TimeDisplay', TimeDisplay);
  12590. /**
  12591. * Displays the current time
  12592. *
  12593. * @extends Component
  12594. */
  12595. var CurrentTimeDisplay =
  12596. /*#__PURE__*/
  12597. function (_TimeDisplay) {
  12598. _inheritsLoose(CurrentTimeDisplay, _TimeDisplay);
  12599. /**
  12600. * Creates an instance of this class.
  12601. *
  12602. * @param {Player} player
  12603. * The `Player` that this class should be attached to.
  12604. *
  12605. * @param {Object} [options]
  12606. * The key/value store of player options.
  12607. */
  12608. function CurrentTimeDisplay(player, options) {
  12609. var _this;
  12610. _this = _TimeDisplay.call(this, player, options) || this;
  12611. _this.on(player, 'ended', _this.handleEnded);
  12612. return _this;
  12613. }
  12614. /**
  12615. * Builds the default DOM `className`.
  12616. *
  12617. * @return {string}
  12618. * The DOM `className` for this object.
  12619. */
  12620. var _proto = CurrentTimeDisplay.prototype;
  12621. _proto.buildCSSClass = function buildCSSClass() {
  12622. return 'vjs-current-time';
  12623. }
  12624. /**
  12625. * Update current time display
  12626. *
  12627. * @param {EventTarget~Event} [event]
  12628. * The `timeupdate` event that caused this function to run.
  12629. *
  12630. * @listens Player#timeupdate
  12631. */
  12632. ;
  12633. _proto.updateContent = function updateContent(event) {
  12634. // Allows for smooth scrubbing, when player can't keep up.
  12635. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  12636. this.updateFormattedTime_(time);
  12637. }
  12638. /**
  12639. * When the player fires ended there should be no time left. Sadly
  12640. * this is not always the case, lets make it seem like that is the case
  12641. * for users.
  12642. *
  12643. * @param {EventTarget~Event} [event]
  12644. * The `ended` event that caused this to run.
  12645. *
  12646. * @listens Player#ended
  12647. */
  12648. ;
  12649. _proto.handleEnded = function handleEnded(event) {
  12650. if (!this.player_.duration()) {
  12651. return;
  12652. }
  12653. this.updateFormattedTime_(this.player_.duration());
  12654. };
  12655. return CurrentTimeDisplay;
  12656. }(TimeDisplay);
  12657. /**
  12658. * The text that is added to the `CurrentTimeDisplay` for screen reader users.
  12659. *
  12660. * @type {string}
  12661. * @private
  12662. */
  12663. CurrentTimeDisplay.prototype.labelText_ = 'Current Time';
  12664. /**
  12665. * The text that should display over the `CurrentTimeDisplay`s controls. Added to for localization.
  12666. *
  12667. * @type {string}
  12668. * @private
  12669. *
  12670. * @deprecated in v7; controlText_ is not used in non-active display Components
  12671. */
  12672. CurrentTimeDisplay.prototype.controlText_ = 'Current Time';
  12673. Component.registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
  12674. /**
  12675. * Displays the duration
  12676. *
  12677. * @extends Component
  12678. */
  12679. var DurationDisplay =
  12680. /*#__PURE__*/
  12681. function (_TimeDisplay) {
  12682. _inheritsLoose(DurationDisplay, _TimeDisplay);
  12683. /**
  12684. * Creates an instance of this class.
  12685. *
  12686. * @param {Player} player
  12687. * The `Player` that this class should be attached to.
  12688. *
  12689. * @param {Object} [options]
  12690. * The key/value store of player options.
  12691. */
  12692. function DurationDisplay(player, options) {
  12693. var _this;
  12694. _this = _TimeDisplay.call(this, player, options) || this; // we do not want to/need to throttle duration changes,
  12695. // as they should always display the changed duration as
  12696. // it has changed
  12697. _this.on(player, 'durationchange', _this.updateContent); // Listen to loadstart because the player duration is reset when a new media element is loaded,
  12698. // but the durationchange on the user agent will not fire.
  12699. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  12700. _this.on(player, 'loadstart', _this.updateContent); // Also listen for timeupdate (in the parent) and loadedmetadata because removing those
  12701. // listeners could have broken dependent applications/libraries. These
  12702. // can likely be removed for 7.0.
  12703. _this.on(player, 'loadedmetadata', _this.throttledUpdateContent);
  12704. return _this;
  12705. }
  12706. /**
  12707. * Builds the default DOM `className`.
  12708. *
  12709. * @return {string}
  12710. * The DOM `className` for this object.
  12711. */
  12712. var _proto = DurationDisplay.prototype;
  12713. _proto.buildCSSClass = function buildCSSClass() {
  12714. return 'vjs-duration';
  12715. }
  12716. /**
  12717. * Update duration time display.
  12718. *
  12719. * @param {EventTarget~Event} [event]
  12720. * The `durationchange`, `timeupdate`, or `loadedmetadata` event that caused
  12721. * this function to be called.
  12722. *
  12723. * @listens Player#durationchange
  12724. * @listens Player#timeupdate
  12725. * @listens Player#loadedmetadata
  12726. */
  12727. ;
  12728. _proto.updateContent = function updateContent(event) {
  12729. var duration = this.player_.duration();
  12730. if (this.duration_ !== duration) {
  12731. this.duration_ = duration;
  12732. this.updateFormattedTime_(duration);
  12733. }
  12734. };
  12735. return DurationDisplay;
  12736. }(TimeDisplay);
  12737. /**
  12738. * The text that is added to the `DurationDisplay` for screen reader users.
  12739. *
  12740. * @type {string}
  12741. * @private
  12742. */
  12743. DurationDisplay.prototype.labelText_ = 'Duration';
  12744. /**
  12745. * The text that should display over the `DurationDisplay`s controls. Added to for localization.
  12746. *
  12747. * @type {string}
  12748. * @private
  12749. *
  12750. * @deprecated in v7; controlText_ is not used in non-active display Components
  12751. */
  12752. DurationDisplay.prototype.controlText_ = 'Duration';
  12753. Component.registerComponent('DurationDisplay', DurationDisplay);
  12754. /**
  12755. * The separator between the current time and duration.
  12756. * Can be hidden if it's not needed in the design.
  12757. *
  12758. * @extends Component
  12759. */
  12760. var TimeDivider =
  12761. /*#__PURE__*/
  12762. function (_Component) {
  12763. _inheritsLoose(TimeDivider, _Component);
  12764. function TimeDivider() {
  12765. return _Component.apply(this, arguments) || this;
  12766. }
  12767. var _proto = TimeDivider.prototype;
  12768. /**
  12769. * Create the component's DOM element
  12770. *
  12771. * @return {Element}
  12772. * The element that was created.
  12773. */
  12774. _proto.createEl = function createEl() {
  12775. return _Component.prototype.createEl.call(this, 'div', {
  12776. className: 'vjs-time-control vjs-time-divider',
  12777. innerHTML: '<div><span>/</span></div>'
  12778. }, {
  12779. // this element and its contents can be hidden from assistive techs since
  12780. // it is made extraneous by the announcement of the control text
  12781. // for the current time and duration displays
  12782. 'aria-hidden': true
  12783. });
  12784. };
  12785. return TimeDivider;
  12786. }(Component);
  12787. Component.registerComponent('TimeDivider', TimeDivider);
  12788. /**
  12789. * Displays the time left in the video
  12790. *
  12791. * @extends Component
  12792. */
  12793. var RemainingTimeDisplay =
  12794. /*#__PURE__*/
  12795. function (_TimeDisplay) {
  12796. _inheritsLoose(RemainingTimeDisplay, _TimeDisplay);
  12797. /**
  12798. * Creates an instance of this class.
  12799. *
  12800. * @param {Player} player
  12801. * The `Player` that this class should be attached to.
  12802. *
  12803. * @param {Object} [options]
  12804. * The key/value store of player options.
  12805. */
  12806. function RemainingTimeDisplay(player, options) {
  12807. var _this;
  12808. _this = _TimeDisplay.call(this, player, options) || this;
  12809. _this.on(player, 'durationchange', _this.throttledUpdateContent);
  12810. _this.on(player, 'ended', _this.handleEnded);
  12811. return _this;
  12812. }
  12813. /**
  12814. * Builds the default DOM `className`.
  12815. *
  12816. * @return {string}
  12817. * The DOM `className` for this object.
  12818. */
  12819. var _proto = RemainingTimeDisplay.prototype;
  12820. _proto.buildCSSClass = function buildCSSClass() {
  12821. return 'vjs-remaining-time';
  12822. }
  12823. /**
  12824. * Create the `Component`'s DOM element with the "minus" characted prepend to the time
  12825. *
  12826. * @return {Element}
  12827. * The element that was created.
  12828. */
  12829. ;
  12830. _proto.createEl = function createEl$1() {
  12831. var el = _TimeDisplay.prototype.createEl.call(this);
  12832. el.insertBefore(createEl('span', {}, {
  12833. 'aria-hidden': true
  12834. }, '-'), this.contentEl_);
  12835. return el;
  12836. }
  12837. /**
  12838. * Update remaining time display.
  12839. *
  12840. * @param {EventTarget~Event} [event]
  12841. * The `timeupdate` or `durationchange` event that caused this to run.
  12842. *
  12843. * @listens Player#timeupdate
  12844. * @listens Player#durationchange
  12845. */
  12846. ;
  12847. _proto.updateContent = function updateContent(event) {
  12848. if (typeof this.player_.duration() !== 'number') {
  12849. return;
  12850. } // @deprecated We should only use remainingTimeDisplay
  12851. // as of video.js 7
  12852. if (this.player_.remainingTimeDisplay) {
  12853. this.updateFormattedTime_(this.player_.remainingTimeDisplay());
  12854. } else {
  12855. this.updateFormattedTime_(this.player_.remainingTime());
  12856. }
  12857. }
  12858. /**
  12859. * When the player fires ended there should be no time left. Sadly
  12860. * this is not always the case, lets make it seem like that is the case
  12861. * for users.
  12862. *
  12863. * @param {EventTarget~Event} [event]
  12864. * The `ended` event that caused this to run.
  12865. *
  12866. * @listens Player#ended
  12867. */
  12868. ;
  12869. _proto.handleEnded = function handleEnded(event) {
  12870. if (!this.player_.duration()) {
  12871. return;
  12872. }
  12873. this.updateFormattedTime_(0);
  12874. };
  12875. return RemainingTimeDisplay;
  12876. }(TimeDisplay);
  12877. /**
  12878. * The text that is added to the `RemainingTimeDisplay` for screen reader users.
  12879. *
  12880. * @type {string}
  12881. * @private
  12882. */
  12883. RemainingTimeDisplay.prototype.labelText_ = 'Remaining Time';
  12884. /**
  12885. * The text that should display over the `RemainingTimeDisplay`s controls. Added to for localization.
  12886. *
  12887. * @type {string}
  12888. * @private
  12889. *
  12890. * @deprecated in v7; controlText_ is not used in non-active display Components
  12891. */
  12892. RemainingTimeDisplay.prototype.controlText_ = 'Remaining Time';
  12893. Component.registerComponent('RemainingTimeDisplay', RemainingTimeDisplay);
  12894. /**
  12895. * Displays the live indicator when duration is Infinity.
  12896. *
  12897. * @extends Component
  12898. */
  12899. var LiveDisplay =
  12900. /*#__PURE__*/
  12901. function (_Component) {
  12902. _inheritsLoose(LiveDisplay, _Component);
  12903. /**
  12904. * Creates an instance of this class.
  12905. *
  12906. * @param {Player} player
  12907. * The `Player` that this class should be attached to.
  12908. *
  12909. * @param {Object} [options]
  12910. * The key/value store of player options.
  12911. */
  12912. function LiveDisplay(player, options) {
  12913. var _this;
  12914. _this = _Component.call(this, player, options) || this;
  12915. _this.updateShowing();
  12916. _this.on(_this.player(), 'durationchange', _this.updateShowing);
  12917. return _this;
  12918. }
  12919. /**
  12920. * Create the `Component`'s DOM element
  12921. *
  12922. * @return {Element}
  12923. * The element that was created.
  12924. */
  12925. var _proto = LiveDisplay.prototype;
  12926. _proto.createEl = function createEl$1() {
  12927. var el = _Component.prototype.createEl.call(this, 'div', {
  12928. className: 'vjs-live-control vjs-control'
  12929. });
  12930. this.contentEl_ = createEl('div', {
  12931. className: 'vjs-live-display',
  12932. innerHTML: "<span class=\"vjs-control-text\">" + this.localize('Stream Type') + "\xA0</span>" + this.localize('LIVE')
  12933. }, {
  12934. 'aria-live': 'off'
  12935. });
  12936. el.appendChild(this.contentEl_);
  12937. return el;
  12938. };
  12939. _proto.dispose = function dispose() {
  12940. this.contentEl_ = null;
  12941. _Component.prototype.dispose.call(this);
  12942. }
  12943. /**
  12944. * Check the duration to see if the LiveDisplay should be showing or not. Then show/hide
  12945. * it accordingly
  12946. *
  12947. * @param {EventTarget~Event} [event]
  12948. * The {@link Player#durationchange} event that caused this function to run.
  12949. *
  12950. * @listens Player#durationchange
  12951. */
  12952. ;
  12953. _proto.updateShowing = function updateShowing(event) {
  12954. if (this.player().duration() === Infinity) {
  12955. this.show();
  12956. } else {
  12957. this.hide();
  12958. }
  12959. };
  12960. return LiveDisplay;
  12961. }(Component);
  12962. Component.registerComponent('LiveDisplay', LiveDisplay);
  12963. /**
  12964. * Displays the live indicator when duration is Infinity.
  12965. *
  12966. * @extends Component
  12967. */
  12968. var SeekToLive =
  12969. /*#__PURE__*/
  12970. function (_Button) {
  12971. _inheritsLoose(SeekToLive, _Button);
  12972. /**
  12973. * Creates an instance of this class.
  12974. *
  12975. * @param {Player} player
  12976. * The `Player` that this class should be attached to.
  12977. *
  12978. * @param {Object} [options]
  12979. * The key/value store of player options.
  12980. */
  12981. function SeekToLive(player, options) {
  12982. var _this;
  12983. _this = _Button.call(this, player, options) || this;
  12984. _this.updateLiveEdgeStatus();
  12985. if (_this.player_.liveTracker) {
  12986. _this.on(_this.player_.liveTracker, 'liveedgechange', _this.updateLiveEdgeStatus);
  12987. }
  12988. return _this;
  12989. }
  12990. /**
  12991. * Create the `Component`'s DOM element
  12992. *
  12993. * @return {Element}
  12994. * The element that was created.
  12995. */
  12996. var _proto = SeekToLive.prototype;
  12997. _proto.createEl = function createEl$1() {
  12998. var el = _Button.prototype.createEl.call(this, 'button', {
  12999. className: 'vjs-seek-to-live-control vjs-control'
  13000. });
  13001. this.textEl_ = createEl('span', {
  13002. className: 'vjs-seek-to-live-text',
  13003. innerHTML: this.localize('LIVE')
  13004. }, {
  13005. 'aria-hidden': 'true'
  13006. });
  13007. el.appendChild(this.textEl_);
  13008. return el;
  13009. }
  13010. /**
  13011. * Update the state of this button if we are at the live edge
  13012. * or not
  13013. */
  13014. ;
  13015. _proto.updateLiveEdgeStatus = function updateLiveEdgeStatus(e) {
  13016. // default to live edge
  13017. if (!this.player_.liveTracker || this.player_.liveTracker.atLiveEdge()) {
  13018. this.setAttribute('aria-disabled', true);
  13019. this.addClass('vjs-at-live-edge');
  13020. this.controlText('Seek to live, currently playing live');
  13021. } else {
  13022. this.setAttribute('aria-disabled', false);
  13023. this.removeClass('vjs-at-live-edge');
  13024. this.controlText('Seek to live, currently behind live');
  13025. }
  13026. }
  13027. /**
  13028. * On click bring us as near to the live point as possible.
  13029. * This requires that we wait for the next `live-seekable-change`
  13030. * event which will happen every segment length seconds.
  13031. */
  13032. ;
  13033. _proto.handleClick = function handleClick() {
  13034. this.player_.liveTracker.seekToLiveEdge();
  13035. }
  13036. /**
  13037. * Dispose of the element and stop tracking
  13038. */
  13039. ;
  13040. _proto.dispose = function dispose() {
  13041. if (this.player_.liveTracker) {
  13042. this.off(this.player_.liveTracker, 'liveedgechange', this.updateLiveEdgeStatus);
  13043. }
  13044. this.textEl_ = null;
  13045. _Button.prototype.dispose.call(this);
  13046. };
  13047. return SeekToLive;
  13048. }(Button);
  13049. SeekToLive.prototype.controlText_ = 'Seek to live, currently playing live';
  13050. Component.registerComponent('SeekToLive', SeekToLive);
  13051. /**
  13052. * The base functionality for a slider. Can be vertical or horizontal.
  13053. * For instance the volume bar or the seek bar on a video is a slider.
  13054. *
  13055. * @extends Component
  13056. */
  13057. var Slider =
  13058. /*#__PURE__*/
  13059. function (_Component) {
  13060. _inheritsLoose(Slider, _Component);
  13061. /**
  13062. * Create an instance of this class
  13063. *
  13064. * @param {Player} player
  13065. * The `Player` that this class should be attached to.
  13066. *
  13067. * @param {Object} [options]
  13068. * The key/value store of player options.
  13069. */
  13070. function Slider(player, options) {
  13071. var _this;
  13072. _this = _Component.call(this, player, options) || this; // Set property names to bar to match with the child Slider class is looking for
  13073. _this.bar = _this.getChild(_this.options_.barName); // Set a horizontal or vertical class on the slider depending on the slider type
  13074. _this.vertical(!!_this.options_.vertical);
  13075. _this.enable();
  13076. return _this;
  13077. }
  13078. /**
  13079. * Are controls are currently enabled for this slider or not.
  13080. *
  13081. * @return {boolean}
  13082. * true if controls are enabled, false otherwise
  13083. */
  13084. var _proto = Slider.prototype;
  13085. _proto.enabled = function enabled() {
  13086. return this.enabled_;
  13087. }
  13088. /**
  13089. * Enable controls for this slider if they are disabled
  13090. */
  13091. ;
  13092. _proto.enable = function enable() {
  13093. if (this.enabled()) {
  13094. return;
  13095. }
  13096. this.on('mousedown', this.handleMouseDown);
  13097. this.on('touchstart', this.handleMouseDown);
  13098. this.on('keydown', this.handleKeyDown);
  13099. this.on('click', this.handleClick); // TODO: deprecated, controlsvisible does not seem to be fired
  13100. this.on(this.player_, 'controlsvisible', this.update);
  13101. if (this.playerEvent) {
  13102. this.on(this.player_, this.playerEvent, this.update);
  13103. }
  13104. this.removeClass('disabled');
  13105. this.setAttribute('tabindex', 0);
  13106. this.enabled_ = true;
  13107. }
  13108. /**
  13109. * Disable controls for this slider if they are enabled
  13110. */
  13111. ;
  13112. _proto.disable = function disable() {
  13113. if (!this.enabled()) {
  13114. return;
  13115. }
  13116. var doc = this.bar.el_.ownerDocument;
  13117. this.off('mousedown', this.handleMouseDown);
  13118. this.off('touchstart', this.handleMouseDown);
  13119. this.off('keydown', this.handleKeyDown);
  13120. this.off('click', this.handleClick);
  13121. this.off(this.player_, 'controlsvisible', this.update);
  13122. this.off(doc, 'mousemove', this.handleMouseMove);
  13123. this.off(doc, 'mouseup', this.handleMouseUp);
  13124. this.off(doc, 'touchmove', this.handleMouseMove);
  13125. this.off(doc, 'touchend', this.handleMouseUp);
  13126. this.removeAttribute('tabindex');
  13127. this.addClass('disabled');
  13128. if (this.playerEvent) {
  13129. this.off(this.player_, this.playerEvent, this.update);
  13130. }
  13131. this.enabled_ = false;
  13132. }
  13133. /**
  13134. * Create the `Slider`s DOM element.
  13135. *
  13136. * @param {string} type
  13137. * Type of element to create.
  13138. *
  13139. * @param {Object} [props={}]
  13140. * List of properties in Object form.
  13141. *
  13142. * @param {Object} [attributes={}]
  13143. * list of attributes in Object form.
  13144. *
  13145. * @return {Element}
  13146. * The element that gets created.
  13147. */
  13148. ;
  13149. _proto.createEl = function createEl(type, props, attributes) {
  13150. if (props === void 0) {
  13151. props = {};
  13152. }
  13153. if (attributes === void 0) {
  13154. attributes = {};
  13155. }
  13156. // Add the slider element class to all sub classes
  13157. props.className = props.className + ' vjs-slider';
  13158. props = assign({
  13159. tabIndex: 0
  13160. }, props);
  13161. attributes = assign({
  13162. 'role': 'slider',
  13163. 'aria-valuenow': 0,
  13164. 'aria-valuemin': 0,
  13165. 'aria-valuemax': 100,
  13166. 'tabIndex': 0
  13167. }, attributes);
  13168. return _Component.prototype.createEl.call(this, type, props, attributes);
  13169. }
  13170. /**
  13171. * Handle `mousedown` or `touchstart` events on the `Slider`.
  13172. *
  13173. * @param {EventTarget~Event} event
  13174. * `mousedown` or `touchstart` event that triggered this function
  13175. *
  13176. * @listens mousedown
  13177. * @listens touchstart
  13178. * @fires Slider#slideractive
  13179. */
  13180. ;
  13181. _proto.handleMouseDown = function handleMouseDown(event) {
  13182. var doc = this.bar.el_.ownerDocument;
  13183. if (event.type === 'mousedown') {
  13184. event.preventDefault();
  13185. } // Do not call preventDefault() on touchstart in Chrome
  13186. // to avoid console warnings. Use a 'touch-action: none' style
  13187. // instead to prevent unintented scrolling.
  13188. // https://developers.google.com/web/updates/2017/01/scrolling-intervention
  13189. if (event.type === 'touchstart' && !IS_CHROME) {
  13190. event.preventDefault();
  13191. }
  13192. blockTextSelection();
  13193. this.addClass('vjs-sliding');
  13194. /**
  13195. * Triggered when the slider is in an active state
  13196. *
  13197. * @event Slider#slideractive
  13198. * @type {EventTarget~Event}
  13199. */
  13200. this.trigger('slideractive');
  13201. this.on(doc, 'mousemove', this.handleMouseMove);
  13202. this.on(doc, 'mouseup', this.handleMouseUp);
  13203. this.on(doc, 'touchmove', this.handleMouseMove);
  13204. this.on(doc, 'touchend', this.handleMouseUp);
  13205. this.handleMouseMove(event);
  13206. }
  13207. /**
  13208. * Handle the `mousemove`, `touchmove`, and `mousedown` events on this `Slider`.
  13209. * The `mousemove` and `touchmove` events will only only trigger this function during
  13210. * `mousedown` and `touchstart`. This is due to {@link Slider#handleMouseDown} and
  13211. * {@link Slider#handleMouseUp}.
  13212. *
  13213. * @param {EventTarget~Event} event
  13214. * `mousedown`, `mousemove`, `touchstart`, or `touchmove` event that triggered
  13215. * this function
  13216. *
  13217. * @listens mousemove
  13218. * @listens touchmove
  13219. */
  13220. ;
  13221. _proto.handleMouseMove = function handleMouseMove(event) {}
  13222. /**
  13223. * Handle `mouseup` or `touchend` events on the `Slider`.
  13224. *
  13225. * @param {EventTarget~Event} event
  13226. * `mouseup` or `touchend` event that triggered this function.
  13227. *
  13228. * @listens touchend
  13229. * @listens mouseup
  13230. * @fires Slider#sliderinactive
  13231. */
  13232. ;
  13233. _proto.handleMouseUp = function handleMouseUp() {
  13234. var doc = this.bar.el_.ownerDocument;
  13235. unblockTextSelection();
  13236. this.removeClass('vjs-sliding');
  13237. /**
  13238. * Triggered when the slider is no longer in an active state.
  13239. *
  13240. * @event Slider#sliderinactive
  13241. * @type {EventTarget~Event}
  13242. */
  13243. this.trigger('sliderinactive');
  13244. this.off(doc, 'mousemove', this.handleMouseMove);
  13245. this.off(doc, 'mouseup', this.handleMouseUp);
  13246. this.off(doc, 'touchmove', this.handleMouseMove);
  13247. this.off(doc, 'touchend', this.handleMouseUp);
  13248. this.update();
  13249. }
  13250. /**
  13251. * Update the progress bar of the `Slider`.
  13252. *
  13253. * @return {number}
  13254. * The percentage of progress the progress bar represents as a
  13255. * number from 0 to 1.
  13256. */
  13257. ;
  13258. _proto.update = function update() {
  13259. // In VolumeBar init we have a setTimeout for update that pops and update
  13260. // to the end of the execution stack. The player is destroyed before then
  13261. // update will cause an error
  13262. if (!this.el_) {
  13263. return;
  13264. } // If scrubbing, we could use a cached value to make the handle keep up
  13265. // with the user's mouse. On HTML5 browsers scrubbing is really smooth, but
  13266. // some flash players are slow, so we might want to utilize this later.
  13267. // var progress = (this.player_.scrubbing()) ? this.player_.getCache().currentTime / this.player_.duration() : this.player_.currentTime() / this.player_.duration();
  13268. var progress = this.getPercent();
  13269. var bar = this.bar; // If there's no bar...
  13270. if (!bar) {
  13271. return;
  13272. } // Protect against no duration and other division issues
  13273. if (typeof progress !== 'number' || progress !== progress || progress < 0 || progress === Infinity) {
  13274. progress = 0;
  13275. } // Convert to a percentage for setting
  13276. var percentage = (progress * 100).toFixed(2) + '%';
  13277. var style = bar.el().style; // Set the new bar width or height
  13278. var sizeKey = this.vertical() ? 'height' : 'width';
  13279. if (style[sizeKey] !== percentage) {
  13280. style[sizeKey] = percentage;
  13281. }
  13282. return progress;
  13283. }
  13284. /**
  13285. * Calculate distance for slider
  13286. *
  13287. * @param {EventTarget~Event} event
  13288. * The event that caused this function to run.
  13289. *
  13290. * @return {number}
  13291. * The current position of the Slider.
  13292. * - position.x for vertical `Slider`s
  13293. * - position.y for horizontal `Slider`s
  13294. */
  13295. ;
  13296. _proto.calculateDistance = function calculateDistance(event) {
  13297. var position = getPointerPosition(this.el_, event);
  13298. if (this.vertical()) {
  13299. return position.y;
  13300. }
  13301. return position.x;
  13302. }
  13303. /**
  13304. * Handle a `keydown` event on the `Slider`. Watches for left, rigth, up, and down
  13305. * arrow keys. This function will only be called when the slider has focus. See
  13306. * {@link Slider#handleFocus} and {@link Slider#handleBlur}.
  13307. *
  13308. * @param {EventTarget~Event} event
  13309. * the `keydown` event that caused this function to run.
  13310. *
  13311. * @listens keydown
  13312. */
  13313. ;
  13314. _proto.handleKeyDown = function handleKeyDown(event) {
  13315. // Left and Down Arrows
  13316. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  13317. event.preventDefault();
  13318. event.stopPropagation();
  13319. this.stepBack(); // Up and Right Arrows
  13320. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  13321. event.preventDefault();
  13322. event.stopPropagation();
  13323. this.stepForward();
  13324. } else {
  13325. // Pass keydown handling up for unsupported keys
  13326. _Component.prototype.handleKeyDown.call(this, event);
  13327. }
  13328. }
  13329. /**
  13330. * Listener for click events on slider, used to prevent clicks
  13331. * from bubbling up to parent elements like button menus.
  13332. *
  13333. * @param {Object} event
  13334. * Event that caused this object to run
  13335. */
  13336. ;
  13337. _proto.handleClick = function handleClick(event) {
  13338. event.stopPropagation();
  13339. event.preventDefault();
  13340. }
  13341. /**
  13342. * Get/set if slider is horizontal for vertical
  13343. *
  13344. * @param {boolean} [bool]
  13345. * - true if slider is vertical,
  13346. * - false is horizontal
  13347. *
  13348. * @return {boolean}
  13349. * - true if slider is vertical, and getting
  13350. * - false if the slider is horizontal, and getting
  13351. */
  13352. ;
  13353. _proto.vertical = function vertical(bool) {
  13354. if (bool === undefined) {
  13355. return this.vertical_ || false;
  13356. }
  13357. this.vertical_ = !!bool;
  13358. if (this.vertical_) {
  13359. this.addClass('vjs-slider-vertical');
  13360. } else {
  13361. this.addClass('vjs-slider-horizontal');
  13362. }
  13363. };
  13364. return Slider;
  13365. }(Component);
  13366. Component.registerComponent('Slider', Slider);
  13367. /**
  13368. * Shows loading progress
  13369. *
  13370. * @extends Component
  13371. */
  13372. var LoadProgressBar =
  13373. /*#__PURE__*/
  13374. function (_Component) {
  13375. _inheritsLoose(LoadProgressBar, _Component);
  13376. /**
  13377. * Creates an instance of this class.
  13378. *
  13379. * @param {Player} player
  13380. * The `Player` that this class should be attached to.
  13381. *
  13382. * @param {Object} [options]
  13383. * The key/value store of player options.
  13384. */
  13385. function LoadProgressBar(player, options) {
  13386. var _this;
  13387. _this = _Component.call(this, player, options) || this;
  13388. _this.partEls_ = [];
  13389. _this.on(player, 'progress', _this.update);
  13390. return _this;
  13391. }
  13392. /**
  13393. * Create the `Component`'s DOM element
  13394. *
  13395. * @return {Element}
  13396. * The element that was created.
  13397. */
  13398. var _proto = LoadProgressBar.prototype;
  13399. _proto.createEl = function createEl() {
  13400. return _Component.prototype.createEl.call(this, 'div', {
  13401. className: 'vjs-load-progress',
  13402. innerHTML: "<span class=\"vjs-control-text\"><span>" + this.localize('Loaded') + "</span>: <span class=\"vjs-control-text-loaded-percentage\">0%</span></span>"
  13403. });
  13404. };
  13405. _proto.dispose = function dispose() {
  13406. this.partEls_ = null;
  13407. _Component.prototype.dispose.call(this);
  13408. }
  13409. /**
  13410. * Update progress bar
  13411. *
  13412. * @param {EventTarget~Event} [event]
  13413. * The `progress` event that caused this function to run.
  13414. *
  13415. * @listens Player#progress
  13416. */
  13417. ;
  13418. _proto.update = function update(event) {
  13419. var liveTracker = this.player_.liveTracker;
  13420. var buffered = this.player_.buffered();
  13421. var duration = liveTracker && liveTracker.isLive() ? liveTracker.seekableEnd() : this.player_.duration();
  13422. var bufferedEnd = this.player_.bufferedEnd();
  13423. var children = this.partEls_;
  13424. var controlTextPercentage = this.$('.vjs-control-text-loaded-percentage'); // get the percent width of a time compared to the total end
  13425. var percentify = function percentify(time, end, rounded) {
  13426. // no NaN
  13427. var percent = time / end || 0;
  13428. percent = (percent >= 1 ? 1 : percent) * 100;
  13429. if (rounded) {
  13430. percent = percent.toFixed(2);
  13431. }
  13432. return percent + '%';
  13433. }; // update the width of the progress bar
  13434. this.el_.style.width = percentify(bufferedEnd, duration); // update the control-text
  13435. textContent(controlTextPercentage, percentify(bufferedEnd, duration, true)); // add child elements to represent the individual buffered time ranges
  13436. for (var i = 0; i < buffered.length; i++) {
  13437. var start = buffered.start(i);
  13438. var end = buffered.end(i);
  13439. var part = children[i];
  13440. if (!part) {
  13441. part = this.el_.appendChild(createEl());
  13442. children[i] = part;
  13443. } // set the percent based on the width of the progress bar (bufferedEnd)
  13444. part.style.left = percentify(start, bufferedEnd);
  13445. part.style.width = percentify(end - start, bufferedEnd);
  13446. } // remove unused buffered range elements
  13447. for (var _i = children.length; _i > buffered.length; _i--) {
  13448. this.el_.removeChild(children[_i - 1]);
  13449. }
  13450. children.length = buffered.length;
  13451. };
  13452. return LoadProgressBar;
  13453. }(Component);
  13454. Component.registerComponent('LoadProgressBar', LoadProgressBar);
  13455. /**
  13456. * Time tooltips display a time above the progress bar.
  13457. *
  13458. * @extends Component
  13459. */
  13460. var TimeTooltip =
  13461. /*#__PURE__*/
  13462. function (_Component) {
  13463. _inheritsLoose(TimeTooltip, _Component);
  13464. /**
  13465. * Creates an instance of this class.
  13466. *
  13467. * @param {Player} player
  13468. * The {@link Player} that this class should be attached to.
  13469. *
  13470. * @param {Object} [options]
  13471. * The key/value store of player options.
  13472. */
  13473. function TimeTooltip(player, options) {
  13474. var _this;
  13475. _this = _Component.call(this, player, options) || this;
  13476. _this.update = throttle(bind(_assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13477. return _this;
  13478. }
  13479. /**
  13480. * Create the time tooltip DOM element
  13481. *
  13482. * @return {Element}
  13483. * The element that was created.
  13484. */
  13485. var _proto = TimeTooltip.prototype;
  13486. _proto.createEl = function createEl() {
  13487. return _Component.prototype.createEl.call(this, 'div', {
  13488. className: 'vjs-time-tooltip'
  13489. }, {
  13490. 'aria-hidden': 'true'
  13491. });
  13492. }
  13493. /**
  13494. * Updates the position of the time tooltip relative to the `SeekBar`.
  13495. *
  13496. * @param {Object} seekBarRect
  13497. * The `ClientRect` for the {@link SeekBar} element.
  13498. *
  13499. * @param {number} seekBarPoint
  13500. * A number from 0 to 1, representing a horizontal reference point
  13501. * from the left edge of the {@link SeekBar}
  13502. */
  13503. ;
  13504. _proto.update = function update(seekBarRect, seekBarPoint, content) {
  13505. var tooltipRect = getBoundingClientRect(this.el_);
  13506. var playerRect = getBoundingClientRect(this.player_.el());
  13507. var seekBarPointPx = seekBarRect.width * seekBarPoint; // do nothing if either rect isn't available
  13508. // for example, if the player isn't in the DOM for testing
  13509. if (!playerRect || !tooltipRect) {
  13510. return;
  13511. } // This is the space left of the `seekBarPoint` available within the bounds
  13512. // of the player. We calculate any gap between the left edge of the player
  13513. // and the left edge of the `SeekBar` and add the number of pixels in the
  13514. // `SeekBar` before hitting the `seekBarPoint`
  13515. var spaceLeftOfPoint = seekBarRect.left - playerRect.left + seekBarPointPx; // This is the space right of the `seekBarPoint` available within the bounds
  13516. // of the player. We calculate the number of pixels from the `seekBarPoint`
  13517. // to the right edge of the `SeekBar` and add to that any gap between the
  13518. // right edge of the `SeekBar` and the player.
  13519. var spaceRightOfPoint = seekBarRect.width - seekBarPointPx + (playerRect.right - seekBarRect.right); // This is the number of pixels by which the tooltip will need to be pulled
  13520. // further to the right to center it over the `seekBarPoint`.
  13521. var pullTooltipBy = tooltipRect.width / 2; // Adjust the `pullTooltipBy` distance to the left or right depending on
  13522. // the results of the space calculations above.
  13523. if (spaceLeftOfPoint < pullTooltipBy) {
  13524. pullTooltipBy += pullTooltipBy - spaceLeftOfPoint;
  13525. } else if (spaceRightOfPoint < pullTooltipBy) {
  13526. pullTooltipBy = spaceRightOfPoint;
  13527. } // Due to the imprecision of decimal/ratio based calculations and varying
  13528. // rounding behaviors, there are cases where the spacing adjustment is off
  13529. // by a pixel or two. This adds insurance to these calculations.
  13530. if (pullTooltipBy < 0) {
  13531. pullTooltipBy = 0;
  13532. } else if (pullTooltipBy > tooltipRect.width) {
  13533. pullTooltipBy = tooltipRect.width;
  13534. }
  13535. this.el_.style.right = "-" + pullTooltipBy + "px";
  13536. this.write(content);
  13537. }
  13538. /**
  13539. * Write the time to the tooltip DOM element.
  13540. *
  13541. * @param {string} content
  13542. * The formatted time for the tooltip.
  13543. */
  13544. ;
  13545. _proto.write = function write(content) {
  13546. textContent(this.el_, content);
  13547. }
  13548. /**
  13549. * Updates the position of the time tooltip relative to the `SeekBar`.
  13550. *
  13551. * @param {Object} seekBarRect
  13552. * The `ClientRect` for the {@link SeekBar} element.
  13553. *
  13554. * @param {number} seekBarPoint
  13555. * A number from 0 to 1, representing a horizontal reference point
  13556. * from the left edge of the {@link SeekBar}
  13557. *
  13558. * @param {number} time
  13559. * The time to update the tooltip to, not used during live playback
  13560. *
  13561. * @param {Function} cb
  13562. * A function that will be called during the request animation frame
  13563. * for tooltips that need to do additional animations from the default
  13564. */
  13565. ;
  13566. _proto.updateTime = function updateTime(seekBarRect, seekBarPoint, time, cb) {
  13567. var _this2 = this;
  13568. // If there is an existing rAF ID, cancel it so we don't over-queue.
  13569. if (this.rafId_) {
  13570. this.cancelAnimationFrame(this.rafId_);
  13571. }
  13572. this.rafId_ = this.requestAnimationFrame(function () {
  13573. var content;
  13574. var duration = _this2.player_.duration();
  13575. if (_this2.player_.liveTracker && _this2.player_.liveTracker.isLive()) {
  13576. var liveWindow = _this2.player_.liveTracker.liveWindow();
  13577. var secondsBehind = liveWindow - seekBarPoint * liveWindow;
  13578. content = (secondsBehind < 1 ? '' : '-') + formatTime(secondsBehind, liveWindow);
  13579. } else {
  13580. content = formatTime(time, duration);
  13581. }
  13582. _this2.update(seekBarRect, seekBarPoint, content);
  13583. if (cb) {
  13584. cb();
  13585. }
  13586. });
  13587. };
  13588. return TimeTooltip;
  13589. }(Component);
  13590. Component.registerComponent('TimeTooltip', TimeTooltip);
  13591. /**
  13592. * Used by {@link SeekBar} to display media playback progress as part of the
  13593. * {@link ProgressControl}.
  13594. *
  13595. * @extends Component
  13596. */
  13597. var PlayProgressBar =
  13598. /*#__PURE__*/
  13599. function (_Component) {
  13600. _inheritsLoose(PlayProgressBar, _Component);
  13601. /**
  13602. * Creates an instance of this class.
  13603. *
  13604. * @param {Player} player
  13605. * The {@link Player} that this class should be attached to.
  13606. *
  13607. * @param {Object} [options]
  13608. * The key/value store of player options.
  13609. */
  13610. function PlayProgressBar(player, options) {
  13611. var _this;
  13612. _this = _Component.call(this, player, options) || this;
  13613. _this.update = throttle(bind(_assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13614. return _this;
  13615. }
  13616. /**
  13617. * Create the the DOM element for this class.
  13618. *
  13619. * @return {Element}
  13620. * The element that was created.
  13621. */
  13622. var _proto = PlayProgressBar.prototype;
  13623. _proto.createEl = function createEl() {
  13624. return _Component.prototype.createEl.call(this, 'div', {
  13625. className: 'vjs-play-progress vjs-slider-bar'
  13626. }, {
  13627. 'aria-hidden': 'true'
  13628. });
  13629. }
  13630. /**
  13631. * Enqueues updates to its own DOM as well as the DOM of its
  13632. * {@link TimeTooltip} child.
  13633. *
  13634. * @param {Object} seekBarRect
  13635. * The `ClientRect` for the {@link SeekBar} element.
  13636. *
  13637. * @param {number} seekBarPoint
  13638. * A number from 0 to 1, representing a horizontal reference point
  13639. * from the left edge of the {@link SeekBar}
  13640. */
  13641. ;
  13642. _proto.update = function update(seekBarRect, seekBarPoint) {
  13643. var timeTooltip = this.getChild('timeTooltip');
  13644. if (!timeTooltip) {
  13645. return;
  13646. }
  13647. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  13648. timeTooltip.updateTime(seekBarRect, seekBarPoint, time);
  13649. };
  13650. return PlayProgressBar;
  13651. }(Component);
  13652. /**
  13653. * Default options for {@link PlayProgressBar}.
  13654. *
  13655. * @type {Object}
  13656. * @private
  13657. */
  13658. PlayProgressBar.prototype.options_ = {
  13659. children: []
  13660. }; // Time tooltips should not be added to a player on mobile devices
  13661. if (!IS_IOS && !IS_ANDROID) {
  13662. PlayProgressBar.prototype.options_.children.push('timeTooltip');
  13663. }
  13664. Component.registerComponent('PlayProgressBar', PlayProgressBar);
  13665. /**
  13666. * The {@link MouseTimeDisplay} component tracks mouse movement over the
  13667. * {@link ProgressControl}. It displays an indicator and a {@link TimeTooltip}
  13668. * indicating the time which is represented by a given point in the
  13669. * {@link ProgressControl}.
  13670. *
  13671. * @extends Component
  13672. */
  13673. var MouseTimeDisplay =
  13674. /*#__PURE__*/
  13675. function (_Component) {
  13676. _inheritsLoose(MouseTimeDisplay, _Component);
  13677. /**
  13678. * Creates an instance of this class.
  13679. *
  13680. * @param {Player} player
  13681. * The {@link Player} that this class should be attached to.
  13682. *
  13683. * @param {Object} [options]
  13684. * The key/value store of player options.
  13685. */
  13686. function MouseTimeDisplay(player, options) {
  13687. var _this;
  13688. _this = _Component.call(this, player, options) || this;
  13689. _this.update = throttle(bind(_assertThisInitialized(_this), _this.update), UPDATE_REFRESH_INTERVAL);
  13690. return _this;
  13691. }
  13692. /**
  13693. * Create the DOM element for this class.
  13694. *
  13695. * @return {Element}
  13696. * The element that was created.
  13697. */
  13698. var _proto = MouseTimeDisplay.prototype;
  13699. _proto.createEl = function createEl() {
  13700. return _Component.prototype.createEl.call(this, 'div', {
  13701. className: 'vjs-mouse-display'
  13702. });
  13703. }
  13704. /**
  13705. * Enqueues updates to its own DOM as well as the DOM of its
  13706. * {@link TimeTooltip} child.
  13707. *
  13708. * @param {Object} seekBarRect
  13709. * The `ClientRect` for the {@link SeekBar} element.
  13710. *
  13711. * @param {number} seekBarPoint
  13712. * A number from 0 to 1, representing a horizontal reference point
  13713. * from the left edge of the {@link SeekBar}
  13714. */
  13715. ;
  13716. _proto.update = function update(seekBarRect, seekBarPoint) {
  13717. var _this2 = this;
  13718. var time = seekBarPoint * this.player_.duration();
  13719. this.getChild('timeTooltip').updateTime(seekBarRect, seekBarPoint, time, function () {
  13720. _this2.el_.style.left = seekBarRect.width * seekBarPoint + "px";
  13721. });
  13722. };
  13723. return MouseTimeDisplay;
  13724. }(Component);
  13725. /**
  13726. * Default options for `MouseTimeDisplay`
  13727. *
  13728. * @type {Object}
  13729. * @private
  13730. */
  13731. MouseTimeDisplay.prototype.options_ = {
  13732. children: ['timeTooltip']
  13733. };
  13734. Component.registerComponent('MouseTimeDisplay', MouseTimeDisplay);
  13735. var STEP_SECONDS = 5; // The multiplier of STEP_SECONDS that PgUp/PgDown move the timeline.
  13736. var PAGE_KEY_MULTIPLIER = 12; // The interval at which the bar should update as it progresses.
  13737. var UPDATE_REFRESH_INTERVAL$1 = 30;
  13738. /**
  13739. * Seek bar and container for the progress bars. Uses {@link PlayProgressBar}
  13740. * as its `bar`.
  13741. *
  13742. * @extends Slider
  13743. */
  13744. var SeekBar =
  13745. /*#__PURE__*/
  13746. function (_Slider) {
  13747. _inheritsLoose(SeekBar, _Slider);
  13748. /**
  13749. * Creates an instance of this class.
  13750. *
  13751. * @param {Player} player
  13752. * The `Player` that this class should be attached to.
  13753. *
  13754. * @param {Object} [options]
  13755. * The key/value store of player options.
  13756. */
  13757. function SeekBar(player, options) {
  13758. var _this;
  13759. _this = _Slider.call(this, player, options) || this;
  13760. _this.setEventHandlers_();
  13761. return _this;
  13762. }
  13763. /**
  13764. * Sets the event handlers
  13765. *
  13766. * @private
  13767. */
  13768. var _proto = SeekBar.prototype;
  13769. _proto.setEventHandlers_ = function setEventHandlers_() {
  13770. this.update = throttle(bind(this, this.update), UPDATE_REFRESH_INTERVAL$1);
  13771. this.on(this.player_, 'timeupdate', this.update);
  13772. this.on(this.player_, 'ended', this.handleEnded);
  13773. this.on(this.player_, 'durationchange', this.update);
  13774. if (this.player_.liveTracker) {
  13775. this.on(this.player_.liveTracker, 'liveedgechange', this.update);
  13776. } // when playing, let's ensure we smoothly update the play progress bar
  13777. // via an interval
  13778. this.updateInterval = null;
  13779. this.on(this.player_, ['playing'], this.enableInterval_);
  13780. this.on(this.player_, ['ended', 'pause', 'waiting'], this.disableInterval_); // we don't need to update the play progress if the document is hidden,
  13781. // also, this causes the CPU to spike and eventually crash the page on IE11.
  13782. if ('hidden' in document && 'visibilityState' in document) {
  13783. this.on(document, 'visibilitychange', this.toggleVisibility_);
  13784. }
  13785. };
  13786. _proto.toggleVisibility_ = function toggleVisibility_(e) {
  13787. if (document.hidden) {
  13788. this.disableInterval_(e);
  13789. } else {
  13790. this.enableInterval_(); // we just switched back to the page and someone may be looking, so, update ASAP
  13791. this.requestAnimationFrame(this.update);
  13792. }
  13793. };
  13794. _proto.enableInterval_ = function enableInterval_() {
  13795. var _this2 = this;
  13796. this.clearInterval(this.updateInterval);
  13797. this.updateInterval = this.setInterval(function () {
  13798. _this2.requestAnimationFrame(_this2.update);
  13799. }, UPDATE_REFRESH_INTERVAL$1);
  13800. };
  13801. _proto.disableInterval_ = function disableInterval_(e) {
  13802. if (this.player_.liveTracker && this.player_.liveTracker.isLive() && e.type !== 'ended') {
  13803. return;
  13804. }
  13805. this.clearInterval(this.updateInterval);
  13806. }
  13807. /**
  13808. * Create the `Component`'s DOM element
  13809. *
  13810. * @return {Element}
  13811. * The element that was created.
  13812. */
  13813. ;
  13814. _proto.createEl = function createEl() {
  13815. return _Slider.prototype.createEl.call(this, 'div', {
  13816. className: 'vjs-progress-holder'
  13817. }, {
  13818. 'aria-label': this.localize('Progress Bar')
  13819. });
  13820. }
  13821. /**
  13822. * This function updates the play progress bar and accessibility
  13823. * attributes to whatever is passed in.
  13824. *
  13825. * @param {number} currentTime
  13826. * The currentTime value that should be used for accessibility
  13827. *
  13828. * @param {number} percent
  13829. * The percentage as a decimal that the bar should be filled from 0-1.
  13830. *
  13831. * @private
  13832. */
  13833. ;
  13834. _proto.update_ = function update_(currentTime, percent) {
  13835. var liveTracker = this.player_.liveTracker;
  13836. var duration = this.player_.duration();
  13837. if (liveTracker && liveTracker.isLive()) {
  13838. duration = this.player_.liveTracker.liveCurrentTime();
  13839. } // machine readable value of progress bar (percentage complete)
  13840. this.el_.setAttribute('aria-valuenow', (percent * 100).toFixed(2)); // human readable value of progress bar (time complete)
  13841. 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`.
  13842. if (this.bar) {
  13843. this.bar.update(getBoundingClientRect(this.el_), percent);
  13844. }
  13845. }
  13846. /**
  13847. * Update the seek bar's UI.
  13848. *
  13849. * @param {EventTarget~Event} [event]
  13850. * The `timeupdate` or `ended` event that caused this to run.
  13851. *
  13852. * @listens Player#timeupdate
  13853. *
  13854. * @return {number}
  13855. * The current percent at a number from 0-1
  13856. */
  13857. ;
  13858. _proto.update = function update(event) {
  13859. // if the offsetParent is null, then this element is hidden, in which case
  13860. // we don't need to update it.
  13861. if (this.el().offsetParent === null) {
  13862. return;
  13863. }
  13864. var percent = _Slider.prototype.update.call(this);
  13865. this.update_(this.getCurrentTime_(), percent);
  13866. return percent;
  13867. }
  13868. /**
  13869. * Get the value of current time but allows for smooth scrubbing,
  13870. * when player can't keep up.
  13871. *
  13872. * @return {number}
  13873. * The current time value to display
  13874. *
  13875. * @private
  13876. */
  13877. ;
  13878. _proto.getCurrentTime_ = function getCurrentTime_() {
  13879. return this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  13880. }
  13881. /**
  13882. * We want the seek bar to be full on ended
  13883. * no matter what the actual internal values are. so we force it.
  13884. *
  13885. * @param {EventTarget~Event} [event]
  13886. * The `timeupdate` or `ended` event that caused this to run.
  13887. *
  13888. * @listens Player#ended
  13889. */
  13890. ;
  13891. _proto.handleEnded = function handleEnded(event) {
  13892. this.update_(this.player_.duration(), 1);
  13893. }
  13894. /**
  13895. * Get the percentage of media played so far.
  13896. *
  13897. * @return {number}
  13898. * The percentage of media played so far (0 to 1).
  13899. */
  13900. ;
  13901. _proto.getPercent = function getPercent() {
  13902. var currentTime = this.getCurrentTime_();
  13903. var percent;
  13904. var liveTracker = this.player_.liveTracker;
  13905. if (liveTracker && liveTracker.isLive()) {
  13906. percent = (currentTime - liveTracker.seekableStart()) / liveTracker.liveWindow(); // prevent the percent from changing at the live edge
  13907. if (liveTracker.atLiveEdge()) {
  13908. percent = 1;
  13909. }
  13910. } else {
  13911. percent = currentTime / this.player_.duration();
  13912. }
  13913. return percent >= 1 ? 1 : percent || 0;
  13914. }
  13915. /**
  13916. * Handle mouse down on seek bar
  13917. *
  13918. * @param {EventTarget~Event} event
  13919. * The `mousedown` event that caused this to run.
  13920. *
  13921. * @listens mousedown
  13922. */
  13923. ;
  13924. _proto.handleMouseDown = function handleMouseDown(event) {
  13925. if (!isSingleLeftClick(event)) {
  13926. return;
  13927. } // Stop event propagation to prevent double fire in progress-control.js
  13928. event.stopPropagation();
  13929. this.player_.scrubbing(true);
  13930. this.videoWasPlaying = !this.player_.paused();
  13931. this.player_.pause();
  13932. _Slider.prototype.handleMouseDown.call(this, event);
  13933. }
  13934. /**
  13935. * Handle mouse move on seek bar
  13936. *
  13937. * @param {EventTarget~Event} event
  13938. * The `mousemove` event that caused this to run.
  13939. *
  13940. * @listens mousemove
  13941. */
  13942. ;
  13943. _proto.handleMouseMove = function handleMouseMove(event) {
  13944. if (!isSingleLeftClick(event)) {
  13945. return;
  13946. }
  13947. var newTime;
  13948. var distance = this.calculateDistance(event);
  13949. var liveTracker = this.player_.liveTracker;
  13950. if (!liveTracker || !liveTracker.isLive()) {
  13951. newTime = distance * this.player_.duration(); // Don't let video end while scrubbing.
  13952. if (newTime === this.player_.duration()) {
  13953. newTime = newTime - 0.1;
  13954. }
  13955. } else {
  13956. var seekableStart = liveTracker.seekableStart();
  13957. var seekableEnd = liveTracker.liveCurrentTime();
  13958. newTime = seekableStart + distance * liveTracker.liveWindow(); // Don't let video end while scrubbing.
  13959. if (newTime >= seekableEnd) {
  13960. newTime = seekableEnd;
  13961. } // Compensate for precision differences so that currentTime is not less
  13962. // than seekable start
  13963. if (newTime <= seekableStart) {
  13964. newTime = seekableStart + 0.1;
  13965. } // On android seekableEnd can be Infinity sometimes,
  13966. // this will cause newTime to be Infinity, which is
  13967. // not a valid currentTime.
  13968. if (newTime === Infinity) {
  13969. return;
  13970. }
  13971. } // Set new time (tell player to seek to new time)
  13972. this.player_.currentTime(newTime);
  13973. };
  13974. _proto.enable = function enable() {
  13975. _Slider.prototype.enable.call(this);
  13976. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  13977. if (!mouseTimeDisplay) {
  13978. return;
  13979. }
  13980. mouseTimeDisplay.show();
  13981. };
  13982. _proto.disable = function disable() {
  13983. _Slider.prototype.disable.call(this);
  13984. var mouseTimeDisplay = this.getChild('mouseTimeDisplay');
  13985. if (!mouseTimeDisplay) {
  13986. return;
  13987. }
  13988. mouseTimeDisplay.hide();
  13989. }
  13990. /**
  13991. * Handle mouse up on seek bar
  13992. *
  13993. * @param {EventTarget~Event} event
  13994. * The `mouseup` event that caused this to run.
  13995. *
  13996. * @listens mouseup
  13997. */
  13998. ;
  13999. _proto.handleMouseUp = function handleMouseUp(event) {
  14000. _Slider.prototype.handleMouseUp.call(this, event); // Stop event propagation to prevent double fire in progress-control.js
  14001. if (event) {
  14002. event.stopPropagation();
  14003. }
  14004. this.player_.scrubbing(false);
  14005. /**
  14006. * Trigger timeupdate because we're done seeking and the time has changed.
  14007. * This is particularly useful for if the player is paused to time the time displays.
  14008. *
  14009. * @event Tech#timeupdate
  14010. * @type {EventTarget~Event}
  14011. */
  14012. this.player_.trigger({
  14013. type: 'timeupdate',
  14014. target: this,
  14015. manuallyTriggered: true
  14016. });
  14017. if (this.videoWasPlaying) {
  14018. silencePromise(this.player_.play());
  14019. }
  14020. }
  14021. /**
  14022. * Move more quickly fast forward for keyboard-only users
  14023. */
  14024. ;
  14025. _proto.stepForward = function stepForward() {
  14026. this.player_.currentTime(this.player_.currentTime() + STEP_SECONDS);
  14027. }
  14028. /**
  14029. * Move more quickly rewind for keyboard-only users
  14030. */
  14031. ;
  14032. _proto.stepBack = function stepBack() {
  14033. this.player_.currentTime(this.player_.currentTime() - STEP_SECONDS);
  14034. }
  14035. /**
  14036. * Toggles the playback state of the player
  14037. * This gets called when enter or space is used on the seekbar
  14038. *
  14039. * @param {EventTarget~Event} event
  14040. * The `keydown` event that caused this function to be called
  14041. *
  14042. */
  14043. ;
  14044. _proto.handleAction = function handleAction(event) {
  14045. if (this.player_.paused()) {
  14046. this.player_.play();
  14047. } else {
  14048. this.player_.pause();
  14049. }
  14050. }
  14051. /**
  14052. * Called when this SeekBar has focus and a key gets pressed down.
  14053. * Supports the following keys:
  14054. *
  14055. * Space or Enter key fire a click event
  14056. * Home key moves to start of the timeline
  14057. * End key moves to end of the timeline
  14058. * Digit "0" through "9" keys move to 0%, 10% ... 80%, 90% of the timeline
  14059. * PageDown key moves back a larger step than ArrowDown
  14060. * PageUp key moves forward a large step
  14061. *
  14062. * @param {EventTarget~Event} event
  14063. * The `keydown` event that caused this function to be called.
  14064. *
  14065. * @listens keydown
  14066. */
  14067. ;
  14068. _proto.handleKeyDown = function handleKeyDown(event) {
  14069. if (keycode.isEventKey(event, 'Space') || keycode.isEventKey(event, 'Enter')) {
  14070. event.preventDefault();
  14071. event.stopPropagation();
  14072. this.handleAction(event);
  14073. } else if (keycode.isEventKey(event, 'Home')) {
  14074. event.preventDefault();
  14075. event.stopPropagation();
  14076. this.player_.currentTime(0);
  14077. } else if (keycode.isEventKey(event, 'End')) {
  14078. event.preventDefault();
  14079. event.stopPropagation();
  14080. this.player_.currentTime(this.player_.duration());
  14081. } else if (/^[0-9]$/.test(keycode(event))) {
  14082. event.preventDefault();
  14083. event.stopPropagation();
  14084. var gotoFraction = (keycode.codes[keycode(event)] - keycode.codes['0']) * 10.0 / 100.0;
  14085. this.player_.currentTime(this.player_.duration() * gotoFraction);
  14086. } else if (keycode.isEventKey(event, 'PgDn')) {
  14087. event.preventDefault();
  14088. event.stopPropagation();
  14089. this.player_.currentTime(this.player_.currentTime() - STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  14090. } else if (keycode.isEventKey(event, 'PgUp')) {
  14091. event.preventDefault();
  14092. event.stopPropagation();
  14093. this.player_.currentTime(this.player_.currentTime() + STEP_SECONDS * PAGE_KEY_MULTIPLIER);
  14094. } else {
  14095. // Pass keydown handling up for unsupported keys
  14096. _Slider.prototype.handleKeyDown.call(this, event);
  14097. }
  14098. };
  14099. return SeekBar;
  14100. }(Slider);
  14101. /**
  14102. * Default options for the `SeekBar`
  14103. *
  14104. * @type {Object}
  14105. * @private
  14106. */
  14107. SeekBar.prototype.options_ = {
  14108. children: ['loadProgressBar', 'playProgressBar'],
  14109. barName: 'playProgressBar'
  14110. }; // MouseTimeDisplay tooltips should not be added to a player on mobile devices
  14111. if (!IS_IOS && !IS_ANDROID) {
  14112. SeekBar.prototype.options_.children.splice(1, 0, 'mouseTimeDisplay');
  14113. }
  14114. Component.registerComponent('SeekBar', SeekBar);
  14115. /**
  14116. * The Progress Control component contains the seek bar, load progress,
  14117. * and play progress.
  14118. *
  14119. * @extends Component
  14120. */
  14121. var ProgressControl =
  14122. /*#__PURE__*/
  14123. function (_Component) {
  14124. _inheritsLoose(ProgressControl, _Component);
  14125. /**
  14126. * Creates an instance of this class.
  14127. *
  14128. * @param {Player} player
  14129. * The `Player` that this class should be attached to.
  14130. *
  14131. * @param {Object} [options]
  14132. * The key/value store of player options.
  14133. */
  14134. function ProgressControl(player, options) {
  14135. var _this;
  14136. _this = _Component.call(this, player, options) || this;
  14137. _this.handleMouseMove = throttle(bind(_assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  14138. _this.throttledHandleMouseSeek = throttle(bind(_assertThisInitialized(_this), _this.handleMouseSeek), UPDATE_REFRESH_INTERVAL);
  14139. _this.enable();
  14140. return _this;
  14141. }
  14142. /**
  14143. * Create the `Component`'s DOM element
  14144. *
  14145. * @return {Element}
  14146. * The element that was created.
  14147. */
  14148. var _proto = ProgressControl.prototype;
  14149. _proto.createEl = function createEl() {
  14150. return _Component.prototype.createEl.call(this, 'div', {
  14151. className: 'vjs-progress-control vjs-control'
  14152. });
  14153. }
  14154. /**
  14155. * When the mouse moves over the `ProgressControl`, the pointer position
  14156. * gets passed down to the `MouseTimeDisplay` component.
  14157. *
  14158. * @param {EventTarget~Event} event
  14159. * The `mousemove` event that caused this function to run.
  14160. *
  14161. * @listen mousemove
  14162. */
  14163. ;
  14164. _proto.handleMouseMove = function handleMouseMove(event) {
  14165. var seekBar = this.getChild('seekBar');
  14166. if (seekBar) {
  14167. var mouseTimeDisplay = seekBar.getChild('mouseTimeDisplay');
  14168. var seekBarEl = seekBar.el();
  14169. var seekBarRect = getBoundingClientRect(seekBarEl);
  14170. var seekBarPoint = getPointerPosition(seekBarEl, event).x; // The default skin has a gap on either side of the `SeekBar`. This means
  14171. // that it's possible to trigger this behavior outside the boundaries of
  14172. // the `SeekBar`. This ensures we stay within it at all times.
  14173. if (seekBarPoint > 1) {
  14174. seekBarPoint = 1;
  14175. } else if (seekBarPoint < 0) {
  14176. seekBarPoint = 0;
  14177. }
  14178. if (mouseTimeDisplay) {
  14179. mouseTimeDisplay.update(seekBarRect, seekBarPoint);
  14180. }
  14181. }
  14182. }
  14183. /**
  14184. * A throttled version of the {@link ProgressControl#handleMouseSeek} listener.
  14185. *
  14186. * @method ProgressControl#throttledHandleMouseSeek
  14187. * @param {EventTarget~Event} event
  14188. * The `mousemove` event that caused this function to run.
  14189. *
  14190. * @listen mousemove
  14191. * @listen touchmove
  14192. */
  14193. /**
  14194. * Handle `mousemove` or `touchmove` events on the `ProgressControl`.
  14195. *
  14196. * @param {EventTarget~Event} event
  14197. * `mousedown` or `touchstart` event that triggered this function
  14198. *
  14199. * @listens mousemove
  14200. * @listens touchmove
  14201. */
  14202. ;
  14203. _proto.handleMouseSeek = function handleMouseSeek(event) {
  14204. var seekBar = this.getChild('seekBar');
  14205. if (seekBar) {
  14206. seekBar.handleMouseMove(event);
  14207. }
  14208. }
  14209. /**
  14210. * Are controls are currently enabled for this progress control.
  14211. *
  14212. * @return {boolean}
  14213. * true if controls are enabled, false otherwise
  14214. */
  14215. ;
  14216. _proto.enabled = function enabled() {
  14217. return this.enabled_;
  14218. }
  14219. /**
  14220. * Disable all controls on the progress control and its children
  14221. */
  14222. ;
  14223. _proto.disable = function disable() {
  14224. this.children().forEach(function (child) {
  14225. return child.disable && child.disable();
  14226. });
  14227. if (!this.enabled()) {
  14228. return;
  14229. }
  14230. this.off(['mousedown', 'touchstart'], this.handleMouseDown);
  14231. this.off(this.el_, 'mousemove', this.handleMouseMove);
  14232. this.handleMouseUp();
  14233. this.addClass('disabled');
  14234. this.enabled_ = false;
  14235. }
  14236. /**
  14237. * Enable all controls on the progress control and its children
  14238. */
  14239. ;
  14240. _proto.enable = function enable() {
  14241. this.children().forEach(function (child) {
  14242. return child.enable && child.enable();
  14243. });
  14244. if (this.enabled()) {
  14245. return;
  14246. }
  14247. this.on(['mousedown', 'touchstart'], this.handleMouseDown);
  14248. this.on(this.el_, 'mousemove', this.handleMouseMove);
  14249. this.removeClass('disabled');
  14250. this.enabled_ = true;
  14251. }
  14252. /**
  14253. * Handle `mousedown` or `touchstart` events on the `ProgressControl`.
  14254. *
  14255. * @param {EventTarget~Event} event
  14256. * `mousedown` or `touchstart` event that triggered this function
  14257. *
  14258. * @listens mousedown
  14259. * @listens touchstart
  14260. */
  14261. ;
  14262. _proto.handleMouseDown = function handleMouseDown(event) {
  14263. var doc = this.el_.ownerDocument;
  14264. var seekBar = this.getChild('seekBar');
  14265. if (seekBar) {
  14266. seekBar.handleMouseDown(event);
  14267. }
  14268. this.on(doc, 'mousemove', this.throttledHandleMouseSeek);
  14269. this.on(doc, 'touchmove', this.throttledHandleMouseSeek);
  14270. this.on(doc, 'mouseup', this.handleMouseUp);
  14271. this.on(doc, 'touchend', this.handleMouseUp);
  14272. }
  14273. /**
  14274. * Handle `mouseup` or `touchend` events on the `ProgressControl`.
  14275. *
  14276. * @param {EventTarget~Event} event
  14277. * `mouseup` or `touchend` event that triggered this function.
  14278. *
  14279. * @listens touchend
  14280. * @listens mouseup
  14281. */
  14282. ;
  14283. _proto.handleMouseUp = function handleMouseUp(event) {
  14284. var doc = this.el_.ownerDocument;
  14285. var seekBar = this.getChild('seekBar');
  14286. if (seekBar) {
  14287. seekBar.handleMouseUp(event);
  14288. }
  14289. this.off(doc, 'mousemove', this.throttledHandleMouseSeek);
  14290. this.off(doc, 'touchmove', this.throttledHandleMouseSeek);
  14291. this.off(doc, 'mouseup', this.handleMouseUp);
  14292. this.off(doc, 'touchend', this.handleMouseUp);
  14293. };
  14294. return ProgressControl;
  14295. }(Component);
  14296. /**
  14297. * Default options for `ProgressControl`
  14298. *
  14299. * @type {Object}
  14300. * @private
  14301. */
  14302. ProgressControl.prototype.options_ = {
  14303. children: ['seekBar']
  14304. };
  14305. Component.registerComponent('ProgressControl', ProgressControl);
  14306. /**
  14307. * Toggle Picture-in-Picture mode
  14308. *
  14309. * @extends Button
  14310. */
  14311. var PictureInPictureToggle =
  14312. /*#__PURE__*/
  14313. function (_Button) {
  14314. _inheritsLoose(PictureInPictureToggle, _Button);
  14315. /**
  14316. * Creates an instance of this class.
  14317. *
  14318. * @param {Player} player
  14319. * The `Player` that this class should be attached to.
  14320. *
  14321. * @param {Object} [options]
  14322. * The key/value store of player options.
  14323. *
  14324. * @listens Player#enterpictureinpicture
  14325. * @listens Player#leavepictureinpicture
  14326. */
  14327. function PictureInPictureToggle(player, options) {
  14328. var _this;
  14329. _this = _Button.call(this, player, options) || this;
  14330. _this.on(player, ['enterpictureinpicture', 'leavepictureinpicture'], _this.handlePictureInPictureChange); // TODO: Activate button on player loadedmetadata event.
  14331. // TODO: Deactivate button on player emptied event.
  14332. // TODO: Deactivate button if disablepictureinpicture attribute is present.
  14333. if (!document.pictureInPictureEnabled) {
  14334. _this.disable();
  14335. }
  14336. return _this;
  14337. }
  14338. /**
  14339. * Builds the default DOM `className`.
  14340. *
  14341. * @return {string}
  14342. * The DOM `className` for this object.
  14343. */
  14344. var _proto = PictureInPictureToggle.prototype;
  14345. _proto.buildCSSClass = function buildCSSClass() {
  14346. return "vjs-picture-in-picture-control " + _Button.prototype.buildCSSClass.call(this);
  14347. }
  14348. /**
  14349. * Handles enterpictureinpicture and leavepictureinpicture on the player and change control text accordingly.
  14350. *
  14351. * @param {EventTarget~Event} [event]
  14352. * The {@link Player#enterpictureinpicture} or {@link Player#leavepictureinpicture} event that caused this function to be
  14353. * called.
  14354. *
  14355. * @listens Player#enterpictureinpicture
  14356. * @listens Player#leavepictureinpicture
  14357. */
  14358. ;
  14359. _proto.handlePictureInPictureChange = function handlePictureInPictureChange(event) {
  14360. if (this.player_.isInPictureInPicture()) {
  14361. this.controlText('Exit Picture-in-Picture');
  14362. } else {
  14363. this.controlText('Picture-in-Picture');
  14364. }
  14365. }
  14366. /**
  14367. * This gets called when an `PictureInPictureToggle` is "clicked". See
  14368. * {@link ClickableComponent} for more detailed information on what a click can be.
  14369. *
  14370. * @param {EventTarget~Event} [event]
  14371. * The `keydown`, `tap`, or `click` event that caused this function to be
  14372. * called.
  14373. *
  14374. * @listens tap
  14375. * @listens click
  14376. */
  14377. ;
  14378. _proto.handleClick = function handleClick(event) {
  14379. if (!this.player_.isInPictureInPicture()) {
  14380. this.player_.requestPictureInPicture();
  14381. } else {
  14382. this.player_.exitPictureInPicture();
  14383. }
  14384. };
  14385. return PictureInPictureToggle;
  14386. }(Button);
  14387. /**
  14388. * The text that should display over the `PictureInPictureToggle`s controls. Added for localization.
  14389. *
  14390. * @type {string}
  14391. * @private
  14392. */
  14393. PictureInPictureToggle.prototype.controlText_ = 'Picture-in-Picture';
  14394. Component.registerComponent('PictureInPictureToggle', PictureInPictureToggle);
  14395. /**
  14396. * Toggle fullscreen video
  14397. *
  14398. * @extends Button
  14399. */
  14400. var FullscreenToggle =
  14401. /*#__PURE__*/
  14402. function (_Button) {
  14403. _inheritsLoose(FullscreenToggle, _Button);
  14404. /**
  14405. * Creates an instance of this class.
  14406. *
  14407. * @param {Player} player
  14408. * The `Player` that this class should be attached to.
  14409. *
  14410. * @param {Object} [options]
  14411. * The key/value store of player options.
  14412. */
  14413. function FullscreenToggle(player, options) {
  14414. var _this;
  14415. _this = _Button.call(this, player, options) || this;
  14416. _this.on(player, 'fullscreenchange', _this.handleFullscreenChange);
  14417. if (document[player.fsApi_.fullscreenEnabled] === false) {
  14418. _this.disable();
  14419. }
  14420. return _this;
  14421. }
  14422. /**
  14423. * Builds the default DOM `className`.
  14424. *
  14425. * @return {string}
  14426. * The DOM `className` for this object.
  14427. */
  14428. var _proto = FullscreenToggle.prototype;
  14429. _proto.buildCSSClass = function buildCSSClass() {
  14430. return "vjs-fullscreen-control " + _Button.prototype.buildCSSClass.call(this);
  14431. }
  14432. /**
  14433. * Handles fullscreenchange on the player and change control text accordingly.
  14434. *
  14435. * @param {EventTarget~Event} [event]
  14436. * The {@link Player#fullscreenchange} event that caused this function to be
  14437. * called.
  14438. *
  14439. * @listens Player#fullscreenchange
  14440. */
  14441. ;
  14442. _proto.handleFullscreenChange = function handleFullscreenChange(event) {
  14443. if (this.player_.isFullscreen()) {
  14444. this.controlText('Non-Fullscreen');
  14445. } else {
  14446. this.controlText('Fullscreen');
  14447. }
  14448. }
  14449. /**
  14450. * This gets called when an `FullscreenToggle` is "clicked". See
  14451. * {@link ClickableComponent} for more detailed information on what a click can be.
  14452. *
  14453. * @param {EventTarget~Event} [event]
  14454. * The `keydown`, `tap`, or `click` event that caused this function to be
  14455. * called.
  14456. *
  14457. * @listens tap
  14458. * @listens click
  14459. */
  14460. ;
  14461. _proto.handleClick = function handleClick(event) {
  14462. if (!this.player_.isFullscreen()) {
  14463. this.player_.requestFullscreen();
  14464. } else {
  14465. this.player_.exitFullscreen();
  14466. }
  14467. };
  14468. return FullscreenToggle;
  14469. }(Button);
  14470. /**
  14471. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  14472. *
  14473. * @type {string}
  14474. * @private
  14475. */
  14476. FullscreenToggle.prototype.controlText_ = 'Fullscreen';
  14477. Component.registerComponent('FullscreenToggle', FullscreenToggle);
  14478. /**
  14479. * Check if volume control is supported and if it isn't hide the
  14480. * `Component` that was passed using the `vjs-hidden` class.
  14481. *
  14482. * @param {Component} self
  14483. * The component that should be hidden if volume is unsupported
  14484. *
  14485. * @param {Player} player
  14486. * A reference to the player
  14487. *
  14488. * @private
  14489. */
  14490. var checkVolumeSupport = function checkVolumeSupport(self, player) {
  14491. // hide volume controls when they're not supported by the current tech
  14492. if (player.tech_ && !player.tech_.featuresVolumeControl) {
  14493. self.addClass('vjs-hidden');
  14494. }
  14495. self.on(player, 'loadstart', function () {
  14496. if (!player.tech_.featuresVolumeControl) {
  14497. self.addClass('vjs-hidden');
  14498. } else {
  14499. self.removeClass('vjs-hidden');
  14500. }
  14501. });
  14502. };
  14503. /**
  14504. * Shows volume level
  14505. *
  14506. * @extends Component
  14507. */
  14508. var VolumeLevel =
  14509. /*#__PURE__*/
  14510. function (_Component) {
  14511. _inheritsLoose(VolumeLevel, _Component);
  14512. function VolumeLevel() {
  14513. return _Component.apply(this, arguments) || this;
  14514. }
  14515. var _proto = VolumeLevel.prototype;
  14516. /**
  14517. * Create the `Component`'s DOM element
  14518. *
  14519. * @return {Element}
  14520. * The element that was created.
  14521. */
  14522. _proto.createEl = function createEl() {
  14523. return _Component.prototype.createEl.call(this, 'div', {
  14524. className: 'vjs-volume-level',
  14525. innerHTML: '<span class="vjs-control-text"></span>'
  14526. });
  14527. };
  14528. return VolumeLevel;
  14529. }(Component);
  14530. Component.registerComponent('VolumeLevel', VolumeLevel);
  14531. /**
  14532. * The bar that contains the volume level and can be clicked on to adjust the level
  14533. *
  14534. * @extends Slider
  14535. */
  14536. var VolumeBar =
  14537. /*#__PURE__*/
  14538. function (_Slider) {
  14539. _inheritsLoose(VolumeBar, _Slider);
  14540. /**
  14541. * Creates an instance of this class.
  14542. *
  14543. * @param {Player} player
  14544. * The `Player` that this class should be attached to.
  14545. *
  14546. * @param {Object} [options]
  14547. * The key/value store of player options.
  14548. */
  14549. function VolumeBar(player, options) {
  14550. var _this;
  14551. _this = _Slider.call(this, player, options) || this;
  14552. _this.on('slideractive', _this.updateLastVolume_);
  14553. _this.on(player, 'volumechange', _this.updateARIAAttributes);
  14554. player.ready(function () {
  14555. return _this.updateARIAAttributes();
  14556. });
  14557. return _this;
  14558. }
  14559. /**
  14560. * Create the `Component`'s DOM element
  14561. *
  14562. * @return {Element}
  14563. * The element that was created.
  14564. */
  14565. var _proto = VolumeBar.prototype;
  14566. _proto.createEl = function createEl() {
  14567. return _Slider.prototype.createEl.call(this, 'div', {
  14568. className: 'vjs-volume-bar vjs-slider-bar'
  14569. }, {
  14570. 'aria-label': this.localize('Volume Level'),
  14571. 'aria-live': 'polite'
  14572. });
  14573. }
  14574. /**
  14575. * Handle mouse down on volume bar
  14576. *
  14577. * @param {EventTarget~Event} event
  14578. * The `mousedown` event that caused this to run.
  14579. *
  14580. * @listens mousedown
  14581. */
  14582. ;
  14583. _proto.handleMouseDown = function handleMouseDown(event) {
  14584. if (!isSingleLeftClick(event)) {
  14585. return;
  14586. }
  14587. _Slider.prototype.handleMouseDown.call(this, event);
  14588. }
  14589. /**
  14590. * Handle movement events on the {@link VolumeMenuButton}.
  14591. *
  14592. * @param {EventTarget~Event} event
  14593. * The event that caused this function to run.
  14594. *
  14595. * @listens mousemove
  14596. */
  14597. ;
  14598. _proto.handleMouseMove = function handleMouseMove(event) {
  14599. if (!isSingleLeftClick(event)) {
  14600. return;
  14601. }
  14602. this.checkMuted();
  14603. this.player_.volume(this.calculateDistance(event));
  14604. }
  14605. /**
  14606. * If the player is muted unmute it.
  14607. */
  14608. ;
  14609. _proto.checkMuted = function checkMuted() {
  14610. if (this.player_.muted()) {
  14611. this.player_.muted(false);
  14612. }
  14613. }
  14614. /**
  14615. * Get percent of volume level
  14616. *
  14617. * @return {number}
  14618. * Volume level percent as a decimal number.
  14619. */
  14620. ;
  14621. _proto.getPercent = function getPercent() {
  14622. if (this.player_.muted()) {
  14623. return 0;
  14624. }
  14625. return this.player_.volume();
  14626. }
  14627. /**
  14628. * Increase volume level for keyboard users
  14629. */
  14630. ;
  14631. _proto.stepForward = function stepForward() {
  14632. this.checkMuted();
  14633. this.player_.volume(this.player_.volume() + 0.1);
  14634. }
  14635. /**
  14636. * Decrease volume level for keyboard users
  14637. */
  14638. ;
  14639. _proto.stepBack = function stepBack() {
  14640. this.checkMuted();
  14641. this.player_.volume(this.player_.volume() - 0.1);
  14642. }
  14643. /**
  14644. * Update ARIA accessibility attributes
  14645. *
  14646. * @param {EventTarget~Event} [event]
  14647. * The `volumechange` event that caused this function to run.
  14648. *
  14649. * @listens Player#volumechange
  14650. */
  14651. ;
  14652. _proto.updateARIAAttributes = function updateARIAAttributes(event) {
  14653. var ariaValue = this.player_.muted() ? 0 : this.volumeAsPercentage_();
  14654. this.el_.setAttribute('aria-valuenow', ariaValue);
  14655. this.el_.setAttribute('aria-valuetext', ariaValue + '%');
  14656. }
  14657. /**
  14658. * Returns the current value of the player volume as a percentage
  14659. *
  14660. * @private
  14661. */
  14662. ;
  14663. _proto.volumeAsPercentage_ = function volumeAsPercentage_() {
  14664. return Math.round(this.player_.volume() * 100);
  14665. }
  14666. /**
  14667. * When user starts dragging the VolumeBar, store the volume and listen for
  14668. * the end of the drag. When the drag ends, if the volume was set to zero,
  14669. * set lastVolume to the stored volume.
  14670. *
  14671. * @listens slideractive
  14672. * @private
  14673. */
  14674. ;
  14675. _proto.updateLastVolume_ = function updateLastVolume_() {
  14676. var _this2 = this;
  14677. var volumeBeforeDrag = this.player_.volume();
  14678. this.one('sliderinactive', function () {
  14679. if (_this2.player_.volume() === 0) {
  14680. _this2.player_.lastVolume_(volumeBeforeDrag);
  14681. }
  14682. });
  14683. };
  14684. return VolumeBar;
  14685. }(Slider);
  14686. /**
  14687. * Default options for the `VolumeBar`
  14688. *
  14689. * @type {Object}
  14690. * @private
  14691. */
  14692. VolumeBar.prototype.options_ = {
  14693. children: ['volumeLevel'],
  14694. barName: 'volumeLevel'
  14695. };
  14696. /**
  14697. * Call the update event for this Slider when this event happens on the player.
  14698. *
  14699. * @type {string}
  14700. */
  14701. VolumeBar.prototype.playerEvent = 'volumechange';
  14702. Component.registerComponent('VolumeBar', VolumeBar);
  14703. /**
  14704. * The component for controlling the volume level
  14705. *
  14706. * @extends Component
  14707. */
  14708. var VolumeControl =
  14709. /*#__PURE__*/
  14710. function (_Component) {
  14711. _inheritsLoose(VolumeControl, _Component);
  14712. /**
  14713. * Creates an instance of this class.
  14714. *
  14715. * @param {Player} player
  14716. * The `Player` that this class should be attached to.
  14717. *
  14718. * @param {Object} [options={}]
  14719. * The key/value store of player options.
  14720. */
  14721. function VolumeControl(player, options) {
  14722. var _this;
  14723. if (options === void 0) {
  14724. options = {};
  14725. }
  14726. options.vertical = options.vertical || false; // Pass the vertical option down to the VolumeBar if
  14727. // the VolumeBar is turned on.
  14728. if (typeof options.volumeBar === 'undefined' || isPlain(options.volumeBar)) {
  14729. options.volumeBar = options.volumeBar || {};
  14730. options.volumeBar.vertical = options.vertical;
  14731. }
  14732. _this = _Component.call(this, player, options) || this; // hide this control if volume support is missing
  14733. checkVolumeSupport(_assertThisInitialized(_this), player);
  14734. _this.throttledHandleMouseMove = throttle(bind(_assertThisInitialized(_this), _this.handleMouseMove), UPDATE_REFRESH_INTERVAL);
  14735. _this.on('mousedown', _this.handleMouseDown);
  14736. _this.on('touchstart', _this.handleMouseDown); // while the slider is active (the mouse has been pressed down and
  14737. // is dragging) or in focus we do not want to hide the VolumeBar
  14738. _this.on(_this.volumeBar, ['focus', 'slideractive'], function () {
  14739. _this.volumeBar.addClass('vjs-slider-active');
  14740. _this.addClass('vjs-slider-active');
  14741. _this.trigger('slideractive');
  14742. });
  14743. _this.on(_this.volumeBar, ['blur', 'sliderinactive'], function () {
  14744. _this.volumeBar.removeClass('vjs-slider-active');
  14745. _this.removeClass('vjs-slider-active');
  14746. _this.trigger('sliderinactive');
  14747. });
  14748. return _this;
  14749. }
  14750. /**
  14751. * Create the `Component`'s DOM element
  14752. *
  14753. * @return {Element}
  14754. * The element that was created.
  14755. */
  14756. var _proto = VolumeControl.prototype;
  14757. _proto.createEl = function createEl() {
  14758. var orientationClass = 'vjs-volume-horizontal';
  14759. if (this.options_.vertical) {
  14760. orientationClass = 'vjs-volume-vertical';
  14761. }
  14762. return _Component.prototype.createEl.call(this, 'div', {
  14763. className: "vjs-volume-control vjs-control " + orientationClass
  14764. });
  14765. }
  14766. /**
  14767. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  14768. *
  14769. * @param {EventTarget~Event} event
  14770. * `mousedown` or `touchstart` event that triggered this function
  14771. *
  14772. * @listens mousedown
  14773. * @listens touchstart
  14774. */
  14775. ;
  14776. _proto.handleMouseDown = function handleMouseDown(event) {
  14777. var doc = this.el_.ownerDocument;
  14778. this.on(doc, 'mousemove', this.throttledHandleMouseMove);
  14779. this.on(doc, 'touchmove', this.throttledHandleMouseMove);
  14780. this.on(doc, 'mouseup', this.handleMouseUp);
  14781. this.on(doc, 'touchend', this.handleMouseUp);
  14782. }
  14783. /**
  14784. * Handle `mouseup` or `touchend` events on the `VolumeControl`.
  14785. *
  14786. * @param {EventTarget~Event} event
  14787. * `mouseup` or `touchend` event that triggered this function.
  14788. *
  14789. * @listens touchend
  14790. * @listens mouseup
  14791. */
  14792. ;
  14793. _proto.handleMouseUp = function handleMouseUp(event) {
  14794. var doc = this.el_.ownerDocument;
  14795. this.off(doc, 'mousemove', this.throttledHandleMouseMove);
  14796. this.off(doc, 'touchmove', this.throttledHandleMouseMove);
  14797. this.off(doc, 'mouseup', this.handleMouseUp);
  14798. this.off(doc, 'touchend', this.handleMouseUp);
  14799. }
  14800. /**
  14801. * Handle `mousedown` or `touchstart` events on the `VolumeControl`.
  14802. *
  14803. * @param {EventTarget~Event} event
  14804. * `mousedown` or `touchstart` event that triggered this function
  14805. *
  14806. * @listens mousedown
  14807. * @listens touchstart
  14808. */
  14809. ;
  14810. _proto.handleMouseMove = function handleMouseMove(event) {
  14811. this.volumeBar.handleMouseMove(event);
  14812. };
  14813. return VolumeControl;
  14814. }(Component);
  14815. /**
  14816. * Default options for the `VolumeControl`
  14817. *
  14818. * @type {Object}
  14819. * @private
  14820. */
  14821. VolumeControl.prototype.options_ = {
  14822. children: ['volumeBar']
  14823. };
  14824. Component.registerComponent('VolumeControl', VolumeControl);
  14825. /**
  14826. * Check if muting volume is supported and if it isn't hide the mute toggle
  14827. * button.
  14828. *
  14829. * @param {Component} self
  14830. * A reference to the mute toggle button
  14831. *
  14832. * @param {Player} player
  14833. * A reference to the player
  14834. *
  14835. * @private
  14836. */
  14837. var checkMuteSupport = function checkMuteSupport(self, player) {
  14838. // hide mute toggle button if it's not supported by the current tech
  14839. if (player.tech_ && !player.tech_.featuresMuteControl) {
  14840. self.addClass('vjs-hidden');
  14841. }
  14842. self.on(player, 'loadstart', function () {
  14843. if (!player.tech_.featuresMuteControl) {
  14844. self.addClass('vjs-hidden');
  14845. } else {
  14846. self.removeClass('vjs-hidden');
  14847. }
  14848. });
  14849. };
  14850. /**
  14851. * A button component for muting the audio.
  14852. *
  14853. * @extends Button
  14854. */
  14855. var MuteToggle =
  14856. /*#__PURE__*/
  14857. function (_Button) {
  14858. _inheritsLoose(MuteToggle, _Button);
  14859. /**
  14860. * Creates an instance of this class.
  14861. *
  14862. * @param {Player} player
  14863. * The `Player` that this class should be attached to.
  14864. *
  14865. * @param {Object} [options]
  14866. * The key/value store of player options.
  14867. */
  14868. function MuteToggle(player, options) {
  14869. var _this;
  14870. _this = _Button.call(this, player, options) || this; // hide this control if volume support is missing
  14871. checkMuteSupport(_assertThisInitialized(_this), player);
  14872. _this.on(player, ['loadstart', 'volumechange'], _this.update);
  14873. return _this;
  14874. }
  14875. /**
  14876. * Builds the default DOM `className`.
  14877. *
  14878. * @return {string}
  14879. * The DOM `className` for this object.
  14880. */
  14881. var _proto = MuteToggle.prototype;
  14882. _proto.buildCSSClass = function buildCSSClass() {
  14883. return "vjs-mute-control " + _Button.prototype.buildCSSClass.call(this);
  14884. }
  14885. /**
  14886. * This gets called when an `MuteToggle` is "clicked". See
  14887. * {@link ClickableComponent} for more detailed information on what a click can be.
  14888. *
  14889. * @param {EventTarget~Event} [event]
  14890. * The `keydown`, `tap`, or `click` event that caused this function to be
  14891. * called.
  14892. *
  14893. * @listens tap
  14894. * @listens click
  14895. */
  14896. ;
  14897. _proto.handleClick = function handleClick(event) {
  14898. var vol = this.player_.volume();
  14899. var lastVolume = this.player_.lastVolume_();
  14900. if (vol === 0) {
  14901. var volumeToSet = lastVolume < 0.1 ? 0.1 : lastVolume;
  14902. this.player_.volume(volumeToSet);
  14903. this.player_.muted(false);
  14904. } else {
  14905. this.player_.muted(this.player_.muted() ? false : true);
  14906. }
  14907. }
  14908. /**
  14909. * Update the `MuteToggle` button based on the state of `volume` and `muted`
  14910. * on the player.
  14911. *
  14912. * @param {EventTarget~Event} [event]
  14913. * The {@link Player#loadstart} event if this function was called
  14914. * through an event.
  14915. *
  14916. * @listens Player#loadstart
  14917. * @listens Player#volumechange
  14918. */
  14919. ;
  14920. _proto.update = function update(event) {
  14921. this.updateIcon_();
  14922. this.updateControlText_();
  14923. }
  14924. /**
  14925. * Update the appearance of the `MuteToggle` icon.
  14926. *
  14927. * Possible states (given `level` variable below):
  14928. * - 0: crossed out
  14929. * - 1: zero bars of volume
  14930. * - 2: one bar of volume
  14931. * - 3: two bars of volume
  14932. *
  14933. * @private
  14934. */
  14935. ;
  14936. _proto.updateIcon_ = function updateIcon_() {
  14937. var vol = this.player_.volume();
  14938. var level = 3; // in iOS when a player is loaded with muted attribute
  14939. // and volume is changed with a native mute button
  14940. // we want to make sure muted state is updated
  14941. if (IS_IOS && this.player_.tech_ && this.player_.tech_.el_) {
  14942. this.player_.muted(this.player_.tech_.el_.muted);
  14943. }
  14944. if (vol === 0 || this.player_.muted()) {
  14945. level = 0;
  14946. } else if (vol < 0.33) {
  14947. level = 1;
  14948. } else if (vol < 0.67) {
  14949. level = 2;
  14950. } // TODO improve muted icon classes
  14951. for (var i = 0; i < 4; i++) {
  14952. removeClass(this.el_, "vjs-vol-" + i);
  14953. }
  14954. addClass(this.el_, "vjs-vol-" + level);
  14955. }
  14956. /**
  14957. * If `muted` has changed on the player, update the control text
  14958. * (`title` attribute on `vjs-mute-control` element and content of
  14959. * `vjs-control-text` element).
  14960. *
  14961. * @private
  14962. */
  14963. ;
  14964. _proto.updateControlText_ = function updateControlText_() {
  14965. var soundOff = this.player_.muted() || this.player_.volume() === 0;
  14966. var text = soundOff ? 'Unmute' : 'Mute';
  14967. if (this.controlText() !== text) {
  14968. this.controlText(text);
  14969. }
  14970. };
  14971. return MuteToggle;
  14972. }(Button);
  14973. /**
  14974. * The text that should display over the `MuteToggle`s controls. Added for localization.
  14975. *
  14976. * @type {string}
  14977. * @private
  14978. */
  14979. MuteToggle.prototype.controlText_ = 'Mute';
  14980. Component.registerComponent('MuteToggle', MuteToggle);
  14981. /**
  14982. * A Component to contain the MuteToggle and VolumeControl so that
  14983. * they can work together.
  14984. *
  14985. * @extends Component
  14986. */
  14987. var VolumePanel =
  14988. /*#__PURE__*/
  14989. function (_Component) {
  14990. _inheritsLoose(VolumePanel, _Component);
  14991. /**
  14992. * Creates an instance of this class.
  14993. *
  14994. * @param {Player} player
  14995. * The `Player` that this class should be attached to.
  14996. *
  14997. * @param {Object} [options={}]
  14998. * The key/value store of player options.
  14999. */
  15000. function VolumePanel(player, options) {
  15001. var _this;
  15002. if (options === void 0) {
  15003. options = {};
  15004. }
  15005. if (typeof options.inline !== 'undefined') {
  15006. options.inline = options.inline;
  15007. } else {
  15008. options.inline = true;
  15009. } // pass the inline option down to the VolumeControl as vertical if
  15010. // the VolumeControl is on.
  15011. if (typeof options.volumeControl === 'undefined' || isPlain(options.volumeControl)) {
  15012. options.volumeControl = options.volumeControl || {};
  15013. options.volumeControl.vertical = !options.inline;
  15014. }
  15015. _this = _Component.call(this, player, options) || this;
  15016. _this.on(player, ['loadstart'], _this.volumePanelState_);
  15017. _this.on(_this.muteToggle, 'keyup', _this.handleKeyPress);
  15018. _this.on(_this.volumeControl, 'keyup', _this.handleVolumeControlKeyUp);
  15019. _this.on('keydown', _this.handleKeyPress);
  15020. _this.on('mouseover', _this.handleMouseOver);
  15021. _this.on('mouseout', _this.handleMouseOut); // while the slider is active (the mouse has been pressed down and
  15022. // is dragging) we do not want to hide the VolumeBar
  15023. _this.on(_this.volumeControl, ['slideractive'], _this.sliderActive_);
  15024. _this.on(_this.volumeControl, ['sliderinactive'], _this.sliderInactive_);
  15025. return _this;
  15026. }
  15027. /**
  15028. * Add vjs-slider-active class to the VolumePanel
  15029. *
  15030. * @listens VolumeControl#slideractive
  15031. * @private
  15032. */
  15033. var _proto = VolumePanel.prototype;
  15034. _proto.sliderActive_ = function sliderActive_() {
  15035. this.addClass('vjs-slider-active');
  15036. }
  15037. /**
  15038. * Removes vjs-slider-active class to the VolumePanel
  15039. *
  15040. * @listens VolumeControl#sliderinactive
  15041. * @private
  15042. */
  15043. ;
  15044. _proto.sliderInactive_ = function sliderInactive_() {
  15045. this.removeClass('vjs-slider-active');
  15046. }
  15047. /**
  15048. * Adds vjs-hidden or vjs-mute-toggle-only to the VolumePanel
  15049. * depending on MuteToggle and VolumeControl state
  15050. *
  15051. * @listens Player#loadstart
  15052. * @private
  15053. */
  15054. ;
  15055. _proto.volumePanelState_ = function volumePanelState_() {
  15056. // hide volume panel if neither volume control or mute toggle
  15057. // are displayed
  15058. if (this.volumeControl.hasClass('vjs-hidden') && this.muteToggle.hasClass('vjs-hidden')) {
  15059. this.addClass('vjs-hidden');
  15060. } // if only mute toggle is visible we don't want
  15061. // volume panel expanding when hovered or active
  15062. if (this.volumeControl.hasClass('vjs-hidden') && !this.muteToggle.hasClass('vjs-hidden')) {
  15063. this.addClass('vjs-mute-toggle-only');
  15064. }
  15065. }
  15066. /**
  15067. * Create the `Component`'s DOM element
  15068. *
  15069. * @return {Element}
  15070. * The element that was created.
  15071. */
  15072. ;
  15073. _proto.createEl = function createEl() {
  15074. var orientationClass = 'vjs-volume-panel-horizontal';
  15075. if (!this.options_.inline) {
  15076. orientationClass = 'vjs-volume-panel-vertical';
  15077. }
  15078. return _Component.prototype.createEl.call(this, 'div', {
  15079. className: "vjs-volume-panel vjs-control " + orientationClass
  15080. });
  15081. }
  15082. /**
  15083. * Dispose of the `volume-panel` and all child components.
  15084. */
  15085. ;
  15086. _proto.dispose = function dispose() {
  15087. this.handleMouseOut();
  15088. _Component.prototype.dispose.call(this);
  15089. }
  15090. /**
  15091. * Handles `keyup` events on the `VolumeControl`, looking for ESC, which closes
  15092. * the volume panel and sets focus on `MuteToggle`.
  15093. *
  15094. * @param {EventTarget~Event} event
  15095. * The `keyup` event that caused this function to be called.
  15096. *
  15097. * @listens keyup
  15098. */
  15099. ;
  15100. _proto.handleVolumeControlKeyUp = function handleVolumeControlKeyUp(event) {
  15101. if (keycode.isEventKey(event, 'Esc')) {
  15102. this.muteToggle.focus();
  15103. }
  15104. }
  15105. /**
  15106. * This gets called when a `VolumePanel` gains hover via a `mouseover` event.
  15107. * Turns on listening for `mouseover` event. When they happen it
  15108. * calls `this.handleMouseOver`.
  15109. *
  15110. * @param {EventTarget~Event} event
  15111. * The `mouseover` event that caused this function to be called.
  15112. *
  15113. * @listens mouseover
  15114. */
  15115. ;
  15116. _proto.handleMouseOver = function handleMouseOver(event) {
  15117. this.addClass('vjs-hover');
  15118. on(document, 'keyup', bind(this, this.handleKeyPress));
  15119. }
  15120. /**
  15121. * This gets called when a `VolumePanel` gains hover via a `mouseout` event.
  15122. * Turns on listening for `mouseout` event. When they happen it
  15123. * calls `this.handleMouseOut`.
  15124. *
  15125. * @param {EventTarget~Event} event
  15126. * The `mouseout` event that caused this function to be called.
  15127. *
  15128. * @listens mouseout
  15129. */
  15130. ;
  15131. _proto.handleMouseOut = function handleMouseOut(event) {
  15132. this.removeClass('vjs-hover');
  15133. off(document, 'keyup', bind(this, this.handleKeyPress));
  15134. }
  15135. /**
  15136. * Handles `keyup` event on the document or `keydown` event on the `VolumePanel`,
  15137. * looking for ESC, which hides the `VolumeControl`.
  15138. *
  15139. * @param {EventTarget~Event} event
  15140. * The keypress that triggered this event.
  15141. *
  15142. * @listens keydown | keyup
  15143. */
  15144. ;
  15145. _proto.handleKeyPress = function handleKeyPress(event) {
  15146. if (keycode.isEventKey(event, 'Esc')) {
  15147. this.handleMouseOut();
  15148. }
  15149. };
  15150. return VolumePanel;
  15151. }(Component);
  15152. /**
  15153. * Default options for the `VolumeControl`
  15154. *
  15155. * @type {Object}
  15156. * @private
  15157. */
  15158. VolumePanel.prototype.options_ = {
  15159. children: ['muteToggle', 'volumeControl']
  15160. };
  15161. Component.registerComponent('VolumePanel', VolumePanel);
  15162. /**
  15163. * The Menu component is used to build popup menus, including subtitle and
  15164. * captions selection menus.
  15165. *
  15166. * @extends Component
  15167. */
  15168. var Menu =
  15169. /*#__PURE__*/
  15170. function (_Component) {
  15171. _inheritsLoose(Menu, _Component);
  15172. /**
  15173. * Create an instance of this class.
  15174. *
  15175. * @param {Player} player
  15176. * the player that this component should attach to
  15177. *
  15178. * @param {Object} [options]
  15179. * Object of option names and values
  15180. *
  15181. */
  15182. function Menu(player, options) {
  15183. var _this;
  15184. _this = _Component.call(this, player, options) || this;
  15185. if (options) {
  15186. _this.menuButton_ = options.menuButton;
  15187. }
  15188. _this.focusedChild_ = -1;
  15189. _this.on('keydown', _this.handleKeyDown); // All the menu item instances share the same blur handler provided by the menu container.
  15190. _this.boundHandleBlur_ = bind(_assertThisInitialized(_this), _this.handleBlur);
  15191. _this.boundHandleTapClick_ = bind(_assertThisInitialized(_this), _this.handleTapClick);
  15192. return _this;
  15193. }
  15194. /**
  15195. * Add event listeners to the {@link MenuItem}.
  15196. *
  15197. * @param {Object} component
  15198. * The instance of the `MenuItem` to add listeners to.
  15199. *
  15200. */
  15201. var _proto = Menu.prototype;
  15202. _proto.addEventListenerForItem = function addEventListenerForItem(component) {
  15203. if (!(component instanceof Component)) {
  15204. return;
  15205. }
  15206. this.on(component, 'blur', this.boundHandleBlur_);
  15207. this.on(component, ['tap', 'click'], this.boundHandleTapClick_);
  15208. }
  15209. /**
  15210. * Remove event listeners from the {@link MenuItem}.
  15211. *
  15212. * @param {Object} component
  15213. * The instance of the `MenuItem` to remove listeners.
  15214. *
  15215. */
  15216. ;
  15217. _proto.removeEventListenerForItem = function removeEventListenerForItem(component) {
  15218. if (!(component instanceof Component)) {
  15219. return;
  15220. }
  15221. this.off(component, 'blur', this.boundHandleBlur_);
  15222. this.off(component, ['tap', 'click'], this.boundHandleTapClick_);
  15223. }
  15224. /**
  15225. * This method will be called indirectly when the component has been added
  15226. * before the component adds to the new menu instance by `addItem`.
  15227. * In this case, the original menu instance will remove the component
  15228. * by calling `removeChild`.
  15229. *
  15230. * @param {Object} component
  15231. * The instance of the `MenuItem`
  15232. */
  15233. ;
  15234. _proto.removeChild = function removeChild(component) {
  15235. if (typeof component === 'string') {
  15236. component = this.getChild(component);
  15237. }
  15238. this.removeEventListenerForItem(component);
  15239. _Component.prototype.removeChild.call(this, component);
  15240. }
  15241. /**
  15242. * Add a {@link MenuItem} to the menu.
  15243. *
  15244. * @param {Object|string} component
  15245. * The name or instance of the `MenuItem` to add.
  15246. *
  15247. */
  15248. ;
  15249. _proto.addItem = function addItem(component) {
  15250. var childComponent = this.addChild(component);
  15251. if (childComponent) {
  15252. this.addEventListenerForItem(childComponent);
  15253. }
  15254. }
  15255. /**
  15256. * Create the `Menu`s DOM element.
  15257. *
  15258. * @return {Element}
  15259. * the element that was created
  15260. */
  15261. ;
  15262. _proto.createEl = function createEl$1() {
  15263. var contentElType = this.options_.contentElType || 'ul';
  15264. this.contentEl_ = createEl(contentElType, {
  15265. className: 'vjs-menu-content'
  15266. });
  15267. this.contentEl_.setAttribute('role', 'menu');
  15268. var el = _Component.prototype.createEl.call(this, 'div', {
  15269. append: this.contentEl_,
  15270. className: 'vjs-menu'
  15271. });
  15272. el.appendChild(this.contentEl_); // Prevent clicks from bubbling up. Needed for Menu Buttons,
  15273. // where a click on the parent is significant
  15274. on(el, 'click', function (event) {
  15275. event.preventDefault();
  15276. event.stopImmediatePropagation();
  15277. });
  15278. return el;
  15279. };
  15280. _proto.dispose = function dispose() {
  15281. this.contentEl_ = null;
  15282. this.boundHandleBlur_ = null;
  15283. this.boundHandleTapClick_ = null;
  15284. _Component.prototype.dispose.call(this);
  15285. }
  15286. /**
  15287. * Called when a `MenuItem` loses focus.
  15288. *
  15289. * @param {EventTarget~Event} event
  15290. * The `blur` event that caused this function to be called.
  15291. *
  15292. * @listens blur
  15293. */
  15294. ;
  15295. _proto.handleBlur = function handleBlur(event) {
  15296. var relatedTarget = event.relatedTarget || document.activeElement; // Close menu popup when a user clicks outside the menu
  15297. if (!this.children().some(function (element) {
  15298. return element.el() === relatedTarget;
  15299. })) {
  15300. var btn = this.menuButton_;
  15301. if (btn && btn.buttonPressed_ && relatedTarget !== btn.el().firstChild) {
  15302. btn.unpressButton();
  15303. }
  15304. }
  15305. }
  15306. /**
  15307. * Called when a `MenuItem` gets clicked or tapped.
  15308. *
  15309. * @param {EventTarget~Event} event
  15310. * The `click` or `tap` event that caused this function to be called.
  15311. *
  15312. * @listens click,tap
  15313. */
  15314. ;
  15315. _proto.handleTapClick = function handleTapClick(event) {
  15316. // Unpress the associated MenuButton, and move focus back to it
  15317. if (this.menuButton_) {
  15318. this.menuButton_.unpressButton();
  15319. var childComponents = this.children();
  15320. if (!Array.isArray(childComponents)) {
  15321. return;
  15322. }
  15323. var foundComponent = childComponents.filter(function (component) {
  15324. return component.el() === event.target;
  15325. })[0];
  15326. if (!foundComponent) {
  15327. return;
  15328. } // don't focus menu button if item is a caption settings item
  15329. // because focus will move elsewhere
  15330. if (foundComponent.name() !== 'CaptionSettingsMenuItem') {
  15331. this.menuButton_.focus();
  15332. }
  15333. }
  15334. }
  15335. /**
  15336. * Handle a `keydown` event on this menu. This listener is added in the constructor.
  15337. *
  15338. * @param {EventTarget~Event} event
  15339. * A `keydown` event that happened on the menu.
  15340. *
  15341. * @listens keydown
  15342. */
  15343. ;
  15344. _proto.handleKeyDown = function handleKeyDown(event) {
  15345. // Left and Down Arrows
  15346. if (keycode.isEventKey(event, 'Left') || keycode.isEventKey(event, 'Down')) {
  15347. event.preventDefault();
  15348. event.stopPropagation();
  15349. this.stepForward(); // Up and Right Arrows
  15350. } else if (keycode.isEventKey(event, 'Right') || keycode.isEventKey(event, 'Up')) {
  15351. event.preventDefault();
  15352. event.stopPropagation();
  15353. this.stepBack();
  15354. }
  15355. }
  15356. /**
  15357. * Move to next (lower) menu item for keyboard users.
  15358. */
  15359. ;
  15360. _proto.stepForward = function stepForward() {
  15361. var stepChild = 0;
  15362. if (this.focusedChild_ !== undefined) {
  15363. stepChild = this.focusedChild_ + 1;
  15364. }
  15365. this.focus(stepChild);
  15366. }
  15367. /**
  15368. * Move to previous (higher) menu item for keyboard users.
  15369. */
  15370. ;
  15371. _proto.stepBack = function stepBack() {
  15372. var stepChild = 0;
  15373. if (this.focusedChild_ !== undefined) {
  15374. stepChild = this.focusedChild_ - 1;
  15375. }
  15376. this.focus(stepChild);
  15377. }
  15378. /**
  15379. * Set focus on a {@link MenuItem} in the `Menu`.
  15380. *
  15381. * @param {Object|string} [item=0]
  15382. * Index of child item set focus on.
  15383. */
  15384. ;
  15385. _proto.focus = function focus(item) {
  15386. if (item === void 0) {
  15387. item = 0;
  15388. }
  15389. var children = this.children().slice();
  15390. var haveTitle = children.length && children[0].className && /vjs-menu-title/.test(children[0].className);
  15391. if (haveTitle) {
  15392. children.shift();
  15393. }
  15394. if (children.length > 0) {
  15395. if (item < 0) {
  15396. item = 0;
  15397. } else if (item >= children.length) {
  15398. item = children.length - 1;
  15399. }
  15400. this.focusedChild_ = item;
  15401. children[item].el_.focus();
  15402. }
  15403. };
  15404. return Menu;
  15405. }(Component);
  15406. Component.registerComponent('Menu', Menu);
  15407. /**
  15408. * A `MenuButton` class for any popup {@link Menu}.
  15409. *
  15410. * @extends Component
  15411. */
  15412. var MenuButton =
  15413. /*#__PURE__*/
  15414. function (_Component) {
  15415. _inheritsLoose(MenuButton, _Component);
  15416. /**
  15417. * Creates an instance of this class.
  15418. *
  15419. * @param {Player} player
  15420. * The `Player` that this class should be attached to.
  15421. *
  15422. * @param {Object} [options={}]
  15423. * The key/value store of player options.
  15424. */
  15425. function MenuButton(player, options) {
  15426. var _this;
  15427. if (options === void 0) {
  15428. options = {};
  15429. }
  15430. _this = _Component.call(this, player, options) || this;
  15431. _this.menuButton_ = new Button(player, options);
  15432. _this.menuButton_.controlText(_this.controlText_);
  15433. _this.menuButton_.el_.setAttribute('aria-haspopup', 'true'); // Add buildCSSClass values to the button, not the wrapper
  15434. var buttonClass = Button.prototype.buildCSSClass();
  15435. _this.menuButton_.el_.className = _this.buildCSSClass() + ' ' + buttonClass;
  15436. _this.menuButton_.removeClass('vjs-control');
  15437. _this.addChild(_this.menuButton_);
  15438. _this.update();
  15439. _this.enabled_ = true;
  15440. _this.on(_this.menuButton_, 'tap', _this.handleClick);
  15441. _this.on(_this.menuButton_, 'click', _this.handleClick);
  15442. _this.on(_this.menuButton_, 'keydown', _this.handleKeyDown);
  15443. _this.on(_this.menuButton_, 'mouseenter', function () {
  15444. _this.addClass('vjs-hover');
  15445. _this.menu.show();
  15446. on(document, 'keyup', bind(_assertThisInitialized(_this), _this.handleMenuKeyUp));
  15447. });
  15448. _this.on('mouseleave', _this.handleMouseLeave);
  15449. _this.on('keydown', _this.handleSubmenuKeyDown);
  15450. return _this;
  15451. }
  15452. /**
  15453. * Update the menu based on the current state of its items.
  15454. */
  15455. var _proto = MenuButton.prototype;
  15456. _proto.update = function update() {
  15457. var menu = this.createMenu();
  15458. if (this.menu) {
  15459. this.menu.dispose();
  15460. this.removeChild(this.menu);
  15461. }
  15462. this.menu = menu;
  15463. this.addChild(menu);
  15464. /**
  15465. * Track the state of the menu button
  15466. *
  15467. * @type {Boolean}
  15468. * @private
  15469. */
  15470. this.buttonPressed_ = false;
  15471. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  15472. if (this.items && this.items.length <= this.hideThreshold_) {
  15473. this.hide();
  15474. } else {
  15475. this.show();
  15476. }
  15477. }
  15478. /**
  15479. * Create the menu and add all items to it.
  15480. *
  15481. * @return {Menu}
  15482. * The constructed menu
  15483. */
  15484. ;
  15485. _proto.createMenu = function createMenu() {
  15486. var menu = new Menu(this.player_, {
  15487. menuButton: this
  15488. });
  15489. /**
  15490. * Hide the menu if the number of items is less than or equal to this threshold. This defaults
  15491. * to 0 and whenever we add items which can be hidden to the menu we'll increment it. We list
  15492. * it here because every time we run `createMenu` we need to reset the value.
  15493. *
  15494. * @protected
  15495. * @type {Number}
  15496. */
  15497. this.hideThreshold_ = 0; // Add a title list item to the top
  15498. if (this.options_.title) {
  15499. var titleEl = createEl('li', {
  15500. className: 'vjs-menu-title',
  15501. innerHTML: toTitleCase(this.options_.title),
  15502. tabIndex: -1
  15503. });
  15504. this.hideThreshold_ += 1;
  15505. var titleComponent = new Component(this.player_, {
  15506. el: titleEl
  15507. });
  15508. menu.addItem(titleComponent);
  15509. }
  15510. this.items = this.createItems();
  15511. if (this.items) {
  15512. // Add menu items to the menu
  15513. for (var i = 0; i < this.items.length; i++) {
  15514. menu.addItem(this.items[i]);
  15515. }
  15516. }
  15517. return menu;
  15518. }
  15519. /**
  15520. * Create the list of menu items. Specific to each subclass.
  15521. *
  15522. * @abstract
  15523. */
  15524. ;
  15525. _proto.createItems = function createItems() {}
  15526. /**
  15527. * Create the `MenuButtons`s DOM element.
  15528. *
  15529. * @return {Element}
  15530. * The element that gets created.
  15531. */
  15532. ;
  15533. _proto.createEl = function createEl() {
  15534. return _Component.prototype.createEl.call(this, 'div', {
  15535. className: this.buildWrapperCSSClass()
  15536. }, {});
  15537. }
  15538. /**
  15539. * Allow sub components to stack CSS class names for the wrapper element
  15540. *
  15541. * @return {string}
  15542. * The constructed wrapper DOM `className`
  15543. */
  15544. ;
  15545. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  15546. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  15547. if (this.options_.inline === true) {
  15548. menuButtonClass += '-inline';
  15549. } else {
  15550. menuButtonClass += '-popup';
  15551. } // TODO: Fix the CSS so that this isn't necessary
  15552. var buttonClass = Button.prototype.buildCSSClass();
  15553. return "vjs-menu-button " + menuButtonClass + " " + buttonClass + " " + _Component.prototype.buildCSSClass.call(this);
  15554. }
  15555. /**
  15556. * Builds the default DOM `className`.
  15557. *
  15558. * @return {string}
  15559. * The DOM `className` for this object.
  15560. */
  15561. ;
  15562. _proto.buildCSSClass = function buildCSSClass() {
  15563. var menuButtonClass = 'vjs-menu-button'; // If the inline option is passed, we want to use different styles altogether.
  15564. if (this.options_.inline === true) {
  15565. menuButtonClass += '-inline';
  15566. } else {
  15567. menuButtonClass += '-popup';
  15568. }
  15569. return "vjs-menu-button " + menuButtonClass + " " + _Component.prototype.buildCSSClass.call(this);
  15570. }
  15571. /**
  15572. * Get or set the localized control text that will be used for accessibility.
  15573. *
  15574. * > NOTE: This will come from the internal `menuButton_` element.
  15575. *
  15576. * @param {string} [text]
  15577. * Control text for element.
  15578. *
  15579. * @param {Element} [el=this.menuButton_.el()]
  15580. * Element to set the title on.
  15581. *
  15582. * @return {string}
  15583. * - The control text when getting
  15584. */
  15585. ;
  15586. _proto.controlText = function controlText(text, el) {
  15587. if (el === void 0) {
  15588. el = this.menuButton_.el();
  15589. }
  15590. return this.menuButton_.controlText(text, el);
  15591. }
  15592. /**
  15593. * Dispose of the `menu-button` and all child components.
  15594. */
  15595. ;
  15596. _proto.dispose = function dispose() {
  15597. this.handleMouseLeave();
  15598. _Component.prototype.dispose.call(this);
  15599. }
  15600. /**
  15601. * Handle a click on a `MenuButton`.
  15602. * See {@link ClickableComponent#handleClick} for instances where this is called.
  15603. *
  15604. * @param {EventTarget~Event} event
  15605. * The `keydown`, `tap`, or `click` event that caused this function to be
  15606. * called.
  15607. *
  15608. * @listens tap
  15609. * @listens click
  15610. */
  15611. ;
  15612. _proto.handleClick = function handleClick(event) {
  15613. if (this.buttonPressed_) {
  15614. this.unpressButton();
  15615. } else {
  15616. this.pressButton();
  15617. }
  15618. }
  15619. /**
  15620. * Handle `mouseleave` for `MenuButton`.
  15621. *
  15622. * @param {EventTarget~Event} event
  15623. * The `mouseleave` event that caused this function to be called.
  15624. *
  15625. * @listens mouseleave
  15626. */
  15627. ;
  15628. _proto.handleMouseLeave = function handleMouseLeave(event) {
  15629. this.removeClass('vjs-hover');
  15630. off(document, 'keyup', bind(this, this.handleMenuKeyUp));
  15631. }
  15632. /**
  15633. * Set the focus to the actual button, not to this element
  15634. */
  15635. ;
  15636. _proto.focus = function focus() {
  15637. this.menuButton_.focus();
  15638. }
  15639. /**
  15640. * Remove the focus from the actual button, not this element
  15641. */
  15642. ;
  15643. _proto.blur = function blur() {
  15644. this.menuButton_.blur();
  15645. }
  15646. /**
  15647. * Handle tab, escape, down arrow, and up arrow keys for `MenuButton`. See
  15648. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  15649. *
  15650. * @param {EventTarget~Event} event
  15651. * The `keydown` event that caused this function to be called.
  15652. *
  15653. * @listens keydown
  15654. */
  15655. ;
  15656. _proto.handleKeyDown = function handleKeyDown(event) {
  15657. // Escape or Tab unpress the 'button'
  15658. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  15659. if (this.buttonPressed_) {
  15660. this.unpressButton();
  15661. } // Don't preventDefault for Tab key - we still want to lose focus
  15662. if (!keycode.isEventKey(event, 'Tab')) {
  15663. event.preventDefault(); // Set focus back to the menu button's button
  15664. this.menuButton_.focus();
  15665. } // Up Arrow or Down Arrow also 'press' the button to open the menu
  15666. } else if (keycode.isEventKey(event, 'Up') || keycode.isEventKey(event, 'Down')) {
  15667. if (!this.buttonPressed_) {
  15668. event.preventDefault();
  15669. this.pressButton();
  15670. }
  15671. }
  15672. }
  15673. /**
  15674. * Handle a `keyup` event on a `MenuButton`. The listener for this is added in
  15675. * the constructor.
  15676. *
  15677. * @param {EventTarget~Event} event
  15678. * Key press event
  15679. *
  15680. * @listens keyup
  15681. */
  15682. ;
  15683. _proto.handleMenuKeyUp = function handleMenuKeyUp(event) {
  15684. // Escape hides popup menu
  15685. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  15686. this.removeClass('vjs-hover');
  15687. }
  15688. }
  15689. /**
  15690. * This method name now delegates to `handleSubmenuKeyDown`. This means
  15691. * anyone calling `handleSubmenuKeyPress` will not see their method calls
  15692. * stop working.
  15693. *
  15694. * @param {EventTarget~Event} event
  15695. * The event that caused this function to be called.
  15696. */
  15697. ;
  15698. _proto.handleSubmenuKeyPress = function handleSubmenuKeyPress(event) {
  15699. this.handleSubmenuKeyDown(event);
  15700. }
  15701. /**
  15702. * Handle a `keydown` event on a sub-menu. The listener for this is added in
  15703. * the constructor.
  15704. *
  15705. * @param {EventTarget~Event} event
  15706. * Key press event
  15707. *
  15708. * @listens keydown
  15709. */
  15710. ;
  15711. _proto.handleSubmenuKeyDown = function handleSubmenuKeyDown(event) {
  15712. // Escape or Tab unpress the 'button'
  15713. if (keycode.isEventKey(event, 'Esc') || keycode.isEventKey(event, 'Tab')) {
  15714. if (this.buttonPressed_) {
  15715. this.unpressButton();
  15716. } // Don't preventDefault for Tab key - we still want to lose focus
  15717. if (!keycode.isEventKey(event, 'Tab')) {
  15718. event.preventDefault(); // Set focus back to the menu button's button
  15719. this.menuButton_.focus();
  15720. }
  15721. }
  15722. }
  15723. /**
  15724. * Put the current `MenuButton` into a pressed state.
  15725. */
  15726. ;
  15727. _proto.pressButton = function pressButton() {
  15728. if (this.enabled_) {
  15729. this.buttonPressed_ = true;
  15730. this.menu.show();
  15731. this.menu.lockShowing();
  15732. this.menuButton_.el_.setAttribute('aria-expanded', 'true'); // set the focus into the submenu, except on iOS where it is resulting in
  15733. // undesired scrolling behavior when the player is in an iframe
  15734. if (IS_IOS && isInFrame()) {
  15735. // Return early so that the menu isn't focused
  15736. return;
  15737. }
  15738. this.menu.focus();
  15739. }
  15740. }
  15741. /**
  15742. * Take the current `MenuButton` out of a pressed state.
  15743. */
  15744. ;
  15745. _proto.unpressButton = function unpressButton() {
  15746. if (this.enabled_) {
  15747. this.buttonPressed_ = false;
  15748. this.menu.unlockShowing();
  15749. this.menu.hide();
  15750. this.menuButton_.el_.setAttribute('aria-expanded', 'false');
  15751. }
  15752. }
  15753. /**
  15754. * Disable the `MenuButton`. Don't allow it to be clicked.
  15755. */
  15756. ;
  15757. _proto.disable = function disable() {
  15758. this.unpressButton();
  15759. this.enabled_ = false;
  15760. this.addClass('vjs-disabled');
  15761. this.menuButton_.disable();
  15762. }
  15763. /**
  15764. * Enable the `MenuButton`. Allow it to be clicked.
  15765. */
  15766. ;
  15767. _proto.enable = function enable() {
  15768. this.enabled_ = true;
  15769. this.removeClass('vjs-disabled');
  15770. this.menuButton_.enable();
  15771. };
  15772. return MenuButton;
  15773. }(Component);
  15774. Component.registerComponent('MenuButton', MenuButton);
  15775. /**
  15776. * The base class for buttons that toggle specific track types (e.g. subtitles).
  15777. *
  15778. * @extends MenuButton
  15779. */
  15780. var TrackButton =
  15781. /*#__PURE__*/
  15782. function (_MenuButton) {
  15783. _inheritsLoose(TrackButton, _MenuButton);
  15784. /**
  15785. * Creates an instance of this class.
  15786. *
  15787. * @param {Player} player
  15788. * The `Player` that this class should be attached to.
  15789. *
  15790. * @param {Object} [options]
  15791. * The key/value store of player options.
  15792. */
  15793. function TrackButton(player, options) {
  15794. var _this;
  15795. var tracks = options.tracks;
  15796. _this = _MenuButton.call(this, player, options) || this;
  15797. if (_this.items.length <= 1) {
  15798. _this.hide();
  15799. }
  15800. if (!tracks) {
  15801. return _assertThisInitialized(_this);
  15802. }
  15803. var updateHandler = bind(_assertThisInitialized(_this), _this.update);
  15804. tracks.addEventListener('removetrack', updateHandler);
  15805. tracks.addEventListener('addtrack', updateHandler);
  15806. _this.player_.on('ready', updateHandler);
  15807. _this.player_.on('dispose', function () {
  15808. tracks.removeEventListener('removetrack', updateHandler);
  15809. tracks.removeEventListener('addtrack', updateHandler);
  15810. });
  15811. return _this;
  15812. }
  15813. return TrackButton;
  15814. }(MenuButton);
  15815. Component.registerComponent('TrackButton', TrackButton);
  15816. /**
  15817. * @file menu-keys.js
  15818. */
  15819. /**
  15820. * All keys used for operation of a menu (`MenuButton`, `Menu`, and `MenuItem`)
  15821. * Note that 'Enter' and 'Space' are not included here (otherwise they would
  15822. * prevent the `MenuButton` and `MenuItem` from being keyboard-clickable)
  15823. * @typedef MenuKeys
  15824. * @array
  15825. */
  15826. var MenuKeys = ['Tab', 'Esc', 'Up', 'Down', 'Right', 'Left'];
  15827. /**
  15828. * The component for a menu item. `<li>`
  15829. *
  15830. * @extends ClickableComponent
  15831. */
  15832. var MenuItem =
  15833. /*#__PURE__*/
  15834. function (_ClickableComponent) {
  15835. _inheritsLoose(MenuItem, _ClickableComponent);
  15836. /**
  15837. * Creates an instance of the this class.
  15838. *
  15839. * @param {Player} player
  15840. * The `Player` that this class should be attached to.
  15841. *
  15842. * @param {Object} [options={}]
  15843. * The key/value store of player options.
  15844. *
  15845. */
  15846. function MenuItem(player, options) {
  15847. var _this;
  15848. _this = _ClickableComponent.call(this, player, options) || this;
  15849. _this.selectable = options.selectable;
  15850. _this.isSelected_ = options.selected || false;
  15851. _this.multiSelectable = options.multiSelectable;
  15852. _this.selected(_this.isSelected_);
  15853. if (_this.selectable) {
  15854. if (_this.multiSelectable) {
  15855. _this.el_.setAttribute('role', 'menuitemcheckbox');
  15856. } else {
  15857. _this.el_.setAttribute('role', 'menuitemradio');
  15858. }
  15859. } else {
  15860. _this.el_.setAttribute('role', 'menuitem');
  15861. }
  15862. return _this;
  15863. }
  15864. /**
  15865. * Create the `MenuItem's DOM element
  15866. *
  15867. * @param {string} [type=li]
  15868. * Element's node type, not actually used, always set to `li`.
  15869. *
  15870. * @param {Object} [props={}]
  15871. * An object of properties that should be set on the element
  15872. *
  15873. * @param {Object} [attrs={}]
  15874. * An object of attributes that should be set on the element
  15875. *
  15876. * @return {Element}
  15877. * The element that gets created.
  15878. */
  15879. var _proto = MenuItem.prototype;
  15880. _proto.createEl = function createEl(type, props, attrs) {
  15881. // The control is textual, not just an icon
  15882. this.nonIconControl = true;
  15883. return _ClickableComponent.prototype.createEl.call(this, 'li', assign({
  15884. className: 'vjs-menu-item',
  15885. innerHTML: "<span class=\"vjs-menu-item-text\">" + this.localize(this.options_.label) + "</span>",
  15886. tabIndex: -1
  15887. }, props), attrs);
  15888. }
  15889. /**
  15890. * Ignore keys which are used by the menu, but pass any other ones up. See
  15891. * {@link ClickableComponent#handleKeyDown} for instances where this is called.
  15892. *
  15893. * @param {EventTarget~Event} event
  15894. * The `keydown` event that caused this function to be called.
  15895. *
  15896. * @listens keydown
  15897. */
  15898. ;
  15899. _proto.handleKeyDown = function handleKeyDown(event) {
  15900. if (!MenuKeys.some(function (key) {
  15901. return keycode.isEventKey(event, key);
  15902. })) {
  15903. // Pass keydown handling up for unused keys
  15904. _ClickableComponent.prototype.handleKeyDown.call(this, event);
  15905. }
  15906. }
  15907. /**
  15908. * Any click on a `MenuItem` puts it into the selected state.
  15909. * See {@link ClickableComponent#handleClick} for instances where this is called.
  15910. *
  15911. * @param {EventTarget~Event} event
  15912. * The `keydown`, `tap`, or `click` event that caused this function to be
  15913. * called.
  15914. *
  15915. * @listens tap
  15916. * @listens click
  15917. */
  15918. ;
  15919. _proto.handleClick = function handleClick(event) {
  15920. this.selected(true);
  15921. }
  15922. /**
  15923. * Set the state for this menu item as selected or not.
  15924. *
  15925. * @param {boolean} selected
  15926. * if the menu item is selected or not
  15927. */
  15928. ;
  15929. _proto.selected = function selected(_selected) {
  15930. if (this.selectable) {
  15931. if (_selected) {
  15932. this.addClass('vjs-selected');
  15933. this.el_.setAttribute('aria-checked', 'true'); // aria-checked isn't fully supported by browsers/screen readers,
  15934. // so indicate selected state to screen reader in the control text.
  15935. this.controlText(', selected');
  15936. this.isSelected_ = true;
  15937. } else {
  15938. this.removeClass('vjs-selected');
  15939. this.el_.setAttribute('aria-checked', 'false'); // Indicate un-selected state to screen reader
  15940. this.controlText('');
  15941. this.isSelected_ = false;
  15942. }
  15943. }
  15944. };
  15945. return MenuItem;
  15946. }(ClickableComponent);
  15947. Component.registerComponent('MenuItem', MenuItem);
  15948. /**
  15949. * The specific menu item type for selecting a language within a text track kind
  15950. *
  15951. * @extends MenuItem
  15952. */
  15953. var TextTrackMenuItem =
  15954. /*#__PURE__*/
  15955. function (_MenuItem) {
  15956. _inheritsLoose(TextTrackMenuItem, _MenuItem);
  15957. /**
  15958. * Creates an instance of this class.
  15959. *
  15960. * @param {Player} player
  15961. * The `Player` that this class should be attached to.
  15962. *
  15963. * @param {Object} [options]
  15964. * The key/value store of player options.
  15965. */
  15966. function TextTrackMenuItem(player, options) {
  15967. var _this;
  15968. var track = options.track;
  15969. var tracks = player.textTracks(); // Modify options for parent MenuItem class's init.
  15970. options.label = track.label || track.language || 'Unknown';
  15971. options.selected = track.mode === 'showing';
  15972. _this = _MenuItem.call(this, player, options) || this;
  15973. _this.track = track; // Determine the relevant kind(s) of tracks for this component and filter
  15974. // out empty kinds.
  15975. _this.kinds = (options.kinds || [options.kind || _this.track.kind]).filter(Boolean);
  15976. var changeHandler = function changeHandler() {
  15977. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  15978. args[_key] = arguments[_key];
  15979. }
  15980. _this.handleTracksChange.apply(_assertThisInitialized(_this), args);
  15981. };
  15982. var selectedLanguageChangeHandler = function selectedLanguageChangeHandler() {
  15983. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  15984. args[_key2] = arguments[_key2];
  15985. }
  15986. _this.handleSelectedLanguageChange.apply(_assertThisInitialized(_this), args);
  15987. };
  15988. player.on(['loadstart', 'texttrackchange'], changeHandler);
  15989. tracks.addEventListener('change', changeHandler);
  15990. tracks.addEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  15991. _this.on('dispose', function () {
  15992. player.off(['loadstart', 'texttrackchange'], changeHandler);
  15993. tracks.removeEventListener('change', changeHandler);
  15994. tracks.removeEventListener('selectedlanguagechange', selectedLanguageChangeHandler);
  15995. }); // iOS7 doesn't dispatch change events to TextTrackLists when an
  15996. // associated track's mode changes. Without something like
  15997. // Object.observe() (also not present on iOS7), it's not
  15998. // possible to detect changes to the mode attribute and polyfill
  15999. // the change event. As a poor substitute, we manually dispatch
  16000. // change events whenever the controls modify the mode.
  16001. if (tracks.onchange === undefined) {
  16002. var event;
  16003. _this.on(['tap', 'click'], function () {
  16004. if (typeof window$1.Event !== 'object') {
  16005. // Android 2.3 throws an Illegal Constructor error for window.Event
  16006. try {
  16007. event = new window$1.Event('change');
  16008. } catch (err) {// continue regardless of error
  16009. }
  16010. }
  16011. if (!event) {
  16012. event = document.createEvent('Event');
  16013. event.initEvent('change', true, true);
  16014. }
  16015. tracks.dispatchEvent(event);
  16016. });
  16017. } // set the default state based on current tracks
  16018. _this.handleTracksChange();
  16019. return _this;
  16020. }
  16021. /**
  16022. * This gets called when an `TextTrackMenuItem` is "clicked". See
  16023. * {@link ClickableComponent} for more detailed information on what a click can be.
  16024. *
  16025. * @param {EventTarget~Event} event
  16026. * The `keydown`, `tap`, or `click` event that caused this function to be
  16027. * called.
  16028. *
  16029. * @listens tap
  16030. * @listens click
  16031. */
  16032. var _proto = TextTrackMenuItem.prototype;
  16033. _proto.handleClick = function handleClick(event) {
  16034. var referenceTrack = this.track;
  16035. var tracks = this.player_.textTracks();
  16036. _MenuItem.prototype.handleClick.call(this, event);
  16037. if (!tracks) {
  16038. return;
  16039. }
  16040. for (var i = 0; i < tracks.length; i++) {
  16041. var track = tracks[i]; // If the track from the text tracks list is not of the right kind,
  16042. // skip it. We do not want to affect tracks of incompatible kind(s).
  16043. if (this.kinds.indexOf(track.kind) === -1) {
  16044. continue;
  16045. } // If this text track is the component's track and it is not showing,
  16046. // set it to showing.
  16047. if (track === referenceTrack) {
  16048. if (track.mode !== 'showing') {
  16049. track.mode = 'showing';
  16050. } // If this text track is not the component's track and it is not
  16051. // disabled, set it to disabled.
  16052. } else if (track.mode !== 'disabled') {
  16053. track.mode = 'disabled';
  16054. }
  16055. }
  16056. }
  16057. /**
  16058. * Handle text track list change
  16059. *
  16060. * @param {EventTarget~Event} event
  16061. * The `change` event that caused this function to be called.
  16062. *
  16063. * @listens TextTrackList#change
  16064. */
  16065. ;
  16066. _proto.handleTracksChange = function handleTracksChange(event) {
  16067. var shouldBeSelected = this.track.mode === 'showing'; // Prevent redundant selected() calls because they may cause
  16068. // screen readers to read the appended control text unnecessarily
  16069. if (shouldBeSelected !== this.isSelected_) {
  16070. this.selected(shouldBeSelected);
  16071. }
  16072. };
  16073. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  16074. if (this.track.mode === 'showing') {
  16075. var selectedLanguage = this.player_.cache_.selectedLanguage; // Don't replace the kind of track across the same language
  16076. if (selectedLanguage && selectedLanguage.enabled && selectedLanguage.language === this.track.language && selectedLanguage.kind !== this.track.kind) {
  16077. return;
  16078. }
  16079. this.player_.cache_.selectedLanguage = {
  16080. enabled: true,
  16081. language: this.track.language,
  16082. kind: this.track.kind
  16083. };
  16084. }
  16085. };
  16086. _proto.dispose = function dispose() {
  16087. // remove reference to track object on dispose
  16088. this.track = null;
  16089. _MenuItem.prototype.dispose.call(this);
  16090. };
  16091. return TextTrackMenuItem;
  16092. }(MenuItem);
  16093. Component.registerComponent('TextTrackMenuItem', TextTrackMenuItem);
  16094. /**
  16095. * A special menu item for turning of a specific type of text track
  16096. *
  16097. * @extends TextTrackMenuItem
  16098. */
  16099. var OffTextTrackMenuItem =
  16100. /*#__PURE__*/
  16101. function (_TextTrackMenuItem) {
  16102. _inheritsLoose(OffTextTrackMenuItem, _TextTrackMenuItem);
  16103. /**
  16104. * Creates an instance of this class.
  16105. *
  16106. * @param {Player} player
  16107. * The `Player` that this class should be attached to.
  16108. *
  16109. * @param {Object} [options]
  16110. * The key/value store of player options.
  16111. */
  16112. function OffTextTrackMenuItem(player, options) {
  16113. // Create pseudo track info
  16114. // Requires options['kind']
  16115. options.track = {
  16116. player: player,
  16117. // it is no longer necessary to store `kind` or `kinds` on the track itself
  16118. // since they are now stored in the `kinds` property of all instances of
  16119. // TextTrackMenuItem, but this will remain for backwards compatibility
  16120. kind: options.kind,
  16121. kinds: options.kinds,
  16122. "default": false,
  16123. mode: 'disabled'
  16124. };
  16125. if (!options.kinds) {
  16126. options.kinds = [options.kind];
  16127. }
  16128. if (options.label) {
  16129. options.track.label = options.label;
  16130. } else {
  16131. options.track.label = options.kinds.join(' and ') + ' off';
  16132. } // MenuItem is selectable
  16133. options.selectable = true; // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  16134. options.multiSelectable = false;
  16135. return _TextTrackMenuItem.call(this, player, options) || this;
  16136. }
  16137. /**
  16138. * Handle text track change
  16139. *
  16140. * @param {EventTarget~Event} event
  16141. * The event that caused this function to run
  16142. */
  16143. var _proto = OffTextTrackMenuItem.prototype;
  16144. _proto.handleTracksChange = function handleTracksChange(event) {
  16145. var tracks = this.player().textTracks();
  16146. var shouldBeSelected = true;
  16147. for (var i = 0, l = tracks.length; i < l; i++) {
  16148. var track = tracks[i];
  16149. if (this.options_.kinds.indexOf(track.kind) > -1 && track.mode === 'showing') {
  16150. shouldBeSelected = false;
  16151. break;
  16152. }
  16153. } // Prevent redundant selected() calls because they may cause
  16154. // screen readers to read the appended control text unnecessarily
  16155. if (shouldBeSelected !== this.isSelected_) {
  16156. this.selected(shouldBeSelected);
  16157. }
  16158. };
  16159. _proto.handleSelectedLanguageChange = function handleSelectedLanguageChange(event) {
  16160. var tracks = this.player().textTracks();
  16161. var allHidden = true;
  16162. for (var i = 0, l = tracks.length; i < l; i++) {
  16163. var track = tracks[i];
  16164. if (['captions', 'descriptions', 'subtitles'].indexOf(track.kind) > -1 && track.mode === 'showing') {
  16165. allHidden = false;
  16166. break;
  16167. }
  16168. }
  16169. if (allHidden) {
  16170. this.player_.cache_.selectedLanguage = {
  16171. enabled: false
  16172. };
  16173. }
  16174. };
  16175. return OffTextTrackMenuItem;
  16176. }(TextTrackMenuItem);
  16177. Component.registerComponent('OffTextTrackMenuItem', OffTextTrackMenuItem);
  16178. /**
  16179. * The base class for buttons that toggle specific text track types (e.g. subtitles)
  16180. *
  16181. * @extends MenuButton
  16182. */
  16183. var TextTrackButton =
  16184. /*#__PURE__*/
  16185. function (_TrackButton) {
  16186. _inheritsLoose(TextTrackButton, _TrackButton);
  16187. /**
  16188. * Creates an instance of this class.
  16189. *
  16190. * @param {Player} player
  16191. * The `Player` that this class should be attached to.
  16192. *
  16193. * @param {Object} [options={}]
  16194. * The key/value store of player options.
  16195. */
  16196. function TextTrackButton(player, options) {
  16197. if (options === void 0) {
  16198. options = {};
  16199. }
  16200. options.tracks = player.textTracks();
  16201. return _TrackButton.call(this, player, options) || this;
  16202. }
  16203. /**
  16204. * Create a menu item for each text track
  16205. *
  16206. * @param {TextTrackMenuItem[]} [items=[]]
  16207. * Existing array of items to use during creation
  16208. *
  16209. * @return {TextTrackMenuItem[]}
  16210. * Array of menu items that were created
  16211. */
  16212. var _proto = TextTrackButton.prototype;
  16213. _proto.createItems = function createItems(items, TrackMenuItem) {
  16214. if (items === void 0) {
  16215. items = [];
  16216. }
  16217. if (TrackMenuItem === void 0) {
  16218. TrackMenuItem = TextTrackMenuItem;
  16219. }
  16220. // Label is an override for the [track] off label
  16221. // USed to localise captions/subtitles
  16222. var label;
  16223. if (this.label_) {
  16224. label = this.label_ + " off";
  16225. } // Add an OFF menu item to turn all tracks off
  16226. items.push(new OffTextTrackMenuItem(this.player_, {
  16227. kinds: this.kinds_,
  16228. kind: this.kind_,
  16229. label: label
  16230. }));
  16231. this.hideThreshold_ += 1;
  16232. var tracks = this.player_.textTracks();
  16233. if (!Array.isArray(this.kinds_)) {
  16234. this.kinds_ = [this.kind_];
  16235. }
  16236. for (var i = 0; i < tracks.length; i++) {
  16237. var track = tracks[i]; // only add tracks that are of an appropriate kind and have a label
  16238. if (this.kinds_.indexOf(track.kind) > -1) {
  16239. var item = new TrackMenuItem(this.player_, {
  16240. track: track,
  16241. kinds: this.kinds_,
  16242. kind: this.kind_,
  16243. // MenuItem is selectable
  16244. selectable: true,
  16245. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  16246. multiSelectable: false
  16247. });
  16248. item.addClass("vjs-" + track.kind + "-menu-item");
  16249. items.push(item);
  16250. }
  16251. }
  16252. return items;
  16253. };
  16254. return TextTrackButton;
  16255. }(TrackButton);
  16256. Component.registerComponent('TextTrackButton', TextTrackButton);
  16257. /**
  16258. * The chapter track menu item
  16259. *
  16260. * @extends MenuItem
  16261. */
  16262. var ChaptersTrackMenuItem =
  16263. /*#__PURE__*/
  16264. function (_MenuItem) {
  16265. _inheritsLoose(ChaptersTrackMenuItem, _MenuItem);
  16266. /**
  16267. * Creates an instance of this class.
  16268. *
  16269. * @param {Player} player
  16270. * The `Player` that this class should be attached to.
  16271. *
  16272. * @param {Object} [options]
  16273. * The key/value store of player options.
  16274. */
  16275. function ChaptersTrackMenuItem(player, options) {
  16276. var _this;
  16277. var track = options.track;
  16278. var cue = options.cue;
  16279. var currentTime = player.currentTime(); // Modify options for parent MenuItem class's init.
  16280. options.selectable = true;
  16281. options.multiSelectable = false;
  16282. options.label = cue.text;
  16283. options.selected = cue.startTime <= currentTime && currentTime < cue.endTime;
  16284. _this = _MenuItem.call(this, player, options) || this;
  16285. _this.track = track;
  16286. _this.cue = cue;
  16287. track.addEventListener('cuechange', bind(_assertThisInitialized(_this), _this.update));
  16288. return _this;
  16289. }
  16290. /**
  16291. * This gets called when an `ChaptersTrackMenuItem` is "clicked". See
  16292. * {@link ClickableComponent} for more detailed information on what a click can be.
  16293. *
  16294. * @param {EventTarget~Event} [event]
  16295. * The `keydown`, `tap`, or `click` event that caused this function to be
  16296. * called.
  16297. *
  16298. * @listens tap
  16299. * @listens click
  16300. */
  16301. var _proto = ChaptersTrackMenuItem.prototype;
  16302. _proto.handleClick = function handleClick(event) {
  16303. _MenuItem.prototype.handleClick.call(this);
  16304. this.player_.currentTime(this.cue.startTime);
  16305. this.update(this.cue.startTime);
  16306. }
  16307. /**
  16308. * Update chapter menu item
  16309. *
  16310. * @param {EventTarget~Event} [event]
  16311. * The `cuechange` event that caused this function to run.
  16312. *
  16313. * @listens TextTrack#cuechange
  16314. */
  16315. ;
  16316. _proto.update = function update(event) {
  16317. var cue = this.cue;
  16318. var currentTime = this.player_.currentTime(); // vjs.log(currentTime, cue.startTime);
  16319. this.selected(cue.startTime <= currentTime && currentTime < cue.endTime);
  16320. };
  16321. return ChaptersTrackMenuItem;
  16322. }(MenuItem);
  16323. Component.registerComponent('ChaptersTrackMenuItem', ChaptersTrackMenuItem);
  16324. /**
  16325. * The button component for toggling and selecting chapters
  16326. * Chapters act much differently than other text tracks
  16327. * Cues are navigation vs. other tracks of alternative languages
  16328. *
  16329. * @extends TextTrackButton
  16330. */
  16331. var ChaptersButton =
  16332. /*#__PURE__*/
  16333. function (_TextTrackButton) {
  16334. _inheritsLoose(ChaptersButton, _TextTrackButton);
  16335. /**
  16336. * Creates an instance of this class.
  16337. *
  16338. * @param {Player} player
  16339. * The `Player` that this class should be attached to.
  16340. *
  16341. * @param {Object} [options]
  16342. * The key/value store of player options.
  16343. *
  16344. * @param {Component~ReadyCallback} [ready]
  16345. * The function to call when this function is ready.
  16346. */
  16347. function ChaptersButton(player, options, ready) {
  16348. return _TextTrackButton.call(this, player, options, ready) || this;
  16349. }
  16350. /**
  16351. * Builds the default DOM `className`.
  16352. *
  16353. * @return {string}
  16354. * The DOM `className` for this object.
  16355. */
  16356. var _proto = ChaptersButton.prototype;
  16357. _proto.buildCSSClass = function buildCSSClass() {
  16358. return "vjs-chapters-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16359. };
  16360. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16361. return "vjs-chapters-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16362. }
  16363. /**
  16364. * Update the menu based on the current state of its items.
  16365. *
  16366. * @param {EventTarget~Event} [event]
  16367. * An event that triggered this function to run.
  16368. *
  16369. * @listens TextTrackList#addtrack
  16370. * @listens TextTrackList#removetrack
  16371. * @listens TextTrackList#change
  16372. */
  16373. ;
  16374. _proto.update = function update(event) {
  16375. if (!this.track_ || event && (event.type === 'addtrack' || event.type === 'removetrack')) {
  16376. this.setTrack(this.findChaptersTrack());
  16377. }
  16378. _TextTrackButton.prototype.update.call(this);
  16379. }
  16380. /**
  16381. * Set the currently selected track for the chapters button.
  16382. *
  16383. * @param {TextTrack} track
  16384. * The new track to select. Nothing will change if this is the currently selected
  16385. * track.
  16386. */
  16387. ;
  16388. _proto.setTrack = function setTrack(track) {
  16389. if (this.track_ === track) {
  16390. return;
  16391. }
  16392. if (!this.updateHandler_) {
  16393. this.updateHandler_ = this.update.bind(this);
  16394. } // here this.track_ refers to the old track instance
  16395. if (this.track_) {
  16396. var remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  16397. if (remoteTextTrackEl) {
  16398. remoteTextTrackEl.removeEventListener('load', this.updateHandler_);
  16399. }
  16400. this.track_ = null;
  16401. }
  16402. this.track_ = track; // here this.track_ refers to the new track instance
  16403. if (this.track_) {
  16404. this.track_.mode = 'hidden';
  16405. var _remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
  16406. if (_remoteTextTrackEl) {
  16407. _remoteTextTrackEl.addEventListener('load', this.updateHandler_);
  16408. }
  16409. }
  16410. }
  16411. /**
  16412. * Find the track object that is currently in use by this ChaptersButton
  16413. *
  16414. * @return {TextTrack|undefined}
  16415. * The current track or undefined if none was found.
  16416. */
  16417. ;
  16418. _proto.findChaptersTrack = function findChaptersTrack() {
  16419. var tracks = this.player_.textTracks() || [];
  16420. for (var i = tracks.length - 1; i >= 0; i--) {
  16421. // We will always choose the last track as our chaptersTrack
  16422. var track = tracks[i];
  16423. if (track.kind === this.kind_) {
  16424. return track;
  16425. }
  16426. }
  16427. }
  16428. /**
  16429. * Get the caption for the ChaptersButton based on the track label. This will also
  16430. * use the current tracks localized kind as a fallback if a label does not exist.
  16431. *
  16432. * @return {string}
  16433. * The tracks current label or the localized track kind.
  16434. */
  16435. ;
  16436. _proto.getMenuCaption = function getMenuCaption() {
  16437. if (this.track_ && this.track_.label) {
  16438. return this.track_.label;
  16439. }
  16440. return this.localize(toTitleCase(this.kind_));
  16441. }
  16442. /**
  16443. * Create menu from chapter track
  16444. *
  16445. * @return {Menu}
  16446. * New menu for the chapter buttons
  16447. */
  16448. ;
  16449. _proto.createMenu = function createMenu() {
  16450. this.options_.title = this.getMenuCaption();
  16451. return _TextTrackButton.prototype.createMenu.call(this);
  16452. }
  16453. /**
  16454. * Create a menu item for each text track
  16455. *
  16456. * @return {TextTrackMenuItem[]}
  16457. * Array of menu items
  16458. */
  16459. ;
  16460. _proto.createItems = function createItems() {
  16461. var items = [];
  16462. if (!this.track_) {
  16463. return items;
  16464. }
  16465. var cues = this.track_.cues;
  16466. if (!cues) {
  16467. return items;
  16468. }
  16469. for (var i = 0, l = cues.length; i < l; i++) {
  16470. var cue = cues[i];
  16471. var mi = new ChaptersTrackMenuItem(this.player_, {
  16472. track: this.track_,
  16473. cue: cue
  16474. });
  16475. items.push(mi);
  16476. }
  16477. return items;
  16478. };
  16479. return ChaptersButton;
  16480. }(TextTrackButton);
  16481. /**
  16482. * `kind` of TextTrack to look for to associate it with this menu.
  16483. *
  16484. * @type {string}
  16485. * @private
  16486. */
  16487. ChaptersButton.prototype.kind_ = 'chapters';
  16488. /**
  16489. * The text that should display over the `ChaptersButton`s controls. Added for localization.
  16490. *
  16491. * @type {string}
  16492. * @private
  16493. */
  16494. ChaptersButton.prototype.controlText_ = 'Chapters';
  16495. Component.registerComponent('ChaptersButton', ChaptersButton);
  16496. /**
  16497. * The button component for toggling and selecting descriptions
  16498. *
  16499. * @extends TextTrackButton
  16500. */
  16501. var DescriptionsButton =
  16502. /*#__PURE__*/
  16503. function (_TextTrackButton) {
  16504. _inheritsLoose(DescriptionsButton, _TextTrackButton);
  16505. /**
  16506. * Creates an instance of this class.
  16507. *
  16508. * @param {Player} player
  16509. * The `Player` that this class should be attached to.
  16510. *
  16511. * @param {Object} [options]
  16512. * The key/value store of player options.
  16513. *
  16514. * @param {Component~ReadyCallback} [ready]
  16515. * The function to call when this component is ready.
  16516. */
  16517. function DescriptionsButton(player, options, ready) {
  16518. var _this;
  16519. _this = _TextTrackButton.call(this, player, options, ready) || this;
  16520. var tracks = player.textTracks();
  16521. var changeHandler = bind(_assertThisInitialized(_this), _this.handleTracksChange);
  16522. tracks.addEventListener('change', changeHandler);
  16523. _this.on('dispose', function () {
  16524. tracks.removeEventListener('change', changeHandler);
  16525. });
  16526. return _this;
  16527. }
  16528. /**
  16529. * Handle text track change
  16530. *
  16531. * @param {EventTarget~Event} event
  16532. * The event that caused this function to run
  16533. *
  16534. * @listens TextTrackList#change
  16535. */
  16536. var _proto = DescriptionsButton.prototype;
  16537. _proto.handleTracksChange = function handleTracksChange(event) {
  16538. var tracks = this.player().textTracks();
  16539. var disabled = false; // Check whether a track of a different kind is showing
  16540. for (var i = 0, l = tracks.length; i < l; i++) {
  16541. var track = tracks[i];
  16542. if (track.kind !== this.kind_ && track.mode === 'showing') {
  16543. disabled = true;
  16544. break;
  16545. }
  16546. } // If another track is showing, disable this menu button
  16547. if (disabled) {
  16548. this.disable();
  16549. } else {
  16550. this.enable();
  16551. }
  16552. }
  16553. /**
  16554. * Builds the default DOM `className`.
  16555. *
  16556. * @return {string}
  16557. * The DOM `className` for this object.
  16558. */
  16559. ;
  16560. _proto.buildCSSClass = function buildCSSClass() {
  16561. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16562. };
  16563. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16564. return "vjs-descriptions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16565. };
  16566. return DescriptionsButton;
  16567. }(TextTrackButton);
  16568. /**
  16569. * `kind` of TextTrack to look for to associate it with this menu.
  16570. *
  16571. * @type {string}
  16572. * @private
  16573. */
  16574. DescriptionsButton.prototype.kind_ = 'descriptions';
  16575. /**
  16576. * The text that should display over the `DescriptionsButton`s controls. Added for localization.
  16577. *
  16578. * @type {string}
  16579. * @private
  16580. */
  16581. DescriptionsButton.prototype.controlText_ = 'Descriptions';
  16582. Component.registerComponent('DescriptionsButton', DescriptionsButton);
  16583. /**
  16584. * The button component for toggling and selecting subtitles
  16585. *
  16586. * @extends TextTrackButton
  16587. */
  16588. var SubtitlesButton =
  16589. /*#__PURE__*/
  16590. function (_TextTrackButton) {
  16591. _inheritsLoose(SubtitlesButton, _TextTrackButton);
  16592. /**
  16593. * Creates an instance of this class.
  16594. *
  16595. * @param {Player} player
  16596. * The `Player` that this class should be attached to.
  16597. *
  16598. * @param {Object} [options]
  16599. * The key/value store of player options.
  16600. *
  16601. * @param {Component~ReadyCallback} [ready]
  16602. * The function to call when this component is ready.
  16603. */
  16604. function SubtitlesButton(player, options, ready) {
  16605. return _TextTrackButton.call(this, player, options, ready) || this;
  16606. }
  16607. /**
  16608. * Builds the default DOM `className`.
  16609. *
  16610. * @return {string}
  16611. * The DOM `className` for this object.
  16612. */
  16613. var _proto = SubtitlesButton.prototype;
  16614. _proto.buildCSSClass = function buildCSSClass() {
  16615. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16616. };
  16617. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16618. return "vjs-subtitles-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16619. };
  16620. return SubtitlesButton;
  16621. }(TextTrackButton);
  16622. /**
  16623. * `kind` of TextTrack to look for to associate it with this menu.
  16624. *
  16625. * @type {string}
  16626. * @private
  16627. */
  16628. SubtitlesButton.prototype.kind_ = 'subtitles';
  16629. /**
  16630. * The text that should display over the `SubtitlesButton`s controls. Added for localization.
  16631. *
  16632. * @type {string}
  16633. * @private
  16634. */
  16635. SubtitlesButton.prototype.controlText_ = 'Subtitles';
  16636. Component.registerComponent('SubtitlesButton', SubtitlesButton);
  16637. /**
  16638. * The menu item for caption track settings menu
  16639. *
  16640. * @extends TextTrackMenuItem
  16641. */
  16642. var CaptionSettingsMenuItem =
  16643. /*#__PURE__*/
  16644. function (_TextTrackMenuItem) {
  16645. _inheritsLoose(CaptionSettingsMenuItem, _TextTrackMenuItem);
  16646. /**
  16647. * Creates an instance of this class.
  16648. *
  16649. * @param {Player} player
  16650. * The `Player` that this class should be attached to.
  16651. *
  16652. * @param {Object} [options]
  16653. * The key/value store of player options.
  16654. */
  16655. function CaptionSettingsMenuItem(player, options) {
  16656. var _this;
  16657. options.track = {
  16658. player: player,
  16659. kind: options.kind,
  16660. label: options.kind + ' settings',
  16661. selectable: false,
  16662. "default": false,
  16663. mode: 'disabled'
  16664. }; // CaptionSettingsMenuItem has no concept of 'selected'
  16665. options.selectable = false;
  16666. options.name = 'CaptionSettingsMenuItem';
  16667. _this = _TextTrackMenuItem.call(this, player, options) || this;
  16668. _this.addClass('vjs-texttrack-settings');
  16669. _this.controlText(', opens ' + options.kind + ' settings dialog');
  16670. return _this;
  16671. }
  16672. /**
  16673. * This gets called when an `CaptionSettingsMenuItem` is "clicked". See
  16674. * {@link ClickableComponent} for more detailed information on what a click can be.
  16675. *
  16676. * @param {EventTarget~Event} [event]
  16677. * The `keydown`, `tap`, or `click` event that caused this function to be
  16678. * called.
  16679. *
  16680. * @listens tap
  16681. * @listens click
  16682. */
  16683. var _proto = CaptionSettingsMenuItem.prototype;
  16684. _proto.handleClick = function handleClick(event) {
  16685. this.player().getChild('textTrackSettings').open();
  16686. };
  16687. return CaptionSettingsMenuItem;
  16688. }(TextTrackMenuItem);
  16689. Component.registerComponent('CaptionSettingsMenuItem', CaptionSettingsMenuItem);
  16690. /**
  16691. * The button component for toggling and selecting captions
  16692. *
  16693. * @extends TextTrackButton
  16694. */
  16695. var CaptionsButton =
  16696. /*#__PURE__*/
  16697. function (_TextTrackButton) {
  16698. _inheritsLoose(CaptionsButton, _TextTrackButton);
  16699. /**
  16700. * Creates an instance of this class.
  16701. *
  16702. * @param {Player} player
  16703. * The `Player` that this class should be attached to.
  16704. *
  16705. * @param {Object} [options]
  16706. * The key/value store of player options.
  16707. *
  16708. * @param {Component~ReadyCallback} [ready]
  16709. * The function to call when this component is ready.
  16710. */
  16711. function CaptionsButton(player, options, ready) {
  16712. return _TextTrackButton.call(this, player, options, ready) || this;
  16713. }
  16714. /**
  16715. * Builds the default DOM `className`.
  16716. *
  16717. * @return {string}
  16718. * The DOM `className` for this object.
  16719. */
  16720. var _proto = CaptionsButton.prototype;
  16721. _proto.buildCSSClass = function buildCSSClass() {
  16722. return "vjs-captions-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16723. };
  16724. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16725. return "vjs-captions-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16726. }
  16727. /**
  16728. * Create caption menu items
  16729. *
  16730. * @return {CaptionSettingsMenuItem[]}
  16731. * The array of current menu items.
  16732. */
  16733. ;
  16734. _proto.createItems = function createItems() {
  16735. var items = [];
  16736. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  16737. items.push(new CaptionSettingsMenuItem(this.player_, {
  16738. kind: this.kind_
  16739. }));
  16740. this.hideThreshold_ += 1;
  16741. }
  16742. return _TextTrackButton.prototype.createItems.call(this, items);
  16743. };
  16744. return CaptionsButton;
  16745. }(TextTrackButton);
  16746. /**
  16747. * `kind` of TextTrack to look for to associate it with this menu.
  16748. *
  16749. * @type {string}
  16750. * @private
  16751. */
  16752. CaptionsButton.prototype.kind_ = 'captions';
  16753. /**
  16754. * The text that should display over the `CaptionsButton`s controls. Added for localization.
  16755. *
  16756. * @type {string}
  16757. * @private
  16758. */
  16759. CaptionsButton.prototype.controlText_ = 'Captions';
  16760. Component.registerComponent('CaptionsButton', CaptionsButton);
  16761. /**
  16762. * SubsCapsMenuItem has an [cc] icon to distinguish captions from subtitles
  16763. * in the SubsCapsMenu.
  16764. *
  16765. * @extends TextTrackMenuItem
  16766. */
  16767. var SubsCapsMenuItem =
  16768. /*#__PURE__*/
  16769. function (_TextTrackMenuItem) {
  16770. _inheritsLoose(SubsCapsMenuItem, _TextTrackMenuItem);
  16771. function SubsCapsMenuItem() {
  16772. return _TextTrackMenuItem.apply(this, arguments) || this;
  16773. }
  16774. var _proto = SubsCapsMenuItem.prototype;
  16775. _proto.createEl = function createEl(type, props, attrs) {
  16776. var innerHTML = "<span class=\"vjs-menu-item-text\">" + this.localize(this.options_.label);
  16777. if (this.options_.track.kind === 'captions') {
  16778. innerHTML += "\n <span aria-hidden=\"true\" class=\"vjs-icon-placeholder\"></span>\n <span class=\"vjs-control-text\"> " + this.localize('Captions') + "</span>\n ";
  16779. }
  16780. innerHTML += '</span>';
  16781. var el = _TextTrackMenuItem.prototype.createEl.call(this, type, assign({
  16782. innerHTML: innerHTML
  16783. }, props), attrs);
  16784. return el;
  16785. };
  16786. return SubsCapsMenuItem;
  16787. }(TextTrackMenuItem);
  16788. Component.registerComponent('SubsCapsMenuItem', SubsCapsMenuItem);
  16789. /**
  16790. * The button component for toggling and selecting captions and/or subtitles
  16791. *
  16792. * @extends TextTrackButton
  16793. */
  16794. var SubsCapsButton =
  16795. /*#__PURE__*/
  16796. function (_TextTrackButton) {
  16797. _inheritsLoose(SubsCapsButton, _TextTrackButton);
  16798. function SubsCapsButton(player, options) {
  16799. var _this;
  16800. if (options === void 0) {
  16801. options = {};
  16802. }
  16803. _this = _TextTrackButton.call(this, player, options) || this; // Although North America uses "captions" in most cases for
  16804. // "captions and subtitles" other locales use "subtitles"
  16805. _this.label_ = 'subtitles';
  16806. if (['en', 'en-us', 'en-ca', 'fr-ca'].indexOf(_this.player_.language_) > -1) {
  16807. _this.label_ = 'captions';
  16808. }
  16809. _this.menuButton_.controlText(toTitleCase(_this.label_));
  16810. return _this;
  16811. }
  16812. /**
  16813. * Builds the default DOM `className`.
  16814. *
  16815. * @return {string}
  16816. * The DOM `className` for this object.
  16817. */
  16818. var _proto = SubsCapsButton.prototype;
  16819. _proto.buildCSSClass = function buildCSSClass() {
  16820. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildCSSClass.call(this);
  16821. };
  16822. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16823. return "vjs-subs-caps-button " + _TextTrackButton.prototype.buildWrapperCSSClass.call(this);
  16824. }
  16825. /**
  16826. * Create caption/subtitles menu items
  16827. *
  16828. * @return {CaptionSettingsMenuItem[]}
  16829. * The array of current menu items.
  16830. */
  16831. ;
  16832. _proto.createItems = function createItems() {
  16833. var items = [];
  16834. if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) && this.player().getChild('textTrackSettings')) {
  16835. items.push(new CaptionSettingsMenuItem(this.player_, {
  16836. kind: this.label_
  16837. }));
  16838. this.hideThreshold_ += 1;
  16839. }
  16840. items = _TextTrackButton.prototype.createItems.call(this, items, SubsCapsMenuItem);
  16841. return items;
  16842. };
  16843. return SubsCapsButton;
  16844. }(TextTrackButton);
  16845. /**
  16846. * `kind`s of TextTrack to look for to associate it with this menu.
  16847. *
  16848. * @type {array}
  16849. * @private
  16850. */
  16851. SubsCapsButton.prototype.kinds_ = ['captions', 'subtitles'];
  16852. /**
  16853. * The text that should display over the `SubsCapsButton`s controls.
  16854. *
  16855. *
  16856. * @type {string}
  16857. * @private
  16858. */
  16859. SubsCapsButton.prototype.controlText_ = 'Subtitles';
  16860. Component.registerComponent('SubsCapsButton', SubsCapsButton);
  16861. /**
  16862. * An {@link AudioTrack} {@link MenuItem}
  16863. *
  16864. * @extends MenuItem
  16865. */
  16866. var AudioTrackMenuItem =
  16867. /*#__PURE__*/
  16868. function (_MenuItem) {
  16869. _inheritsLoose(AudioTrackMenuItem, _MenuItem);
  16870. /**
  16871. * Creates an instance of this class.
  16872. *
  16873. * @param {Player} player
  16874. * The `Player` that this class should be attached to.
  16875. *
  16876. * @param {Object} [options]
  16877. * The key/value store of player options.
  16878. */
  16879. function AudioTrackMenuItem(player, options) {
  16880. var _this;
  16881. var track = options.track;
  16882. var tracks = player.audioTracks(); // Modify options for parent MenuItem class's init.
  16883. options.label = track.label || track.language || 'Unknown';
  16884. options.selected = track.enabled;
  16885. _this = _MenuItem.call(this, player, options) || this;
  16886. _this.track = track;
  16887. _this.addClass("vjs-" + track.kind + "-menu-item");
  16888. var changeHandler = function changeHandler() {
  16889. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  16890. args[_key] = arguments[_key];
  16891. }
  16892. _this.handleTracksChange.apply(_assertThisInitialized(_this), args);
  16893. };
  16894. tracks.addEventListener('change', changeHandler);
  16895. _this.on('dispose', function () {
  16896. tracks.removeEventListener('change', changeHandler);
  16897. });
  16898. return _this;
  16899. }
  16900. var _proto = AudioTrackMenuItem.prototype;
  16901. _proto.createEl = function createEl(type, props, attrs) {
  16902. var innerHTML = "<span class=\"vjs-menu-item-text\">" + this.localize(this.options_.label);
  16903. if (this.options_.track.kind === 'main-desc') {
  16904. innerHTML += "\n <span aria-hidden=\"true\" class=\"vjs-icon-placeholder\"></span>\n <span class=\"vjs-control-text\"> " + this.localize('Descriptions') + "</span>\n ";
  16905. }
  16906. innerHTML += '</span>';
  16907. var el = _MenuItem.prototype.createEl.call(this, type, assign({
  16908. innerHTML: innerHTML
  16909. }, props), attrs);
  16910. return el;
  16911. }
  16912. /**
  16913. * This gets called when an `AudioTrackMenuItem is "clicked". See {@link ClickableComponent}
  16914. * for more detailed information on what a click can be.
  16915. *
  16916. * @param {EventTarget~Event} [event]
  16917. * The `keydown`, `tap`, or `click` event that caused this function to be
  16918. * called.
  16919. *
  16920. * @listens tap
  16921. * @listens click
  16922. */
  16923. ;
  16924. _proto.handleClick = function handleClick(event) {
  16925. var tracks = this.player_.audioTracks();
  16926. _MenuItem.prototype.handleClick.call(this, event);
  16927. for (var i = 0; i < tracks.length; i++) {
  16928. var track = tracks[i];
  16929. track.enabled = track === this.track;
  16930. }
  16931. }
  16932. /**
  16933. * Handle any {@link AudioTrack} change.
  16934. *
  16935. * @param {EventTarget~Event} [event]
  16936. * The {@link AudioTrackList#change} event that caused this to run.
  16937. *
  16938. * @listens AudioTrackList#change
  16939. */
  16940. ;
  16941. _proto.handleTracksChange = function handleTracksChange(event) {
  16942. this.selected(this.track.enabled);
  16943. };
  16944. return AudioTrackMenuItem;
  16945. }(MenuItem);
  16946. Component.registerComponent('AudioTrackMenuItem', AudioTrackMenuItem);
  16947. /**
  16948. * The base class for buttons that toggle specific {@link AudioTrack} types.
  16949. *
  16950. * @extends TrackButton
  16951. */
  16952. var AudioTrackButton =
  16953. /*#__PURE__*/
  16954. function (_TrackButton) {
  16955. _inheritsLoose(AudioTrackButton, _TrackButton);
  16956. /**
  16957. * Creates an instance of this class.
  16958. *
  16959. * @param {Player} player
  16960. * The `Player` that this class should be attached to.
  16961. *
  16962. * @param {Object} [options={}]
  16963. * The key/value store of player options.
  16964. */
  16965. function AudioTrackButton(player, options) {
  16966. if (options === void 0) {
  16967. options = {};
  16968. }
  16969. options.tracks = player.audioTracks();
  16970. return _TrackButton.call(this, player, options) || this;
  16971. }
  16972. /**
  16973. * Builds the default DOM `className`.
  16974. *
  16975. * @return {string}
  16976. * The DOM `className` for this object.
  16977. */
  16978. var _proto = AudioTrackButton.prototype;
  16979. _proto.buildCSSClass = function buildCSSClass() {
  16980. return "vjs-audio-button " + _TrackButton.prototype.buildCSSClass.call(this);
  16981. };
  16982. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  16983. return "vjs-audio-button " + _TrackButton.prototype.buildWrapperCSSClass.call(this);
  16984. }
  16985. /**
  16986. * Create a menu item for each audio track
  16987. *
  16988. * @param {AudioTrackMenuItem[]} [items=[]]
  16989. * An array of existing menu items to use.
  16990. *
  16991. * @return {AudioTrackMenuItem[]}
  16992. * An array of menu items
  16993. */
  16994. ;
  16995. _proto.createItems = function createItems(items) {
  16996. if (items === void 0) {
  16997. items = [];
  16998. }
  16999. // if there's only one audio track, there no point in showing it
  17000. this.hideThreshold_ = 1;
  17001. var tracks = this.player_.audioTracks();
  17002. for (var i = 0; i < tracks.length; i++) {
  17003. var track = tracks[i];
  17004. items.push(new AudioTrackMenuItem(this.player_, {
  17005. track: track,
  17006. // MenuItem is selectable
  17007. selectable: true,
  17008. // MenuItem is NOT multiSelectable (i.e. only one can be marked "selected" at a time)
  17009. multiSelectable: false
  17010. }));
  17011. }
  17012. return items;
  17013. };
  17014. return AudioTrackButton;
  17015. }(TrackButton);
  17016. /**
  17017. * The text that should display over the `AudioTrackButton`s controls. Added for localization.
  17018. *
  17019. * @type {string}
  17020. * @private
  17021. */
  17022. AudioTrackButton.prototype.controlText_ = 'Audio Track';
  17023. Component.registerComponent('AudioTrackButton', AudioTrackButton);
  17024. /**
  17025. * The specific menu item type for selecting a playback rate.
  17026. *
  17027. * @extends MenuItem
  17028. */
  17029. var PlaybackRateMenuItem =
  17030. /*#__PURE__*/
  17031. function (_MenuItem) {
  17032. _inheritsLoose(PlaybackRateMenuItem, _MenuItem);
  17033. /**
  17034. * Creates an instance of this class.
  17035. *
  17036. * @param {Player} player
  17037. * The `Player` that this class should be attached to.
  17038. *
  17039. * @param {Object} [options]
  17040. * The key/value store of player options.
  17041. */
  17042. function PlaybackRateMenuItem(player, options) {
  17043. var _this;
  17044. var label = options.rate;
  17045. var rate = parseFloat(label, 10); // Modify options for parent MenuItem class's init.
  17046. options.label = label;
  17047. options.selected = rate === 1;
  17048. options.selectable = true;
  17049. options.multiSelectable = false;
  17050. _this = _MenuItem.call(this, player, options) || this;
  17051. _this.label = label;
  17052. _this.rate = rate;
  17053. _this.on(player, 'ratechange', _this.update);
  17054. return _this;
  17055. }
  17056. /**
  17057. * This gets called when an `PlaybackRateMenuItem` is "clicked". See
  17058. * {@link ClickableComponent} for more detailed information on what a click can be.
  17059. *
  17060. * @param {EventTarget~Event} [event]
  17061. * The `keydown`, `tap`, or `click` event that caused this function to be
  17062. * called.
  17063. *
  17064. * @listens tap
  17065. * @listens click
  17066. */
  17067. var _proto = PlaybackRateMenuItem.prototype;
  17068. _proto.handleClick = function handleClick(event) {
  17069. _MenuItem.prototype.handleClick.call(this);
  17070. this.player().playbackRate(this.rate);
  17071. }
  17072. /**
  17073. * Update the PlaybackRateMenuItem when the playbackrate changes.
  17074. *
  17075. * @param {EventTarget~Event} [event]
  17076. * The `ratechange` event that caused this function to run.
  17077. *
  17078. * @listens Player#ratechange
  17079. */
  17080. ;
  17081. _proto.update = function update(event) {
  17082. this.selected(this.player().playbackRate() === this.rate);
  17083. };
  17084. return PlaybackRateMenuItem;
  17085. }(MenuItem);
  17086. /**
  17087. * The text that should display over the `PlaybackRateMenuItem`s controls. Added for localization.
  17088. *
  17089. * @type {string}
  17090. * @private
  17091. */
  17092. PlaybackRateMenuItem.prototype.contentElType = 'button';
  17093. Component.registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem);
  17094. /**
  17095. * The component for controlling the playback rate.
  17096. *
  17097. * @extends MenuButton
  17098. */
  17099. var PlaybackRateMenuButton =
  17100. /*#__PURE__*/
  17101. function (_MenuButton) {
  17102. _inheritsLoose(PlaybackRateMenuButton, _MenuButton);
  17103. /**
  17104. * Creates an instance of this class.
  17105. *
  17106. * @param {Player} player
  17107. * The `Player` that this class should be attached to.
  17108. *
  17109. * @param {Object} [options]
  17110. * The key/value store of player options.
  17111. */
  17112. function PlaybackRateMenuButton(player, options) {
  17113. var _this;
  17114. _this = _MenuButton.call(this, player, options) || this;
  17115. _this.updateVisibility();
  17116. _this.updateLabel();
  17117. _this.on(player, 'loadstart', _this.updateVisibility);
  17118. _this.on(player, 'ratechange', _this.updateLabel);
  17119. return _this;
  17120. }
  17121. /**
  17122. * Create the `Component`'s DOM element
  17123. *
  17124. * @return {Element}
  17125. * The element that was created.
  17126. */
  17127. var _proto = PlaybackRateMenuButton.prototype;
  17128. _proto.createEl = function createEl$1() {
  17129. var el = _MenuButton.prototype.createEl.call(this);
  17130. this.labelEl_ = createEl('div', {
  17131. className: 'vjs-playback-rate-value',
  17132. innerHTML: '1x'
  17133. });
  17134. el.appendChild(this.labelEl_);
  17135. return el;
  17136. };
  17137. _proto.dispose = function dispose() {
  17138. this.labelEl_ = null;
  17139. _MenuButton.prototype.dispose.call(this);
  17140. }
  17141. /**
  17142. * Builds the default DOM `className`.
  17143. *
  17144. * @return {string}
  17145. * The DOM `className` for this object.
  17146. */
  17147. ;
  17148. _proto.buildCSSClass = function buildCSSClass() {
  17149. return "vjs-playback-rate " + _MenuButton.prototype.buildCSSClass.call(this);
  17150. };
  17151. _proto.buildWrapperCSSClass = function buildWrapperCSSClass() {
  17152. return "vjs-playback-rate " + _MenuButton.prototype.buildWrapperCSSClass.call(this);
  17153. }
  17154. /**
  17155. * Create the playback rate menu
  17156. *
  17157. * @return {Menu}
  17158. * Menu object populated with {@link PlaybackRateMenuItem}s
  17159. */
  17160. ;
  17161. _proto.createMenu = function createMenu() {
  17162. var menu = new Menu(this.player());
  17163. var rates = this.playbackRates();
  17164. if (rates) {
  17165. for (var i = rates.length - 1; i >= 0; i--) {
  17166. menu.addChild(new PlaybackRateMenuItem(this.player(), {
  17167. rate: rates[i] + 'x'
  17168. }));
  17169. }
  17170. }
  17171. return menu;
  17172. }
  17173. /**
  17174. * Updates ARIA accessibility attributes
  17175. */
  17176. ;
  17177. _proto.updateARIAAttributes = function updateARIAAttributes() {
  17178. // Current playback rate
  17179. this.el().setAttribute('aria-valuenow', this.player().playbackRate());
  17180. }
  17181. /**
  17182. * This gets called when an `PlaybackRateMenuButton` is "clicked". See
  17183. * {@link ClickableComponent} for more detailed information on what a click can be.
  17184. *
  17185. * @param {EventTarget~Event} [event]
  17186. * The `keydown`, `tap`, or `click` event that caused this function to be
  17187. * called.
  17188. *
  17189. * @listens tap
  17190. * @listens click
  17191. */
  17192. ;
  17193. _proto.handleClick = function handleClick(event) {
  17194. // select next rate option
  17195. var currentRate = this.player().playbackRate();
  17196. var rates = this.playbackRates(); // this will select first one if the last one currently selected
  17197. var newRate = rates[0];
  17198. for (var i = 0; i < rates.length; i++) {
  17199. if (rates[i] > currentRate) {
  17200. newRate = rates[i];
  17201. break;
  17202. }
  17203. }
  17204. this.player().playbackRate(newRate);
  17205. }
  17206. /**
  17207. * Get possible playback rates
  17208. *
  17209. * @return {Array}
  17210. * All possible playback rates
  17211. */
  17212. ;
  17213. _proto.playbackRates = function playbackRates() {
  17214. return this.options_.playbackRates || this.options_.playerOptions && this.options_.playerOptions.playbackRates;
  17215. }
  17216. /**
  17217. * Get whether playback rates is supported by the tech
  17218. * and an array of playback rates exists
  17219. *
  17220. * @return {boolean}
  17221. * Whether changing playback rate is supported
  17222. */
  17223. ;
  17224. _proto.playbackRateSupported = function playbackRateSupported() {
  17225. return this.player().tech_ && this.player().tech_.featuresPlaybackRate && this.playbackRates() && this.playbackRates().length > 0;
  17226. }
  17227. /**
  17228. * Hide playback rate controls when they're no playback rate options to select
  17229. *
  17230. * @param {EventTarget~Event} [event]
  17231. * The event that caused this function to run.
  17232. *
  17233. * @listens Player#loadstart
  17234. */
  17235. ;
  17236. _proto.updateVisibility = function updateVisibility(event) {
  17237. if (this.playbackRateSupported()) {
  17238. this.removeClass('vjs-hidden');
  17239. } else {
  17240. this.addClass('vjs-hidden');
  17241. }
  17242. }
  17243. /**
  17244. * Update button label when rate changed
  17245. *
  17246. * @param {EventTarget~Event} [event]
  17247. * The event that caused this function to run.
  17248. *
  17249. * @listens Player#ratechange
  17250. */
  17251. ;
  17252. _proto.updateLabel = function updateLabel(event) {
  17253. if (this.playbackRateSupported()) {
  17254. this.labelEl_.innerHTML = this.player().playbackRate() + 'x';
  17255. }
  17256. };
  17257. return PlaybackRateMenuButton;
  17258. }(MenuButton);
  17259. /**
  17260. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  17261. *
  17262. * @type {string}
  17263. * @private
  17264. */
  17265. PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
  17266. Component.registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
  17267. /**
  17268. * Just an empty spacer element that can be used as an append point for plugins, etc.
  17269. * Also can be used to create space between elements when necessary.
  17270. *
  17271. * @extends Component
  17272. */
  17273. var Spacer =
  17274. /*#__PURE__*/
  17275. function (_Component) {
  17276. _inheritsLoose(Spacer, _Component);
  17277. function Spacer() {
  17278. return _Component.apply(this, arguments) || this;
  17279. }
  17280. var _proto = Spacer.prototype;
  17281. /**
  17282. * Builds the default DOM `className`.
  17283. *
  17284. * @return {string}
  17285. * The DOM `className` for this object.
  17286. */
  17287. _proto.buildCSSClass = function buildCSSClass() {
  17288. return "vjs-spacer " + _Component.prototype.buildCSSClass.call(this);
  17289. }
  17290. /**
  17291. * Create the `Component`'s DOM element
  17292. *
  17293. * @return {Element}
  17294. * The element that was created.
  17295. */
  17296. ;
  17297. _proto.createEl = function createEl() {
  17298. return _Component.prototype.createEl.call(this, 'div', {
  17299. className: this.buildCSSClass()
  17300. });
  17301. };
  17302. return Spacer;
  17303. }(Component);
  17304. Component.registerComponent('Spacer', Spacer);
  17305. /**
  17306. * Spacer specifically meant to be used as an insertion point for new plugins, etc.
  17307. *
  17308. * @extends Spacer
  17309. */
  17310. var CustomControlSpacer =
  17311. /*#__PURE__*/
  17312. function (_Spacer) {
  17313. _inheritsLoose(CustomControlSpacer, _Spacer);
  17314. function CustomControlSpacer() {
  17315. return _Spacer.apply(this, arguments) || this;
  17316. }
  17317. var _proto = CustomControlSpacer.prototype;
  17318. /**
  17319. * Builds the default DOM `className`.
  17320. *
  17321. * @return {string}
  17322. * The DOM `className` for this object.
  17323. */
  17324. _proto.buildCSSClass = function buildCSSClass() {
  17325. return "vjs-custom-control-spacer " + _Spacer.prototype.buildCSSClass.call(this);
  17326. }
  17327. /**
  17328. * Create the `Component`'s DOM element
  17329. *
  17330. * @return {Element}
  17331. * The element that was created.
  17332. */
  17333. ;
  17334. _proto.createEl = function createEl() {
  17335. var el = _Spacer.prototype.createEl.call(this, {
  17336. className: this.buildCSSClass()
  17337. }); // No-flex/table-cell mode requires there be some content
  17338. // in the cell to fill the remaining space of the table.
  17339. el.innerHTML = "\xA0";
  17340. return el;
  17341. };
  17342. return CustomControlSpacer;
  17343. }(Spacer);
  17344. Component.registerComponent('CustomControlSpacer', CustomControlSpacer);
  17345. /**
  17346. * Container of main controls.
  17347. *
  17348. * @extends Component
  17349. */
  17350. var ControlBar =
  17351. /*#__PURE__*/
  17352. function (_Component) {
  17353. _inheritsLoose(ControlBar, _Component);
  17354. function ControlBar() {
  17355. return _Component.apply(this, arguments) || this;
  17356. }
  17357. var _proto = ControlBar.prototype;
  17358. /**
  17359. * Create the `Component`'s DOM element
  17360. *
  17361. * @return {Element}
  17362. * The element that was created.
  17363. */
  17364. _proto.createEl = function createEl() {
  17365. return _Component.prototype.createEl.call(this, 'div', {
  17366. className: 'vjs-control-bar',
  17367. dir: 'ltr'
  17368. });
  17369. };
  17370. return ControlBar;
  17371. }(Component);
  17372. /**
  17373. * Default options for `ControlBar`
  17374. *
  17375. * @type {Object}
  17376. * @private
  17377. */
  17378. ControlBar.prototype.options_ = {
  17379. children: ['playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'seekToLive', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'descriptionsButton', 'subsCapsButton', 'audioTrackButton', 'fullscreenToggle']
  17380. };
  17381. if ('exitPictureInPicture' in document) {
  17382. ControlBar.prototype.options_.children.splice(ControlBar.prototype.options_.children.length - 1, 0, 'pictureInPictureToggle');
  17383. }
  17384. Component.registerComponent('ControlBar', ControlBar);
  17385. /**
  17386. * A display that indicates an error has occurred. This means that the video
  17387. * is unplayable.
  17388. *
  17389. * @extends ModalDialog
  17390. */
  17391. var ErrorDisplay =
  17392. /*#__PURE__*/
  17393. function (_ModalDialog) {
  17394. _inheritsLoose(ErrorDisplay, _ModalDialog);
  17395. /**
  17396. * Creates an instance of this class.
  17397. *
  17398. * @param {Player} player
  17399. * The `Player` that this class should be attached to.
  17400. *
  17401. * @param {Object} [options]
  17402. * The key/value store of player options.
  17403. */
  17404. function ErrorDisplay(player, options) {
  17405. var _this;
  17406. _this = _ModalDialog.call(this, player, options) || this;
  17407. _this.on(player, 'error', _this.open);
  17408. return _this;
  17409. }
  17410. /**
  17411. * Builds the default DOM `className`.
  17412. *
  17413. * @return {string}
  17414. * The DOM `className` for this object.
  17415. *
  17416. * @deprecated Since version 5.
  17417. */
  17418. var _proto = ErrorDisplay.prototype;
  17419. _proto.buildCSSClass = function buildCSSClass() {
  17420. return "vjs-error-display " + _ModalDialog.prototype.buildCSSClass.call(this);
  17421. }
  17422. /**
  17423. * Gets the localized error message based on the `Player`s error.
  17424. *
  17425. * @return {string}
  17426. * The `Player`s error message localized or an empty string.
  17427. */
  17428. ;
  17429. _proto.content = function content() {
  17430. var error = this.player().error();
  17431. return error ? this.localize(error.message) : '';
  17432. };
  17433. return ErrorDisplay;
  17434. }(ModalDialog);
  17435. /**
  17436. * The default options for an `ErrorDisplay`.
  17437. *
  17438. * @private
  17439. */
  17440. ErrorDisplay.prototype.options_ = mergeOptions(ModalDialog.prototype.options_, {
  17441. pauseOnOpen: false,
  17442. fillAlways: true,
  17443. temporary: false,
  17444. uncloseable: true
  17445. });
  17446. Component.registerComponent('ErrorDisplay', ErrorDisplay);
  17447. var LOCAL_STORAGE_KEY = 'vjs-text-track-settings';
  17448. var COLOR_BLACK = ['#000', 'Black'];
  17449. var COLOR_BLUE = ['#00F', 'Blue'];
  17450. var COLOR_CYAN = ['#0FF', 'Cyan'];
  17451. var COLOR_GREEN = ['#0F0', 'Green'];
  17452. var COLOR_MAGENTA = ['#F0F', 'Magenta'];
  17453. var COLOR_RED = ['#F00', 'Red'];
  17454. var COLOR_WHITE = ['#FFF', 'White'];
  17455. var COLOR_YELLOW = ['#FF0', 'Yellow'];
  17456. var OPACITY_OPAQUE = ['1', 'Opaque'];
  17457. var OPACITY_SEMI = ['0.5', 'Semi-Transparent'];
  17458. var OPACITY_TRANS = ['0', 'Transparent']; // Configuration for the various <select> elements in the DOM of this component.
  17459. //
  17460. // Possible keys include:
  17461. //
  17462. // `default`:
  17463. // The default option index. Only needs to be provided if not zero.
  17464. // `parser`:
  17465. // A function which is used to parse the value from the selected option in
  17466. // a customized way.
  17467. // `selector`:
  17468. // The selector used to find the associated <select> element.
  17469. var selectConfigs = {
  17470. backgroundColor: {
  17471. selector: '.vjs-bg-color > select',
  17472. id: 'captions-background-color-%s',
  17473. label: 'Color',
  17474. options: [COLOR_BLACK, COLOR_WHITE, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  17475. },
  17476. backgroundOpacity: {
  17477. selector: '.vjs-bg-opacity > select',
  17478. id: 'captions-background-opacity-%s',
  17479. label: 'Transparency',
  17480. options: [OPACITY_OPAQUE, OPACITY_SEMI, OPACITY_TRANS]
  17481. },
  17482. color: {
  17483. selector: '.vjs-fg-color > select',
  17484. id: 'captions-foreground-color-%s',
  17485. label: 'Color',
  17486. options: [COLOR_WHITE, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN]
  17487. },
  17488. edgeStyle: {
  17489. selector: '.vjs-edge-style > select',
  17490. id: '%s',
  17491. label: 'Text Edge Style',
  17492. options: [['none', 'None'], ['raised', 'Raised'], ['depressed', 'Depressed'], ['uniform', 'Uniform'], ['dropshadow', 'Dropshadow']]
  17493. },
  17494. fontFamily: {
  17495. selector: '.vjs-font-family > select',
  17496. id: 'captions-font-family-%s',
  17497. label: 'Font Family',
  17498. options: [['proportionalSansSerif', 'Proportional Sans-Serif'], ['monospaceSansSerif', 'Monospace Sans-Serif'], ['proportionalSerif', 'Proportional Serif'], ['monospaceSerif', 'Monospace Serif'], ['casual', 'Casual'], ['script', 'Script'], ['small-caps', 'Small Caps']]
  17499. },
  17500. fontPercent: {
  17501. selector: '.vjs-font-percent > select',
  17502. id: 'captions-font-size-%s',
  17503. label: 'Font Size',
  17504. 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%']],
  17505. "default": 2,
  17506. parser: function parser(v) {
  17507. return v === '1.00' ? null : Number(v);
  17508. }
  17509. },
  17510. textOpacity: {
  17511. selector: '.vjs-text-opacity > select',
  17512. id: 'captions-foreground-opacity-%s',
  17513. label: 'Transparency',
  17514. options: [OPACITY_OPAQUE, OPACITY_SEMI]
  17515. },
  17516. // Options for this object are defined below.
  17517. windowColor: {
  17518. selector: '.vjs-window-color > select',
  17519. id: 'captions-window-color-%s',
  17520. label: 'Color'
  17521. },
  17522. // Options for this object are defined below.
  17523. windowOpacity: {
  17524. selector: '.vjs-window-opacity > select',
  17525. id: 'captions-window-opacity-%s',
  17526. label: 'Transparency',
  17527. options: [OPACITY_TRANS, OPACITY_SEMI, OPACITY_OPAQUE]
  17528. }
  17529. };
  17530. selectConfigs.windowColor.options = selectConfigs.backgroundColor.options;
  17531. /**
  17532. * Get the actual value of an option.
  17533. *
  17534. * @param {string} value
  17535. * The value to get
  17536. *
  17537. * @param {Function} [parser]
  17538. * Optional function to adjust the value.
  17539. *
  17540. * @return {Mixed}
  17541. * - Will be `undefined` if no value exists
  17542. * - Will be `undefined` if the given value is "none".
  17543. * - Will be the actual value otherwise.
  17544. *
  17545. * @private
  17546. */
  17547. function parseOptionValue(value, parser) {
  17548. if (parser) {
  17549. value = parser(value);
  17550. }
  17551. if (value && value !== 'none') {
  17552. return value;
  17553. }
  17554. }
  17555. /**
  17556. * Gets the value of the selected <option> element within a <select> element.
  17557. *
  17558. * @param {Element} el
  17559. * the element to look in
  17560. *
  17561. * @param {Function} [parser]
  17562. * Optional function to adjust the value.
  17563. *
  17564. * @return {Mixed}
  17565. * - Will be `undefined` if no value exists
  17566. * - Will be `undefined` if the given value is "none".
  17567. * - Will be the actual value otherwise.
  17568. *
  17569. * @private
  17570. */
  17571. function getSelectedOptionValue(el, parser) {
  17572. var value = el.options[el.options.selectedIndex].value;
  17573. return parseOptionValue(value, parser);
  17574. }
  17575. /**
  17576. * Sets the selected <option> element within a <select> element based on a
  17577. * given value.
  17578. *
  17579. * @param {Element} el
  17580. * The element to look in.
  17581. *
  17582. * @param {string} value
  17583. * the property to look on.
  17584. *
  17585. * @param {Function} [parser]
  17586. * Optional function to adjust the value before comparing.
  17587. *
  17588. * @private
  17589. */
  17590. function setSelectedOption(el, value, parser) {
  17591. if (!value) {
  17592. return;
  17593. }
  17594. for (var i = 0; i < el.options.length; i++) {
  17595. if (parseOptionValue(el.options[i].value, parser) === value) {
  17596. el.selectedIndex = i;
  17597. break;
  17598. }
  17599. }
  17600. }
  17601. /**
  17602. * Manipulate Text Tracks settings.
  17603. *
  17604. * @extends ModalDialog
  17605. */
  17606. var TextTrackSettings =
  17607. /*#__PURE__*/
  17608. function (_ModalDialog) {
  17609. _inheritsLoose(TextTrackSettings, _ModalDialog);
  17610. /**
  17611. * Creates an instance of this class.
  17612. *
  17613. * @param {Player} player
  17614. * The `Player` that this class should be attached to.
  17615. *
  17616. * @param {Object} [options]
  17617. * The key/value store of player options.
  17618. */
  17619. function TextTrackSettings(player, options) {
  17620. var _this;
  17621. options.temporary = false;
  17622. _this = _ModalDialog.call(this, player, options) || this;
  17623. _this.updateDisplay = bind(_assertThisInitialized(_this), _this.updateDisplay); // fill the modal and pretend we have opened it
  17624. _this.fill();
  17625. _this.hasBeenOpened_ = _this.hasBeenFilled_ = true;
  17626. _this.endDialog = createEl('p', {
  17627. className: 'vjs-control-text',
  17628. textContent: _this.localize('End of dialog window.')
  17629. });
  17630. _this.el().appendChild(_this.endDialog);
  17631. _this.setDefaults(); // Grab `persistTextTrackSettings` from the player options if not passed in child options
  17632. if (options.persistTextTrackSettings === undefined) {
  17633. _this.options_.persistTextTrackSettings = _this.options_.playerOptions.persistTextTrackSettings;
  17634. }
  17635. _this.on(_this.$('.vjs-done-button'), 'click', function () {
  17636. _this.saveSettings();
  17637. _this.close();
  17638. });
  17639. _this.on(_this.$('.vjs-default-button'), 'click', function () {
  17640. _this.setDefaults();
  17641. _this.updateDisplay();
  17642. });
  17643. each(selectConfigs, function (config) {
  17644. _this.on(_this.$(config.selector), 'change', _this.updateDisplay);
  17645. });
  17646. if (_this.options_.persistTextTrackSettings) {
  17647. _this.restoreSettings();
  17648. }
  17649. return _this;
  17650. }
  17651. var _proto = TextTrackSettings.prototype;
  17652. _proto.dispose = function dispose() {
  17653. this.endDialog = null;
  17654. _ModalDialog.prototype.dispose.call(this);
  17655. }
  17656. /**
  17657. * Create a <select> element with configured options.
  17658. *
  17659. * @param {string} key
  17660. * Configuration key to use during creation.
  17661. *
  17662. * @return {string}
  17663. * An HTML string.
  17664. *
  17665. * @private
  17666. */
  17667. ;
  17668. _proto.createElSelect_ = function createElSelect_(key, legendId, type) {
  17669. var _this2 = this;
  17670. if (legendId === void 0) {
  17671. legendId = '';
  17672. }
  17673. if (type === void 0) {
  17674. type = 'label';
  17675. }
  17676. var config = selectConfigs[key];
  17677. var id = config.id.replace('%s', this.id_);
  17678. var selectLabelledbyIds = [legendId, id].join(' ').trim();
  17679. return ["<" + type + " id=\"" + id + "\" class=\"" + (type === 'label' ? 'vjs-label' : '') + "\">", this.localize(config.label), "</" + type + ">", "<select aria-labelledby=\"" + selectLabelledbyIds + "\">"].concat(config.options.map(function (o) {
  17680. var optionId = id + '-' + o[1].replace(/\W+/g, '');
  17681. return ["<option id=\"" + optionId + "\" value=\"" + o[0] + "\" ", "aria-labelledby=\"" + selectLabelledbyIds + " " + optionId + "\">", _this2.localize(o[1]), '</option>'].join('');
  17682. })).concat('</select>').join('');
  17683. }
  17684. /**
  17685. * Create foreground color element for the component
  17686. *
  17687. * @return {string}
  17688. * An HTML string.
  17689. *
  17690. * @private
  17691. */
  17692. ;
  17693. _proto.createElFgColor_ = function createElFgColor_() {
  17694. var legendId = "captions-text-legend-" + this.id_;
  17695. 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('');
  17696. }
  17697. /**
  17698. * Create background color element for the component
  17699. *
  17700. * @return {string}
  17701. * An HTML string.
  17702. *
  17703. * @private
  17704. */
  17705. ;
  17706. _proto.createElBgColor_ = function createElBgColor_() {
  17707. var legendId = "captions-background-" + this.id_;
  17708. 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('');
  17709. }
  17710. /**
  17711. * Create window color element for the component
  17712. *
  17713. * @return {string}
  17714. * An HTML string.
  17715. *
  17716. * @private
  17717. */
  17718. ;
  17719. _proto.createElWinColor_ = function createElWinColor_() {
  17720. var legendId = "captions-window-" + this.id_;
  17721. 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('');
  17722. }
  17723. /**
  17724. * Create color elements for the component
  17725. *
  17726. * @return {Element}
  17727. * The element that was created
  17728. *
  17729. * @private
  17730. */
  17731. ;
  17732. _proto.createElColors_ = function createElColors_() {
  17733. return createEl('div', {
  17734. className: 'vjs-track-settings-colors',
  17735. innerHTML: [this.createElFgColor_(), this.createElBgColor_(), this.createElWinColor_()].join('')
  17736. });
  17737. }
  17738. /**
  17739. * Create font elements for the component
  17740. *
  17741. * @return {Element}
  17742. * The element that was created.
  17743. *
  17744. * @private
  17745. */
  17746. ;
  17747. _proto.createElFont_ = function createElFont_() {
  17748. return createEl('div', {
  17749. className: 'vjs-track-settings-font',
  17750. 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('')
  17751. });
  17752. }
  17753. /**
  17754. * Create controls for the component
  17755. *
  17756. * @return {Element}
  17757. * The element that was created.
  17758. *
  17759. * @private
  17760. */
  17761. ;
  17762. _proto.createElControls_ = function createElControls_() {
  17763. var defaultsDescription = this.localize('restore all settings to the default values');
  17764. return createEl('div', {
  17765. className: 'vjs-track-settings-controls',
  17766. 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('')
  17767. });
  17768. };
  17769. _proto.content = function content() {
  17770. return [this.createElColors_(), this.createElFont_(), this.createElControls_()];
  17771. };
  17772. _proto.label = function label() {
  17773. return this.localize('Caption Settings Dialog');
  17774. };
  17775. _proto.description = function description() {
  17776. return this.localize('Beginning of dialog window. Escape will cancel and close the window.');
  17777. };
  17778. _proto.buildCSSClass = function buildCSSClass() {
  17779. return _ModalDialog.prototype.buildCSSClass.call(this) + ' vjs-text-track-settings';
  17780. }
  17781. /**
  17782. * Gets an object of text track settings (or null).
  17783. *
  17784. * @return {Object}
  17785. * An object with config values parsed from the DOM or localStorage.
  17786. */
  17787. ;
  17788. _proto.getValues = function getValues() {
  17789. var _this3 = this;
  17790. return reduce(selectConfigs, function (accum, config, key) {
  17791. var value = getSelectedOptionValue(_this3.$(config.selector), config.parser);
  17792. if (value !== undefined) {
  17793. accum[key] = value;
  17794. }
  17795. return accum;
  17796. }, {});
  17797. }
  17798. /**
  17799. * Sets text track settings from an object of values.
  17800. *
  17801. * @param {Object} values
  17802. * An object with config values parsed from the DOM or localStorage.
  17803. */
  17804. ;
  17805. _proto.setValues = function setValues(values) {
  17806. var _this4 = this;
  17807. each(selectConfigs, function (config, key) {
  17808. setSelectedOption(_this4.$(config.selector), values[key], config.parser);
  17809. });
  17810. }
  17811. /**
  17812. * Sets all `<select>` elements to their default values.
  17813. */
  17814. ;
  17815. _proto.setDefaults = function setDefaults() {
  17816. var _this5 = this;
  17817. each(selectConfigs, function (config) {
  17818. var index = config.hasOwnProperty('default') ? config["default"] : 0;
  17819. _this5.$(config.selector).selectedIndex = index;
  17820. });
  17821. }
  17822. /**
  17823. * Restore texttrack settings from localStorage
  17824. */
  17825. ;
  17826. _proto.restoreSettings = function restoreSettings() {
  17827. var values;
  17828. try {
  17829. values = JSON.parse(window$1.localStorage.getItem(LOCAL_STORAGE_KEY));
  17830. } catch (err) {
  17831. log.warn(err);
  17832. }
  17833. if (values) {
  17834. this.setValues(values);
  17835. }
  17836. }
  17837. /**
  17838. * Save text track settings to localStorage
  17839. */
  17840. ;
  17841. _proto.saveSettings = function saveSettings() {
  17842. if (!this.options_.persistTextTrackSettings) {
  17843. return;
  17844. }
  17845. var values = this.getValues();
  17846. try {
  17847. if (Object.keys(values).length) {
  17848. window$1.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(values));
  17849. } else {
  17850. window$1.localStorage.removeItem(LOCAL_STORAGE_KEY);
  17851. }
  17852. } catch (err) {
  17853. log.warn(err);
  17854. }
  17855. }
  17856. /**
  17857. * Update display of text track settings
  17858. */
  17859. ;
  17860. _proto.updateDisplay = function updateDisplay() {
  17861. var ttDisplay = this.player_.getChild('textTrackDisplay');
  17862. if (ttDisplay) {
  17863. ttDisplay.updateDisplay();
  17864. }
  17865. }
  17866. /**
  17867. * conditionally blur the element and refocus the captions button
  17868. *
  17869. * @private
  17870. */
  17871. ;
  17872. _proto.conditionalBlur_ = function conditionalBlur_() {
  17873. this.previouslyActiveEl_ = null;
  17874. var cb = this.player_.controlBar;
  17875. var subsCapsBtn = cb && cb.subsCapsButton;
  17876. var ccBtn = cb && cb.captionsButton;
  17877. if (subsCapsBtn) {
  17878. subsCapsBtn.focus();
  17879. } else if (ccBtn) {
  17880. ccBtn.focus();
  17881. }
  17882. };
  17883. return TextTrackSettings;
  17884. }(ModalDialog);
  17885. Component.registerComponent('TextTrackSettings', TextTrackSettings);
  17886. /**
  17887. * A Resize Manager. It is in charge of triggering `playerresize` on the player in the right conditions.
  17888. *
  17889. * 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}.
  17890. *
  17891. * If the ResizeObserver is available natively, it will be used. A polyfill can be passed in as an option.
  17892. * If a `playerresize` event is not needed, the ResizeManager component can be removed from the player, see the example below.
  17893. * @example <caption>How to disable the resize manager</caption>
  17894. * const player = videojs('#vid', {
  17895. * resizeManager: false
  17896. * });
  17897. *
  17898. * @see {@link https://wicg.github.io/ResizeObserver/|ResizeObserver specification}
  17899. *
  17900. * @extends Component
  17901. */
  17902. var ResizeManager =
  17903. /*#__PURE__*/
  17904. function (_Component) {
  17905. _inheritsLoose(ResizeManager, _Component);
  17906. /**
  17907. * Create the ResizeManager.
  17908. *
  17909. * @param {Object} player
  17910. * The `Player` that this class should be attached to.
  17911. *
  17912. * @param {Object} [options]
  17913. * The key/value store of ResizeManager options.
  17914. *
  17915. * @param {Object} [options.ResizeObserver]
  17916. * A polyfill for ResizeObserver can be passed in here.
  17917. * If this is set to null it will ignore the native ResizeObserver and fall back to the iframe fallback.
  17918. */
  17919. function ResizeManager(player, options) {
  17920. var _this;
  17921. var RESIZE_OBSERVER_AVAILABLE = options.ResizeObserver || window$1.ResizeObserver; // if `null` was passed, we want to disable the ResizeObserver
  17922. if (options.ResizeObserver === null) {
  17923. RESIZE_OBSERVER_AVAILABLE = false;
  17924. } // Only create an element when ResizeObserver isn't available
  17925. var options_ = mergeOptions({
  17926. createEl: !RESIZE_OBSERVER_AVAILABLE,
  17927. reportTouchActivity: false
  17928. }, options);
  17929. _this = _Component.call(this, player, options_) || this;
  17930. _this.ResizeObserver = options.ResizeObserver || window$1.ResizeObserver;
  17931. _this.loadListener_ = null;
  17932. _this.resizeObserver_ = null;
  17933. _this.debouncedHandler_ = debounce(function () {
  17934. _this.resizeHandler();
  17935. }, 100, false, _assertThisInitialized(_this));
  17936. if (RESIZE_OBSERVER_AVAILABLE) {
  17937. _this.resizeObserver_ = new _this.ResizeObserver(_this.debouncedHandler_);
  17938. _this.resizeObserver_.observe(player.el());
  17939. } else {
  17940. _this.loadListener_ = function () {
  17941. if (!_this.el_ || !_this.el_.contentWindow) {
  17942. return;
  17943. }
  17944. var debouncedHandler_ = _this.debouncedHandler_;
  17945. var unloadListener_ = _this.unloadListener_ = function () {
  17946. off(this, 'resize', debouncedHandler_);
  17947. off(this, 'unload', unloadListener_);
  17948. unloadListener_ = null;
  17949. }; // safari and edge can unload the iframe before resizemanager dispose
  17950. // we have to dispose of event handlers correctly before that happens
  17951. on(_this.el_.contentWindow, 'unload', unloadListener_);
  17952. on(_this.el_.contentWindow, 'resize', debouncedHandler_);
  17953. };
  17954. _this.one('load', _this.loadListener_);
  17955. }
  17956. return _this;
  17957. }
  17958. var _proto = ResizeManager.prototype;
  17959. _proto.createEl = function createEl() {
  17960. return _Component.prototype.createEl.call(this, 'iframe', {
  17961. className: 'vjs-resize-manager',
  17962. tabIndex: -1
  17963. }, {
  17964. 'aria-hidden': 'true'
  17965. });
  17966. }
  17967. /**
  17968. * Called when a resize is triggered on the iframe or a resize is observed via the ResizeObserver
  17969. *
  17970. * @fires Player#playerresize
  17971. */
  17972. ;
  17973. _proto.resizeHandler = function resizeHandler() {
  17974. /**
  17975. * Called when the player size has changed
  17976. *
  17977. * @event Player#playerresize
  17978. * @type {EventTarget~Event}
  17979. */
  17980. // make sure player is still around to trigger
  17981. // prevents this from causing an error after dispose
  17982. if (!this.player_ || !this.player_.trigger) {
  17983. return;
  17984. }
  17985. this.player_.trigger('playerresize');
  17986. };
  17987. _proto.dispose = function dispose() {
  17988. if (this.debouncedHandler_) {
  17989. this.debouncedHandler_.cancel();
  17990. }
  17991. if (this.resizeObserver_) {
  17992. if (this.player_.el()) {
  17993. this.resizeObserver_.unobserve(this.player_.el());
  17994. }
  17995. this.resizeObserver_.disconnect();
  17996. }
  17997. if (this.loadListener_) {
  17998. this.off('load', this.loadListener_);
  17999. }
  18000. if (this.el_ && this.el_.contentWindow && this.unloadListener_) {
  18001. this.unloadListener_.call(this.el_.contentWindow);
  18002. }
  18003. this.ResizeObserver = null;
  18004. this.resizeObserver = null;
  18005. this.debouncedHandler_ = null;
  18006. this.loadListener_ = null;
  18007. _Component.prototype.dispose.call(this);
  18008. };
  18009. return ResizeManager;
  18010. }(Component);
  18011. Component.registerComponent('ResizeManager', ResizeManager);
  18012. /**
  18013. * Computes the median of an array.
  18014. *
  18015. * @param {number[]} arr
  18016. * Input array of numbers.
  18017. *
  18018. * @return {number}
  18019. * Median value.
  18020. */
  18021. var median = function median(arr) {
  18022. var mid = Math.floor(arr.length / 2);
  18023. var sortedList = [].concat(arr).sort(function (a, b) {
  18024. return a - b;
  18025. });
  18026. return arr.length % 2 !== 0 ? sortedList[mid] : (sortedList[mid - 1] + sortedList[mid]) / 2;
  18027. };
  18028. /* track when we are at the live edge, and other helpers for live playback */
  18029. var LiveTracker =
  18030. /*#__PURE__*/
  18031. function (_Component) {
  18032. _inheritsLoose(LiveTracker, _Component);
  18033. function LiveTracker(player, options) {
  18034. var _this;
  18035. // LiveTracker does not need an element
  18036. var options_ = mergeOptions({
  18037. createEl: false
  18038. }, options);
  18039. _this = _Component.call(this, player, options_) || this;
  18040. _this.reset_();
  18041. _this.on(_this.player_, 'durationchange', _this.handleDurationchange); // we don't need to track live playback if the document is hidden,
  18042. // also, tracking when the document is hidden can
  18043. // cause the CPU to spike and eventually crash the page on IE11.
  18044. if (IE_VERSION && 'hidden' in document && 'visibilityState' in document) {
  18045. _this.on(document, 'visibilitychange', _this.handleVisibilityChange);
  18046. }
  18047. return _this;
  18048. }
  18049. var _proto = LiveTracker.prototype;
  18050. _proto.handleVisibilityChange = function handleVisibilityChange() {
  18051. if (this.player_.duration() !== Infinity) {
  18052. return;
  18053. }
  18054. if (document.hidden) {
  18055. this.stopTracking();
  18056. } else {
  18057. this.startTracking();
  18058. }
  18059. };
  18060. _proto.isBehind_ = function isBehind_() {
  18061. // don't report that we are behind until a timeupdate has been seen
  18062. if (!this.timeupdateSeen_) {
  18063. return false;
  18064. }
  18065. var liveCurrentTime = this.liveCurrentTime();
  18066. var currentTime = this.player_.currentTime(); // the live edge window is the amount of seconds away from live
  18067. // that a player can be, but still be considered live.
  18068. // we add 0.07 because the live tracking happens every 30ms
  18069. // and we want some wiggle room for short segment live playback
  18070. var liveEdgeWindow = this.seekableIncrement_ * 2 + 0.07; // on Android liveCurrentTime can bee Infinity, because seekableEnd
  18071. // can be Infinity, so we handle that case.
  18072. return liveCurrentTime !== Infinity && liveCurrentTime - liveEdgeWindow >= currentTime;
  18073. } // all the functionality for tracking when seek end changes
  18074. // and for tracking how far past seek end we should be
  18075. ;
  18076. _proto.trackLive_ = function trackLive_() {
  18077. this.pastSeekEnd_ = this.pastSeekEnd_;
  18078. var seekable = this.player_.seekable(); // skip undefined seekable
  18079. if (!seekable || !seekable.length) {
  18080. return;
  18081. }
  18082. var newSeekEnd = this.seekableEnd(); // we can only tell if we are behind live, when seekable changes
  18083. // once we detect that seekable has changed we check the new seek
  18084. // end against current time, with a fudge value of half a second.
  18085. if (newSeekEnd !== this.lastSeekEnd_) {
  18086. if (this.lastSeekEnd_) {
  18087. // we try to get the best fit value for the seeking increment
  18088. // variable from the last 12 values.
  18089. this.seekableIncrementList_ = this.seekableIncrementList_.slice(-11);
  18090. this.seekableIncrementList_.push(Math.abs(newSeekEnd - this.lastSeekEnd_));
  18091. if (this.seekableIncrementList_.length > 3) {
  18092. this.seekableIncrement_ = median(this.seekableIncrementList_);
  18093. }
  18094. }
  18095. this.pastSeekEnd_ = 0;
  18096. this.lastSeekEnd_ = newSeekEnd;
  18097. this.trigger('seekableendchange');
  18098. }
  18099. this.pastSeekEnd_ = this.pastSeekEnd() + 0.03;
  18100. if (this.isBehind_() !== this.behindLiveEdge()) {
  18101. this.behindLiveEdge_ = this.isBehind_();
  18102. this.trigger('liveedgechange');
  18103. }
  18104. }
  18105. /**
  18106. * handle a durationchange event on the player
  18107. * and start/stop tracking accordingly.
  18108. */
  18109. ;
  18110. _proto.handleDurationchange = function handleDurationchange() {
  18111. if (this.player_.duration() === Infinity) {
  18112. this.startTracking();
  18113. } else {
  18114. this.stopTracking();
  18115. }
  18116. }
  18117. /**
  18118. * start tracking live playback
  18119. */
  18120. ;
  18121. _proto.startTracking = function startTracking() {
  18122. var _this2 = this;
  18123. if (this.isTracking()) {
  18124. return;
  18125. } // If we haven't seen a timeupdate, we need to check whether playback
  18126. // began before this component started tracking. This can happen commonly
  18127. // when using autoplay.
  18128. if (!this.timeupdateSeen_) {
  18129. this.timeupdateSeen_ = this.player_.hasStarted();
  18130. }
  18131. this.trackingInterval_ = this.setInterval(this.trackLive_, 30);
  18132. this.trackLive_();
  18133. this.on(this.player_, 'play', this.trackLive_);
  18134. this.on(this.player_, 'pause', this.trackLive_); // this is to prevent showing that we are not live
  18135. // before a video starts to play
  18136. if (!this.timeupdateSeen_) {
  18137. this.one(this.player_, 'play', this.handlePlay);
  18138. this.handleTimeupdate = function () {
  18139. _this2.timeupdateSeen_ = true;
  18140. _this2.handleTimeupdate = null;
  18141. };
  18142. this.one(this.player_, 'timeupdate', this.handleTimeupdate);
  18143. }
  18144. };
  18145. _proto.handlePlay = function handlePlay() {
  18146. this.one(this.player_, 'timeupdate', this.seekToLiveEdge);
  18147. }
  18148. /**
  18149. * Stop tracking, and set all internal variables to
  18150. * their initial value.
  18151. */
  18152. ;
  18153. _proto.reset_ = function reset_() {
  18154. this.pastSeekEnd_ = 0;
  18155. this.lastSeekEnd_ = null;
  18156. this.behindLiveEdge_ = null;
  18157. this.timeupdateSeen_ = false;
  18158. this.clearInterval(this.trackingInterval_);
  18159. this.trackingInterval_ = null;
  18160. this.seekableIncrement_ = 12;
  18161. this.seekableIncrementList_ = [];
  18162. this.off(this.player_, 'play', this.trackLive_);
  18163. this.off(this.player_, 'pause', this.trackLive_);
  18164. this.off(this.player_, 'play', this.handlePlay);
  18165. this.off(this.player_, 'timeupdate', this.seekToLiveEdge);
  18166. if (this.handleTimeupdate) {
  18167. this.off(this.player_, 'timeupdate', this.handleTimeupdate);
  18168. this.handleTimeupdate = null;
  18169. }
  18170. }
  18171. /**
  18172. * stop tracking live playback
  18173. */
  18174. ;
  18175. _proto.stopTracking = function stopTracking() {
  18176. if (!this.isTracking()) {
  18177. return;
  18178. }
  18179. this.reset_();
  18180. }
  18181. /**
  18182. * A helper to get the player seekable end
  18183. * so that we don't have to null check everywhere
  18184. */
  18185. ;
  18186. _proto.seekableEnd = function seekableEnd() {
  18187. var seekable = this.player_.seekable();
  18188. var seekableEnds = [];
  18189. var i = seekable ? seekable.length : 0;
  18190. while (i--) {
  18191. seekableEnds.push(seekable.end(i));
  18192. } // grab the furthest seekable end after sorting, or if there are none
  18193. // default to Infinity
  18194. return seekableEnds.length ? seekableEnds.sort()[seekableEnds.length - 1] : Infinity;
  18195. }
  18196. /**
  18197. * A helper to get the player seekable start
  18198. * so that we don't have to null check everywhere
  18199. */
  18200. ;
  18201. _proto.seekableStart = function seekableStart() {
  18202. var seekable = this.player_.seekable();
  18203. var seekableStarts = [];
  18204. var i = seekable ? seekable.length : 0;
  18205. while (i--) {
  18206. seekableStarts.push(seekable.start(i));
  18207. } // grab the first seekable start after sorting, or if there are none
  18208. // default to 0
  18209. return seekableStarts.length ? seekableStarts.sort()[0] : 0;
  18210. }
  18211. /**
  18212. * Get the live time window
  18213. */
  18214. ;
  18215. _proto.liveWindow = function liveWindow() {
  18216. var liveCurrentTime = this.liveCurrentTime();
  18217. if (liveCurrentTime === Infinity) {
  18218. return Infinity;
  18219. }
  18220. return liveCurrentTime - this.seekableStart();
  18221. }
  18222. /**
  18223. * Determines if the player is live, only checks if this component
  18224. * is tracking live playback or not
  18225. */
  18226. ;
  18227. _proto.isLive = function isLive() {
  18228. return this.isTracking();
  18229. }
  18230. /**
  18231. * Determines if currentTime is at the live edge and won't fall behind
  18232. * on each seekableendchange
  18233. */
  18234. ;
  18235. _proto.atLiveEdge = function atLiveEdge() {
  18236. return !this.behindLiveEdge();
  18237. }
  18238. /**
  18239. * get what we expect the live current time to be
  18240. */
  18241. ;
  18242. _proto.liveCurrentTime = function liveCurrentTime() {
  18243. return this.pastSeekEnd() + this.seekableEnd();
  18244. }
  18245. /**
  18246. * Returns how far past seek end we expect current time to be
  18247. */
  18248. ;
  18249. _proto.pastSeekEnd = function pastSeekEnd() {
  18250. return this.pastSeekEnd_;
  18251. }
  18252. /**
  18253. * If we are currently behind the live edge, aka currentTime will be
  18254. * behind on a seekableendchange
  18255. */
  18256. ;
  18257. _proto.behindLiveEdge = function behindLiveEdge() {
  18258. return this.behindLiveEdge_;
  18259. };
  18260. _proto.isTracking = function isTracking() {
  18261. return typeof this.trackingInterval_ === 'number';
  18262. }
  18263. /**
  18264. * Seek to the live edge if we are behind the live edge
  18265. */
  18266. ;
  18267. _proto.seekToLiveEdge = function seekToLiveEdge() {
  18268. if (this.atLiveEdge()) {
  18269. return;
  18270. }
  18271. this.player_.currentTime(this.liveCurrentTime());
  18272. if (this.player_.paused()) {
  18273. this.player_.play();
  18274. }
  18275. };
  18276. _proto.dispose = function dispose() {
  18277. this.stopTracking();
  18278. _Component.prototype.dispose.call(this);
  18279. };
  18280. return LiveTracker;
  18281. }(Component);
  18282. Component.registerComponent('LiveTracker', LiveTracker);
  18283. /**
  18284. * This function is used to fire a sourceset when there is something
  18285. * similar to `mediaEl.load()` being called. It will try to find the source via
  18286. * the `src` attribute and then the `<source>` elements. It will then fire `sourceset`
  18287. * with the source that was found or empty string if we cannot know. If it cannot
  18288. * find a source then `sourceset` will not be fired.
  18289. *
  18290. * @param {Html5} tech
  18291. * The tech object that sourceset was setup on
  18292. *
  18293. * @return {boolean}
  18294. * returns false if the sourceset was not fired and true otherwise.
  18295. */
  18296. var sourcesetLoad = function sourcesetLoad(tech) {
  18297. var el = tech.el(); // if `el.src` is set, that source will be loaded.
  18298. if (el.hasAttribute('src')) {
  18299. tech.triggerSourceset(el.src);
  18300. return true;
  18301. }
  18302. /**
  18303. * Since there isn't a src property on the media element, source elements will be used for
  18304. * implementing the source selection algorithm. This happens asynchronously and
  18305. * for most cases were there is more than one source we cannot tell what source will
  18306. * be loaded, without re-implementing the source selection algorithm. At this time we are not
  18307. * going to do that. There are three special cases that we do handle here though:
  18308. *
  18309. * 1. If there are no sources, do not fire `sourceset`.
  18310. * 2. If there is only one `<source>` with a `src` property/attribute that is our `src`
  18311. * 3. If there is more than one `<source>` but all of them have the same `src` url.
  18312. * That will be our src.
  18313. */
  18314. var sources = tech.$$('source');
  18315. var srcUrls = [];
  18316. var src = ''; // if there are no sources, do not fire sourceset
  18317. if (!sources.length) {
  18318. return false;
  18319. } // only count valid/non-duplicate source elements
  18320. for (var i = 0; i < sources.length; i++) {
  18321. var url = sources[i].src;
  18322. if (url && srcUrls.indexOf(url) === -1) {
  18323. srcUrls.push(url);
  18324. }
  18325. } // there were no valid sources
  18326. if (!srcUrls.length) {
  18327. return false;
  18328. } // there is only one valid source element url
  18329. // use that
  18330. if (srcUrls.length === 1) {
  18331. src = srcUrls[0];
  18332. }
  18333. tech.triggerSourceset(src);
  18334. return true;
  18335. };
  18336. /**
  18337. * our implementation of an `innerHTML` descriptor for browsers
  18338. * that do not have one.
  18339. */
  18340. var innerHTMLDescriptorPolyfill = Object.defineProperty({}, 'innerHTML', {
  18341. get: function get() {
  18342. return this.cloneNode(true).innerHTML;
  18343. },
  18344. set: function set(v) {
  18345. // make a dummy node to use innerHTML on
  18346. var dummy = document.createElement(this.nodeName.toLowerCase()); // set innerHTML to the value provided
  18347. dummy.innerHTML = v; // make a document fragment to hold the nodes from dummy
  18348. var docFrag = document.createDocumentFragment(); // copy all of the nodes created by the innerHTML on dummy
  18349. // to the document fragment
  18350. while (dummy.childNodes.length) {
  18351. docFrag.appendChild(dummy.childNodes[0]);
  18352. } // remove content
  18353. this.innerText = ''; // now we add all of that html in one by appending the
  18354. // document fragment. This is how innerHTML does it.
  18355. window$1.Element.prototype.appendChild.call(this, docFrag); // then return the result that innerHTML's setter would
  18356. return this.innerHTML;
  18357. }
  18358. });
  18359. /**
  18360. * Get a property descriptor given a list of priorities and the
  18361. * property to get.
  18362. */
  18363. var getDescriptor = function getDescriptor(priority, prop) {
  18364. var descriptor = {};
  18365. for (var i = 0; i < priority.length; i++) {
  18366. descriptor = Object.getOwnPropertyDescriptor(priority[i], prop);
  18367. if (descriptor && descriptor.set && descriptor.get) {
  18368. break;
  18369. }
  18370. }
  18371. descriptor.enumerable = true;
  18372. descriptor.configurable = true;
  18373. return descriptor;
  18374. };
  18375. var getInnerHTMLDescriptor = function getInnerHTMLDescriptor(tech) {
  18376. return getDescriptor([tech.el(), window$1.HTMLMediaElement.prototype, window$1.Element.prototype, innerHTMLDescriptorPolyfill], 'innerHTML');
  18377. };
  18378. /**
  18379. * Patches browser internal functions so that we can tell synchronously
  18380. * if a `<source>` was appended to the media element. For some reason this
  18381. * causes a `sourceset` if the the media element is ready and has no source.
  18382. * This happens when:
  18383. * - The page has just loaded and the media element does not have a source.
  18384. * - The media element was emptied of all sources, then `load()` was called.
  18385. *
  18386. * It does this by patching the following functions/properties when they are supported:
  18387. *
  18388. * - `append()` - can be used to add a `<source>` element to the media element
  18389. * - `appendChild()` - can be used to add a `<source>` element to the media element
  18390. * - `insertAdjacentHTML()` - can be used to add a `<source>` element to the media element
  18391. * - `innerHTML` - can be used to add a `<source>` element to the media element
  18392. *
  18393. * @param {Html5} tech
  18394. * The tech object that sourceset is being setup on.
  18395. */
  18396. var firstSourceWatch = function firstSourceWatch(tech) {
  18397. var el = tech.el(); // make sure firstSourceWatch isn't setup twice.
  18398. if (el.resetSourceWatch_) {
  18399. return;
  18400. }
  18401. var old = {};
  18402. var innerDescriptor = getInnerHTMLDescriptor(tech);
  18403. var appendWrapper = function appendWrapper(appendFn) {
  18404. return function () {
  18405. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  18406. args[_key] = arguments[_key];
  18407. }
  18408. var retval = appendFn.apply(el, args);
  18409. sourcesetLoad(tech);
  18410. return retval;
  18411. };
  18412. };
  18413. ['append', 'appendChild', 'insertAdjacentHTML'].forEach(function (k) {
  18414. if (!el[k]) {
  18415. return;
  18416. } // store the old function
  18417. old[k] = el[k]; // call the old function with a sourceset if a source
  18418. // was loaded
  18419. el[k] = appendWrapper(old[k]);
  18420. });
  18421. Object.defineProperty(el, 'innerHTML', mergeOptions(innerDescriptor, {
  18422. set: appendWrapper(innerDescriptor.set)
  18423. }));
  18424. el.resetSourceWatch_ = function () {
  18425. el.resetSourceWatch_ = null;
  18426. Object.keys(old).forEach(function (k) {
  18427. el[k] = old[k];
  18428. });
  18429. Object.defineProperty(el, 'innerHTML', innerDescriptor);
  18430. }; // on the first sourceset, we need to revert our changes
  18431. tech.one('sourceset', el.resetSourceWatch_);
  18432. };
  18433. /**
  18434. * our implementation of a `src` descriptor for browsers
  18435. * that do not have one.
  18436. */
  18437. var srcDescriptorPolyfill = Object.defineProperty({}, 'src', {
  18438. get: function get() {
  18439. if (this.hasAttribute('src')) {
  18440. return getAbsoluteURL(window$1.Element.prototype.getAttribute.call(this, 'src'));
  18441. }
  18442. return '';
  18443. },
  18444. set: function set(v) {
  18445. window$1.Element.prototype.setAttribute.call(this, 'src', v);
  18446. return v;
  18447. }
  18448. });
  18449. var getSrcDescriptor = function getSrcDescriptor(tech) {
  18450. return getDescriptor([tech.el(), window$1.HTMLMediaElement.prototype, srcDescriptorPolyfill], 'src');
  18451. };
  18452. /**
  18453. * setup `sourceset` handling on the `Html5` tech. This function
  18454. * patches the following element properties/functions:
  18455. *
  18456. * - `src` - to determine when `src` is set
  18457. * - `setAttribute()` - to determine when `src` is set
  18458. * - `load()` - this re-triggers the source selection algorithm, and can
  18459. * cause a sourceset.
  18460. *
  18461. * If there is no source when we are adding `sourceset` support or during a `load()`
  18462. * we also patch the functions listed in `firstSourceWatch`.
  18463. *
  18464. * @param {Html5} tech
  18465. * The tech to patch
  18466. */
  18467. var setupSourceset = function setupSourceset(tech) {
  18468. if (!tech.featuresSourceset) {
  18469. return;
  18470. }
  18471. var el = tech.el(); // make sure sourceset isn't setup twice.
  18472. if (el.resetSourceset_) {
  18473. return;
  18474. }
  18475. var srcDescriptor = getSrcDescriptor(tech);
  18476. var oldSetAttribute = el.setAttribute;
  18477. var oldLoad = el.load;
  18478. Object.defineProperty(el, 'src', mergeOptions(srcDescriptor, {
  18479. set: function set(v) {
  18480. var retval = srcDescriptor.set.call(el, v); // we use the getter here to get the actual value set on src
  18481. tech.triggerSourceset(el.src);
  18482. return retval;
  18483. }
  18484. }));
  18485. el.setAttribute = function (n, v) {
  18486. var retval = oldSetAttribute.call(el, n, v);
  18487. if (/src/i.test(n)) {
  18488. tech.triggerSourceset(el.src);
  18489. }
  18490. return retval;
  18491. };
  18492. el.load = function () {
  18493. var retval = oldLoad.call(el); // if load was called, but there was no source to fire
  18494. // sourceset on. We have to watch for a source append
  18495. // as that can trigger a `sourceset` when the media element
  18496. // has no source
  18497. if (!sourcesetLoad(tech)) {
  18498. tech.triggerSourceset('');
  18499. firstSourceWatch(tech);
  18500. }
  18501. return retval;
  18502. };
  18503. if (el.currentSrc) {
  18504. tech.triggerSourceset(el.currentSrc);
  18505. } else if (!sourcesetLoad(tech)) {
  18506. firstSourceWatch(tech);
  18507. }
  18508. el.resetSourceset_ = function () {
  18509. el.resetSourceset_ = null;
  18510. el.load = oldLoad;
  18511. el.setAttribute = oldSetAttribute;
  18512. Object.defineProperty(el, 'src', srcDescriptor);
  18513. if (el.resetSourceWatch_) {
  18514. el.resetSourceWatch_();
  18515. }
  18516. };
  18517. };
  18518. /**
  18519. * HTML5 Media Controller - Wrapper for HTML5 Media API
  18520. *
  18521. * @mixes Tech~SourceHandlerAdditions
  18522. * @extends Tech
  18523. */
  18524. var Html5 =
  18525. /*#__PURE__*/
  18526. function (_Tech) {
  18527. _inheritsLoose(Html5, _Tech);
  18528. /**
  18529. * Create an instance of this Tech.
  18530. *
  18531. * @param {Object} [options]
  18532. * The key/value store of player options.
  18533. *
  18534. * @param {Component~ReadyCallback} ready
  18535. * Callback function to call when the `HTML5` Tech is ready.
  18536. */
  18537. function Html5(options, ready) {
  18538. var _this;
  18539. _this = _Tech.call(this, options, ready) || this;
  18540. var source = options.source;
  18541. var crossoriginTracks = false; // Set the source if one is provided
  18542. // 1) Check if the source is new (if not, we want to keep the original so playback isn't interrupted)
  18543. // 2) Check to see if the network state of the tag was failed at init, and if so, reset the source
  18544. // anyway so the error gets fired.
  18545. if (source && (_this.el_.currentSrc !== source.src || options.tag && options.tag.initNetworkState_ === 3)) {
  18546. _this.setSource(source);
  18547. } else {
  18548. _this.handleLateInit_(_this.el_);
  18549. } // setup sourceset after late sourceset/init
  18550. if (options.enableSourceset) {
  18551. _this.setupSourcesetHandling_();
  18552. }
  18553. if (_this.el_.hasChildNodes()) {
  18554. var nodes = _this.el_.childNodes;
  18555. var nodesLength = nodes.length;
  18556. var removeNodes = [];
  18557. while (nodesLength--) {
  18558. var node = nodes[nodesLength];
  18559. var nodeName = node.nodeName.toLowerCase();
  18560. if (nodeName === 'track') {
  18561. if (!_this.featuresNativeTextTracks) {
  18562. // Empty video tag tracks so the built-in player doesn't use them also.
  18563. // This may not be fast enough to stop HTML5 browsers from reading the tags
  18564. // so we'll need to turn off any default tracks if we're manually doing
  18565. // captions and subtitles. videoElement.textTracks
  18566. removeNodes.push(node);
  18567. } else {
  18568. // store HTMLTrackElement and TextTrack to remote list
  18569. _this.remoteTextTrackEls().addTrackElement_(node);
  18570. _this.remoteTextTracks().addTrack(node.track);
  18571. _this.textTracks().addTrack(node.track);
  18572. if (!crossoriginTracks && !_this.el_.hasAttribute('crossorigin') && isCrossOrigin(node.src)) {
  18573. crossoriginTracks = true;
  18574. }
  18575. }
  18576. }
  18577. }
  18578. for (var i = 0; i < removeNodes.length; i++) {
  18579. _this.el_.removeChild(removeNodes[i]);
  18580. }
  18581. }
  18582. _this.proxyNativeTracks_();
  18583. if (_this.featuresNativeTextTracks && crossoriginTracks) {
  18584. 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.');
  18585. } // prevent iOS Safari from disabling metadata text tracks during native playback
  18586. _this.restoreMetadataTracksInIOSNativePlayer_(); // Determine if native controls should be used
  18587. // Our goal should be to get the custom controls on mobile solid everywhere
  18588. // so we can remove this all together. Right now this will block custom
  18589. // controls on touch enabled laptops like the Chrome Pixel
  18590. if ((TOUCH_ENABLED || IS_IPHONE || IS_NATIVE_ANDROID) && options.nativeControlsForTouch === true) {
  18591. _this.setControls(true);
  18592. } // on iOS, we want to proxy `webkitbeginfullscreen` and `webkitendfullscreen`
  18593. // into a `fullscreenchange` event
  18594. _this.proxyWebkitFullscreen_();
  18595. _this.triggerReady();
  18596. return _this;
  18597. }
  18598. /**
  18599. * Dispose of `HTML5` media element and remove all tracks.
  18600. */
  18601. var _proto = Html5.prototype;
  18602. _proto.dispose = function dispose() {
  18603. if (this.el_ && this.el_.resetSourceset_) {
  18604. this.el_.resetSourceset_();
  18605. }
  18606. Html5.disposeMediaElement(this.el_);
  18607. this.options_ = null; // tech will handle clearing of the emulated track list
  18608. _Tech.prototype.dispose.call(this);
  18609. }
  18610. /**
  18611. * Modify the media element so that we can detect when
  18612. * the source is changed. Fires `sourceset` just after the source has changed
  18613. */
  18614. ;
  18615. _proto.setupSourcesetHandling_ = function setupSourcesetHandling_() {
  18616. setupSourceset(this);
  18617. }
  18618. /**
  18619. * When a captions track is enabled in the iOS Safari native player, all other
  18620. * tracks are disabled (including metadata tracks), which nulls all of their
  18621. * associated cue points. This will restore metadata tracks to their pre-fullscreen
  18622. * state in those cases so that cue points are not needlessly lost.
  18623. *
  18624. * @private
  18625. */
  18626. ;
  18627. _proto.restoreMetadataTracksInIOSNativePlayer_ = function restoreMetadataTracksInIOSNativePlayer_() {
  18628. var textTracks = this.textTracks();
  18629. var metadataTracksPreFullscreenState; // captures a snapshot of every metadata track's current state
  18630. var takeMetadataTrackSnapshot = function takeMetadataTrackSnapshot() {
  18631. metadataTracksPreFullscreenState = [];
  18632. for (var i = 0; i < textTracks.length; i++) {
  18633. var track = textTracks[i];
  18634. if (track.kind === 'metadata') {
  18635. metadataTracksPreFullscreenState.push({
  18636. track: track,
  18637. storedMode: track.mode
  18638. });
  18639. }
  18640. }
  18641. }; // snapshot each metadata track's initial state, and update the snapshot
  18642. // each time there is a track 'change' event
  18643. takeMetadataTrackSnapshot();
  18644. textTracks.addEventListener('change', takeMetadataTrackSnapshot);
  18645. this.on('dispose', function () {
  18646. return textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  18647. });
  18648. var restoreTrackMode = function restoreTrackMode() {
  18649. for (var i = 0; i < metadataTracksPreFullscreenState.length; i++) {
  18650. var storedTrack = metadataTracksPreFullscreenState[i];
  18651. if (storedTrack.track.mode === 'disabled' && storedTrack.track.mode !== storedTrack.storedMode) {
  18652. storedTrack.track.mode = storedTrack.storedMode;
  18653. }
  18654. } // we only want this handler to be executed on the first 'change' event
  18655. textTracks.removeEventListener('change', restoreTrackMode);
  18656. }; // when we enter fullscreen playback, stop updating the snapshot and
  18657. // restore all track modes to their pre-fullscreen state
  18658. this.on('webkitbeginfullscreen', function () {
  18659. textTracks.removeEventListener('change', takeMetadataTrackSnapshot); // remove the listener before adding it just in case it wasn't previously removed
  18660. textTracks.removeEventListener('change', restoreTrackMode);
  18661. textTracks.addEventListener('change', restoreTrackMode);
  18662. }); // start updating the snapshot again after leaving fullscreen
  18663. this.on('webkitendfullscreen', function () {
  18664. // remove the listener before adding it just in case it wasn't previously removed
  18665. textTracks.removeEventListener('change', takeMetadataTrackSnapshot);
  18666. textTracks.addEventListener('change', takeMetadataTrackSnapshot); // remove the restoreTrackMode handler in case it wasn't triggered during fullscreen playback
  18667. textTracks.removeEventListener('change', restoreTrackMode);
  18668. });
  18669. }
  18670. /**
  18671. * Attempt to force override of tracks for the given type
  18672. *
  18673. * @param {string} type - Track type to override, possible values include 'Audio',
  18674. * 'Video', and 'Text'.
  18675. * @param {boolean} override - If set to true native audio/video will be overridden,
  18676. * otherwise native audio/video will potentially be used.
  18677. * @private
  18678. */
  18679. ;
  18680. _proto.overrideNative_ = function overrideNative_(type, override) {
  18681. var _this2 = this;
  18682. // If there is no behavioral change don't add/remove listeners
  18683. if (override !== this["featuresNative" + type + "Tracks"]) {
  18684. return;
  18685. }
  18686. var lowerCaseType = type.toLowerCase();
  18687. if (this[lowerCaseType + "TracksListeners_"]) {
  18688. Object.keys(this[lowerCaseType + "TracksListeners_"]).forEach(function (eventName) {
  18689. var elTracks = _this2.el()[lowerCaseType + "Tracks"];
  18690. elTracks.removeEventListener(eventName, _this2[lowerCaseType + "TracksListeners_"][eventName]);
  18691. });
  18692. }
  18693. this["featuresNative" + type + "Tracks"] = !override;
  18694. this[lowerCaseType + "TracksListeners_"] = null;
  18695. this.proxyNativeTracksForType_(lowerCaseType);
  18696. }
  18697. /**
  18698. * Attempt to force override of native audio tracks.
  18699. *
  18700. * @param {boolean} override - If set to true native audio will be overridden,
  18701. * otherwise native audio will potentially be used.
  18702. */
  18703. ;
  18704. _proto.overrideNativeAudioTracks = function overrideNativeAudioTracks(override) {
  18705. this.overrideNative_('Audio', override);
  18706. }
  18707. /**
  18708. * Attempt to force override of native video tracks.
  18709. *
  18710. * @param {boolean} override - If set to true native video will be overridden,
  18711. * otherwise native video will potentially be used.
  18712. */
  18713. ;
  18714. _proto.overrideNativeVideoTracks = function overrideNativeVideoTracks(override) {
  18715. this.overrideNative_('Video', override);
  18716. }
  18717. /**
  18718. * Proxy native track list events for the given type to our track
  18719. * lists if the browser we are playing in supports that type of track list.
  18720. *
  18721. * @param {string} name - Track type; values include 'audio', 'video', and 'text'
  18722. * @private
  18723. */
  18724. ;
  18725. _proto.proxyNativeTracksForType_ = function proxyNativeTracksForType_(name) {
  18726. var _this3 = this;
  18727. var props = NORMAL[name];
  18728. var elTracks = this.el()[props.getterName];
  18729. var techTracks = this[props.getterName]();
  18730. if (!this["featuresNative" + props.capitalName + "Tracks"] || !elTracks || !elTracks.addEventListener) {
  18731. return;
  18732. }
  18733. var listeners = {
  18734. change: function change(e) {
  18735. techTracks.trigger({
  18736. type: 'change',
  18737. target: techTracks,
  18738. currentTarget: techTracks,
  18739. srcElement: techTracks
  18740. });
  18741. },
  18742. addtrack: function addtrack(e) {
  18743. techTracks.addTrack(e.track);
  18744. },
  18745. removetrack: function removetrack(e) {
  18746. techTracks.removeTrack(e.track);
  18747. }
  18748. };
  18749. var removeOldTracks = function removeOldTracks() {
  18750. var removeTracks = [];
  18751. for (var i = 0; i < techTracks.length; i++) {
  18752. var found = false;
  18753. for (var j = 0; j < elTracks.length; j++) {
  18754. if (elTracks[j] === techTracks[i]) {
  18755. found = true;
  18756. break;
  18757. }
  18758. }
  18759. if (!found) {
  18760. removeTracks.push(techTracks[i]);
  18761. }
  18762. }
  18763. while (removeTracks.length) {
  18764. techTracks.removeTrack(removeTracks.shift());
  18765. }
  18766. };
  18767. this[props.getterName + 'Listeners_'] = listeners;
  18768. Object.keys(listeners).forEach(function (eventName) {
  18769. var listener = listeners[eventName];
  18770. elTracks.addEventListener(eventName, listener);
  18771. _this3.on('dispose', function (e) {
  18772. return elTracks.removeEventListener(eventName, listener);
  18773. });
  18774. }); // Remove (native) tracks that are not used anymore
  18775. this.on('loadstart', removeOldTracks);
  18776. this.on('dispose', function (e) {
  18777. return _this3.off('loadstart', removeOldTracks);
  18778. });
  18779. }
  18780. /**
  18781. * Proxy all native track list events to our track lists if the browser we are playing
  18782. * in supports that type of track list.
  18783. *
  18784. * @private
  18785. */
  18786. ;
  18787. _proto.proxyNativeTracks_ = function proxyNativeTracks_() {
  18788. var _this4 = this;
  18789. NORMAL.names.forEach(function (name) {
  18790. _this4.proxyNativeTracksForType_(name);
  18791. });
  18792. }
  18793. /**
  18794. * Create the `Html5` Tech's DOM element.
  18795. *
  18796. * @return {Element}
  18797. * The element that gets created.
  18798. */
  18799. ;
  18800. _proto.createEl = function createEl() {
  18801. var el = this.options_.tag; // Check if this browser supports moving the element into the box.
  18802. // On the iPhone video will break if you move the element,
  18803. // So we have to create a brand new element.
  18804. // If we ingested the player div, we do not need to move the media element.
  18805. if (!el || !(this.options_.playerElIngest || this.movingMediaElementInDOM)) {
  18806. // If the original tag is still there, clone and remove it.
  18807. if (el) {
  18808. var clone = el.cloneNode(true);
  18809. if (el.parentNode) {
  18810. el.parentNode.insertBefore(clone, el);
  18811. }
  18812. Html5.disposeMediaElement(el);
  18813. el = clone;
  18814. } else {
  18815. el = document.createElement('video'); // determine if native controls should be used
  18816. var tagAttributes = this.options_.tag && getAttributes(this.options_.tag);
  18817. var attributes = mergeOptions({}, tagAttributes);
  18818. if (!TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
  18819. delete attributes.controls;
  18820. }
  18821. setAttributes(el, assign(attributes, {
  18822. id: this.options_.techId,
  18823. "class": 'vjs-tech'
  18824. }));
  18825. }
  18826. el.playerId = this.options_.playerId;
  18827. }
  18828. if (typeof this.options_.preload !== 'undefined') {
  18829. setAttribute(el, 'preload', this.options_.preload);
  18830. } // Update specific tag settings, in case they were overridden
  18831. // `autoplay` has to be *last* so that `muted` and `playsinline` are present
  18832. // when iOS/Safari or other browsers attempt to autoplay.
  18833. var settingsAttrs = ['loop', 'muted', 'playsinline', 'autoplay'];
  18834. for (var i = 0; i < settingsAttrs.length; i++) {
  18835. var attr = settingsAttrs[i];
  18836. var value = this.options_[attr];
  18837. if (typeof value !== 'undefined') {
  18838. if (value) {
  18839. setAttribute(el, attr, attr);
  18840. } else {
  18841. removeAttribute(el, attr);
  18842. }
  18843. el[attr] = value;
  18844. }
  18845. }
  18846. return el;
  18847. }
  18848. /**
  18849. * This will be triggered if the loadstart event has already fired, before videojs was
  18850. * ready. Two known examples of when this can happen are:
  18851. * 1. If we're loading the playback object after it has started loading
  18852. * 2. The media is already playing the (often with autoplay on) then
  18853. *
  18854. * This function will fire another loadstart so that videojs can catchup.
  18855. *
  18856. * @fires Tech#loadstart
  18857. *
  18858. * @return {undefined}
  18859. * returns nothing.
  18860. */
  18861. ;
  18862. _proto.handleLateInit_ = function handleLateInit_(el) {
  18863. if (el.networkState === 0 || el.networkState === 3) {
  18864. // The video element hasn't started loading the source yet
  18865. // or didn't find a source
  18866. return;
  18867. }
  18868. if (el.readyState === 0) {
  18869. // NetworkState is set synchronously BUT loadstart is fired at the
  18870. // end of the current stack, usually before setInterval(fn, 0).
  18871. // So at this point we know loadstart may have already fired or is
  18872. // about to fire, and either way the player hasn't seen it yet.
  18873. // We don't want to fire loadstart prematurely here and cause a
  18874. // double loadstart so we'll wait and see if it happens between now
  18875. // and the next loop, and fire it if not.
  18876. // HOWEVER, we also want to make sure it fires before loadedmetadata
  18877. // which could also happen between now and the next loop, so we'll
  18878. // watch for that also.
  18879. var loadstartFired = false;
  18880. var setLoadstartFired = function setLoadstartFired() {
  18881. loadstartFired = true;
  18882. };
  18883. this.on('loadstart', setLoadstartFired);
  18884. var triggerLoadstart = function triggerLoadstart() {
  18885. // We did miss the original loadstart. Make sure the player
  18886. // sees loadstart before loadedmetadata
  18887. if (!loadstartFired) {
  18888. this.trigger('loadstart');
  18889. }
  18890. };
  18891. this.on('loadedmetadata', triggerLoadstart);
  18892. this.ready(function () {
  18893. this.off('loadstart', setLoadstartFired);
  18894. this.off('loadedmetadata', triggerLoadstart);
  18895. if (!loadstartFired) {
  18896. // We did miss the original native loadstart. Fire it now.
  18897. this.trigger('loadstart');
  18898. }
  18899. });
  18900. return;
  18901. } // From here on we know that loadstart already fired and we missed it.
  18902. // The other readyState events aren't as much of a problem if we double
  18903. // them, so not going to go to as much trouble as loadstart to prevent
  18904. // that unless we find reason to.
  18905. var eventsToTrigger = ['loadstart']; // loadedmetadata: newly equal to HAVE_METADATA (1) or greater
  18906. eventsToTrigger.push('loadedmetadata'); // loadeddata: newly increased to HAVE_CURRENT_DATA (2) or greater
  18907. if (el.readyState >= 2) {
  18908. eventsToTrigger.push('loadeddata');
  18909. } // canplay: newly increased to HAVE_FUTURE_DATA (3) or greater
  18910. if (el.readyState >= 3) {
  18911. eventsToTrigger.push('canplay');
  18912. } // canplaythrough: newly equal to HAVE_ENOUGH_DATA (4)
  18913. if (el.readyState >= 4) {
  18914. eventsToTrigger.push('canplaythrough');
  18915. } // We still need to give the player time to add event listeners
  18916. this.ready(function () {
  18917. eventsToTrigger.forEach(function (type) {
  18918. this.trigger(type);
  18919. }, this);
  18920. });
  18921. }
  18922. /**
  18923. * Set current time for the `HTML5` tech.
  18924. *
  18925. * @param {number} seconds
  18926. * Set the current time of the media to this.
  18927. */
  18928. ;
  18929. _proto.setCurrentTime = function setCurrentTime(seconds) {
  18930. try {
  18931. this.el_.currentTime = seconds;
  18932. } catch (e) {
  18933. log(e, 'Video is not ready. (Video.js)'); // this.warning(VideoJS.warnings.videoNotReady);
  18934. }
  18935. }
  18936. /**
  18937. * Get the current duration of the HTML5 media element.
  18938. *
  18939. * @return {number}
  18940. * The duration of the media or 0 if there is no duration.
  18941. */
  18942. ;
  18943. _proto.duration = function duration() {
  18944. var _this5 = this;
  18945. // Android Chrome will report duration as Infinity for VOD HLS until after
  18946. // playback has started, which triggers the live display erroneously.
  18947. // Return NaN if playback has not started and trigger a durationupdate once
  18948. // the duration can be reliably known.
  18949. if (this.el_.duration === Infinity && IS_ANDROID && IS_CHROME && this.el_.currentTime === 0) {
  18950. // Wait for the first `timeupdate` with currentTime > 0 - there may be
  18951. // several with 0
  18952. var checkProgress = function checkProgress() {
  18953. if (_this5.el_.currentTime > 0) {
  18954. // Trigger durationchange for genuinely live video
  18955. if (_this5.el_.duration === Infinity) {
  18956. _this5.trigger('durationchange');
  18957. }
  18958. _this5.off('timeupdate', checkProgress);
  18959. }
  18960. };
  18961. this.on('timeupdate', checkProgress);
  18962. return NaN;
  18963. }
  18964. return this.el_.duration || NaN;
  18965. }
  18966. /**
  18967. * Get the current width of the HTML5 media element.
  18968. *
  18969. * @return {number}
  18970. * The width of the HTML5 media element.
  18971. */
  18972. ;
  18973. _proto.width = function width() {
  18974. return this.el_.offsetWidth;
  18975. }
  18976. /**
  18977. * Get the current height of the HTML5 media element.
  18978. *
  18979. * @return {number}
  18980. * The height of the HTML5 media element.
  18981. */
  18982. ;
  18983. _proto.height = function height() {
  18984. return this.el_.offsetHeight;
  18985. }
  18986. /**
  18987. * Proxy iOS `webkitbeginfullscreen` and `webkitendfullscreen` into
  18988. * `fullscreenchange` event.
  18989. *
  18990. * @private
  18991. * @fires fullscreenchange
  18992. * @listens webkitendfullscreen
  18993. * @listens webkitbeginfullscreen
  18994. * @listens webkitbeginfullscreen
  18995. */
  18996. ;
  18997. _proto.proxyWebkitFullscreen_ = function proxyWebkitFullscreen_() {
  18998. var _this6 = this;
  18999. if (!('webkitDisplayingFullscreen' in this.el_)) {
  19000. return;
  19001. }
  19002. var endFn = function endFn() {
  19003. this.trigger('fullscreenchange', {
  19004. isFullscreen: false
  19005. });
  19006. };
  19007. var beginFn = function beginFn() {
  19008. if ('webkitPresentationMode' in this.el_ && this.el_.webkitPresentationMode !== 'picture-in-picture') {
  19009. this.one('webkitendfullscreen', endFn);
  19010. this.trigger('fullscreenchange', {
  19011. isFullscreen: true
  19012. });
  19013. }
  19014. };
  19015. this.on('webkitbeginfullscreen', beginFn);
  19016. this.on('dispose', function () {
  19017. _this6.off('webkitbeginfullscreen', beginFn);
  19018. _this6.off('webkitendfullscreen', endFn);
  19019. });
  19020. }
  19021. /**
  19022. * Check if fullscreen is supported on the current playback device.
  19023. *
  19024. * @return {boolean}
  19025. * - True if fullscreen is supported.
  19026. * - False if fullscreen is not supported.
  19027. */
  19028. ;
  19029. _proto.supportsFullScreen = function supportsFullScreen() {
  19030. if (typeof this.el_.webkitEnterFullScreen === 'function') {
  19031. var userAgent = window$1.navigator && window$1.navigator.userAgent || ''; // Seems to be broken in Chromium/Chrome && Safari in Leopard
  19032. if (/Android/.test(userAgent) || !/Chrome|Mac OS X 10.5/.test(userAgent)) {
  19033. return true;
  19034. }
  19035. }
  19036. return false;
  19037. }
  19038. /**
  19039. * Request that the `HTML5` Tech enter fullscreen.
  19040. */
  19041. ;
  19042. _proto.enterFullScreen = function enterFullScreen() {
  19043. var video = this.el_;
  19044. if (video.paused && video.networkState <= video.HAVE_METADATA) {
  19045. // attempt to prime the video element for programmatic access
  19046. // this isn't necessary on the desktop but shouldn't hurt
  19047. this.el_.play(); // playing and pausing synchronously during the transition to fullscreen
  19048. // can get iOS ~6.1 devices into a play/pause loop
  19049. this.setTimeout(function () {
  19050. video.pause();
  19051. video.webkitEnterFullScreen();
  19052. }, 0);
  19053. } else {
  19054. video.webkitEnterFullScreen();
  19055. }
  19056. }
  19057. /**
  19058. * Request that the `HTML5` Tech exit fullscreen.
  19059. */
  19060. ;
  19061. _proto.exitFullScreen = function exitFullScreen() {
  19062. this.el_.webkitExitFullScreen();
  19063. }
  19064. /**
  19065. * Create a floating video window always on top of other windows so that users may
  19066. * continue consuming media while they interact with other content sites, or
  19067. * applications on their device.
  19068. *
  19069. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  19070. *
  19071. * @return {Promise}
  19072. * A promise with a Picture-in-Picture window.
  19073. */
  19074. ;
  19075. _proto.requestPictureInPicture = function requestPictureInPicture() {
  19076. return this.el_.requestPictureInPicture();
  19077. }
  19078. /**
  19079. * A getter/setter for the `Html5` Tech's source object.
  19080. * > Note: Please use {@link Html5#setSource}
  19081. *
  19082. * @param {Tech~SourceObject} [src]
  19083. * The source object you want to set on the `HTML5` techs element.
  19084. *
  19085. * @return {Tech~SourceObject|undefined}
  19086. * - The current source object when a source is not passed in.
  19087. * - undefined when setting
  19088. *
  19089. * @deprecated Since version 5.
  19090. */
  19091. ;
  19092. _proto.src = function src(_src) {
  19093. if (_src === undefined) {
  19094. return this.el_.src;
  19095. } // Setting src through `src` instead of `setSrc` will be deprecated
  19096. this.setSrc(_src);
  19097. }
  19098. /**
  19099. * Reset the tech by removing all sources and then calling
  19100. * {@link Html5.resetMediaElement}.
  19101. */
  19102. ;
  19103. _proto.reset = function reset() {
  19104. Html5.resetMediaElement(this.el_);
  19105. }
  19106. /**
  19107. * Get the current source on the `HTML5` Tech. Falls back to returning the source from
  19108. * the HTML5 media element.
  19109. *
  19110. * @return {Tech~SourceObject}
  19111. * The current source object from the HTML5 tech. With a fallback to the
  19112. * elements source.
  19113. */
  19114. ;
  19115. _proto.currentSrc = function currentSrc() {
  19116. if (this.currentSource_) {
  19117. return this.currentSource_.src;
  19118. }
  19119. return this.el_.currentSrc;
  19120. }
  19121. /**
  19122. * Set controls attribute for the HTML5 media Element.
  19123. *
  19124. * @param {string} val
  19125. * Value to set the controls attribute to
  19126. */
  19127. ;
  19128. _proto.setControls = function setControls(val) {
  19129. this.el_.controls = !!val;
  19130. }
  19131. /**
  19132. * Create and returns a remote {@link TextTrack} object.
  19133. *
  19134. * @param {string} kind
  19135. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata)
  19136. *
  19137. * @param {string} [label]
  19138. * Label to identify the text track
  19139. *
  19140. * @param {string} [language]
  19141. * Two letter language abbreviation
  19142. *
  19143. * @return {TextTrack}
  19144. * The TextTrack that gets created.
  19145. */
  19146. ;
  19147. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  19148. if (!this.featuresNativeTextTracks) {
  19149. return _Tech.prototype.addTextTrack.call(this, kind, label, language);
  19150. }
  19151. return this.el_.addTextTrack(kind, label, language);
  19152. }
  19153. /**
  19154. * Creates either native TextTrack or an emulated TextTrack depending
  19155. * on the value of `featuresNativeTextTracks`
  19156. *
  19157. * @param {Object} options
  19158. * The object should contain the options to initialize the TextTrack with.
  19159. *
  19160. * @param {string} [options.kind]
  19161. * `TextTrack` kind (subtitles, captions, descriptions, chapters, or metadata).
  19162. *
  19163. * @param {string} [options.label]
  19164. * Label to identify the text track
  19165. *
  19166. * @param {string} [options.language]
  19167. * Two letter language abbreviation.
  19168. *
  19169. * @param {boolean} [options.default]
  19170. * Default this track to on.
  19171. *
  19172. * @param {string} [options.id]
  19173. * The internal id to assign this track.
  19174. *
  19175. * @param {string} [options.src]
  19176. * A source url for the track.
  19177. *
  19178. * @return {HTMLTrackElement}
  19179. * The track element that gets created.
  19180. */
  19181. ;
  19182. _proto.createRemoteTextTrack = function createRemoteTextTrack(options) {
  19183. if (!this.featuresNativeTextTracks) {
  19184. return _Tech.prototype.createRemoteTextTrack.call(this, options);
  19185. }
  19186. var htmlTrackElement = document.createElement('track');
  19187. if (options.kind) {
  19188. htmlTrackElement.kind = options.kind;
  19189. }
  19190. if (options.label) {
  19191. htmlTrackElement.label = options.label;
  19192. }
  19193. if (options.language || options.srclang) {
  19194. htmlTrackElement.srclang = options.language || options.srclang;
  19195. }
  19196. if (options["default"]) {
  19197. htmlTrackElement["default"] = options["default"];
  19198. }
  19199. if (options.id) {
  19200. htmlTrackElement.id = options.id;
  19201. }
  19202. if (options.src) {
  19203. htmlTrackElement.src = options.src;
  19204. }
  19205. return htmlTrackElement;
  19206. }
  19207. /**
  19208. * Creates a remote text track object and returns an html track element.
  19209. *
  19210. * @param {Object} options The object should contain values for
  19211. * kind, language, label, and src (location of the WebVTT file)
  19212. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  19213. * automatically removed from the video element whenever the source changes
  19214. * @return {HTMLTrackElement} An Html Track Element.
  19215. * This can be an emulated {@link HTMLTrackElement} or a native one.
  19216. * @deprecated The default value of the "manualCleanup" parameter will default
  19217. * to "false" in upcoming versions of Video.js
  19218. */
  19219. ;
  19220. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  19221. var htmlTrackElement = _Tech.prototype.addRemoteTextTrack.call(this, options, manualCleanup);
  19222. if (this.featuresNativeTextTracks) {
  19223. this.el().appendChild(htmlTrackElement);
  19224. }
  19225. return htmlTrackElement;
  19226. }
  19227. /**
  19228. * Remove remote `TextTrack` from `TextTrackList` object
  19229. *
  19230. * @param {TextTrack} track
  19231. * `TextTrack` object to remove
  19232. */
  19233. ;
  19234. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  19235. _Tech.prototype.removeRemoteTextTrack.call(this, track);
  19236. if (this.featuresNativeTextTracks) {
  19237. var tracks = this.$$('track');
  19238. var i = tracks.length;
  19239. while (i--) {
  19240. if (track === tracks[i] || track === tracks[i].track) {
  19241. this.el().removeChild(tracks[i]);
  19242. }
  19243. }
  19244. }
  19245. }
  19246. /**
  19247. * Gets available media playback quality metrics as specified by the W3C's Media
  19248. * Playback Quality API.
  19249. *
  19250. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  19251. *
  19252. * @return {Object}
  19253. * An object with supported media playback quality metrics
  19254. */
  19255. ;
  19256. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  19257. if (typeof this.el().getVideoPlaybackQuality === 'function') {
  19258. return this.el().getVideoPlaybackQuality();
  19259. }
  19260. var videoPlaybackQuality = {};
  19261. if (typeof this.el().webkitDroppedFrameCount !== 'undefined' && typeof this.el().webkitDecodedFrameCount !== 'undefined') {
  19262. videoPlaybackQuality.droppedVideoFrames = this.el().webkitDroppedFrameCount;
  19263. videoPlaybackQuality.totalVideoFrames = this.el().webkitDecodedFrameCount;
  19264. }
  19265. if (window$1.performance && typeof window$1.performance.now === 'function') {
  19266. videoPlaybackQuality.creationTime = window$1.performance.now();
  19267. } else if (window$1.performance && window$1.performance.timing && typeof window$1.performance.timing.navigationStart === 'number') {
  19268. videoPlaybackQuality.creationTime = window$1.Date.now() - window$1.performance.timing.navigationStart;
  19269. }
  19270. return videoPlaybackQuality;
  19271. };
  19272. return Html5;
  19273. }(Tech);
  19274. /* HTML5 Support Testing ---------------------------------------------------- */
  19275. if (isReal()) {
  19276. /**
  19277. * Element for testing browser HTML5 media capabilities
  19278. *
  19279. * @type {Element}
  19280. * @constant
  19281. * @private
  19282. */
  19283. Html5.TEST_VID = document.createElement('video');
  19284. var track = document.createElement('track');
  19285. track.kind = 'captions';
  19286. track.srclang = 'en';
  19287. track.label = 'English';
  19288. Html5.TEST_VID.appendChild(track);
  19289. }
  19290. /**
  19291. * Check if HTML5 media is supported by this browser/device.
  19292. *
  19293. * @return {boolean}
  19294. * - True if HTML5 media is supported.
  19295. * - False if HTML5 media is not supported.
  19296. */
  19297. Html5.isSupported = function () {
  19298. // IE with no Media Player is a LIAR! (#984)
  19299. try {
  19300. Html5.TEST_VID.volume = 0.5;
  19301. } catch (e) {
  19302. return false;
  19303. }
  19304. return !!(Html5.TEST_VID && Html5.TEST_VID.canPlayType);
  19305. };
  19306. /**
  19307. * Check if the tech can support the given type
  19308. *
  19309. * @param {string} type
  19310. * The mimetype to check
  19311. * @return {string} 'probably', 'maybe', or '' (empty string)
  19312. */
  19313. Html5.canPlayType = function (type) {
  19314. return Html5.TEST_VID.canPlayType(type);
  19315. };
  19316. /**
  19317. * Check if the tech can support the given source
  19318. *
  19319. * @param {Object} srcObj
  19320. * The source object
  19321. * @param {Object} options
  19322. * The options passed to the tech
  19323. * @return {string} 'probably', 'maybe', or '' (empty string)
  19324. */
  19325. Html5.canPlaySource = function (srcObj, options) {
  19326. return Html5.canPlayType(srcObj.type);
  19327. };
  19328. /**
  19329. * Check if the volume can be changed in this browser/device.
  19330. * Volume cannot be changed in a lot of mobile devices.
  19331. * Specifically, it can't be changed from 1 on iOS.
  19332. *
  19333. * @return {boolean}
  19334. * - True if volume can be controlled
  19335. * - False otherwise
  19336. */
  19337. Html5.canControlVolume = function () {
  19338. // IE will error if Windows Media Player not installed #3315
  19339. try {
  19340. var volume = Html5.TEST_VID.volume;
  19341. Html5.TEST_VID.volume = volume / 2 + 0.1;
  19342. return volume !== Html5.TEST_VID.volume;
  19343. } catch (e) {
  19344. return false;
  19345. }
  19346. };
  19347. /**
  19348. * Check if the volume can be muted in this browser/device.
  19349. * Some devices, e.g. iOS, don't allow changing volume
  19350. * but permits muting/unmuting.
  19351. *
  19352. * @return {bolean}
  19353. * - True if volume can be muted
  19354. * - False otherwise
  19355. */
  19356. Html5.canMuteVolume = function () {
  19357. try {
  19358. var muted = Html5.TEST_VID.muted; // in some versions of iOS muted property doesn't always
  19359. // work, so we want to set both property and attribute
  19360. Html5.TEST_VID.muted = !muted;
  19361. if (Html5.TEST_VID.muted) {
  19362. setAttribute(Html5.TEST_VID, 'muted', 'muted');
  19363. } else {
  19364. removeAttribute(Html5.TEST_VID, 'muted', 'muted');
  19365. }
  19366. return muted !== Html5.TEST_VID.muted;
  19367. } catch (e) {
  19368. return false;
  19369. }
  19370. };
  19371. /**
  19372. * Check if the playback rate can be changed in this browser/device.
  19373. *
  19374. * @return {boolean}
  19375. * - True if playback rate can be controlled
  19376. * - False otherwise
  19377. */
  19378. Html5.canControlPlaybackRate = function () {
  19379. // Playback rate API is implemented in Android Chrome, but doesn't do anything
  19380. // https://github.com/videojs/video.js/issues/3180
  19381. if (IS_ANDROID && IS_CHROME && CHROME_VERSION < 58) {
  19382. return false;
  19383. } // IE will error if Windows Media Player not installed #3315
  19384. try {
  19385. var playbackRate = Html5.TEST_VID.playbackRate;
  19386. Html5.TEST_VID.playbackRate = playbackRate / 2 + 0.1;
  19387. return playbackRate !== Html5.TEST_VID.playbackRate;
  19388. } catch (e) {
  19389. return false;
  19390. }
  19391. };
  19392. /**
  19393. * Check if we can override a video/audio elements attributes, with
  19394. * Object.defineProperty.
  19395. *
  19396. * @return {boolean}
  19397. * - True if builtin attributes can be overridden
  19398. * - False otherwise
  19399. */
  19400. Html5.canOverrideAttributes = function () {
  19401. // if we cannot overwrite the src/innerHTML property, there is no support
  19402. // iOS 7 safari for instance cannot do this.
  19403. try {
  19404. var noop = function noop() {};
  19405. Object.defineProperty(document.createElement('video'), 'src', {
  19406. get: noop,
  19407. set: noop
  19408. });
  19409. Object.defineProperty(document.createElement('audio'), 'src', {
  19410. get: noop,
  19411. set: noop
  19412. });
  19413. Object.defineProperty(document.createElement('video'), 'innerHTML', {
  19414. get: noop,
  19415. set: noop
  19416. });
  19417. Object.defineProperty(document.createElement('audio'), 'innerHTML', {
  19418. get: noop,
  19419. set: noop
  19420. });
  19421. } catch (e) {
  19422. return false;
  19423. }
  19424. return true;
  19425. };
  19426. /**
  19427. * Check to see if native `TextTrack`s are supported by this browser/device.
  19428. *
  19429. * @return {boolean}
  19430. * - True if native `TextTrack`s are supported.
  19431. * - False otherwise
  19432. */
  19433. Html5.supportsNativeTextTracks = function () {
  19434. return IS_ANY_SAFARI || IS_IOS && IS_CHROME;
  19435. };
  19436. /**
  19437. * Check to see if native `VideoTrack`s are supported by this browser/device
  19438. *
  19439. * @return {boolean}
  19440. * - True if native `VideoTrack`s are supported.
  19441. * - False otherwise
  19442. */
  19443. Html5.supportsNativeVideoTracks = function () {
  19444. return !!(Html5.TEST_VID && Html5.TEST_VID.videoTracks);
  19445. };
  19446. /**
  19447. * Check to see if native `AudioTrack`s are supported by this browser/device
  19448. *
  19449. * @return {boolean}
  19450. * - True if native `AudioTrack`s are supported.
  19451. * - False otherwise
  19452. */
  19453. Html5.supportsNativeAudioTracks = function () {
  19454. return !!(Html5.TEST_VID && Html5.TEST_VID.audioTracks);
  19455. };
  19456. /**
  19457. * An array of events available on the Html5 tech.
  19458. *
  19459. * @private
  19460. * @type {Array}
  19461. */
  19462. 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'];
  19463. /**
  19464. * Boolean indicating whether the `Tech` supports volume control.
  19465. *
  19466. * @type {boolean}
  19467. * @default {@link Html5.canControlVolume}
  19468. */
  19469. Html5.prototype.featuresVolumeControl = Html5.canControlVolume();
  19470. /**
  19471. * Boolean indicating whether the `Tech` supports muting volume.
  19472. *
  19473. * @type {bolean}
  19474. * @default {@link Html5.canMuteVolume}
  19475. */
  19476. Html5.prototype.featuresMuteControl = Html5.canMuteVolume();
  19477. /**
  19478. * Boolean indicating whether the `Tech` supports changing the speed at which the media
  19479. * plays. Examples:
  19480. * - Set player to play 2x (twice) as fast
  19481. * - Set player to play 0.5x (half) as fast
  19482. *
  19483. * @type {boolean}
  19484. * @default {@link Html5.canControlPlaybackRate}
  19485. */
  19486. Html5.prototype.featuresPlaybackRate = Html5.canControlPlaybackRate();
  19487. /**
  19488. * Boolean indicating whether the `Tech` supports the `sourceset` event.
  19489. *
  19490. * @type {boolean}
  19491. * @default
  19492. */
  19493. Html5.prototype.featuresSourceset = Html5.canOverrideAttributes();
  19494. /**
  19495. * Boolean indicating whether the `HTML5` tech currently supports the media element
  19496. * moving in the DOM. iOS breaks if you move the media element, so this is set this to
  19497. * false there. Everywhere else this should be true.
  19498. *
  19499. * @type {boolean}
  19500. * @default
  19501. */
  19502. Html5.prototype.movingMediaElementInDOM = !IS_IOS; // TODO: Previous comment: No longer appears to be used. Can probably be removed.
  19503. // Is this true?
  19504. /**
  19505. * Boolean indicating whether the `HTML5` tech currently supports automatic media resize
  19506. * when going into fullscreen.
  19507. *
  19508. * @type {boolean}
  19509. * @default
  19510. */
  19511. Html5.prototype.featuresFullscreenResize = true;
  19512. /**
  19513. * Boolean indicating whether the `HTML5` tech currently supports the progress event.
  19514. * If this is false, manual `progress` events will be triggered instead.
  19515. *
  19516. * @type {boolean}
  19517. * @default
  19518. */
  19519. Html5.prototype.featuresProgressEvents = true;
  19520. /**
  19521. * Boolean indicating whether the `HTML5` tech currently supports the timeupdate event.
  19522. * If this is false, manual `timeupdate` events will be triggered instead.
  19523. *
  19524. * @default
  19525. */
  19526. Html5.prototype.featuresTimeupdateEvents = true;
  19527. /**
  19528. * Boolean indicating whether the `HTML5` tech currently supports native `TextTrack`s.
  19529. *
  19530. * @type {boolean}
  19531. * @default {@link Html5.supportsNativeTextTracks}
  19532. */
  19533. Html5.prototype.featuresNativeTextTracks = Html5.supportsNativeTextTracks();
  19534. /**
  19535. * Boolean indicating whether the `HTML5` tech currently supports native `VideoTrack`s.
  19536. *
  19537. * @type {boolean}
  19538. * @default {@link Html5.supportsNativeVideoTracks}
  19539. */
  19540. Html5.prototype.featuresNativeVideoTracks = Html5.supportsNativeVideoTracks();
  19541. /**
  19542. * Boolean indicating whether the `HTML5` tech currently supports native `AudioTrack`s.
  19543. *
  19544. * @type {boolean}
  19545. * @default {@link Html5.supportsNativeAudioTracks}
  19546. */
  19547. Html5.prototype.featuresNativeAudioTracks = Html5.supportsNativeAudioTracks(); // HTML5 Feature detection and Device Fixes --------------------------------- //
  19548. var canPlayType = Html5.TEST_VID && Html5.TEST_VID.constructor.prototype.canPlayType;
  19549. var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
  19550. Html5.patchCanPlayType = function () {
  19551. // Android 4.0 and above can play HLS to some extent but it reports being unable to do so
  19552. // Firefox and Chrome report correctly
  19553. if (ANDROID_VERSION >= 4.0 && !IS_FIREFOX && !IS_CHROME) {
  19554. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  19555. if (type && mpegurlRE.test(type)) {
  19556. return 'maybe';
  19557. }
  19558. return canPlayType.call(this, type);
  19559. };
  19560. }
  19561. };
  19562. Html5.unpatchCanPlayType = function () {
  19563. var r = Html5.TEST_VID.constructor.prototype.canPlayType;
  19564. Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
  19565. return r;
  19566. }; // by default, patch the media element
  19567. Html5.patchCanPlayType();
  19568. Html5.disposeMediaElement = function (el) {
  19569. if (!el) {
  19570. return;
  19571. }
  19572. if (el.parentNode) {
  19573. el.parentNode.removeChild(el);
  19574. } // remove any child track or source nodes to prevent their loading
  19575. while (el.hasChildNodes()) {
  19576. el.removeChild(el.firstChild);
  19577. } // remove any src reference. not setting `src=''` because that causes a warning
  19578. // in firefox
  19579. el.removeAttribute('src'); // force the media element to update its loading state by calling load()
  19580. // however IE on Windows 7N has a bug that throws an error so need a try/catch (#793)
  19581. if (typeof el.load === 'function') {
  19582. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  19583. (function () {
  19584. try {
  19585. el.load();
  19586. } catch (e) {// not supported
  19587. }
  19588. })();
  19589. }
  19590. };
  19591. Html5.resetMediaElement = function (el) {
  19592. if (!el) {
  19593. return;
  19594. }
  19595. var sources = el.querySelectorAll('source');
  19596. var i = sources.length;
  19597. while (i--) {
  19598. el.removeChild(sources[i]);
  19599. } // remove any src reference.
  19600. // not setting `src=''` because that throws an error
  19601. el.removeAttribute('src');
  19602. if (typeof el.load === 'function') {
  19603. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  19604. (function () {
  19605. try {
  19606. el.load();
  19607. } catch (e) {// satisfy linter
  19608. }
  19609. })();
  19610. }
  19611. };
  19612. /* Native HTML5 element property wrapping ----------------------------------- */
  19613. // Wrap native boolean attributes with getters that check both property and attribute
  19614. // The list is as followed:
  19615. // muted, defaultMuted, autoplay, controls, loop, playsinline
  19616. [
  19617. /**
  19618. * Get the value of `muted` from the media element. `muted` indicates
  19619. * that the volume for the media should be set to silent. This does not actually change
  19620. * the `volume` attribute.
  19621. *
  19622. * @method Html5#muted
  19623. * @return {boolean}
  19624. * - True if the value of `volume` should be ignored and the audio set to silent.
  19625. * - False if the value of `volume` should be used.
  19626. *
  19627. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  19628. */
  19629. 'muted',
  19630. /**
  19631. * Get the value of `defaultMuted` from the media element. `defaultMuted` indicates
  19632. * whether the media should start muted or not. Only changes the default state of the
  19633. * media. `muted` and `defaultMuted` can have different values. {@link Html5#muted} indicates the
  19634. * current state.
  19635. *
  19636. * @method Html5#defaultMuted
  19637. * @return {boolean}
  19638. * - The value of `defaultMuted` from the media element.
  19639. * - True indicates that the media should start muted.
  19640. * - False indicates that the media should not start muted
  19641. *
  19642. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  19643. */
  19644. 'defaultMuted',
  19645. /**
  19646. * Get the value of `autoplay` from the media element. `autoplay` indicates
  19647. * that the media should start to play as soon as the page is ready.
  19648. *
  19649. * @method Html5#autoplay
  19650. * @return {boolean}
  19651. * - The value of `autoplay` from the media element.
  19652. * - True indicates that the media should start as soon as the page loads.
  19653. * - False indicates that the media should not start as soon as the page loads.
  19654. *
  19655. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  19656. */
  19657. 'autoplay',
  19658. /**
  19659. * Get the value of `controls` from the media element. `controls` indicates
  19660. * whether the native media controls should be shown or hidden.
  19661. *
  19662. * @method Html5#controls
  19663. * @return {boolean}
  19664. * - The value of `controls` from the media element.
  19665. * - True indicates that native controls should be showing.
  19666. * - False indicates that native controls should be hidden.
  19667. *
  19668. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-controls}
  19669. */
  19670. 'controls',
  19671. /**
  19672. * Get the value of `loop` from the media element. `loop` indicates
  19673. * that the media should return to the start of the media and continue playing once
  19674. * it reaches the end.
  19675. *
  19676. * @method Html5#loop
  19677. * @return {boolean}
  19678. * - The value of `loop` from the media element.
  19679. * - True indicates that playback should seek back to start once
  19680. * the end of a media is reached.
  19681. * - False indicates that playback should not loop back to the start when the
  19682. * end of the media is reached.
  19683. *
  19684. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  19685. */
  19686. 'loop',
  19687. /**
  19688. * Get the value of `playsinline` from the media element. `playsinline` indicates
  19689. * to the browser that non-fullscreen playback is preferred when fullscreen
  19690. * playback is the native default, such as in iOS Safari.
  19691. *
  19692. * @method Html5#playsinline
  19693. * @return {boolean}
  19694. * - The value of `playsinline` from the media element.
  19695. * - True indicates that the media should play inline.
  19696. * - False indicates that the media should not play inline.
  19697. *
  19698. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  19699. */
  19700. 'playsinline'].forEach(function (prop) {
  19701. Html5.prototype[prop] = function () {
  19702. return this.el_[prop] || this.el_.hasAttribute(prop);
  19703. };
  19704. }); // Wrap native boolean attributes with setters that set both property and attribute
  19705. // The list is as followed:
  19706. // setMuted, setDefaultMuted, setAutoplay, setLoop, setPlaysinline
  19707. // setControls is special-cased above
  19708. [
  19709. /**
  19710. * Set the value of `muted` on the media element. `muted` indicates that the current
  19711. * audio level should be silent.
  19712. *
  19713. * @method Html5#setMuted
  19714. * @param {boolean} muted
  19715. * - True if the audio should be set to silent
  19716. * - False otherwise
  19717. *
  19718. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-muted}
  19719. */
  19720. 'muted',
  19721. /**
  19722. * Set the value of `defaultMuted` on the media element. `defaultMuted` indicates that the current
  19723. * audio level should be silent, but will only effect the muted level on intial playback..
  19724. *
  19725. * @method Html5.prototype.setDefaultMuted
  19726. * @param {boolean} defaultMuted
  19727. * - True if the audio should be set to silent
  19728. * - False otherwise
  19729. *
  19730. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultmuted}
  19731. */
  19732. 'defaultMuted',
  19733. /**
  19734. * Set the value of `autoplay` on the media element. `autoplay` indicates
  19735. * that the media should start to play as soon as the page is ready.
  19736. *
  19737. * @method Html5#setAutoplay
  19738. * @param {boolean} autoplay
  19739. * - True indicates that the media should start as soon as the page loads.
  19740. * - False indicates that the media should not start as soon as the page loads.
  19741. *
  19742. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-autoplay}
  19743. */
  19744. 'autoplay',
  19745. /**
  19746. * Set the value of `loop` on the media element. `loop` indicates
  19747. * that the media should return to the start of the media and continue playing once
  19748. * it reaches the end.
  19749. *
  19750. * @method Html5#setLoop
  19751. * @param {boolean} loop
  19752. * - True indicates that playback should seek back to start once
  19753. * the end of a media is reached.
  19754. * - False indicates that playback should not loop back to the start when the
  19755. * end of the media is reached.
  19756. *
  19757. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-loop}
  19758. */
  19759. 'loop',
  19760. /**
  19761. * Set the value of `playsinline` from the media element. `playsinline` indicates
  19762. * to the browser that non-fullscreen playback is preferred when fullscreen
  19763. * playback is the native default, such as in iOS Safari.
  19764. *
  19765. * @method Html5#setPlaysinline
  19766. * @param {boolean} playsinline
  19767. * - True indicates that the media should play inline.
  19768. * - False indicates that the media should not play inline.
  19769. *
  19770. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  19771. */
  19772. 'playsinline'].forEach(function (prop) {
  19773. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  19774. this.el_[prop] = v;
  19775. if (v) {
  19776. this.el_.setAttribute(prop, prop);
  19777. } else {
  19778. this.el_.removeAttribute(prop);
  19779. }
  19780. };
  19781. }); // Wrap native properties with a getter
  19782. // The list is as followed
  19783. // paused, currentTime, buffered, volume, poster, preload, error, seeking
  19784. // seekable, ended, playbackRate, defaultPlaybackRate, played, networkState
  19785. // readyState, videoWidth, videoHeight
  19786. [
  19787. /**
  19788. * Get the value of `paused` from the media element. `paused` indicates whether the media element
  19789. * is currently paused or not.
  19790. *
  19791. * @method Html5#paused
  19792. * @return {boolean}
  19793. * The value of `paused` from the media element.
  19794. *
  19795. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-paused}
  19796. */
  19797. 'paused',
  19798. /**
  19799. * Get the value of `currentTime` from the media element. `currentTime` indicates
  19800. * the current second that the media is at in playback.
  19801. *
  19802. * @method Html5#currentTime
  19803. * @return {number}
  19804. * The value of `currentTime` from the media element.
  19805. *
  19806. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-currenttime}
  19807. */
  19808. 'currentTime',
  19809. /**
  19810. * Get the value of `buffered` from the media element. `buffered` is a `TimeRange`
  19811. * object that represents the parts of the media that are already downloaded and
  19812. * available for playback.
  19813. *
  19814. * @method Html5#buffered
  19815. * @return {TimeRange}
  19816. * The value of `buffered` from the media element.
  19817. *
  19818. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-buffered}
  19819. */
  19820. 'buffered',
  19821. /**
  19822. * Get the value of `volume` from the media element. `volume` indicates
  19823. * the current playback volume of audio for a media. `volume` will be a value from 0
  19824. * (silent) to 1 (loudest and default).
  19825. *
  19826. * @method Html5#volume
  19827. * @return {number}
  19828. * The value of `volume` from the media element. Value will be between 0-1.
  19829. *
  19830. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  19831. */
  19832. 'volume',
  19833. /**
  19834. * Get the value of `poster` from the media element. `poster` indicates
  19835. * that the url of an image file that can/will be shown when no media data is available.
  19836. *
  19837. * @method Html5#poster
  19838. * @return {string}
  19839. * The value of `poster` from the media element. Value will be a url to an
  19840. * image.
  19841. *
  19842. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-video-poster}
  19843. */
  19844. 'poster',
  19845. /**
  19846. * Get the value of `preload` from the media element. `preload` indicates
  19847. * what should download before the media is interacted with. It can have the following
  19848. * values:
  19849. * - none: nothing should be downloaded
  19850. * - metadata: poster and the first few frames of the media may be downloaded to get
  19851. * media dimensions and other metadata
  19852. * - auto: allow the media and metadata for the media to be downloaded before
  19853. * interaction
  19854. *
  19855. * @method Html5#preload
  19856. * @return {string}
  19857. * The value of `preload` from the media element. Will be 'none', 'metadata',
  19858. * or 'auto'.
  19859. *
  19860. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  19861. */
  19862. 'preload',
  19863. /**
  19864. * Get the value of the `error` from the media element. `error` indicates any
  19865. * MediaError that may have occurred during playback. If error returns null there is no
  19866. * current error.
  19867. *
  19868. * @method Html5#error
  19869. * @return {MediaError|null}
  19870. * The value of `error` from the media element. Will be `MediaError` if there
  19871. * is a current error and null otherwise.
  19872. *
  19873. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-error}
  19874. */
  19875. 'error',
  19876. /**
  19877. * Get the value of `seeking` from the media element. `seeking` indicates whether the
  19878. * media is currently seeking to a new position or not.
  19879. *
  19880. * @method Html5#seeking
  19881. * @return {boolean}
  19882. * - The value of `seeking` from the media element.
  19883. * - True indicates that the media is currently seeking to a new position.
  19884. * - False indicates that the media is not seeking to a new position at this time.
  19885. *
  19886. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seeking}
  19887. */
  19888. 'seeking',
  19889. /**
  19890. * Get the value of `seekable` from the media element. `seekable` returns a
  19891. * `TimeRange` object indicating ranges of time that can currently be `seeked` to.
  19892. *
  19893. * @method Html5#seekable
  19894. * @return {TimeRange}
  19895. * The value of `seekable` from the media element. A `TimeRange` object
  19896. * indicating the current ranges of time that can be seeked to.
  19897. *
  19898. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-seekable}
  19899. */
  19900. 'seekable',
  19901. /**
  19902. * Get the value of `ended` from the media element. `ended` indicates whether
  19903. * the media has reached the end or not.
  19904. *
  19905. * @method Html5#ended
  19906. * @return {boolean}
  19907. * - The value of `ended` from the media element.
  19908. * - True indicates that the media has ended.
  19909. * - False indicates that the media has not ended.
  19910. *
  19911. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-ended}
  19912. */
  19913. 'ended',
  19914. /**
  19915. * Get the value of `playbackRate` from the media element. `playbackRate` indicates
  19916. * the rate at which the media is currently playing back. Examples:
  19917. * - if playbackRate is set to 2, media will play twice as fast.
  19918. * - if playbackRate is set to 0.5, media will play half as fast.
  19919. *
  19920. * @method Html5#playbackRate
  19921. * @return {number}
  19922. * The value of `playbackRate` from the media element. A number indicating
  19923. * the current playback speed of the media, where 1 is normal speed.
  19924. *
  19925. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  19926. */
  19927. 'playbackRate',
  19928. /**
  19929. * Get the value of `defaultPlaybackRate` from the media element. `defaultPlaybackRate` indicates
  19930. * the rate at which the media is currently playing back. This value will not indicate the current
  19931. * `playbackRate` after playback has started, use {@link Html5#playbackRate} for that.
  19932. *
  19933. * Examples:
  19934. * - if defaultPlaybackRate is set to 2, media will play twice as fast.
  19935. * - if defaultPlaybackRate is set to 0.5, media will play half as fast.
  19936. *
  19937. * @method Html5.prototype.defaultPlaybackRate
  19938. * @return {number}
  19939. * The value of `defaultPlaybackRate` from the media element. A number indicating
  19940. * the current playback speed of the media, where 1 is normal speed.
  19941. *
  19942. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  19943. */
  19944. 'defaultPlaybackRate',
  19945. /**
  19946. * Get the value of `played` from the media element. `played` returns a `TimeRange`
  19947. * object representing points in the media timeline that have been played.
  19948. *
  19949. * @method Html5#played
  19950. * @return {TimeRange}
  19951. * The value of `played` from the media element. A `TimeRange` object indicating
  19952. * the ranges of time that have been played.
  19953. *
  19954. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-played}
  19955. */
  19956. 'played',
  19957. /**
  19958. * Get the value of `networkState` from the media element. `networkState` indicates
  19959. * the current network state. It returns an enumeration from the following list:
  19960. * - 0: NETWORK_EMPTY
  19961. * - 1: NETWORK_IDLE
  19962. * - 2: NETWORK_LOADING
  19963. * - 3: NETWORK_NO_SOURCE
  19964. *
  19965. * @method Html5#networkState
  19966. * @return {number}
  19967. * The value of `networkState` from the media element. This will be a number
  19968. * from the list in the description.
  19969. *
  19970. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-networkstate}
  19971. */
  19972. 'networkState',
  19973. /**
  19974. * Get the value of `readyState` from the media element. `readyState` indicates
  19975. * the current state of the media element. It returns an enumeration from the
  19976. * following list:
  19977. * - 0: HAVE_NOTHING
  19978. * - 1: HAVE_METADATA
  19979. * - 2: HAVE_CURRENT_DATA
  19980. * - 3: HAVE_FUTURE_DATA
  19981. * - 4: HAVE_ENOUGH_DATA
  19982. *
  19983. * @method Html5#readyState
  19984. * @return {number}
  19985. * The value of `readyState` from the media element. This will be a number
  19986. * from the list in the description.
  19987. *
  19988. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#ready-states}
  19989. */
  19990. 'readyState',
  19991. /**
  19992. * Get the value of `videoWidth` from the video element. `videoWidth` indicates
  19993. * the current width of the video in css pixels.
  19994. *
  19995. * @method Html5#videoWidth
  19996. * @return {number}
  19997. * The value of `videoWidth` from the video element. This will be a number
  19998. * in css pixels.
  19999. *
  20000. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  20001. */
  20002. 'videoWidth',
  20003. /**
  20004. * Get the value of `videoHeight` from the video element. `videoHeight` indicates
  20005. * the current height of the video in css pixels.
  20006. *
  20007. * @method Html5#videoHeight
  20008. * @return {number}
  20009. * The value of `videoHeight` from the video element. This will be a number
  20010. * in css pixels.
  20011. *
  20012. * @see [Spec] {@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth}
  20013. */
  20014. 'videoHeight'].forEach(function (prop) {
  20015. Html5.prototype[prop] = function () {
  20016. return this.el_[prop];
  20017. };
  20018. }); // Wrap native properties with a setter in this format:
  20019. // set + toTitleCase(name)
  20020. // The list is as follows:
  20021. // setVolume, setSrc, setPoster, setPreload, setPlaybackRate, setDefaultPlaybackRate
  20022. [
  20023. /**
  20024. * Set the value of `volume` on the media element. `volume` indicates the current
  20025. * audio level as a percentage in decimal form. This means that 1 is 100%, 0.5 is 50%, and
  20026. * so on.
  20027. *
  20028. * @method Html5#setVolume
  20029. * @param {number} percentAsDecimal
  20030. * The volume percent as a decimal. Valid range is from 0-1.
  20031. *
  20032. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-a-volume}
  20033. */
  20034. 'volume',
  20035. /**
  20036. * Set the value of `src` on the media element. `src` indicates the current
  20037. * {@link Tech~SourceObject} for the media.
  20038. *
  20039. * @method Html5#setSrc
  20040. * @param {Tech~SourceObject} src
  20041. * The source object to set as the current source.
  20042. *
  20043. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-src}
  20044. */
  20045. 'src',
  20046. /**
  20047. * Set the value of `poster` on the media element. `poster` is the url to
  20048. * an image file that can/will be shown when no media data is available.
  20049. *
  20050. * @method Html5#setPoster
  20051. * @param {string} poster
  20052. * The url to an image that should be used as the `poster` for the media
  20053. * element.
  20054. *
  20055. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-poster}
  20056. */
  20057. 'poster',
  20058. /**
  20059. * Set the value of `preload` on the media element. `preload` indicates
  20060. * what should download before the media is interacted with. It can have the following
  20061. * values:
  20062. * - none: nothing should be downloaded
  20063. * - metadata: poster and the first few frames of the media may be downloaded to get
  20064. * media dimensions and other metadata
  20065. * - auto: allow the media and metadata for the media to be downloaded before
  20066. * interaction
  20067. *
  20068. * @method Html5#setPreload
  20069. * @param {string} preload
  20070. * The value of `preload` to set on the media element. Must be 'none', 'metadata',
  20071. * or 'auto'.
  20072. *
  20073. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#attr-media-preload}
  20074. */
  20075. 'preload',
  20076. /**
  20077. * Set the value of `playbackRate` on the media element. `playbackRate` indicates
  20078. * the rate at which the media should play back. Examples:
  20079. * - if playbackRate is set to 2, media will play twice as fast.
  20080. * - if playbackRate is set to 0.5, media will play half as fast.
  20081. *
  20082. * @method Html5#setPlaybackRate
  20083. * @return {number}
  20084. * The value of `playbackRate` from the media element. A number indicating
  20085. * the current playback speed of the media, where 1 is normal speed.
  20086. *
  20087. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-playbackrate}
  20088. */
  20089. 'playbackRate',
  20090. /**
  20091. * Set the value of `defaultPlaybackRate` on the media element. `defaultPlaybackRate` indicates
  20092. * the rate at which the media should play back upon initial startup. Changing this value
  20093. * after a video has started will do nothing. Instead you should used {@link Html5#setPlaybackRate}.
  20094. *
  20095. * Example Values:
  20096. * - if playbackRate is set to 2, media will play twice as fast.
  20097. * - if playbackRate is set to 0.5, media will play half as fast.
  20098. *
  20099. * @method Html5.prototype.setDefaultPlaybackRate
  20100. * @return {number}
  20101. * The value of `defaultPlaybackRate` from the media element. A number indicating
  20102. * the current playback speed of the media, where 1 is normal speed.
  20103. *
  20104. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-defaultplaybackrate}
  20105. */
  20106. 'defaultPlaybackRate'].forEach(function (prop) {
  20107. Html5.prototype['set' + toTitleCase(prop)] = function (v) {
  20108. this.el_[prop] = v;
  20109. };
  20110. }); // wrap native functions with a function
  20111. // The list is as follows:
  20112. // pause, load, play
  20113. [
  20114. /**
  20115. * A wrapper around the media elements `pause` function. This will call the `HTML5`
  20116. * media elements `pause` function.
  20117. *
  20118. * @method Html5#pause
  20119. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-pause}
  20120. */
  20121. 'pause',
  20122. /**
  20123. * A wrapper around the media elements `load` function. This will call the `HTML5`s
  20124. * media element `load` function.
  20125. *
  20126. * @method Html5#load
  20127. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-load}
  20128. */
  20129. 'load',
  20130. /**
  20131. * A wrapper around the media elements `play` function. This will call the `HTML5`s
  20132. * media element `play` function.
  20133. *
  20134. * @method Html5#play
  20135. * @see [Spec]{@link https://www.w3.org/TR/html5/embedded-content-0.html#dom-media-play}
  20136. */
  20137. 'play'].forEach(function (prop) {
  20138. Html5.prototype[prop] = function () {
  20139. return this.el_[prop]();
  20140. };
  20141. });
  20142. Tech.withSourceHandlers(Html5);
  20143. /**
  20144. * Native source handler for Html5, simply passes the source to the media element.
  20145. *
  20146. * @property {Tech~SourceObject} source
  20147. * The source object
  20148. *
  20149. * @property {Html5} tech
  20150. * The instance of the HTML5 tech.
  20151. */
  20152. Html5.nativeSourceHandler = {};
  20153. /**
  20154. * Check if the media element can play the given mime type.
  20155. *
  20156. * @param {string} type
  20157. * The mimetype to check
  20158. *
  20159. * @return {string}
  20160. * 'probably', 'maybe', or '' (empty string)
  20161. */
  20162. Html5.nativeSourceHandler.canPlayType = function (type) {
  20163. // IE without MediaPlayer throws an error (#519)
  20164. try {
  20165. return Html5.TEST_VID.canPlayType(type);
  20166. } catch (e) {
  20167. return '';
  20168. }
  20169. };
  20170. /**
  20171. * Check if the media element can handle a source natively.
  20172. *
  20173. * @param {Tech~SourceObject} source
  20174. * The source object
  20175. *
  20176. * @param {Object} [options]
  20177. * Options to be passed to the tech.
  20178. *
  20179. * @return {string}
  20180. * 'probably', 'maybe', or '' (empty string).
  20181. */
  20182. Html5.nativeSourceHandler.canHandleSource = function (source, options) {
  20183. // If a type was provided we should rely on that
  20184. if (source.type) {
  20185. return Html5.nativeSourceHandler.canPlayType(source.type); // If no type, fall back to checking 'video/[EXTENSION]'
  20186. } else if (source.src) {
  20187. var ext = getFileExtension(source.src);
  20188. return Html5.nativeSourceHandler.canPlayType("video/" + ext);
  20189. }
  20190. return '';
  20191. };
  20192. /**
  20193. * Pass the source to the native media element.
  20194. *
  20195. * @param {Tech~SourceObject} source
  20196. * The source object
  20197. *
  20198. * @param {Html5} tech
  20199. * The instance of the Html5 tech
  20200. *
  20201. * @param {Object} [options]
  20202. * The options to pass to the source
  20203. */
  20204. Html5.nativeSourceHandler.handleSource = function (source, tech, options) {
  20205. tech.setSrc(source.src);
  20206. };
  20207. /**
  20208. * A noop for the native dispose function, as cleanup is not needed.
  20209. */
  20210. Html5.nativeSourceHandler.dispose = function () {}; // Register the native source handler
  20211. Html5.registerSourceHandler(Html5.nativeSourceHandler);
  20212. Tech.registerTech('Html5', Html5);
  20213. // on the player when they happen
  20214. var TECH_EVENTS_RETRIGGER = [
  20215. /**
  20216. * Fired while the user agent is downloading media data.
  20217. *
  20218. * @event Player#progress
  20219. * @type {EventTarget~Event}
  20220. */
  20221. /**
  20222. * Retrigger the `progress` event that was triggered by the {@link Tech}.
  20223. *
  20224. * @private
  20225. * @method Player#handleTechProgress_
  20226. * @fires Player#progress
  20227. * @listens Tech#progress
  20228. */
  20229. 'progress',
  20230. /**
  20231. * Fires when the loading of an audio/video is aborted.
  20232. *
  20233. * @event Player#abort
  20234. * @type {EventTarget~Event}
  20235. */
  20236. /**
  20237. * Retrigger the `abort` event that was triggered by the {@link Tech}.
  20238. *
  20239. * @private
  20240. * @method Player#handleTechAbort_
  20241. * @fires Player#abort
  20242. * @listens Tech#abort
  20243. */
  20244. 'abort',
  20245. /**
  20246. * Fires when the browser is intentionally not getting media data.
  20247. *
  20248. * @event Player#suspend
  20249. * @type {EventTarget~Event}
  20250. */
  20251. /**
  20252. * Retrigger the `suspend` event that was triggered by the {@link Tech}.
  20253. *
  20254. * @private
  20255. * @method Player#handleTechSuspend_
  20256. * @fires Player#suspend
  20257. * @listens Tech#suspend
  20258. */
  20259. 'suspend',
  20260. /**
  20261. * Fires when the current playlist is empty.
  20262. *
  20263. * @event Player#emptied
  20264. * @type {EventTarget~Event}
  20265. */
  20266. /**
  20267. * Retrigger the `emptied` event that was triggered by the {@link Tech}.
  20268. *
  20269. * @private
  20270. * @method Player#handleTechEmptied_
  20271. * @fires Player#emptied
  20272. * @listens Tech#emptied
  20273. */
  20274. 'emptied',
  20275. /**
  20276. * Fires when the browser is trying to get media data, but data is not available.
  20277. *
  20278. * @event Player#stalled
  20279. * @type {EventTarget~Event}
  20280. */
  20281. /**
  20282. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  20283. *
  20284. * @private
  20285. * @method Player#handleTechStalled_
  20286. * @fires Player#stalled
  20287. * @listens Tech#stalled
  20288. */
  20289. 'stalled',
  20290. /**
  20291. * Fires when the browser has loaded meta data for the audio/video.
  20292. *
  20293. * @event Player#loadedmetadata
  20294. * @type {EventTarget~Event}
  20295. */
  20296. /**
  20297. * Retrigger the `stalled` event that was triggered by the {@link Tech}.
  20298. *
  20299. * @private
  20300. * @method Player#handleTechLoadedmetadata_
  20301. * @fires Player#loadedmetadata
  20302. * @listens Tech#loadedmetadata
  20303. */
  20304. 'loadedmetadata',
  20305. /**
  20306. * Fires when the browser has loaded the current frame of the audio/video.
  20307. *
  20308. * @event Player#loadeddata
  20309. * @type {event}
  20310. */
  20311. /**
  20312. * Retrigger the `loadeddata` event that was triggered by the {@link Tech}.
  20313. *
  20314. * @private
  20315. * @method Player#handleTechLoaddeddata_
  20316. * @fires Player#loadeddata
  20317. * @listens Tech#loadeddata
  20318. */
  20319. 'loadeddata',
  20320. /**
  20321. * Fires when the current playback position has changed.
  20322. *
  20323. * @event Player#timeupdate
  20324. * @type {event}
  20325. */
  20326. /**
  20327. * Retrigger the `timeupdate` event that was triggered by the {@link Tech}.
  20328. *
  20329. * @private
  20330. * @method Player#handleTechTimeUpdate_
  20331. * @fires Player#timeupdate
  20332. * @listens Tech#timeupdate
  20333. */
  20334. 'timeupdate',
  20335. /**
  20336. * Fires when the video's intrinsic dimensions change
  20337. *
  20338. * @event Player#resize
  20339. * @type {event}
  20340. */
  20341. /**
  20342. * Retrigger the `resize` event that was triggered by the {@link Tech}.
  20343. *
  20344. * @private
  20345. * @method Player#handleTechResize_
  20346. * @fires Player#resize
  20347. * @listens Tech#resize
  20348. */
  20349. 'resize',
  20350. /**
  20351. * Fires when the volume has been changed
  20352. *
  20353. * @event Player#volumechange
  20354. * @type {event}
  20355. */
  20356. /**
  20357. * Retrigger the `volumechange` event that was triggered by the {@link Tech}.
  20358. *
  20359. * @private
  20360. * @method Player#handleTechVolumechange_
  20361. * @fires Player#volumechange
  20362. * @listens Tech#volumechange
  20363. */
  20364. 'volumechange',
  20365. /**
  20366. * Fires when the text track has been changed
  20367. *
  20368. * @event Player#texttrackchange
  20369. * @type {event}
  20370. */
  20371. /**
  20372. * Retrigger the `texttrackchange` event that was triggered by the {@link Tech}.
  20373. *
  20374. * @private
  20375. * @method Player#handleTechTexttrackchange_
  20376. * @fires Player#texttrackchange
  20377. * @listens Tech#texttrackchange
  20378. */
  20379. 'texttrackchange']; // events to queue when playback rate is zero
  20380. // this is a hash for the sole purpose of mapping non-camel-cased event names
  20381. // to camel-cased function names
  20382. var TECH_EVENTS_QUEUE = {
  20383. canplay: 'CanPlay',
  20384. canplaythrough: 'CanPlayThrough',
  20385. playing: 'Playing',
  20386. seeked: 'Seeked'
  20387. };
  20388. var BREAKPOINT_ORDER = ['tiny', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'huge'];
  20389. var BREAKPOINT_CLASSES = {}; // grep: vjs-layout-tiny
  20390. // grep: vjs-layout-x-small
  20391. // grep: vjs-layout-small
  20392. // grep: vjs-layout-medium
  20393. // grep: vjs-layout-large
  20394. // grep: vjs-layout-x-large
  20395. // grep: vjs-layout-huge
  20396. BREAKPOINT_ORDER.forEach(function (k) {
  20397. var v = k.charAt(0) === 'x' ? "x-" + k.substring(1) : k;
  20398. BREAKPOINT_CLASSES[k] = "vjs-layout-" + v;
  20399. });
  20400. var DEFAULT_BREAKPOINTS = {
  20401. tiny: 210,
  20402. xsmall: 320,
  20403. small: 425,
  20404. medium: 768,
  20405. large: 1440,
  20406. xlarge: 2560,
  20407. huge: Infinity
  20408. };
  20409. /**
  20410. * An instance of the `Player` class is created when any of the Video.js setup methods
  20411. * are used to initialize a video.
  20412. *
  20413. * After an instance has been created it can be accessed globally in two ways:
  20414. * 1. By calling `videojs('example_video_1');`
  20415. * 2. By using it directly via `videojs.players.example_video_1;`
  20416. *
  20417. * @extends Component
  20418. */
  20419. var Player =
  20420. /*#__PURE__*/
  20421. function (_Component) {
  20422. _inheritsLoose(Player, _Component);
  20423. /**
  20424. * Create an instance of this class.
  20425. *
  20426. * @param {Element} tag
  20427. * The original video DOM element used for configuring options.
  20428. *
  20429. * @param {Object} [options]
  20430. * Object of option names and values.
  20431. *
  20432. * @param {Component~ReadyCallback} [ready]
  20433. * Ready callback function.
  20434. */
  20435. function Player(tag, options, ready) {
  20436. var _this;
  20437. // Make sure tag ID exists
  20438. tag.id = tag.id || options.id || "vjs_video_" + newGUID(); // Set Options
  20439. // The options argument overrides options set in the video tag
  20440. // which overrides globally set options.
  20441. // This latter part coincides with the load order
  20442. // (tag must exist before Player)
  20443. options = assign(Player.getTagSettings(tag), options); // Delay the initialization of children because we need to set up
  20444. // player properties first, and can't use `this` before `super()`
  20445. options.initChildren = false; // Same with creating the element
  20446. options.createEl = false; // don't auto mixin the evented mixin
  20447. options.evented = false; // we don't want the player to report touch activity on itself
  20448. // see enableTouchActivity in Component
  20449. options.reportTouchActivity = false; // If language is not set, get the closest lang attribute
  20450. if (!options.language) {
  20451. if (typeof tag.closest === 'function') {
  20452. var closest = tag.closest('[lang]');
  20453. if (closest && closest.getAttribute) {
  20454. options.language = closest.getAttribute('lang');
  20455. }
  20456. } else {
  20457. var element = tag;
  20458. while (element && element.nodeType === 1) {
  20459. if (getAttributes(element).hasOwnProperty('lang')) {
  20460. options.language = element.getAttribute('lang');
  20461. break;
  20462. }
  20463. element = element.parentNode;
  20464. }
  20465. }
  20466. } // Run base component initializing with new options
  20467. _this = _Component.call(this, null, options, ready) || this; // Create bound methods for document listeners.
  20468. _this.boundDocumentFullscreenChange_ = bind(_assertThisInitialized(_this), _this.documentFullscreenChange_);
  20469. _this.boundFullWindowOnEscKey_ = bind(_assertThisInitialized(_this), _this.fullWindowOnEscKey); // create logger
  20470. _this.log = createLogger$1(_this.id_); // Hold our own reference to fullscreen api so it can be mocked in tests
  20471. _this.fsApi_ = FullscreenApi; // Tracks when a tech changes the poster
  20472. _this.isPosterFromTech_ = false; // Holds callback info that gets queued when playback rate is zero
  20473. // and a seek is happening
  20474. _this.queuedCallbacks_ = []; // Turn off API access because we're loading a new tech that might load asynchronously
  20475. _this.isReady_ = false; // Init state hasStarted_
  20476. _this.hasStarted_ = false; // Init state userActive_
  20477. _this.userActive_ = false; // if the global option object was accidentally blown away by
  20478. // someone, bail early with an informative error
  20479. if (!_this.options_ || !_this.options_.techOrder || !_this.options_.techOrder.length) {
  20480. throw new Error('No techOrder specified. Did you overwrite ' + 'videojs.options instead of just changing the ' + 'properties you want to override?');
  20481. } // Store the original tag used to set options
  20482. _this.tag = tag; // Store the tag attributes used to restore html5 element
  20483. _this.tagAttributes = tag && getAttributes(tag); // Update current language
  20484. _this.language(_this.options_.language); // Update Supported Languages
  20485. if (options.languages) {
  20486. // Normalise player option languages to lowercase
  20487. var languagesToLower = {};
  20488. Object.getOwnPropertyNames(options.languages).forEach(function (name) {
  20489. languagesToLower[name.toLowerCase()] = options.languages[name];
  20490. });
  20491. _this.languages_ = languagesToLower;
  20492. } else {
  20493. _this.languages_ = Player.prototype.options_.languages;
  20494. }
  20495. _this.resetCache_(); // Set poster
  20496. _this.poster_ = options.poster || ''; // Set controls
  20497. _this.controls_ = !!options.controls; // Original tag settings stored in options
  20498. // now remove immediately so native controls don't flash.
  20499. // May be turned back on by HTML5 tech if nativeControlsForTouch is true
  20500. tag.controls = false;
  20501. tag.removeAttribute('controls');
  20502. _this.changingSrc_ = false;
  20503. _this.playCallbacks_ = [];
  20504. _this.playTerminatedQueue_ = []; // the attribute overrides the option
  20505. if (tag.hasAttribute('autoplay')) {
  20506. _this.autoplay(true);
  20507. } else {
  20508. // otherwise use the setter to validate and
  20509. // set the correct value.
  20510. _this.autoplay(_this.options_.autoplay);
  20511. } // check plugins
  20512. if (options.plugins) {
  20513. Object.keys(options.plugins).forEach(function (name) {
  20514. if (typeof _this[name] !== 'function') {
  20515. throw new Error("plugin \"" + name + "\" does not exist");
  20516. }
  20517. });
  20518. }
  20519. /*
  20520. * Store the internal state of scrubbing
  20521. *
  20522. * @private
  20523. * @return {Boolean} True if the user is scrubbing
  20524. */
  20525. _this.scrubbing_ = false;
  20526. _this.el_ = _this.createEl(); // Make this an evented object and use `el_` as its event bus.
  20527. evented(_assertThisInitialized(_this), {
  20528. eventBusKey: 'el_'
  20529. });
  20530. if (_this.fluid_) {
  20531. _this.on('playerreset', _this.updateStyleEl_);
  20532. } // We also want to pass the original player options to each component and plugin
  20533. // as well so they don't need to reach back into the player for options later.
  20534. // We also need to do another copy of this.options_ so we don't end up with
  20535. // an infinite loop.
  20536. var playerOptionsCopy = mergeOptions(_this.options_); // Load plugins
  20537. if (options.plugins) {
  20538. Object.keys(options.plugins).forEach(function (name) {
  20539. _this[name](options.plugins[name]);
  20540. });
  20541. }
  20542. _this.options_.playerOptions = playerOptionsCopy;
  20543. _this.middleware_ = [];
  20544. _this.initChildren(); // Set isAudio based on whether or not an audio tag was used
  20545. _this.isAudio(tag.nodeName.toLowerCase() === 'audio'); // Update controls className. Can't do this when the controls are initially
  20546. // set because the element doesn't exist yet.
  20547. if (_this.controls()) {
  20548. _this.addClass('vjs-controls-enabled');
  20549. } else {
  20550. _this.addClass('vjs-controls-disabled');
  20551. } // Set ARIA label and region role depending on player type
  20552. _this.el_.setAttribute('role', 'region');
  20553. if (_this.isAudio()) {
  20554. _this.el_.setAttribute('aria-label', _this.localize('Audio Player'));
  20555. } else {
  20556. _this.el_.setAttribute('aria-label', _this.localize('Video Player'));
  20557. }
  20558. if (_this.isAudio()) {
  20559. _this.addClass('vjs-audio');
  20560. }
  20561. if (_this.flexNotSupported_()) {
  20562. _this.addClass('vjs-no-flex');
  20563. } // TODO: Make this smarter. Toggle user state between touching/mousing
  20564. // using events, since devices can have both touch and mouse events.
  20565. // TODO: Make this check be performed again when the window switches between monitors
  20566. // (See https://github.com/videojs/video.js/issues/5683)
  20567. if (TOUCH_ENABLED) {
  20568. _this.addClass('vjs-touch-enabled');
  20569. } // iOS Safari has broken hover handling
  20570. if (!IS_IOS) {
  20571. _this.addClass('vjs-workinghover');
  20572. } // Make player easily findable by ID
  20573. Player.players[_this.id_] = _assertThisInitialized(_this); // Add a major version class to aid css in plugins
  20574. var majorVersion = version.split('.')[0];
  20575. _this.addClass("vjs-v" + majorVersion); // When the player is first initialized, trigger activity so components
  20576. // like the control bar show themselves if needed
  20577. _this.userActive(true);
  20578. _this.reportUserActivity();
  20579. _this.one('play', _this.listenForUserActivity_);
  20580. _this.on('stageclick', _this.handleStageClick_);
  20581. _this.on('keydown', _this.handleKeyDown);
  20582. _this.breakpoints(_this.options_.breakpoints);
  20583. _this.responsive(_this.options_.responsive);
  20584. return _this;
  20585. }
  20586. /**
  20587. * Destroys the video player and does any necessary cleanup.
  20588. *
  20589. * This is especially helpful if you are dynamically adding and removing videos
  20590. * to/from the DOM.
  20591. *
  20592. * @fires Player#dispose
  20593. */
  20594. var _proto = Player.prototype;
  20595. _proto.dispose = function dispose() {
  20596. var _this2 = this;
  20597. /**
  20598. * Called when the player is being disposed of.
  20599. *
  20600. * @event Player#dispose
  20601. * @type {EventTarget~Event}
  20602. */
  20603. this.trigger('dispose'); // prevent dispose from being called twice
  20604. this.off('dispose'); // Make sure all player-specific document listeners are unbound. This is
  20605. off(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_);
  20606. off(document, 'keydown', this.boundFullWindowOnEscKey_);
  20607. if (this.styleEl_ && this.styleEl_.parentNode) {
  20608. this.styleEl_.parentNode.removeChild(this.styleEl_);
  20609. this.styleEl_ = null;
  20610. } // Kill reference to this player
  20611. Player.players[this.id_] = null;
  20612. if (this.tag && this.tag.player) {
  20613. this.tag.player = null;
  20614. }
  20615. if (this.el_ && this.el_.player) {
  20616. this.el_.player = null;
  20617. }
  20618. if (this.tech_) {
  20619. this.tech_.dispose();
  20620. this.isPosterFromTech_ = false;
  20621. this.poster_ = '';
  20622. }
  20623. if (this.playerElIngest_) {
  20624. this.playerElIngest_ = null;
  20625. }
  20626. if (this.tag) {
  20627. this.tag = null;
  20628. }
  20629. clearCacheForPlayer(this); // remove all event handlers for track lists
  20630. // all tracks and track listeners are removed on
  20631. // tech dispose
  20632. ALL.names.forEach(function (name) {
  20633. var props = ALL[name];
  20634. var list = _this2[props.getterName](); // if it is not a native list
  20635. // we have to manually remove event listeners
  20636. if (list && list.off) {
  20637. list.off();
  20638. }
  20639. }); // the actual .el_ is removed here
  20640. _Component.prototype.dispose.call(this);
  20641. }
  20642. /**
  20643. * Create the `Player`'s DOM element.
  20644. *
  20645. * @return {Element}
  20646. * The DOM element that gets created.
  20647. */
  20648. ;
  20649. _proto.createEl = function createEl() {
  20650. var tag = this.tag;
  20651. var el;
  20652. var playerElIngest = this.playerElIngest_ = tag.parentNode && tag.parentNode.hasAttribute && tag.parentNode.hasAttribute('data-vjs-player');
  20653. var divEmbed = this.tag.tagName.toLowerCase() === 'video-js';
  20654. if (playerElIngest) {
  20655. el = this.el_ = tag.parentNode;
  20656. } else if (!divEmbed) {
  20657. el = this.el_ = _Component.prototype.createEl.call(this, 'div');
  20658. } // Copy over all the attributes from the tag, including ID and class
  20659. // ID will now reference player box, not the video tag
  20660. var attrs = getAttributes(tag);
  20661. if (divEmbed) {
  20662. el = this.el_ = tag;
  20663. tag = this.tag = document.createElement('video');
  20664. while (el.children.length) {
  20665. tag.appendChild(el.firstChild);
  20666. }
  20667. if (!hasClass(el, 'video-js')) {
  20668. addClass(el, 'video-js');
  20669. }
  20670. el.appendChild(tag);
  20671. playerElIngest = this.playerElIngest_ = el; // move properties over from our custom `video-js` element
  20672. // to our new `video` element. This will move things like
  20673. // `src` or `controls` that were set via js before the player
  20674. // was initialized.
  20675. Object.keys(el).forEach(function (k) {
  20676. tag[k] = el[k];
  20677. });
  20678. } // set tabindex to -1 to remove the video element from the focus order
  20679. tag.setAttribute('tabindex', '-1');
  20680. attrs.tabindex = '-1'; // Workaround for #4583 (JAWS+IE doesn't announce BPB or play button), and
  20681. // for the same issue with Chrome (on Windows) with JAWS.
  20682. // See https://github.com/FreedomScientific/VFO-standards-support/issues/78
  20683. // Note that we can't detect if JAWS is being used, but this ARIA attribute
  20684. // doesn't change behavior of IE11 or Chrome if JAWS is not being used
  20685. if (IE_VERSION || IS_CHROME && IS_WINDOWS) {
  20686. tag.setAttribute('role', 'application');
  20687. attrs.role = 'application';
  20688. } // Remove width/height attrs from tag so CSS can make it 100% width/height
  20689. tag.removeAttribute('width');
  20690. tag.removeAttribute('height');
  20691. if ('width' in attrs) {
  20692. delete attrs.width;
  20693. }
  20694. if ('height' in attrs) {
  20695. delete attrs.height;
  20696. }
  20697. Object.getOwnPropertyNames(attrs).forEach(function (attr) {
  20698. // don't copy over the class attribute to the player element when we're in a div embed
  20699. // the class is already set up properly in the divEmbed case
  20700. // and we want to make sure that the `video-js` class doesn't get lost
  20701. if (!(divEmbed && attr === 'class')) {
  20702. el.setAttribute(attr, attrs[attr]);
  20703. }
  20704. if (divEmbed) {
  20705. tag.setAttribute(attr, attrs[attr]);
  20706. }
  20707. }); // Update tag id/class for use as HTML5 playback tech
  20708. // Might think we should do this after embedding in container so .vjs-tech class
  20709. // doesn't flash 100% width/height, but class only applies with .video-js parent
  20710. tag.playerId = tag.id;
  20711. tag.id += '_html5_api';
  20712. tag.className = 'vjs-tech'; // Make player findable on elements
  20713. tag.player = el.player = this; // Default state of video is paused
  20714. this.addClass('vjs-paused'); // Add a style element in the player that we'll use to set the width/height
  20715. // of the player in a way that's still overrideable by CSS, just like the
  20716. // video element
  20717. if (window$1.VIDEOJS_NO_DYNAMIC_STYLE !== true) {
  20718. this.styleEl_ = createStyleElement('vjs-styles-dimensions');
  20719. var defaultsStyleEl = $('.vjs-styles-defaults');
  20720. var head = $('head');
  20721. head.insertBefore(this.styleEl_, defaultsStyleEl ? defaultsStyleEl.nextSibling : head.firstChild);
  20722. }
  20723. this.fill_ = false;
  20724. this.fluid_ = false; // Pass in the width/height/aspectRatio options which will update the style el
  20725. this.width(this.options_.width);
  20726. this.height(this.options_.height);
  20727. this.fill(this.options_.fill);
  20728. this.fluid(this.options_.fluid);
  20729. this.aspectRatio(this.options_.aspectRatio); // Hide any links within the video/audio tag,
  20730. // because IE doesn't hide them completely from screen readers.
  20731. var links = tag.getElementsByTagName('a');
  20732. for (var i = 0; i < links.length; i++) {
  20733. var linkEl = links.item(i);
  20734. addClass(linkEl, 'vjs-hidden');
  20735. linkEl.setAttribute('hidden', 'hidden');
  20736. } // insertElFirst seems to cause the networkState to flicker from 3 to 2, so
  20737. // keep track of the original for later so we can know if the source originally failed
  20738. tag.initNetworkState_ = tag.networkState; // Wrap video tag in div (el/box) container
  20739. if (tag.parentNode && !playerElIngest) {
  20740. tag.parentNode.insertBefore(el, tag);
  20741. } // insert the tag as the first child of the player element
  20742. // then manually add it to the children array so that this.addChild
  20743. // will work properly for other components
  20744. //
  20745. // Breaks iPhone, fixed in HTML5 setup.
  20746. prependTo(tag, el);
  20747. this.children_.unshift(tag); // Set lang attr on player to ensure CSS :lang() in consistent with player
  20748. // if it's been set to something different to the doc
  20749. this.el_.setAttribute('lang', this.language_);
  20750. this.el_ = el;
  20751. return el;
  20752. }
  20753. /**
  20754. * A getter/setter for the `Player`'s width. Returns the player's configured value.
  20755. * To get the current width use `currentWidth()`.
  20756. *
  20757. * @param {number} [value]
  20758. * The value to set the `Player`'s width to.
  20759. *
  20760. * @return {number}
  20761. * The current width of the `Player` when getting.
  20762. */
  20763. ;
  20764. _proto.width = function width(value) {
  20765. return this.dimension('width', value);
  20766. }
  20767. /**
  20768. * A getter/setter for the `Player`'s height. Returns the player's configured value.
  20769. * To get the current height use `currentheight()`.
  20770. *
  20771. * @param {number} [value]
  20772. * The value to set the `Player`'s heigth to.
  20773. *
  20774. * @return {number}
  20775. * The current height of the `Player` when getting.
  20776. */
  20777. ;
  20778. _proto.height = function height(value) {
  20779. return this.dimension('height', value);
  20780. }
  20781. /**
  20782. * A getter/setter for the `Player`'s width & height.
  20783. *
  20784. * @param {string} dimension
  20785. * This string can be:
  20786. * - 'width'
  20787. * - 'height'
  20788. *
  20789. * @param {number} [value]
  20790. * Value for dimension specified in the first argument.
  20791. *
  20792. * @return {number}
  20793. * The dimension arguments value when getting (width/height).
  20794. */
  20795. ;
  20796. _proto.dimension = function dimension(_dimension, value) {
  20797. var privDimension = _dimension + '_';
  20798. if (value === undefined) {
  20799. return this[privDimension] || 0;
  20800. }
  20801. if (value === '') {
  20802. // If an empty string is given, reset the dimension to be automatic
  20803. this[privDimension] = undefined;
  20804. this.updateStyleEl_();
  20805. return;
  20806. }
  20807. var parsedVal = parseFloat(value);
  20808. if (isNaN(parsedVal)) {
  20809. log.error("Improper value \"" + value + "\" supplied for for " + _dimension);
  20810. return;
  20811. }
  20812. this[privDimension] = parsedVal;
  20813. this.updateStyleEl_();
  20814. }
  20815. /**
  20816. * A getter/setter/toggler for the vjs-fluid `className` on the `Player`.
  20817. *
  20818. * Turning this on will turn off fill mode.
  20819. *
  20820. * @param {boolean} [bool]
  20821. * - A value of true adds the class.
  20822. * - A value of false removes the class.
  20823. * - No value will be a getter.
  20824. *
  20825. * @return {boolean|undefined}
  20826. * - The value of fluid when getting.
  20827. * - `undefined` when setting.
  20828. */
  20829. ;
  20830. _proto.fluid = function fluid(bool) {
  20831. if (bool === undefined) {
  20832. return !!this.fluid_;
  20833. }
  20834. this.fluid_ = !!bool;
  20835. if (isEvented(this)) {
  20836. this.off('playerreset', this.updateStyleEl_);
  20837. }
  20838. if (bool) {
  20839. this.addClass('vjs-fluid');
  20840. this.fill(false);
  20841. addEventedCallback(function () {
  20842. this.on('playerreset', this.updateStyleEl_);
  20843. });
  20844. } else {
  20845. this.removeClass('vjs-fluid');
  20846. }
  20847. this.updateStyleEl_();
  20848. }
  20849. /**
  20850. * A getter/setter/toggler for the vjs-fill `className` on the `Player`.
  20851. *
  20852. * Turning this on will turn off fluid mode.
  20853. *
  20854. * @param {boolean} [bool]
  20855. * - A value of true adds the class.
  20856. * - A value of false removes the class.
  20857. * - No value will be a getter.
  20858. *
  20859. * @return {boolean|undefined}
  20860. * - The value of fluid when getting.
  20861. * - `undefined` when setting.
  20862. */
  20863. ;
  20864. _proto.fill = function fill(bool) {
  20865. if (bool === undefined) {
  20866. return !!this.fill_;
  20867. }
  20868. this.fill_ = !!bool;
  20869. if (bool) {
  20870. this.addClass('vjs-fill');
  20871. this.fluid(false);
  20872. } else {
  20873. this.removeClass('vjs-fill');
  20874. }
  20875. }
  20876. /**
  20877. * Get/Set the aspect ratio
  20878. *
  20879. * @param {string} [ratio]
  20880. * Aspect ratio for player
  20881. *
  20882. * @return {string|undefined}
  20883. * returns the current aspect ratio when getting
  20884. */
  20885. /**
  20886. * A getter/setter for the `Player`'s aspect ratio.
  20887. *
  20888. * @param {string} [ratio]
  20889. * The value to set the `Player's aspect ratio to.
  20890. *
  20891. * @return {string|undefined}
  20892. * - The current aspect ratio of the `Player` when getting.
  20893. * - undefined when setting
  20894. */
  20895. ;
  20896. _proto.aspectRatio = function aspectRatio(ratio) {
  20897. if (ratio === undefined) {
  20898. return this.aspectRatio_;
  20899. } // Check for width:height format
  20900. if (!/^\d+\:\d+$/.test(ratio)) {
  20901. throw new Error('Improper value supplied for aspect ratio. The format should be width:height, for example 16:9.');
  20902. }
  20903. this.aspectRatio_ = ratio; // We're assuming if you set an aspect ratio you want fluid mode,
  20904. // because in fixed mode you could calculate width and height yourself.
  20905. this.fluid(true);
  20906. this.updateStyleEl_();
  20907. }
  20908. /**
  20909. * Update styles of the `Player` element (height, width and aspect ratio).
  20910. *
  20911. * @private
  20912. * @listens Tech#loadedmetadata
  20913. */
  20914. ;
  20915. _proto.updateStyleEl_ = function updateStyleEl_() {
  20916. if (window$1.VIDEOJS_NO_DYNAMIC_STYLE === true) {
  20917. var _width = typeof this.width_ === 'number' ? this.width_ : this.options_.width;
  20918. var _height = typeof this.height_ === 'number' ? this.height_ : this.options_.height;
  20919. var techEl = this.tech_ && this.tech_.el();
  20920. if (techEl) {
  20921. if (_width >= 0) {
  20922. techEl.width = _width;
  20923. }
  20924. if (_height >= 0) {
  20925. techEl.height = _height;
  20926. }
  20927. }
  20928. return;
  20929. }
  20930. var width;
  20931. var height;
  20932. var aspectRatio;
  20933. var idClass; // The aspect ratio is either used directly or to calculate width and height.
  20934. if (this.aspectRatio_ !== undefined && this.aspectRatio_ !== 'auto') {
  20935. // Use any aspectRatio that's been specifically set
  20936. aspectRatio = this.aspectRatio_;
  20937. } else if (this.videoWidth() > 0) {
  20938. // Otherwise try to get the aspect ratio from the video metadata
  20939. aspectRatio = this.videoWidth() + ':' + this.videoHeight();
  20940. } else {
  20941. // Or use a default. The video element's is 2:1, but 16:9 is more common.
  20942. aspectRatio = '16:9';
  20943. } // Get the ratio as a decimal we can use to calculate dimensions
  20944. var ratioParts = aspectRatio.split(':');
  20945. var ratioMultiplier = ratioParts[1] / ratioParts[0];
  20946. if (this.width_ !== undefined) {
  20947. // Use any width that's been specifically set
  20948. width = this.width_;
  20949. } else if (this.height_ !== undefined) {
  20950. // Or calulate the width from the aspect ratio if a height has been set
  20951. width = this.height_ / ratioMultiplier;
  20952. } else {
  20953. // Or use the video's metadata, or use the video el's default of 300
  20954. width = this.videoWidth() || 300;
  20955. }
  20956. if (this.height_ !== undefined) {
  20957. // Use any height that's been specifically set
  20958. height = this.height_;
  20959. } else {
  20960. // Otherwise calculate the height from the ratio and the width
  20961. height = width * ratioMultiplier;
  20962. } // Ensure the CSS class is valid by starting with an alpha character
  20963. if (/^[^a-zA-Z]/.test(this.id())) {
  20964. idClass = 'dimensions-' + this.id();
  20965. } else {
  20966. idClass = this.id() + '-dimensions';
  20967. } // Ensure the right class is still on the player for the style element
  20968. this.addClass(idClass);
  20969. 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 ");
  20970. }
  20971. /**
  20972. * Load/Create an instance of playback {@link Tech} including element
  20973. * and API methods. Then append the `Tech` element in `Player` as a child.
  20974. *
  20975. * @param {string} techName
  20976. * name of the playback technology
  20977. *
  20978. * @param {string} source
  20979. * video source
  20980. *
  20981. * @private
  20982. */
  20983. ;
  20984. _proto.loadTech_ = function loadTech_(techName, source) {
  20985. var _this3 = this;
  20986. // Pause and remove current playback technology
  20987. if (this.tech_) {
  20988. this.unloadTech_();
  20989. }
  20990. var titleTechName = toTitleCase(techName);
  20991. var camelTechName = techName.charAt(0).toLowerCase() + techName.slice(1); // get rid of the HTML5 video tag as soon as we are using another tech
  20992. if (titleTechName !== 'Html5' && this.tag) {
  20993. Tech.getTech('Html5').disposeMediaElement(this.tag);
  20994. this.tag.player = null;
  20995. this.tag = null;
  20996. }
  20997. this.techName_ = titleTechName; // Turn off API access because we're loading a new tech that might load asynchronously
  20998. this.isReady_ = false; // if autoplay is a string we pass false to the tech
  20999. // because the player is going to handle autoplay on `loadstart`
  21000. var autoplay = typeof this.autoplay() === 'string' ? false : this.autoplay(); // Grab tech-specific options from player options and add source and parent element to use.
  21001. var techOptions = {
  21002. source: source,
  21003. autoplay: autoplay,
  21004. 'nativeControlsForTouch': this.options_.nativeControlsForTouch,
  21005. 'playerId': this.id(),
  21006. 'techId': this.id() + "_" + camelTechName + "_api",
  21007. 'playsinline': this.options_.playsinline,
  21008. 'preload': this.options_.preload,
  21009. 'loop': this.options_.loop,
  21010. 'muted': this.options_.muted,
  21011. 'poster': this.poster(),
  21012. 'language': this.language(),
  21013. 'playerElIngest': this.playerElIngest_ || false,
  21014. 'vtt.js': this.options_['vtt.js'],
  21015. 'canOverridePoster': !!this.options_.techCanOverridePoster,
  21016. 'enableSourceset': this.options_.enableSourceset,
  21017. 'Promise': this.options_.Promise
  21018. };
  21019. ALL.names.forEach(function (name) {
  21020. var props = ALL[name];
  21021. techOptions[props.getterName] = _this3[props.privateName];
  21022. });
  21023. assign(techOptions, this.options_[titleTechName]);
  21024. assign(techOptions, this.options_[camelTechName]);
  21025. assign(techOptions, this.options_[techName.toLowerCase()]);
  21026. if (this.tag) {
  21027. techOptions.tag = this.tag;
  21028. }
  21029. if (source && source.src === this.cache_.src && this.cache_.currentTime > 0) {
  21030. techOptions.startTime = this.cache_.currentTime;
  21031. } // Initialize tech instance
  21032. var TechClass = Tech.getTech(techName);
  21033. if (!TechClass) {
  21034. throw new Error("No Tech named '" + titleTechName + "' exists! '" + titleTechName + "' should be registered using videojs.registerTech()'");
  21035. }
  21036. this.tech_ = new TechClass(techOptions); // player.triggerReady is always async, so don't need this to be async
  21037. this.tech_.ready(bind(this, this.handleTechReady_), true);
  21038. textTrackConverter.jsonToTextTracks(this.textTracksJson_ || [], this.tech_); // Listen to all HTML5-defined events and trigger them on the player
  21039. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  21040. _this3.on(_this3.tech_, event, _this3["handleTech" + toTitleCase(event) + "_"]);
  21041. });
  21042. Object.keys(TECH_EVENTS_QUEUE).forEach(function (event) {
  21043. _this3.on(_this3.tech_, event, function (eventObj) {
  21044. if (_this3.tech_.playbackRate() === 0 && _this3.tech_.seeking()) {
  21045. _this3.queuedCallbacks_.push({
  21046. callback: _this3["handleTech" + TECH_EVENTS_QUEUE[event] + "_"].bind(_this3),
  21047. event: eventObj
  21048. });
  21049. return;
  21050. }
  21051. _this3["handleTech" + TECH_EVENTS_QUEUE[event] + "_"](eventObj);
  21052. });
  21053. });
  21054. this.on(this.tech_, 'loadstart', this.handleTechLoadStart_);
  21055. this.on(this.tech_, 'sourceset', this.handleTechSourceset_);
  21056. this.on(this.tech_, 'waiting', this.handleTechWaiting_);
  21057. this.on(this.tech_, 'ended', this.handleTechEnded_);
  21058. this.on(this.tech_, 'seeking', this.handleTechSeeking_);
  21059. this.on(this.tech_, 'play', this.handleTechPlay_);
  21060. this.on(this.tech_, 'firstplay', this.handleTechFirstPlay_);
  21061. this.on(this.tech_, 'pause', this.handleTechPause_);
  21062. this.on(this.tech_, 'durationchange', this.handleTechDurationChange_);
  21063. this.on(this.tech_, 'fullscreenchange', this.handleTechFullscreenChange_);
  21064. this.on(this.tech_, 'enterpictureinpicture', this.handleTechEnterPictureInPicture_);
  21065. this.on(this.tech_, 'leavepictureinpicture', this.handleTechLeavePictureInPicture_);
  21066. this.on(this.tech_, 'error', this.handleTechError_);
  21067. this.on(this.tech_, 'loadedmetadata', this.updateStyleEl_);
  21068. this.on(this.tech_, 'posterchange', this.handleTechPosterChange_);
  21069. this.on(this.tech_, 'textdata', this.handleTechTextData_);
  21070. this.on(this.tech_, 'ratechange', this.handleTechRateChange_);
  21071. this.usingNativeControls(this.techGet_('controls'));
  21072. if (this.controls() && !this.usingNativeControls()) {
  21073. this.addTechControlsListeners_();
  21074. } // Add the tech element in the DOM if it was not already there
  21075. // Make sure to not insert the original video element if using Html5
  21076. if (this.tech_.el().parentNode !== this.el() && (titleTechName !== 'Html5' || !this.tag)) {
  21077. prependTo(this.tech_.el(), this.el());
  21078. } // Get rid of the original video tag reference after the first tech is loaded
  21079. if (this.tag) {
  21080. this.tag.player = null;
  21081. this.tag = null;
  21082. }
  21083. }
  21084. /**
  21085. * Unload and dispose of the current playback {@link Tech}.
  21086. *
  21087. * @private
  21088. */
  21089. ;
  21090. _proto.unloadTech_ = function unloadTech_() {
  21091. var _this4 = this;
  21092. // Save the current text tracks so that we can reuse the same text tracks with the next tech
  21093. ALL.names.forEach(function (name) {
  21094. var props = ALL[name];
  21095. _this4[props.privateName] = _this4[props.getterName]();
  21096. });
  21097. this.textTracksJson_ = textTrackConverter.textTracksToJson(this.tech_);
  21098. this.isReady_ = false;
  21099. this.tech_.dispose();
  21100. this.tech_ = false;
  21101. if (this.isPosterFromTech_) {
  21102. this.poster_ = '';
  21103. this.trigger('posterchange');
  21104. }
  21105. this.isPosterFromTech_ = false;
  21106. }
  21107. /**
  21108. * Return a reference to the current {@link Tech}.
  21109. * It will print a warning by default about the danger of using the tech directly
  21110. * but any argument that is passed in will silence the warning.
  21111. *
  21112. * @param {*} [safety]
  21113. * Anything passed in to silence the warning
  21114. *
  21115. * @return {Tech}
  21116. * The Tech
  21117. */
  21118. ;
  21119. _proto.tech = function tech(safety) {
  21120. if (safety === undefined) {
  21121. 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');
  21122. }
  21123. return this.tech_;
  21124. }
  21125. /**
  21126. * Set up click and touch listeners for the playback element
  21127. *
  21128. * - On desktops: a click on the video itself will toggle playback
  21129. * - On mobile devices: a click on the video toggles controls
  21130. * which is done by toggling the user state between active and
  21131. * inactive
  21132. * - A tap can signal that a user has become active or has become inactive
  21133. * e.g. a quick tap on an iPhone movie should reveal the controls. Another
  21134. * quick tap should hide them again (signaling the user is in an inactive
  21135. * viewing state)
  21136. * - In addition to this, we still want the user to be considered inactive after
  21137. * a few seconds of inactivity.
  21138. *
  21139. * > Note: the only part of iOS interaction we can't mimic with this setup
  21140. * is a touch and hold on the video element counting as activity in order to
  21141. * keep the controls showing, but that shouldn't be an issue. A touch and hold
  21142. * on any controls will still keep the user active
  21143. *
  21144. * @private
  21145. */
  21146. ;
  21147. _proto.addTechControlsListeners_ = function addTechControlsListeners_() {
  21148. // Make sure to remove all the previous listeners in case we are called multiple times.
  21149. this.removeTechControlsListeners_(); // Some browsers (Chrome & IE) don't trigger a click on a flash swf, but do
  21150. // trigger mousedown/up.
  21151. // http://stackoverflow.com/questions/1444562/javascript-onclick-event-over-flash-object
  21152. // Any touch events are set to block the mousedown event from happening
  21153. this.on(this.tech_, 'mouseup', this.handleTechClick_);
  21154. this.on(this.tech_, 'dblclick', this.handleTechDoubleClick_); // If the controls were hidden we don't want that to change without a tap event
  21155. // so we'll check if the controls were already showing before reporting user
  21156. // activity
  21157. this.on(this.tech_, 'touchstart', this.handleTechTouchStart_);
  21158. this.on(this.tech_, 'touchmove', this.handleTechTouchMove_);
  21159. this.on(this.tech_, 'touchend', this.handleTechTouchEnd_); // The tap listener needs to come after the touchend listener because the tap
  21160. // listener cancels out any reportedUserActivity when setting userActive(false)
  21161. this.on(this.tech_, 'tap', this.handleTechTap_);
  21162. }
  21163. /**
  21164. * Remove the listeners used for click and tap controls. This is needed for
  21165. * toggling to controls disabled, where a tap/touch should do nothing.
  21166. *
  21167. * @private
  21168. */
  21169. ;
  21170. _proto.removeTechControlsListeners_ = function removeTechControlsListeners_() {
  21171. // We don't want to just use `this.off()` because there might be other needed
  21172. // listeners added by techs that extend this.
  21173. this.off(this.tech_, 'tap', this.handleTechTap_);
  21174. this.off(this.tech_, 'touchstart', this.handleTechTouchStart_);
  21175. this.off(this.tech_, 'touchmove', this.handleTechTouchMove_);
  21176. this.off(this.tech_, 'touchend', this.handleTechTouchEnd_);
  21177. this.off(this.tech_, 'mouseup', this.handleTechClick_);
  21178. this.off(this.tech_, 'dblclick', this.handleTechDoubleClick_);
  21179. }
  21180. /**
  21181. * Player waits for the tech to be ready
  21182. *
  21183. * @private
  21184. */
  21185. ;
  21186. _proto.handleTechReady_ = function handleTechReady_() {
  21187. this.triggerReady(); // Keep the same volume as before
  21188. if (this.cache_.volume) {
  21189. this.techCall_('setVolume', this.cache_.volume);
  21190. } // Look if the tech found a higher resolution poster while loading
  21191. this.handleTechPosterChange_(); // Update the duration if available
  21192. this.handleTechDurationChange_();
  21193. }
  21194. /**
  21195. * Retrigger the `loadstart` event that was triggered by the {@link Tech}. This
  21196. * function will also trigger {@link Player#firstplay} if it is the first loadstart
  21197. * for a video.
  21198. *
  21199. * @fires Player#loadstart
  21200. * @fires Player#firstplay
  21201. * @listens Tech#loadstart
  21202. * @private
  21203. */
  21204. ;
  21205. _proto.handleTechLoadStart_ = function handleTechLoadStart_() {
  21206. // TODO: Update to use `emptied` event instead. See #1277.
  21207. this.removeClass('vjs-ended');
  21208. this.removeClass('vjs-seeking'); // reset the error state
  21209. this.error(null); // Update the duration
  21210. this.handleTechDurationChange_(); // If it's already playing we want to trigger a firstplay event now.
  21211. // The firstplay event relies on both the play and loadstart events
  21212. // which can happen in any order for a new source
  21213. if (!this.paused()) {
  21214. /**
  21215. * Fired when the user agent begins looking for media data
  21216. *
  21217. * @event Player#loadstart
  21218. * @type {EventTarget~Event}
  21219. */
  21220. this.trigger('loadstart');
  21221. this.trigger('firstplay');
  21222. } else {
  21223. // reset the hasStarted state
  21224. this.hasStarted(false);
  21225. this.trigger('loadstart');
  21226. } // autoplay happens after loadstart for the browser,
  21227. // so we mimic that behavior
  21228. this.manualAutoplay_(this.autoplay());
  21229. }
  21230. /**
  21231. * Handle autoplay string values, rather than the typical boolean
  21232. * values that should be handled by the tech. Note that this is not
  21233. * part of any specification. Valid values and what they do can be
  21234. * found on the autoplay getter at Player#autoplay()
  21235. */
  21236. ;
  21237. _proto.manualAutoplay_ = function manualAutoplay_(type) {
  21238. var _this5 = this;
  21239. if (!this.tech_ || typeof type !== 'string') {
  21240. return;
  21241. }
  21242. var muted = function muted() {
  21243. var previouslyMuted = _this5.muted();
  21244. _this5.muted(true);
  21245. var restoreMuted = function restoreMuted() {
  21246. _this5.muted(previouslyMuted);
  21247. }; // restore muted on play terminatation
  21248. _this5.playTerminatedQueue_.push(restoreMuted);
  21249. var mutedPromise = _this5.play();
  21250. if (!isPromise(mutedPromise)) {
  21251. return;
  21252. }
  21253. return mutedPromise["catch"](restoreMuted);
  21254. };
  21255. var promise; // if muted defaults to true
  21256. // the only thing we can do is call play
  21257. if (type === 'any' && this.muted() !== true) {
  21258. promise = this.play();
  21259. if (isPromise(promise)) {
  21260. promise = promise["catch"](muted);
  21261. }
  21262. } else if (type === 'muted' && this.muted() !== true) {
  21263. promise = muted();
  21264. } else {
  21265. promise = this.play();
  21266. }
  21267. if (!isPromise(promise)) {
  21268. return;
  21269. }
  21270. return promise.then(function () {
  21271. _this5.trigger({
  21272. type: 'autoplay-success',
  21273. autoplay: type
  21274. });
  21275. })["catch"](function (e) {
  21276. _this5.trigger({
  21277. type: 'autoplay-failure',
  21278. autoplay: type
  21279. });
  21280. });
  21281. }
  21282. /**
  21283. * Update the internal source caches so that we return the correct source from
  21284. * `src()`, `currentSource()`, and `currentSources()`.
  21285. *
  21286. * > Note: `currentSources` will not be updated if the source that is passed in exists
  21287. * in the current `currentSources` cache.
  21288. *
  21289. *
  21290. * @param {Tech~SourceObject} srcObj
  21291. * A string or object source to update our caches to.
  21292. */
  21293. ;
  21294. _proto.updateSourceCaches_ = function updateSourceCaches_(srcObj) {
  21295. if (srcObj === void 0) {
  21296. srcObj = '';
  21297. }
  21298. var src = srcObj;
  21299. var type = '';
  21300. if (typeof src !== 'string') {
  21301. src = srcObj.src;
  21302. type = srcObj.type;
  21303. } // make sure all the caches are set to default values
  21304. // to prevent null checking
  21305. this.cache_.source = this.cache_.source || {};
  21306. this.cache_.sources = this.cache_.sources || []; // try to get the type of the src that was passed in
  21307. if (src && !type) {
  21308. type = findMimetype(this, src);
  21309. } // update `currentSource` cache always
  21310. this.cache_.source = mergeOptions({}, srcObj, {
  21311. src: src,
  21312. type: type
  21313. });
  21314. var matchingSources = this.cache_.sources.filter(function (s) {
  21315. return s.src && s.src === src;
  21316. });
  21317. var sourceElSources = [];
  21318. var sourceEls = this.$$('source');
  21319. var matchingSourceEls = [];
  21320. for (var i = 0; i < sourceEls.length; i++) {
  21321. var sourceObj = getAttributes(sourceEls[i]);
  21322. sourceElSources.push(sourceObj);
  21323. if (sourceObj.src && sourceObj.src === src) {
  21324. matchingSourceEls.push(sourceObj.src);
  21325. }
  21326. } // if we have matching source els but not matching sources
  21327. // the current source cache is not up to date
  21328. if (matchingSourceEls.length && !matchingSources.length) {
  21329. this.cache_.sources = sourceElSources; // if we don't have matching source or source els set the
  21330. // sources cache to the `currentSource` cache
  21331. } else if (!matchingSources.length) {
  21332. this.cache_.sources = [this.cache_.source];
  21333. } // update the tech `src` cache
  21334. this.cache_.src = src;
  21335. }
  21336. /**
  21337. * *EXPERIMENTAL* Fired when the source is set or changed on the {@link Tech}
  21338. * causing the media element to reload.
  21339. *
  21340. * It will fire for the initial source and each subsequent source.
  21341. * This event is a custom event from Video.js and is triggered by the {@link Tech}.
  21342. *
  21343. * The event object for this event contains a `src` property that will contain the source
  21344. * that was available when the event was triggered. This is generally only necessary if Video.js
  21345. * is switching techs while the source was being changed.
  21346. *
  21347. * It is also fired when `load` is called on the player (or media element)
  21348. * because the {@link https://html.spec.whatwg.org/multipage/media.html#dom-media-load|specification for `load`}
  21349. * says that the resource selection algorithm needs to be aborted and restarted.
  21350. * In this case, it is very likely that the `src` property will be set to the
  21351. * empty string `""` to indicate we do not know what the source will be but
  21352. * that it is changing.
  21353. *
  21354. * *This event is currently still experimental and may change in minor releases.*
  21355. * __To use this, pass `enableSourceset` option to the player.__
  21356. *
  21357. * @event Player#sourceset
  21358. * @type {EventTarget~Event}
  21359. * @prop {string} src
  21360. * The source url available when the `sourceset` was triggered.
  21361. * It will be an empty string if we cannot know what the source is
  21362. * but know that the source will change.
  21363. */
  21364. /**
  21365. * Retrigger the `sourceset` event that was triggered by the {@link Tech}.
  21366. *
  21367. * @fires Player#sourceset
  21368. * @listens Tech#sourceset
  21369. * @private
  21370. */
  21371. ;
  21372. _proto.handleTechSourceset_ = function handleTechSourceset_(event) {
  21373. var _this6 = this;
  21374. // only update the source cache when the source
  21375. // was not updated using the player api
  21376. if (!this.changingSrc_) {
  21377. var updateSourceCaches = function updateSourceCaches(src) {
  21378. return _this6.updateSourceCaches_(src);
  21379. };
  21380. var playerSrc = this.currentSource().src;
  21381. var eventSrc = event.src; // if we have a playerSrc that is not a blob, and a tech src that is a blob
  21382. if (playerSrc && !/^blob:/.test(playerSrc) && /^blob:/.test(eventSrc)) {
  21383. // if both the tech source and the player source were updated we assume
  21384. // something like @videojs/http-streaming did the sourceset and skip updating the source cache.
  21385. if (!this.lastSource_ || this.lastSource_.tech !== eventSrc && this.lastSource_.player !== playerSrc) {
  21386. updateSourceCaches = function updateSourceCaches() {};
  21387. }
  21388. } // update the source to the intial source right away
  21389. // in some cases this will be empty string
  21390. updateSourceCaches(eventSrc); // if the `sourceset` `src` was an empty string
  21391. // wait for a `loadstart` to update the cache to `currentSrc`.
  21392. // If a sourceset happens before a `loadstart`, we reset the state
  21393. if (!event.src) {
  21394. this.tech_.any(['sourceset', 'loadstart'], function (e) {
  21395. // if a sourceset happens before a `loadstart` there
  21396. // is nothing to do as this `handleTechSourceset_`
  21397. // will be called again and this will be handled there.
  21398. if (e.type === 'sourceset') {
  21399. return;
  21400. }
  21401. var techSrc = _this6.techGet('currentSrc');
  21402. _this6.lastSource_.tech = techSrc;
  21403. _this6.updateSourceCaches_(techSrc);
  21404. });
  21405. }
  21406. }
  21407. this.lastSource_ = {
  21408. player: this.currentSource().src,
  21409. tech: event.src
  21410. };
  21411. this.trigger({
  21412. src: event.src,
  21413. type: 'sourceset'
  21414. });
  21415. }
  21416. /**
  21417. * Add/remove the vjs-has-started class
  21418. *
  21419. * @fires Player#firstplay
  21420. *
  21421. * @param {boolean} request
  21422. * - true: adds the class
  21423. * - false: remove the class
  21424. *
  21425. * @return {boolean}
  21426. * the boolean value of hasStarted_
  21427. */
  21428. ;
  21429. _proto.hasStarted = function hasStarted(request) {
  21430. if (request === undefined) {
  21431. // act as getter, if we have no request to change
  21432. return this.hasStarted_;
  21433. }
  21434. if (request === this.hasStarted_) {
  21435. return;
  21436. }
  21437. this.hasStarted_ = request;
  21438. if (this.hasStarted_) {
  21439. this.addClass('vjs-has-started');
  21440. this.trigger('firstplay');
  21441. } else {
  21442. this.removeClass('vjs-has-started');
  21443. }
  21444. }
  21445. /**
  21446. * Fired whenever the media begins or resumes playback
  21447. *
  21448. * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play}
  21449. * @fires Player#play
  21450. * @listens Tech#play
  21451. * @private
  21452. */
  21453. ;
  21454. _proto.handleTechPlay_ = function handleTechPlay_() {
  21455. this.removeClass('vjs-ended');
  21456. this.removeClass('vjs-paused');
  21457. this.addClass('vjs-playing'); // hide the poster when the user hits play
  21458. this.hasStarted(true);
  21459. /**
  21460. * Triggered whenever an {@link Tech#play} event happens. Indicates that
  21461. * playback has started or resumed.
  21462. *
  21463. * @event Player#play
  21464. * @type {EventTarget~Event}
  21465. */
  21466. this.trigger('play');
  21467. }
  21468. /**
  21469. * Retrigger the `ratechange` event that was triggered by the {@link Tech}.
  21470. *
  21471. * If there were any events queued while the playback rate was zero, fire
  21472. * those events now.
  21473. *
  21474. * @private
  21475. * @method Player#handleTechRateChange_
  21476. * @fires Player#ratechange
  21477. * @listens Tech#ratechange
  21478. */
  21479. ;
  21480. _proto.handleTechRateChange_ = function handleTechRateChange_() {
  21481. if (this.tech_.playbackRate() > 0 && this.cache_.lastPlaybackRate === 0) {
  21482. this.queuedCallbacks_.forEach(function (queued) {
  21483. return queued.callback(queued.event);
  21484. });
  21485. this.queuedCallbacks_ = [];
  21486. }
  21487. this.cache_.lastPlaybackRate = this.tech_.playbackRate();
  21488. /**
  21489. * Fires when the playing speed of the audio/video is changed
  21490. *
  21491. * @event Player#ratechange
  21492. * @type {event}
  21493. */
  21494. this.trigger('ratechange');
  21495. }
  21496. /**
  21497. * Retrigger the `waiting` event that was triggered by the {@link Tech}.
  21498. *
  21499. * @fires Player#waiting
  21500. * @listens Tech#waiting
  21501. * @private
  21502. */
  21503. ;
  21504. _proto.handleTechWaiting_ = function handleTechWaiting_() {
  21505. var _this7 = this;
  21506. this.addClass('vjs-waiting');
  21507. /**
  21508. * A readyState change on the DOM element has caused playback to stop.
  21509. *
  21510. * @event Player#waiting
  21511. * @type {EventTarget~Event}
  21512. */
  21513. this.trigger('waiting'); // Browsers may emit a timeupdate event after a waiting event. In order to prevent
  21514. // premature removal of the waiting class, wait for the time to change.
  21515. var timeWhenWaiting = this.currentTime();
  21516. var timeUpdateListener = function timeUpdateListener() {
  21517. if (timeWhenWaiting !== _this7.currentTime()) {
  21518. _this7.removeClass('vjs-waiting');
  21519. _this7.off('timeupdate', timeUpdateListener);
  21520. }
  21521. };
  21522. this.on('timeupdate', timeUpdateListener);
  21523. }
  21524. /**
  21525. * Retrigger the `canplay` event that was triggered by the {@link Tech}.
  21526. * > Note: This is not consistent between browsers. See #1351
  21527. *
  21528. * @fires Player#canplay
  21529. * @listens Tech#canplay
  21530. * @private
  21531. */
  21532. ;
  21533. _proto.handleTechCanPlay_ = function handleTechCanPlay_() {
  21534. this.removeClass('vjs-waiting');
  21535. /**
  21536. * The media has a readyState of HAVE_FUTURE_DATA or greater.
  21537. *
  21538. * @event Player#canplay
  21539. * @type {EventTarget~Event}
  21540. */
  21541. this.trigger('canplay');
  21542. }
  21543. /**
  21544. * Retrigger the `canplaythrough` event that was triggered by the {@link Tech}.
  21545. *
  21546. * @fires Player#canplaythrough
  21547. * @listens Tech#canplaythrough
  21548. * @private
  21549. */
  21550. ;
  21551. _proto.handleTechCanPlayThrough_ = function handleTechCanPlayThrough_() {
  21552. this.removeClass('vjs-waiting');
  21553. /**
  21554. * The media has a readyState of HAVE_ENOUGH_DATA or greater. This means that the
  21555. * entire media file can be played without buffering.
  21556. *
  21557. * @event Player#canplaythrough
  21558. * @type {EventTarget~Event}
  21559. */
  21560. this.trigger('canplaythrough');
  21561. }
  21562. /**
  21563. * Retrigger the `playing` event that was triggered by the {@link Tech}.
  21564. *
  21565. * @fires Player#playing
  21566. * @listens Tech#playing
  21567. * @private
  21568. */
  21569. ;
  21570. _proto.handleTechPlaying_ = function handleTechPlaying_() {
  21571. this.removeClass('vjs-waiting');
  21572. /**
  21573. * The media is no longer blocked from playback, and has started playing.
  21574. *
  21575. * @event Player#playing
  21576. * @type {EventTarget~Event}
  21577. */
  21578. this.trigger('playing');
  21579. }
  21580. /**
  21581. * Retrigger the `seeking` event that was triggered by the {@link Tech}.
  21582. *
  21583. * @fires Player#seeking
  21584. * @listens Tech#seeking
  21585. * @private
  21586. */
  21587. ;
  21588. _proto.handleTechSeeking_ = function handleTechSeeking_() {
  21589. this.addClass('vjs-seeking');
  21590. /**
  21591. * Fired whenever the player is jumping to a new time
  21592. *
  21593. * @event Player#seeking
  21594. * @type {EventTarget~Event}
  21595. */
  21596. this.trigger('seeking');
  21597. }
  21598. /**
  21599. * Retrigger the `seeked` event that was triggered by the {@link Tech}.
  21600. *
  21601. * @fires Player#seeked
  21602. * @listens Tech#seeked
  21603. * @private
  21604. */
  21605. ;
  21606. _proto.handleTechSeeked_ = function handleTechSeeked_() {
  21607. this.removeClass('vjs-seeking');
  21608. this.removeClass('vjs-ended');
  21609. /**
  21610. * Fired when the player has finished jumping to a new time
  21611. *
  21612. * @event Player#seeked
  21613. * @type {EventTarget~Event}
  21614. */
  21615. this.trigger('seeked');
  21616. }
  21617. /**
  21618. * Retrigger the `firstplay` event that was triggered by the {@link Tech}.
  21619. *
  21620. * @fires Player#firstplay
  21621. * @listens Tech#firstplay
  21622. * @deprecated As of 6.0 firstplay event is deprecated.
  21623. * As of 6.0 passing the `starttime` option to the player and the firstplay event are deprecated.
  21624. * @private
  21625. */
  21626. ;
  21627. _proto.handleTechFirstPlay_ = function handleTechFirstPlay_() {
  21628. // If the first starttime attribute is specified
  21629. // then we will start at the given offset in seconds
  21630. if (this.options_.starttime) {
  21631. log.warn('Passing the `starttime` option to the player will be deprecated in 6.0');
  21632. this.currentTime(this.options_.starttime);
  21633. }
  21634. this.addClass('vjs-has-started');
  21635. /**
  21636. * Fired the first time a video is played. Not part of the HLS spec, and this is
  21637. * probably not the best implementation yet, so use sparingly. If you don't have a
  21638. * reason to prevent playback, use `myPlayer.one('play');` instead.
  21639. *
  21640. * @event Player#firstplay
  21641. * @deprecated As of 6.0 firstplay event is deprecated.
  21642. * @type {EventTarget~Event}
  21643. */
  21644. this.trigger('firstplay');
  21645. }
  21646. /**
  21647. * Retrigger the `pause` event that was triggered by the {@link Tech}.
  21648. *
  21649. * @fires Player#pause
  21650. * @listens Tech#pause
  21651. * @private
  21652. */
  21653. ;
  21654. _proto.handleTechPause_ = function handleTechPause_() {
  21655. this.removeClass('vjs-playing');
  21656. this.addClass('vjs-paused');
  21657. /**
  21658. * Fired whenever the media has been paused
  21659. *
  21660. * @event Player#pause
  21661. * @type {EventTarget~Event}
  21662. */
  21663. this.trigger('pause');
  21664. }
  21665. /**
  21666. * Retrigger the `ended` event that was triggered by the {@link Tech}.
  21667. *
  21668. * @fires Player#ended
  21669. * @listens Tech#ended
  21670. * @private
  21671. */
  21672. ;
  21673. _proto.handleTechEnded_ = function handleTechEnded_() {
  21674. this.addClass('vjs-ended');
  21675. if (this.options_.loop) {
  21676. this.currentTime(0);
  21677. this.play();
  21678. } else if (!this.paused()) {
  21679. this.pause();
  21680. }
  21681. /**
  21682. * Fired when the end of the media resource is reached (currentTime == duration)
  21683. *
  21684. * @event Player#ended
  21685. * @type {EventTarget~Event}
  21686. */
  21687. this.trigger('ended');
  21688. }
  21689. /**
  21690. * Fired when the duration of the media resource is first known or changed
  21691. *
  21692. * @listens Tech#durationchange
  21693. * @private
  21694. */
  21695. ;
  21696. _proto.handleTechDurationChange_ = function handleTechDurationChange_() {
  21697. this.duration(this.techGet_('duration'));
  21698. }
  21699. /**
  21700. * Handle a click on the media element to play/pause
  21701. *
  21702. * @param {EventTarget~Event} event
  21703. * the event that caused this function to trigger
  21704. *
  21705. * @listens Tech#mouseup
  21706. * @private
  21707. */
  21708. ;
  21709. _proto.handleTechClick_ = function handleTechClick_(event) {
  21710. if (!isSingleLeftClick(event)) {
  21711. return;
  21712. } // When controls are disabled a click should not toggle playback because
  21713. // the click is considered a control
  21714. if (!this.controls_) {
  21715. return;
  21716. }
  21717. if (this.paused()) {
  21718. silencePromise(this.play());
  21719. } else {
  21720. this.pause();
  21721. }
  21722. }
  21723. /**
  21724. * Handle a double-click on the media element to enter/exit fullscreen
  21725. *
  21726. * @param {EventTarget~Event} event
  21727. * the event that caused this function to trigger
  21728. *
  21729. * @listens Tech#dblclick
  21730. * @private
  21731. */
  21732. ;
  21733. _proto.handleTechDoubleClick_ = function handleTechDoubleClick_(event) {
  21734. if (!this.controls_) {
  21735. return;
  21736. } // we do not want to toggle fullscreen state
  21737. // when double-clicking inside a control bar or a modal
  21738. var inAllowedEls = Array.prototype.some.call(this.$$('.vjs-control-bar, .vjs-modal-dialog'), function (el) {
  21739. return el.contains(event.target);
  21740. });
  21741. if (!inAllowedEls) {
  21742. /*
  21743. * options.userActions.doubleClick
  21744. *
  21745. * If `undefined` or `true`, double-click toggles fullscreen if controls are present
  21746. * Set to `false` to disable double-click handling
  21747. * Set to a function to substitute an external double-click handler
  21748. */
  21749. if (this.options_ === undefined || this.options_.userActions === undefined || this.options_.userActions.doubleClick === undefined || this.options_.userActions.doubleClick !== false) {
  21750. if (this.options_ !== undefined && this.options_.userActions !== undefined && typeof this.options_.userActions.doubleClick === 'function') {
  21751. this.options_.userActions.doubleClick.call(this, event);
  21752. } else if (this.isFullscreen()) {
  21753. this.exitFullscreen();
  21754. } else {
  21755. this.requestFullscreen();
  21756. }
  21757. }
  21758. }
  21759. }
  21760. /**
  21761. * Handle a tap on the media element. It will toggle the user
  21762. * activity state, which hides and shows the controls.
  21763. *
  21764. * @listens Tech#tap
  21765. * @private
  21766. */
  21767. ;
  21768. _proto.handleTechTap_ = function handleTechTap_() {
  21769. this.userActive(!this.userActive());
  21770. }
  21771. /**
  21772. * Handle touch to start
  21773. *
  21774. * @listens Tech#touchstart
  21775. * @private
  21776. */
  21777. ;
  21778. _proto.handleTechTouchStart_ = function handleTechTouchStart_() {
  21779. this.userWasActive = this.userActive();
  21780. }
  21781. /**
  21782. * Handle touch to move
  21783. *
  21784. * @listens Tech#touchmove
  21785. * @private
  21786. */
  21787. ;
  21788. _proto.handleTechTouchMove_ = function handleTechTouchMove_() {
  21789. if (this.userWasActive) {
  21790. this.reportUserActivity();
  21791. }
  21792. }
  21793. /**
  21794. * Handle touch to end
  21795. *
  21796. * @param {EventTarget~Event} event
  21797. * the touchend event that triggered
  21798. * this function
  21799. *
  21800. * @listens Tech#touchend
  21801. * @private
  21802. */
  21803. ;
  21804. _proto.handleTechTouchEnd_ = function handleTechTouchEnd_(event) {
  21805. // Stop the mouse events from also happening
  21806. event.preventDefault();
  21807. }
  21808. /**
  21809. * native click events on the SWF aren't triggered on IE11, Win8.1RT
  21810. * use stageclick events triggered from inside the SWF instead
  21811. *
  21812. * @private
  21813. * @listens stageclick
  21814. */
  21815. ;
  21816. _proto.handleStageClick_ = function handleStageClick_() {
  21817. this.reportUserActivity();
  21818. }
  21819. /**
  21820. * @private
  21821. */
  21822. ;
  21823. _proto.toggleFullscreenClass_ = function toggleFullscreenClass_() {
  21824. if (this.isFullscreen()) {
  21825. this.addClass('vjs-fullscreen');
  21826. } else {
  21827. this.removeClass('vjs-fullscreen');
  21828. }
  21829. }
  21830. /**
  21831. * when the document fschange event triggers it calls this
  21832. */
  21833. ;
  21834. _proto.documentFullscreenChange_ = function documentFullscreenChange_(e) {
  21835. var el = this.el();
  21836. var isFs = document[this.fsApi_.fullscreenElement] === el;
  21837. if (!isFs && el.matches) {
  21838. isFs = el.matches(':' + this.fsApi_.fullscreen);
  21839. } else if (!isFs && el.msMatchesSelector) {
  21840. isFs = el.msMatchesSelector(':' + this.fsApi_.fullscreen);
  21841. }
  21842. this.isFullscreen(isFs); // If cancelling fullscreen, remove event listener.
  21843. if (this.isFullscreen() === false) {
  21844. off(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_);
  21845. }
  21846. if (this.fsApi_.prefixed) {
  21847. /**
  21848. * @event Player#fullscreenchange
  21849. * @type {EventTarget~Event}
  21850. */
  21851. this.trigger('fullscreenchange');
  21852. }
  21853. }
  21854. /**
  21855. * Handle Tech Fullscreen Change
  21856. *
  21857. * @param {EventTarget~Event} event
  21858. * the fullscreenchange event that triggered this function
  21859. *
  21860. * @param {Object} data
  21861. * the data that was sent with the event
  21862. *
  21863. * @private
  21864. * @listens Tech#fullscreenchange
  21865. * @fires Player#fullscreenchange
  21866. */
  21867. ;
  21868. _proto.handleTechFullscreenChange_ = function handleTechFullscreenChange_(event, data) {
  21869. if (data) {
  21870. this.isFullscreen(data.isFullscreen);
  21871. }
  21872. /**
  21873. * Fired when going in and out of fullscreen.
  21874. *
  21875. * @event Player#fullscreenchange
  21876. * @type {EventTarget~Event}
  21877. */
  21878. this.trigger('fullscreenchange');
  21879. }
  21880. /**
  21881. * @private
  21882. */
  21883. ;
  21884. _proto.togglePictureInPictureClass_ = function togglePictureInPictureClass_() {
  21885. if (this.isInPictureInPicture()) {
  21886. this.addClass('vjs-picture-in-picture');
  21887. } else {
  21888. this.removeClass('vjs-picture-in-picture');
  21889. }
  21890. }
  21891. /**
  21892. * Handle Tech Enter Picture-in-Picture.
  21893. *
  21894. * @param {EventTarget~Event} event
  21895. * the enterpictureinpicture event that triggered this function
  21896. *
  21897. * @private
  21898. * @listens Tech#enterpictureinpicture
  21899. */
  21900. ;
  21901. _proto.handleTechEnterPictureInPicture_ = function handleTechEnterPictureInPicture_(event) {
  21902. this.isInPictureInPicture(true);
  21903. }
  21904. /**
  21905. * Handle Tech Leave Picture-in-Picture.
  21906. *
  21907. * @param {EventTarget~Event} event
  21908. * the leavepictureinpicture event that triggered this function
  21909. *
  21910. * @private
  21911. * @listens Tech#leavepictureinpicture
  21912. */
  21913. ;
  21914. _proto.handleTechLeavePictureInPicture_ = function handleTechLeavePictureInPicture_(event) {
  21915. this.isInPictureInPicture(false);
  21916. }
  21917. /**
  21918. * Fires when an error occurred during the loading of an audio/video.
  21919. *
  21920. * @private
  21921. * @listens Tech#error
  21922. */
  21923. ;
  21924. _proto.handleTechError_ = function handleTechError_() {
  21925. var error = this.tech_.error();
  21926. this.error(error);
  21927. }
  21928. /**
  21929. * Retrigger the `textdata` event that was triggered by the {@link Tech}.
  21930. *
  21931. * @fires Player#textdata
  21932. * @listens Tech#textdata
  21933. * @private
  21934. */
  21935. ;
  21936. _proto.handleTechTextData_ = function handleTechTextData_() {
  21937. var data = null;
  21938. if (arguments.length > 1) {
  21939. data = arguments[1];
  21940. }
  21941. /**
  21942. * Fires when we get a textdata event from tech
  21943. *
  21944. * @event Player#textdata
  21945. * @type {EventTarget~Event}
  21946. */
  21947. this.trigger('textdata', data);
  21948. }
  21949. /**
  21950. * Get object for cached values.
  21951. *
  21952. * @return {Object}
  21953. * get the current object cache
  21954. */
  21955. ;
  21956. _proto.getCache = function getCache() {
  21957. return this.cache_;
  21958. }
  21959. /**
  21960. * Resets the internal cache object.
  21961. *
  21962. * Using this function outside the player constructor or reset method may
  21963. * have unintended side-effects.
  21964. *
  21965. * @private
  21966. */
  21967. ;
  21968. _proto.resetCache_ = function resetCache_() {
  21969. this.cache_ = {
  21970. // Right now, the currentTime is not _really_ cached because it is always
  21971. // retrieved from the tech (see: currentTime). However, for completeness,
  21972. // we set it to zero here to ensure that if we do start actually caching
  21973. // it, we reset it along with everything else.
  21974. currentTime: 0,
  21975. inactivityTimeout: this.options_.inactivityTimeout,
  21976. duration: NaN,
  21977. lastVolume: 1,
  21978. lastPlaybackRate: this.defaultPlaybackRate(),
  21979. media: null,
  21980. src: '',
  21981. source: {},
  21982. sources: [],
  21983. volume: 1
  21984. };
  21985. }
  21986. /**
  21987. * Pass values to the playback tech
  21988. *
  21989. * @param {string} [method]
  21990. * the method to call
  21991. *
  21992. * @param {Object} arg
  21993. * the argument to pass
  21994. *
  21995. * @private
  21996. */
  21997. ;
  21998. _proto.techCall_ = function techCall_(method, arg) {
  21999. // If it's not ready yet, call method when it is
  22000. this.ready(function () {
  22001. if (method in allowedSetters) {
  22002. return set(this.middleware_, this.tech_, method, arg);
  22003. } else if (method in allowedMediators) {
  22004. return mediate(this.middleware_, this.tech_, method, arg);
  22005. }
  22006. try {
  22007. if (this.tech_) {
  22008. this.tech_[method](arg);
  22009. }
  22010. } catch (e) {
  22011. log(e);
  22012. throw e;
  22013. }
  22014. }, true);
  22015. }
  22016. /**
  22017. * Get calls can't wait for the tech, and sometimes don't need to.
  22018. *
  22019. * @param {string} method
  22020. * Tech method
  22021. *
  22022. * @return {Function|undefined}
  22023. * the method or undefined
  22024. *
  22025. * @private
  22026. */
  22027. ;
  22028. _proto.techGet_ = function techGet_(method) {
  22029. if (!this.tech_ || !this.tech_.isReady_) {
  22030. return;
  22031. }
  22032. if (method in allowedGetters) {
  22033. return get(this.middleware_, this.tech_, method);
  22034. } else if (method in allowedMediators) {
  22035. return mediate(this.middleware_, this.tech_, method);
  22036. } // Flash likes to die and reload when you hide or reposition it.
  22037. // In these cases the object methods go away and we get errors.
  22038. // When that happens we'll catch the errors and inform tech that it's not ready any more.
  22039. try {
  22040. return this.tech_[method]();
  22041. } catch (e) {
  22042. // When building additional tech libs, an expected method may not be defined yet
  22043. if (this.tech_[method] === undefined) {
  22044. log("Video.js: " + method + " method not defined for " + this.techName_ + " playback technology.", e);
  22045. throw e;
  22046. } // When a method isn't available on the object it throws a TypeError
  22047. if (e.name === 'TypeError') {
  22048. log("Video.js: " + method + " unavailable on " + this.techName_ + " playback technology element.", e);
  22049. this.tech_.isReady_ = false;
  22050. throw e;
  22051. } // If error unknown, just log and throw
  22052. log(e);
  22053. throw e;
  22054. }
  22055. }
  22056. /**
  22057. * Attempt to begin playback at the first opportunity.
  22058. *
  22059. * @return {Promise|undefined}
  22060. * Returns a promise if the browser supports Promises (or one
  22061. * was passed in as an option). This promise will be resolved on
  22062. * the return value of play. If this is undefined it will fulfill the
  22063. * promise chain otherwise the promise chain will be fulfilled when
  22064. * the promise from play is fulfilled.
  22065. */
  22066. ;
  22067. _proto.play = function play() {
  22068. var _this8 = this;
  22069. var PromiseClass = this.options_.Promise || window$1.Promise;
  22070. if (PromiseClass) {
  22071. return new PromiseClass(function (resolve) {
  22072. _this8.play_(resolve);
  22073. });
  22074. }
  22075. return this.play_();
  22076. }
  22077. /**
  22078. * The actual logic for play, takes a callback that will be resolved on the
  22079. * return value of play. This allows us to resolve to the play promise if there
  22080. * is one on modern browsers.
  22081. *
  22082. * @private
  22083. * @param {Function} [callback]
  22084. * The callback that should be called when the techs play is actually called
  22085. */
  22086. ;
  22087. _proto.play_ = function play_(callback) {
  22088. var _this9 = this;
  22089. if (callback === void 0) {
  22090. callback = silencePromise;
  22091. }
  22092. this.playCallbacks_.push(callback);
  22093. var isSrcReady = Boolean(!this.changingSrc_ && (this.src() || this.currentSrc())); // treat calls to play_ somewhat like the `one` event function
  22094. if (this.waitToPlay_) {
  22095. this.off(['ready', 'loadstart'], this.waitToPlay_);
  22096. this.waitToPlay_ = null;
  22097. } // if the player/tech is not ready or the src itself is not ready
  22098. // queue up a call to play on `ready` or `loadstart`
  22099. if (!this.isReady_ || !isSrcReady) {
  22100. this.waitToPlay_ = function (e) {
  22101. _this9.play_();
  22102. };
  22103. this.one(['ready', 'loadstart'], this.waitToPlay_); // if we are in Safari, there is a high chance that loadstart will trigger after the gesture timeperiod
  22104. // in that case, we need to prime the video element by calling load so it'll be ready in time
  22105. if (!isSrcReady && (IS_ANY_SAFARI || IS_IOS)) {
  22106. this.load();
  22107. }
  22108. return;
  22109. } // If the player/tech is ready and we have a source, we can attempt playback.
  22110. var val = this.techGet_('play'); // play was terminated if the returned value is null
  22111. if (val === null) {
  22112. this.runPlayTerminatedQueue_();
  22113. } else {
  22114. this.runPlayCallbacks_(val);
  22115. }
  22116. }
  22117. /**
  22118. * These functions will be run when if play is terminated. If play
  22119. * runPlayCallbacks_ is run these function will not be run. This allows us
  22120. * to differenciate between a terminated play and an actual call to play.
  22121. */
  22122. ;
  22123. _proto.runPlayTerminatedQueue_ = function runPlayTerminatedQueue_() {
  22124. var queue = this.playTerminatedQueue_.slice(0);
  22125. this.playTerminatedQueue_ = [];
  22126. queue.forEach(function (q) {
  22127. q();
  22128. });
  22129. }
  22130. /**
  22131. * When a callback to play is delayed we have to run these
  22132. * callbacks when play is actually called on the tech. This function
  22133. * runs the callbacks that were delayed and accepts the return value
  22134. * from the tech.
  22135. *
  22136. * @param {undefined|Promise} val
  22137. * The return value from the tech.
  22138. */
  22139. ;
  22140. _proto.runPlayCallbacks_ = function runPlayCallbacks_(val) {
  22141. var callbacks = this.playCallbacks_.slice(0);
  22142. this.playCallbacks_ = []; // clear play terminatedQueue since we finished a real play
  22143. this.playTerminatedQueue_ = [];
  22144. callbacks.forEach(function (cb) {
  22145. cb(val);
  22146. });
  22147. }
  22148. /**
  22149. * Pause the video playback
  22150. *
  22151. * @return {Player}
  22152. * A reference to the player object this function was called on
  22153. */
  22154. ;
  22155. _proto.pause = function pause() {
  22156. this.techCall_('pause');
  22157. }
  22158. /**
  22159. * Check if the player is paused or has yet to play
  22160. *
  22161. * @return {boolean}
  22162. * - false: if the media is currently playing
  22163. * - true: if media is not currently playing
  22164. */
  22165. ;
  22166. _proto.paused = function paused() {
  22167. // The initial state of paused should be true (in Safari it's actually false)
  22168. return this.techGet_('paused') === false ? false : true;
  22169. }
  22170. /**
  22171. * Get a TimeRange object representing the current ranges of time that the user
  22172. * has played.
  22173. *
  22174. * @return {TimeRange}
  22175. * A time range object that represents all the increments of time that have
  22176. * been played.
  22177. */
  22178. ;
  22179. _proto.played = function played() {
  22180. return this.techGet_('played') || createTimeRanges(0, 0);
  22181. }
  22182. /**
  22183. * Returns whether or not the user is "scrubbing". Scrubbing is
  22184. * when the user has clicked the progress bar handle and is
  22185. * dragging it along the progress bar.
  22186. *
  22187. * @param {boolean} [isScrubbing]
  22188. * whether the user is or is not scrubbing
  22189. *
  22190. * @return {boolean}
  22191. * The value of scrubbing when getting
  22192. */
  22193. ;
  22194. _proto.scrubbing = function scrubbing(isScrubbing) {
  22195. if (typeof isScrubbing === 'undefined') {
  22196. return this.scrubbing_;
  22197. }
  22198. this.scrubbing_ = !!isScrubbing;
  22199. if (isScrubbing) {
  22200. this.addClass('vjs-scrubbing');
  22201. } else {
  22202. this.removeClass('vjs-scrubbing');
  22203. }
  22204. }
  22205. /**
  22206. * Get or set the current time (in seconds)
  22207. *
  22208. * @param {number|string} [seconds]
  22209. * The time to seek to in seconds
  22210. *
  22211. * @return {number}
  22212. * - the current time in seconds when getting
  22213. */
  22214. ;
  22215. _proto.currentTime = function currentTime(seconds) {
  22216. if (typeof seconds !== 'undefined') {
  22217. if (seconds < 0) {
  22218. seconds = 0;
  22219. }
  22220. this.techCall_('setCurrentTime', seconds);
  22221. return;
  22222. } // cache last currentTime and return. default to 0 seconds
  22223. //
  22224. // Caching the currentTime is meant to prevent a massive amount of reads on the tech's
  22225. // currentTime when scrubbing, but may not provide much performance benefit afterall.
  22226. // Should be tested. Also something has to read the actual current time or the cache will
  22227. // never get updated.
  22228. this.cache_.currentTime = this.techGet_('currentTime') || 0;
  22229. return this.cache_.currentTime;
  22230. }
  22231. /**
  22232. * Normally gets the length in time of the video in seconds;
  22233. * in all but the rarest use cases an argument will NOT be passed to the method
  22234. *
  22235. * > **NOTE**: The video must have started loading before the duration can be
  22236. * known, and in the case of Flash, may not be known until the video starts
  22237. * playing.
  22238. *
  22239. * @fires Player#durationchange
  22240. *
  22241. * @param {number} [seconds]
  22242. * The duration of the video to set in seconds
  22243. *
  22244. * @return {number}
  22245. * - The duration of the video in seconds when getting
  22246. */
  22247. ;
  22248. _proto.duration = function duration(seconds) {
  22249. if (seconds === undefined) {
  22250. // return NaN if the duration is not known
  22251. return this.cache_.duration !== undefined ? this.cache_.duration : NaN;
  22252. }
  22253. seconds = parseFloat(seconds); // Standardize on Infinity for signaling video is live
  22254. if (seconds < 0) {
  22255. seconds = Infinity;
  22256. }
  22257. if (seconds !== this.cache_.duration) {
  22258. // Cache the last set value for optimized scrubbing (esp. Flash)
  22259. this.cache_.duration = seconds;
  22260. if (seconds === Infinity) {
  22261. this.addClass('vjs-live');
  22262. if (this.options_.liveui && this.player_.liveTracker) {
  22263. this.addClass('vjs-liveui');
  22264. }
  22265. } else {
  22266. this.removeClass('vjs-live');
  22267. this.removeClass('vjs-liveui');
  22268. }
  22269. if (!isNaN(seconds)) {
  22270. // Do not fire durationchange unless the duration value is known.
  22271. // @see [Spec]{@link https://www.w3.org/TR/2011/WD-html5-20110113/video.html#media-element-load-algorithm}
  22272. /**
  22273. * @event Player#durationchange
  22274. * @type {EventTarget~Event}
  22275. */
  22276. this.trigger('durationchange');
  22277. }
  22278. }
  22279. }
  22280. /**
  22281. * Calculates how much time is left in the video. Not part
  22282. * of the native video API.
  22283. *
  22284. * @return {number}
  22285. * The time remaining in seconds
  22286. */
  22287. ;
  22288. _proto.remainingTime = function remainingTime() {
  22289. return this.duration() - this.currentTime();
  22290. }
  22291. /**
  22292. * A remaining time function that is intented to be used when
  22293. * the time is to be displayed directly to the user.
  22294. *
  22295. * @return {number}
  22296. * The rounded time remaining in seconds
  22297. */
  22298. ;
  22299. _proto.remainingTimeDisplay = function remainingTimeDisplay() {
  22300. return Math.floor(this.duration()) - Math.floor(this.currentTime());
  22301. } //
  22302. // Kind of like an array of portions of the video that have been downloaded.
  22303. /**
  22304. * Get a TimeRange object with an array of the times of the video
  22305. * that have been downloaded. If you just want the percent of the
  22306. * video that's been downloaded, use bufferedPercent.
  22307. *
  22308. * @see [Buffered Spec]{@link http://dev.w3.org/html5/spec/video.html#dom-media-buffered}
  22309. *
  22310. * @return {TimeRange}
  22311. * A mock TimeRange object (following HTML spec)
  22312. */
  22313. ;
  22314. _proto.buffered = function buffered() {
  22315. var buffered = this.techGet_('buffered');
  22316. if (!buffered || !buffered.length) {
  22317. buffered = createTimeRanges(0, 0);
  22318. }
  22319. return buffered;
  22320. }
  22321. /**
  22322. * Get the percent (as a decimal) of the video that's been downloaded.
  22323. * This method is not a part of the native HTML video API.
  22324. *
  22325. * @return {number}
  22326. * A decimal between 0 and 1 representing the percent
  22327. * that is buffered 0 being 0% and 1 being 100%
  22328. */
  22329. ;
  22330. _proto.bufferedPercent = function bufferedPercent$1() {
  22331. return bufferedPercent(this.buffered(), this.duration());
  22332. }
  22333. /**
  22334. * Get the ending time of the last buffered time range
  22335. * This is used in the progress bar to encapsulate all time ranges.
  22336. *
  22337. * @return {number}
  22338. * The end of the last buffered time range
  22339. */
  22340. ;
  22341. _proto.bufferedEnd = function bufferedEnd() {
  22342. var buffered = this.buffered();
  22343. var duration = this.duration();
  22344. var end = buffered.end(buffered.length - 1);
  22345. if (end > duration) {
  22346. end = duration;
  22347. }
  22348. return end;
  22349. }
  22350. /**
  22351. * Get or set the current volume of the media
  22352. *
  22353. * @param {number} [percentAsDecimal]
  22354. * The new volume as a decimal percent:
  22355. * - 0 is muted/0%/off
  22356. * - 1.0 is 100%/full
  22357. * - 0.5 is half volume or 50%
  22358. *
  22359. * @return {number}
  22360. * The current volume as a percent when getting
  22361. */
  22362. ;
  22363. _proto.volume = function volume(percentAsDecimal) {
  22364. var vol;
  22365. if (percentAsDecimal !== undefined) {
  22366. // Force value to between 0 and 1
  22367. vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal)));
  22368. this.cache_.volume = vol;
  22369. this.techCall_('setVolume', vol);
  22370. if (vol > 0) {
  22371. this.lastVolume_(vol);
  22372. }
  22373. return;
  22374. } // Default to 1 when returning current volume.
  22375. vol = parseFloat(this.techGet_('volume'));
  22376. return isNaN(vol) ? 1 : vol;
  22377. }
  22378. /**
  22379. * Get the current muted state, or turn mute on or off
  22380. *
  22381. * @param {boolean} [muted]
  22382. * - true to mute
  22383. * - false to unmute
  22384. *
  22385. * @return {boolean}
  22386. * - true if mute is on and getting
  22387. * - false if mute is off and getting
  22388. */
  22389. ;
  22390. _proto.muted = function muted(_muted) {
  22391. if (_muted !== undefined) {
  22392. this.techCall_('setMuted', _muted);
  22393. return;
  22394. }
  22395. return this.techGet_('muted') || false;
  22396. }
  22397. /**
  22398. * Get the current defaultMuted state, or turn defaultMuted on or off. defaultMuted
  22399. * indicates the state of muted on initial playback.
  22400. *
  22401. * ```js
  22402. * var myPlayer = videojs('some-player-id');
  22403. *
  22404. * myPlayer.src("http://www.example.com/path/to/video.mp4");
  22405. *
  22406. * // get, should be false
  22407. * console.log(myPlayer.defaultMuted());
  22408. * // set to true
  22409. * myPlayer.defaultMuted(true);
  22410. * // get should be true
  22411. * console.log(myPlayer.defaultMuted());
  22412. * ```
  22413. *
  22414. * @param {boolean} [defaultMuted]
  22415. * - true to mute
  22416. * - false to unmute
  22417. *
  22418. * @return {boolean|Player}
  22419. * - true if defaultMuted is on and getting
  22420. * - false if defaultMuted is off and getting
  22421. * - A reference to the current player when setting
  22422. */
  22423. ;
  22424. _proto.defaultMuted = function defaultMuted(_defaultMuted) {
  22425. if (_defaultMuted !== undefined) {
  22426. return this.techCall_('setDefaultMuted', _defaultMuted);
  22427. }
  22428. return this.techGet_('defaultMuted') || false;
  22429. }
  22430. /**
  22431. * Get the last volume, or set it
  22432. *
  22433. * @param {number} [percentAsDecimal]
  22434. * The new last volume as a decimal percent:
  22435. * - 0 is muted/0%/off
  22436. * - 1.0 is 100%/full
  22437. * - 0.5 is half volume or 50%
  22438. *
  22439. * @return {number}
  22440. * the current value of lastVolume as a percent when getting
  22441. *
  22442. * @private
  22443. */
  22444. ;
  22445. _proto.lastVolume_ = function lastVolume_(percentAsDecimal) {
  22446. if (percentAsDecimal !== undefined && percentAsDecimal !== 0) {
  22447. this.cache_.lastVolume = percentAsDecimal;
  22448. return;
  22449. }
  22450. return this.cache_.lastVolume;
  22451. }
  22452. /**
  22453. * Check if current tech can support native fullscreen
  22454. * (e.g. with built in controls like iOS, so not our flash swf)
  22455. *
  22456. * @return {boolean}
  22457. * if native fullscreen is supported
  22458. */
  22459. ;
  22460. _proto.supportsFullScreen = function supportsFullScreen() {
  22461. return this.techGet_('supportsFullScreen') || false;
  22462. }
  22463. /**
  22464. * Check if the player is in fullscreen mode or tell the player that it
  22465. * is or is not in fullscreen mode.
  22466. *
  22467. * > NOTE: As of the latest HTML5 spec, isFullscreen is no longer an official
  22468. * property and instead document.fullscreenElement is used. But isFullscreen is
  22469. * still a valuable property for internal player workings.
  22470. *
  22471. * @param {boolean} [isFS]
  22472. * Set the players current fullscreen state
  22473. *
  22474. * @return {boolean}
  22475. * - true if fullscreen is on and getting
  22476. * - false if fullscreen is off and getting
  22477. */
  22478. ;
  22479. _proto.isFullscreen = function isFullscreen(isFS) {
  22480. if (isFS !== undefined) {
  22481. this.isFullscreen_ = !!isFS;
  22482. this.toggleFullscreenClass_();
  22483. return;
  22484. }
  22485. return !!this.isFullscreen_;
  22486. }
  22487. /**
  22488. * Increase the size of the video to full screen
  22489. * In some browsers, full screen is not supported natively, so it enters
  22490. * "full window mode", where the video fills the browser window.
  22491. * In browsers and devices that support native full screen, sometimes the
  22492. * browser's default controls will be shown, and not the Video.js custom skin.
  22493. * This includes most mobile devices (iOS, Android) and older versions of
  22494. * Safari.
  22495. *
  22496. * @param {Object} [fullscreenOptions]
  22497. * Override the player fullscreen options
  22498. *
  22499. * @fires Player#fullscreenchange
  22500. */
  22501. ;
  22502. _proto.requestFullscreen = function requestFullscreen(fullscreenOptions) {
  22503. var fsOptions;
  22504. this.isFullscreen(true);
  22505. if (this.fsApi_.requestFullscreen) {
  22506. // the browser supports going fullscreen at the element level so we can
  22507. // take the controls fullscreen as well as the video
  22508. // Trigger fullscreenchange event after change
  22509. // We have to specifically add this each time, and remove
  22510. // when canceling fullscreen. Otherwise if there's multiple
  22511. // players on a page, they would all be reacting to the same fullscreen
  22512. // events
  22513. on(document, this.fsApi_.fullscreenchange, this.boundDocumentFullscreenChange_); // only pass FullscreenOptions to requestFullscreen if it isn't prefixed
  22514. if (!this.fsApi_.prefixed) {
  22515. fsOptions = this.options_.fullscreen && this.options_.fullscreen.options || {};
  22516. if (fullscreenOptions !== undefined) {
  22517. fsOptions = fullscreenOptions;
  22518. }
  22519. }
  22520. silencePromise(this.el_[this.fsApi_.requestFullscreen](fsOptions));
  22521. } else if (this.tech_.supportsFullScreen()) {
  22522. // we can't take the video.js controls fullscreen but we can go fullscreen
  22523. // with native controls
  22524. this.techCall_('enterFullScreen');
  22525. } else {
  22526. // fullscreen isn't supported so we'll just stretch the video element to
  22527. // fill the viewport
  22528. this.enterFullWindow();
  22529. /**
  22530. * @event Player#fullscreenchange
  22531. * @type {EventTarget~Event}
  22532. */
  22533. this.trigger('fullscreenchange');
  22534. }
  22535. }
  22536. /**
  22537. * Return the video to its normal size after having been in full screen mode
  22538. *
  22539. * @fires Player#fullscreenchange
  22540. */
  22541. ;
  22542. _proto.exitFullscreen = function exitFullscreen() {
  22543. this.isFullscreen(false); // Check for browser element fullscreen support
  22544. if (this.fsApi_.requestFullscreen) {
  22545. silencePromise(document[this.fsApi_.exitFullscreen]());
  22546. } else if (this.tech_.supportsFullScreen()) {
  22547. this.techCall_('exitFullScreen');
  22548. } else {
  22549. this.exitFullWindow();
  22550. /**
  22551. * @event Player#fullscreenchange
  22552. * @type {EventTarget~Event}
  22553. */
  22554. this.trigger('fullscreenchange');
  22555. }
  22556. }
  22557. /**
  22558. * When fullscreen isn't supported we can stretch the
  22559. * video container to as wide as the browser will let us.
  22560. *
  22561. * @fires Player#enterFullWindow
  22562. */
  22563. ;
  22564. _proto.enterFullWindow = function enterFullWindow() {
  22565. this.isFullWindow = true; // Storing original doc overflow value to return to when fullscreen is off
  22566. this.docOrigOverflow = document.documentElement.style.overflow; // Add listener for esc key to exit fullscreen
  22567. on(document, 'keydown', this.boundFullWindowOnEscKey_); // Hide any scroll bars
  22568. document.documentElement.style.overflow = 'hidden'; // Apply fullscreen styles
  22569. addClass(document.body, 'vjs-full-window');
  22570. /**
  22571. * @event Player#enterFullWindow
  22572. * @type {EventTarget~Event}
  22573. */
  22574. this.trigger('enterFullWindow');
  22575. }
  22576. /**
  22577. * Check for call to either exit full window or
  22578. * full screen on ESC key
  22579. *
  22580. * @param {string} event
  22581. * Event to check for key press
  22582. */
  22583. ;
  22584. _proto.fullWindowOnEscKey = function fullWindowOnEscKey(event) {
  22585. if (keycode.isEventKey(event, 'Esc')) {
  22586. if (this.isFullscreen() === true) {
  22587. this.exitFullscreen();
  22588. } else {
  22589. this.exitFullWindow();
  22590. }
  22591. }
  22592. }
  22593. /**
  22594. * Exit full window
  22595. *
  22596. * @fires Player#exitFullWindow
  22597. */
  22598. ;
  22599. _proto.exitFullWindow = function exitFullWindow() {
  22600. this.isFullWindow = false;
  22601. off(document, 'keydown', this.boundFullWindowOnEscKey_); // Unhide scroll bars.
  22602. document.documentElement.style.overflow = this.docOrigOverflow; // Remove fullscreen styles
  22603. removeClass(document.body, 'vjs-full-window'); // Resize the box, controller, and poster to original sizes
  22604. // this.positionAll();
  22605. /**
  22606. * @event Player#exitFullWindow
  22607. * @type {EventTarget~Event}
  22608. */
  22609. this.trigger('exitFullWindow');
  22610. }
  22611. /**
  22612. * Check if the player is in Picture-in-Picture mode or tell the player that it
  22613. * is or is not in Picture-in-Picture mode.
  22614. *
  22615. * @param {boolean} [isPiP]
  22616. * Set the players current Picture-in-Picture state
  22617. *
  22618. * @return {boolean}
  22619. * - true if Picture-in-Picture is on and getting
  22620. * - false if Picture-in-Picture is off and getting
  22621. */
  22622. ;
  22623. _proto.isInPictureInPicture = function isInPictureInPicture(isPiP) {
  22624. if (isPiP !== undefined) {
  22625. this.isInPictureInPicture_ = !!isPiP;
  22626. this.togglePictureInPictureClass_();
  22627. return;
  22628. }
  22629. return !!this.isInPictureInPicture_;
  22630. }
  22631. /**
  22632. * Create a floating video window always on top of other windows so that users may
  22633. * continue consuming media while they interact with other content sites, or
  22634. * applications on their device.
  22635. *
  22636. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  22637. *
  22638. * @fires Player#enterpictureinpicture
  22639. *
  22640. * @return {Promise}
  22641. * A promise with a Picture-in-Picture window.
  22642. */
  22643. ;
  22644. _proto.requestPictureInPicture = function requestPictureInPicture() {
  22645. if ('pictureInPictureEnabled' in document) {
  22646. /**
  22647. * This event fires when the player enters picture in picture mode
  22648. *
  22649. * @event Player#enterpictureinpicture
  22650. * @type {EventTarget~Event}
  22651. */
  22652. return this.techGet_('requestPictureInPicture');
  22653. }
  22654. }
  22655. /**
  22656. * Exit Picture-in-Picture mode.
  22657. *
  22658. * @see [Spec]{@link https://wicg.github.io/picture-in-picture}
  22659. *
  22660. * @fires Player#leavepictureinpicture
  22661. *
  22662. * @return {Promise}
  22663. * A promise.
  22664. */
  22665. ;
  22666. _proto.exitPictureInPicture = function exitPictureInPicture() {
  22667. if ('pictureInPictureEnabled' in document) {
  22668. /**
  22669. * This event fires when the player leaves picture in picture mode
  22670. *
  22671. * @event Player#leavepictureinpicture
  22672. * @type {EventTarget~Event}
  22673. */
  22674. return document.exitPictureInPicture();
  22675. }
  22676. }
  22677. /**
  22678. * Called when this Player has focus and a key gets pressed down, or when
  22679. * any Component of this player receives a key press that it doesn't handle.
  22680. * This allows player-wide hotkeys (either as defined below, or optionally
  22681. * by an external function).
  22682. *
  22683. * @param {EventTarget~Event} event
  22684. * The `keydown` event that caused this function to be called.
  22685. *
  22686. * @listens keydown
  22687. */
  22688. ;
  22689. _proto.handleKeyDown = function handleKeyDown(event) {
  22690. var userActions = this.options_.userActions; // Bail out if hotkeys are not configured.
  22691. if (!userActions || !userActions.hotkeys) {
  22692. return;
  22693. } // Function that determines whether or not to exclude an element from
  22694. // hotkeys handling.
  22695. var excludeElement = function excludeElement(el) {
  22696. var tagName = el.tagName.toLowerCase(); // The first and easiest test is for `contenteditable` elements.
  22697. if (el.isContentEditable) {
  22698. return true;
  22699. } // Inputs matching these types will still trigger hotkey handling as
  22700. // they are not text inputs.
  22701. var allowedInputTypes = ['button', 'checkbox', 'hidden', 'radio', 'reset', 'submit'];
  22702. if (tagName === 'input') {
  22703. return allowedInputTypes.indexOf(el.type) === -1;
  22704. } // The final test is by tag name. These tags will be excluded entirely.
  22705. var excludedTags = ['textarea'];
  22706. return excludedTags.indexOf(tagName) !== -1;
  22707. }; // Bail out if the user is focused on an interactive form element.
  22708. if (excludeElement(this.el_.ownerDocument.activeElement)) {
  22709. return;
  22710. }
  22711. if (typeof userActions.hotkeys === 'function') {
  22712. userActions.hotkeys.call(this, event);
  22713. } else {
  22714. this.handleHotkeys(event);
  22715. }
  22716. }
  22717. /**
  22718. * Called when this Player receives a hotkey keydown event.
  22719. * Supported player-wide hotkeys are:
  22720. *
  22721. * f - toggle fullscreen
  22722. * m - toggle mute
  22723. * k or Space - toggle play/pause
  22724. *
  22725. * @param {EventTarget~Event} event
  22726. * The `keydown` event that caused this function to be called.
  22727. */
  22728. ;
  22729. _proto.handleHotkeys = function handleHotkeys(event) {
  22730. var hotkeys = this.options_.userActions ? this.options_.userActions.hotkeys : {}; // set fullscreenKey, muteKey, playPauseKey from `hotkeys`, use defaults if not set
  22731. var _hotkeys$fullscreenKe = hotkeys.fullscreenKey,
  22732. fullscreenKey = _hotkeys$fullscreenKe === void 0 ? function (keydownEvent) {
  22733. return keycode.isEventKey(keydownEvent, 'f');
  22734. } : _hotkeys$fullscreenKe,
  22735. _hotkeys$muteKey = hotkeys.muteKey,
  22736. muteKey = _hotkeys$muteKey === void 0 ? function (keydownEvent) {
  22737. return keycode.isEventKey(keydownEvent, 'm');
  22738. } : _hotkeys$muteKey,
  22739. _hotkeys$playPauseKey = hotkeys.playPauseKey,
  22740. playPauseKey = _hotkeys$playPauseKey === void 0 ? function (keydownEvent) {
  22741. return keycode.isEventKey(keydownEvent, 'k') || keycode.isEventKey(keydownEvent, 'Space');
  22742. } : _hotkeys$playPauseKey;
  22743. if (fullscreenKey.call(this, event)) {
  22744. event.preventDefault();
  22745. event.stopPropagation();
  22746. var FSToggle = Component.getComponent('FullscreenToggle');
  22747. if (document[this.fsApi_.fullscreenEnabled] !== false) {
  22748. FSToggle.prototype.handleClick.call(this, event);
  22749. }
  22750. } else if (muteKey.call(this, event)) {
  22751. event.preventDefault();
  22752. event.stopPropagation();
  22753. var MuteToggle = Component.getComponent('MuteToggle');
  22754. MuteToggle.prototype.handleClick.call(this, event);
  22755. } else if (playPauseKey.call(this, event)) {
  22756. event.preventDefault();
  22757. event.stopPropagation();
  22758. var PlayToggle = Component.getComponent('PlayToggle');
  22759. PlayToggle.prototype.handleClick.call(this, event);
  22760. }
  22761. }
  22762. /**
  22763. * Check whether the player can play a given mimetype
  22764. *
  22765. * @see https://www.w3.org/TR/2011/WD-html5-20110113/video.html#dom-navigator-canplaytype
  22766. *
  22767. * @param {string} type
  22768. * The mimetype to check
  22769. *
  22770. * @return {string}
  22771. * 'probably', 'maybe', or '' (empty string)
  22772. */
  22773. ;
  22774. _proto.canPlayType = function canPlayType(type) {
  22775. var can; // Loop through each playback technology in the options order
  22776. for (var i = 0, j = this.options_.techOrder; i < j.length; i++) {
  22777. var techName = j[i];
  22778. var tech = Tech.getTech(techName); // Support old behavior of techs being registered as components.
  22779. // Remove once that deprecated behavior is removed.
  22780. if (!tech) {
  22781. tech = Component.getComponent(techName);
  22782. } // Check if the current tech is defined before continuing
  22783. if (!tech) {
  22784. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  22785. continue;
  22786. } // Check if the browser supports this technology
  22787. if (tech.isSupported()) {
  22788. can = tech.canPlayType(type);
  22789. if (can) {
  22790. return can;
  22791. }
  22792. }
  22793. }
  22794. return '';
  22795. }
  22796. /**
  22797. * Select source based on tech-order or source-order
  22798. * Uses source-order selection if `options.sourceOrder` is truthy. Otherwise,
  22799. * defaults to tech-order selection
  22800. *
  22801. * @param {Array} sources
  22802. * The sources for a media asset
  22803. *
  22804. * @return {Object|boolean}
  22805. * Object of source and tech order or false
  22806. */
  22807. ;
  22808. _proto.selectSource = function selectSource(sources) {
  22809. var _this10 = this;
  22810. // Get only the techs specified in `techOrder` that exist and are supported by the
  22811. // current platform
  22812. var techs = this.options_.techOrder.map(function (techName) {
  22813. return [techName, Tech.getTech(techName)];
  22814. }).filter(function (_ref) {
  22815. var techName = _ref[0],
  22816. tech = _ref[1];
  22817. // Check if the current tech is defined before continuing
  22818. if (tech) {
  22819. // Check if the browser supports this technology
  22820. return tech.isSupported();
  22821. }
  22822. log.error("The \"" + techName + "\" tech is undefined. Skipped browser support check for that tech.");
  22823. return false;
  22824. }); // Iterate over each `innerArray` element once per `outerArray` element and execute
  22825. // `tester` with both. If `tester` returns a non-falsy value, exit early and return
  22826. // that value.
  22827. var findFirstPassingTechSourcePair = function findFirstPassingTechSourcePair(outerArray, innerArray, tester) {
  22828. var found;
  22829. outerArray.some(function (outerChoice) {
  22830. return innerArray.some(function (innerChoice) {
  22831. found = tester(outerChoice, innerChoice);
  22832. if (found) {
  22833. return true;
  22834. }
  22835. });
  22836. });
  22837. return found;
  22838. };
  22839. var foundSourceAndTech;
  22840. var flip = function flip(fn) {
  22841. return function (a, b) {
  22842. return fn(b, a);
  22843. };
  22844. };
  22845. var finder = function finder(_ref2, source) {
  22846. var techName = _ref2[0],
  22847. tech = _ref2[1];
  22848. if (tech.canPlaySource(source, _this10.options_[techName.toLowerCase()])) {
  22849. return {
  22850. source: source,
  22851. tech: techName
  22852. };
  22853. }
  22854. }; // Depending on the truthiness of `options.sourceOrder`, we swap the order of techs and sources
  22855. // to select from them based on their priority.
  22856. if (this.options_.sourceOrder) {
  22857. // Source-first ordering
  22858. foundSourceAndTech = findFirstPassingTechSourcePair(sources, techs, flip(finder));
  22859. } else {
  22860. // Tech-first ordering
  22861. foundSourceAndTech = findFirstPassingTechSourcePair(techs, sources, finder);
  22862. }
  22863. return foundSourceAndTech || false;
  22864. }
  22865. /**
  22866. * Get or set the video source.
  22867. *
  22868. * @param {Tech~SourceObject|Tech~SourceObject[]|string} [source]
  22869. * A SourceObject, an array of SourceObjects, or a string referencing
  22870. * a URL to a media source. It is _highly recommended_ that an object
  22871. * or array of objects is used here, so that source selection
  22872. * algorithms can take the `type` into account.
  22873. *
  22874. * If not provided, this method acts as a getter.
  22875. *
  22876. * @return {string|undefined}
  22877. * If the `source` argument is missing, returns the current source
  22878. * URL. Otherwise, returns nothing/undefined.
  22879. */
  22880. ;
  22881. _proto.src = function src(source) {
  22882. var _this11 = this;
  22883. // getter usage
  22884. if (typeof source === 'undefined') {
  22885. return this.cache_.src || '';
  22886. } // filter out invalid sources and turn our source into
  22887. // an array of source objects
  22888. var sources = filterSource(source); // if a source was passed in then it is invalid because
  22889. // it was filtered to a zero length Array. So we have to
  22890. // show an error
  22891. if (!sources.length) {
  22892. this.setTimeout(function () {
  22893. this.error({
  22894. code: 4,
  22895. message: this.localize(this.options_.notSupportedMessage)
  22896. });
  22897. }, 0);
  22898. return;
  22899. } // intial sources
  22900. this.changingSrc_ = true;
  22901. this.cache_.sources = sources;
  22902. this.updateSourceCaches_(sources[0]); // middlewareSource is the source after it has been changed by middleware
  22903. setSource(this, sources[0], function (middlewareSource, mws) {
  22904. _this11.middleware_ = mws; // since sourceSet is async we have to update the cache again after we select a source since
  22905. // the source that is selected could be out of order from the cache update above this callback.
  22906. _this11.cache_.sources = sources;
  22907. _this11.updateSourceCaches_(middlewareSource);
  22908. var err = _this11.src_(middlewareSource);
  22909. if (err) {
  22910. if (sources.length > 1) {
  22911. return _this11.src(sources.slice(1));
  22912. }
  22913. _this11.changingSrc_ = false; // We need to wrap this in a timeout to give folks a chance to add error event handlers
  22914. _this11.setTimeout(function () {
  22915. this.error({
  22916. code: 4,
  22917. message: this.localize(this.options_.notSupportedMessage)
  22918. });
  22919. }, 0); // we could not find an appropriate tech, but let's still notify the delegate that this is it
  22920. // this needs a better comment about why this is needed
  22921. _this11.triggerReady();
  22922. return;
  22923. }
  22924. setTech(mws, _this11.tech_);
  22925. });
  22926. }
  22927. /**
  22928. * Set the source object on the tech, returns a boolean that indicates whether
  22929. * there is a tech that can play the source or not
  22930. *
  22931. * @param {Tech~SourceObject} source
  22932. * The source object to set on the Tech
  22933. *
  22934. * @return {boolean}
  22935. * - True if there is no Tech to playback this source
  22936. * - False otherwise
  22937. *
  22938. * @private
  22939. */
  22940. ;
  22941. _proto.src_ = function src_(source) {
  22942. var _this12 = this;
  22943. var sourceTech = this.selectSource([source]);
  22944. if (!sourceTech) {
  22945. return true;
  22946. }
  22947. if (!titleCaseEquals(sourceTech.tech, this.techName_)) {
  22948. this.changingSrc_ = true; // load this technology with the chosen source
  22949. this.loadTech_(sourceTech.tech, sourceTech.source);
  22950. this.tech_.ready(function () {
  22951. _this12.changingSrc_ = false;
  22952. });
  22953. return false;
  22954. } // wait until the tech is ready to set the source
  22955. // and set it synchronously if possible (#2326)
  22956. this.ready(function () {
  22957. // The setSource tech method was added with source handlers
  22958. // so older techs won't support it
  22959. // We need to check the direct prototype for the case where subclasses
  22960. // of the tech do not support source handlers
  22961. if (this.tech_.constructor.prototype.hasOwnProperty('setSource')) {
  22962. this.techCall_('setSource', source);
  22963. } else {
  22964. this.techCall_('src', source.src);
  22965. }
  22966. this.changingSrc_ = false;
  22967. }, true);
  22968. return false;
  22969. }
  22970. /**
  22971. * Begin loading the src data.
  22972. */
  22973. ;
  22974. _proto.load = function load() {
  22975. this.techCall_('load');
  22976. }
  22977. /**
  22978. * Reset the player. Loads the first tech in the techOrder,
  22979. * removes all the text tracks in the existing `tech`,
  22980. * and calls `reset` on the `tech`.
  22981. */
  22982. ;
  22983. _proto.reset = function reset() {
  22984. var _this13 = this;
  22985. var PromiseClass = this.options_.Promise || window$1.Promise;
  22986. if (this.paused() || !PromiseClass) {
  22987. this.doReset_();
  22988. } else {
  22989. var playPromise = this.play();
  22990. silencePromise(playPromise.then(function () {
  22991. return _this13.doReset_();
  22992. }));
  22993. }
  22994. };
  22995. _proto.doReset_ = function doReset_() {
  22996. if (this.tech_) {
  22997. this.tech_.clearTracks('text');
  22998. }
  22999. this.resetCache_();
  23000. this.poster('');
  23001. this.loadTech_(this.options_.techOrder[0], null);
  23002. this.techCall_('reset');
  23003. this.resetControlBarUI_();
  23004. if (isEvented(this)) {
  23005. this.trigger('playerreset');
  23006. }
  23007. }
  23008. /**
  23009. * Reset Control Bar's UI by calling sub-methods that reset
  23010. * all of Control Bar's components
  23011. */
  23012. ;
  23013. _proto.resetControlBarUI_ = function resetControlBarUI_() {
  23014. this.resetProgressBar_();
  23015. this.resetPlaybackRate_();
  23016. this.resetVolumeBar_();
  23017. }
  23018. /**
  23019. * Reset tech's progress so progress bar is reset in the UI
  23020. */
  23021. ;
  23022. _proto.resetProgressBar_ = function resetProgressBar_() {
  23023. this.currentTime(0);
  23024. var _this$controlBar = this.controlBar,
  23025. durationDisplay = _this$controlBar.durationDisplay,
  23026. remainingTimeDisplay = _this$controlBar.remainingTimeDisplay;
  23027. if (durationDisplay) {
  23028. durationDisplay.updateContent();
  23029. }
  23030. if (remainingTimeDisplay) {
  23031. remainingTimeDisplay.updateContent();
  23032. }
  23033. }
  23034. /**
  23035. * Reset Playback ratio
  23036. */
  23037. ;
  23038. _proto.resetPlaybackRate_ = function resetPlaybackRate_() {
  23039. this.playbackRate(this.defaultPlaybackRate());
  23040. this.handleTechRateChange_();
  23041. }
  23042. /**
  23043. * Reset Volume bar
  23044. */
  23045. ;
  23046. _proto.resetVolumeBar_ = function resetVolumeBar_() {
  23047. this.volume(1.0);
  23048. this.trigger('volumechange');
  23049. }
  23050. /**
  23051. * Returns all of the current source objects.
  23052. *
  23053. * @return {Tech~SourceObject[]}
  23054. * The current source objects
  23055. */
  23056. ;
  23057. _proto.currentSources = function currentSources() {
  23058. var source = this.currentSource();
  23059. var sources = []; // assume `{}` or `{ src }`
  23060. if (Object.keys(source).length !== 0) {
  23061. sources.push(source);
  23062. }
  23063. return this.cache_.sources || sources;
  23064. }
  23065. /**
  23066. * Returns the current source object.
  23067. *
  23068. * @return {Tech~SourceObject}
  23069. * The current source object
  23070. */
  23071. ;
  23072. _proto.currentSource = function currentSource() {
  23073. return this.cache_.source || {};
  23074. }
  23075. /**
  23076. * Returns the fully qualified URL of the current source value e.g. http://mysite.com/video.mp4
  23077. * Can be used in conjunction with `currentType` to assist in rebuilding the current source object.
  23078. *
  23079. * @return {string}
  23080. * The current source
  23081. */
  23082. ;
  23083. _proto.currentSrc = function currentSrc() {
  23084. return this.currentSource() && this.currentSource().src || '';
  23085. }
  23086. /**
  23087. * Get the current source type e.g. video/mp4
  23088. * This can allow you rebuild the current source object so that you could load the same
  23089. * source and tech later
  23090. *
  23091. * @return {string}
  23092. * The source MIME type
  23093. */
  23094. ;
  23095. _proto.currentType = function currentType() {
  23096. return this.currentSource() && this.currentSource().type || '';
  23097. }
  23098. /**
  23099. * Get or set the preload attribute
  23100. *
  23101. * @param {boolean} [value]
  23102. * - true means that we should preload
  23103. * - false means that we should not preload
  23104. *
  23105. * @return {string}
  23106. * The preload attribute value when getting
  23107. */
  23108. ;
  23109. _proto.preload = function preload(value) {
  23110. if (value !== undefined) {
  23111. this.techCall_('setPreload', value);
  23112. this.options_.preload = value;
  23113. return;
  23114. }
  23115. return this.techGet_('preload');
  23116. }
  23117. /**
  23118. * Get or set the autoplay option. When this is a boolean it will
  23119. * modify the attribute on the tech. When this is a string the attribute on
  23120. * the tech will be removed and `Player` will handle autoplay on loadstarts.
  23121. *
  23122. * @param {boolean|string} [value]
  23123. * - true: autoplay using the browser behavior
  23124. * - false: do not autoplay
  23125. * - 'play': call play() on every loadstart
  23126. * - 'muted': call muted() then play() on every loadstart
  23127. * - 'any': call play() on every loadstart. if that fails call muted() then play().
  23128. * - *: values other than those listed here will be set `autoplay` to true
  23129. *
  23130. * @return {boolean|string}
  23131. * The current value of autoplay when getting
  23132. */
  23133. ;
  23134. _proto.autoplay = function autoplay(value) {
  23135. // getter usage
  23136. if (value === undefined) {
  23137. return this.options_.autoplay || false;
  23138. }
  23139. var techAutoplay; // if the value is a valid string set it to that
  23140. if (typeof value === 'string' && /(any|play|muted)/.test(value)) {
  23141. this.options_.autoplay = value;
  23142. this.manualAutoplay_(value);
  23143. techAutoplay = false; // any falsy value sets autoplay to false in the browser,
  23144. // lets do the same
  23145. } else if (!value) {
  23146. this.options_.autoplay = false; // any other value (ie truthy) sets autoplay to true
  23147. } else {
  23148. this.options_.autoplay = true;
  23149. }
  23150. techAutoplay = typeof techAutoplay === 'undefined' ? this.options_.autoplay : techAutoplay; // if we don't have a tech then we do not queue up
  23151. // a setAutoplay call on tech ready. We do this because the
  23152. // autoplay option will be passed in the constructor and we
  23153. // do not need to set it twice
  23154. if (this.tech_) {
  23155. this.techCall_('setAutoplay', techAutoplay);
  23156. }
  23157. }
  23158. /**
  23159. * Set or unset the playsinline attribute.
  23160. * Playsinline tells the browser that non-fullscreen playback is preferred.
  23161. *
  23162. * @param {boolean} [value]
  23163. * - true means that we should try to play inline by default
  23164. * - false means that we should use the browser's default playback mode,
  23165. * which in most cases is inline. iOS Safari is a notable exception
  23166. * and plays fullscreen by default.
  23167. *
  23168. * @return {string|Player}
  23169. * - the current value of playsinline
  23170. * - the player when setting
  23171. *
  23172. * @see [Spec]{@link https://html.spec.whatwg.org/#attr-video-playsinline}
  23173. */
  23174. ;
  23175. _proto.playsinline = function playsinline(value) {
  23176. if (value !== undefined) {
  23177. this.techCall_('setPlaysinline', value);
  23178. this.options_.playsinline = value;
  23179. return this;
  23180. }
  23181. return this.techGet_('playsinline');
  23182. }
  23183. /**
  23184. * Get or set the loop attribute on the video element.
  23185. *
  23186. * @param {boolean} [value]
  23187. * - true means that we should loop the video
  23188. * - false means that we should not loop the video
  23189. *
  23190. * @return {boolean}
  23191. * The current value of loop when getting
  23192. */
  23193. ;
  23194. _proto.loop = function loop(value) {
  23195. if (value !== undefined) {
  23196. this.techCall_('setLoop', value);
  23197. this.options_.loop = value;
  23198. return;
  23199. }
  23200. return this.techGet_('loop');
  23201. }
  23202. /**
  23203. * Get or set the poster image source url
  23204. *
  23205. * @fires Player#posterchange
  23206. *
  23207. * @param {string} [src]
  23208. * Poster image source URL
  23209. *
  23210. * @return {string}
  23211. * The current value of poster when getting
  23212. */
  23213. ;
  23214. _proto.poster = function poster(src) {
  23215. if (src === undefined) {
  23216. return this.poster_;
  23217. } // The correct way to remove a poster is to set as an empty string
  23218. // other falsey values will throw errors
  23219. if (!src) {
  23220. src = '';
  23221. }
  23222. if (src === this.poster_) {
  23223. return;
  23224. } // update the internal poster variable
  23225. this.poster_ = src; // update the tech's poster
  23226. this.techCall_('setPoster', src);
  23227. this.isPosterFromTech_ = false; // alert components that the poster has been set
  23228. /**
  23229. * This event fires when the poster image is changed on the player.
  23230. *
  23231. * @event Player#posterchange
  23232. * @type {EventTarget~Event}
  23233. */
  23234. this.trigger('posterchange');
  23235. }
  23236. /**
  23237. * Some techs (e.g. YouTube) can provide a poster source in an
  23238. * asynchronous way. We want the poster component to use this
  23239. * poster source so that it covers up the tech's controls.
  23240. * (YouTube's play button). However we only want to use this
  23241. * source if the player user hasn't set a poster through
  23242. * the normal APIs.
  23243. *
  23244. * @fires Player#posterchange
  23245. * @listens Tech#posterchange
  23246. * @private
  23247. */
  23248. ;
  23249. _proto.handleTechPosterChange_ = function handleTechPosterChange_() {
  23250. if ((!this.poster_ || this.options_.techCanOverridePoster) && this.tech_ && this.tech_.poster) {
  23251. var newPoster = this.tech_.poster() || '';
  23252. if (newPoster !== this.poster_) {
  23253. this.poster_ = newPoster;
  23254. this.isPosterFromTech_ = true; // Let components know the poster has changed
  23255. this.trigger('posterchange');
  23256. }
  23257. }
  23258. }
  23259. /**
  23260. * Get or set whether or not the controls are showing.
  23261. *
  23262. * @fires Player#controlsenabled
  23263. *
  23264. * @param {boolean} [bool]
  23265. * - true to turn controls on
  23266. * - false to turn controls off
  23267. *
  23268. * @return {boolean}
  23269. * The current value of controls when getting
  23270. */
  23271. ;
  23272. _proto.controls = function controls(bool) {
  23273. if (bool === undefined) {
  23274. return !!this.controls_;
  23275. }
  23276. bool = !!bool; // Don't trigger a change event unless it actually changed
  23277. if (this.controls_ === bool) {
  23278. return;
  23279. }
  23280. this.controls_ = bool;
  23281. if (this.usingNativeControls()) {
  23282. this.techCall_('setControls', bool);
  23283. }
  23284. if (this.controls_) {
  23285. this.removeClass('vjs-controls-disabled');
  23286. this.addClass('vjs-controls-enabled');
  23287. /**
  23288. * @event Player#controlsenabled
  23289. * @type {EventTarget~Event}
  23290. */
  23291. this.trigger('controlsenabled');
  23292. if (!this.usingNativeControls()) {
  23293. this.addTechControlsListeners_();
  23294. }
  23295. } else {
  23296. this.removeClass('vjs-controls-enabled');
  23297. this.addClass('vjs-controls-disabled');
  23298. /**
  23299. * @event Player#controlsdisabled
  23300. * @type {EventTarget~Event}
  23301. */
  23302. this.trigger('controlsdisabled');
  23303. if (!this.usingNativeControls()) {
  23304. this.removeTechControlsListeners_();
  23305. }
  23306. }
  23307. }
  23308. /**
  23309. * Toggle native controls on/off. Native controls are the controls built into
  23310. * devices (e.g. default iPhone controls), Flash, or other techs
  23311. * (e.g. Vimeo Controls)
  23312. * **This should only be set by the current tech, because only the tech knows
  23313. * if it can support native controls**
  23314. *
  23315. * @fires Player#usingnativecontrols
  23316. * @fires Player#usingcustomcontrols
  23317. *
  23318. * @param {boolean} [bool]
  23319. * - true to turn native controls on
  23320. * - false to turn native controls off
  23321. *
  23322. * @return {boolean}
  23323. * The current value of native controls when getting
  23324. */
  23325. ;
  23326. _proto.usingNativeControls = function usingNativeControls(bool) {
  23327. if (bool === undefined) {
  23328. return !!this.usingNativeControls_;
  23329. }
  23330. bool = !!bool; // Don't trigger a change event unless it actually changed
  23331. if (this.usingNativeControls_ === bool) {
  23332. return;
  23333. }
  23334. this.usingNativeControls_ = bool;
  23335. if (this.usingNativeControls_) {
  23336. this.addClass('vjs-using-native-controls');
  23337. /**
  23338. * player is using the native device controls
  23339. *
  23340. * @event Player#usingnativecontrols
  23341. * @type {EventTarget~Event}
  23342. */
  23343. this.trigger('usingnativecontrols');
  23344. } else {
  23345. this.removeClass('vjs-using-native-controls');
  23346. /**
  23347. * player is using the custom HTML controls
  23348. *
  23349. * @event Player#usingcustomcontrols
  23350. * @type {EventTarget~Event}
  23351. */
  23352. this.trigger('usingcustomcontrols');
  23353. }
  23354. }
  23355. /**
  23356. * Set or get the current MediaError
  23357. *
  23358. * @fires Player#error
  23359. *
  23360. * @param {MediaError|string|number} [err]
  23361. * A MediaError or a string/number to be turned
  23362. * into a MediaError
  23363. *
  23364. * @return {MediaError|null}
  23365. * The current MediaError when getting (or null)
  23366. */
  23367. ;
  23368. _proto.error = function error(err) {
  23369. if (err === undefined) {
  23370. return this.error_ || null;
  23371. } // Suppress the first error message for no compatible source until
  23372. // user interaction
  23373. if (this.options_.suppressNotSupportedError && err && err.message && err.message === this.localize(this.options_.notSupportedMessage)) {
  23374. var triggerSuppressedError = function triggerSuppressedError() {
  23375. this.error(err);
  23376. };
  23377. this.options_.suppressNotSupportedError = false;
  23378. this.any(['click', 'touchstart'], triggerSuppressedError);
  23379. this.one('loadstart', function () {
  23380. this.off(['click', 'touchstart'], triggerSuppressedError);
  23381. });
  23382. return;
  23383. } // restoring to default
  23384. if (err === null) {
  23385. this.error_ = err;
  23386. this.removeClass('vjs-error');
  23387. if (this.errorDisplay) {
  23388. this.errorDisplay.close();
  23389. }
  23390. return;
  23391. }
  23392. this.error_ = new MediaError(err); // add the vjs-error classname to the player
  23393. this.addClass('vjs-error'); // log the name of the error type and any message
  23394. // IE11 logs "[object object]" and required you to expand message to see error object
  23395. log.error("(CODE:" + this.error_.code + " " + MediaError.errorTypes[this.error_.code] + ")", this.error_.message, this.error_);
  23396. /**
  23397. * @event Player#error
  23398. * @type {EventTarget~Event}
  23399. */
  23400. this.trigger('error');
  23401. return;
  23402. }
  23403. /**
  23404. * Report user activity
  23405. *
  23406. * @param {Object} event
  23407. * Event object
  23408. */
  23409. ;
  23410. _proto.reportUserActivity = function reportUserActivity(event) {
  23411. this.userActivity_ = true;
  23412. }
  23413. /**
  23414. * Get/set if user is active
  23415. *
  23416. * @fires Player#useractive
  23417. * @fires Player#userinactive
  23418. *
  23419. * @param {boolean} [bool]
  23420. * - true if the user is active
  23421. * - false if the user is inactive
  23422. *
  23423. * @return {boolean}
  23424. * The current value of userActive when getting
  23425. */
  23426. ;
  23427. _proto.userActive = function userActive(bool) {
  23428. if (bool === undefined) {
  23429. return this.userActive_;
  23430. }
  23431. bool = !!bool;
  23432. if (bool === this.userActive_) {
  23433. return;
  23434. }
  23435. this.userActive_ = bool;
  23436. if (this.userActive_) {
  23437. this.userActivity_ = true;
  23438. this.removeClass('vjs-user-inactive');
  23439. this.addClass('vjs-user-active');
  23440. /**
  23441. * @event Player#useractive
  23442. * @type {EventTarget~Event}
  23443. */
  23444. this.trigger('useractive');
  23445. return;
  23446. } // Chrome/Safari/IE have bugs where when you change the cursor it can
  23447. // trigger a mousemove event. This causes an issue when you're hiding
  23448. // the cursor when the user is inactive, and a mousemove signals user
  23449. // activity. Making it impossible to go into inactive mode. Specifically
  23450. // this happens in fullscreen when we really need to hide the cursor.
  23451. //
  23452. // When this gets resolved in ALL browsers it can be removed
  23453. // https://code.google.com/p/chromium/issues/detail?id=103041
  23454. if (this.tech_) {
  23455. this.tech_.one('mousemove', function (e) {
  23456. e.stopPropagation();
  23457. e.preventDefault();
  23458. });
  23459. }
  23460. this.userActivity_ = false;
  23461. this.removeClass('vjs-user-active');
  23462. this.addClass('vjs-user-inactive');
  23463. /**
  23464. * @event Player#userinactive
  23465. * @type {EventTarget~Event}
  23466. */
  23467. this.trigger('userinactive');
  23468. }
  23469. /**
  23470. * Listen for user activity based on timeout value
  23471. *
  23472. * @private
  23473. */
  23474. ;
  23475. _proto.listenForUserActivity_ = function listenForUserActivity_() {
  23476. var mouseInProgress;
  23477. var lastMoveX;
  23478. var lastMoveY;
  23479. var handleActivity = bind(this, this.reportUserActivity);
  23480. var handleMouseMove = function handleMouseMove(e) {
  23481. // #1068 - Prevent mousemove spamming
  23482. // Chrome Bug: https://code.google.com/p/chromium/issues/detail?id=366970
  23483. if (e.screenX !== lastMoveX || e.screenY !== lastMoveY) {
  23484. lastMoveX = e.screenX;
  23485. lastMoveY = e.screenY;
  23486. handleActivity();
  23487. }
  23488. };
  23489. var handleMouseDown = function handleMouseDown() {
  23490. handleActivity(); // For as long as the they are touching the device or have their mouse down,
  23491. // we consider them active even if they're not moving their finger or mouse.
  23492. // So we want to continue to update that they are active
  23493. this.clearInterval(mouseInProgress); // Setting userActivity=true now and setting the interval to the same time
  23494. // as the activityCheck interval (250) should ensure we never miss the
  23495. // next activityCheck
  23496. mouseInProgress = this.setInterval(handleActivity, 250);
  23497. };
  23498. var handleMouseUp = function handleMouseUp(event) {
  23499. handleActivity(); // Stop the interval that maintains activity if the mouse/touch is down
  23500. this.clearInterval(mouseInProgress);
  23501. }; // Any mouse movement will be considered user activity
  23502. this.on('mousedown', handleMouseDown);
  23503. this.on('mousemove', handleMouseMove);
  23504. this.on('mouseup', handleMouseUp);
  23505. var controlBar = this.getChild('controlBar'); // Fixes bug on Android & iOS where when tapping progressBar (when control bar is displayed)
  23506. // controlBar would no longer be hidden by default timeout.
  23507. if (controlBar && !IS_IOS && !IS_ANDROID) {
  23508. controlBar.on('mouseenter', function (event) {
  23509. this.player().cache_.inactivityTimeout = this.player().options_.inactivityTimeout;
  23510. this.player().options_.inactivityTimeout = 0;
  23511. });
  23512. controlBar.on('mouseleave', function (event) {
  23513. this.player().options_.inactivityTimeout = this.player().cache_.inactivityTimeout;
  23514. });
  23515. } // Listen for keyboard navigation
  23516. // Shouldn't need to use inProgress interval because of key repeat
  23517. this.on('keydown', handleActivity);
  23518. this.on('keyup', handleActivity); // Run an interval every 250 milliseconds instead of stuffing everything into
  23519. // the mousemove/touchmove function itself, to prevent performance degradation.
  23520. // `this.reportUserActivity` simply sets this.userActivity_ to true, which
  23521. // then gets picked up by this loop
  23522. // http://ejohn.org/blog/learning-from-twitter/
  23523. var inactivityTimeout;
  23524. this.setInterval(function () {
  23525. // Check to see if mouse/touch activity has happened
  23526. if (!this.userActivity_) {
  23527. return;
  23528. } // Reset the activity tracker
  23529. this.userActivity_ = false; // If the user state was inactive, set the state to active
  23530. this.userActive(true); // Clear any existing inactivity timeout to start the timer over
  23531. this.clearTimeout(inactivityTimeout);
  23532. var timeout = this.options_.inactivityTimeout;
  23533. if (timeout <= 0) {
  23534. return;
  23535. } // In <timeout> milliseconds, if no more activity has occurred the
  23536. // user will be considered inactive
  23537. inactivityTimeout = this.setTimeout(function () {
  23538. // Protect against the case where the inactivityTimeout can trigger just
  23539. // before the next user activity is picked up by the activity check loop
  23540. // causing a flicker
  23541. if (!this.userActivity_) {
  23542. this.userActive(false);
  23543. }
  23544. }, timeout);
  23545. }, 250);
  23546. }
  23547. /**
  23548. * Gets or sets the current playback rate. A playback rate of
  23549. * 1.0 represents normal speed and 0.5 would indicate half-speed
  23550. * playback, for instance.
  23551. *
  23552. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-playbackrate
  23553. *
  23554. * @param {number} [rate]
  23555. * New playback rate to set.
  23556. *
  23557. * @return {number}
  23558. * The current playback rate when getting or 1.0
  23559. */
  23560. ;
  23561. _proto.playbackRate = function playbackRate(rate) {
  23562. if (rate !== undefined) {
  23563. // NOTE: this.cache_.lastPlaybackRate is set from the tech handler
  23564. // that is registered above
  23565. this.techCall_('setPlaybackRate', rate);
  23566. return;
  23567. }
  23568. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  23569. return this.cache_.lastPlaybackRate || this.techGet_('playbackRate');
  23570. }
  23571. return 1.0;
  23572. }
  23573. /**
  23574. * Gets or sets the current default playback rate. A default playback rate of
  23575. * 1.0 represents normal speed and 0.5 would indicate half-speed playback, for instance.
  23576. * defaultPlaybackRate will only represent what the initial playbackRate of a video was, not
  23577. * not the current playbackRate.
  23578. *
  23579. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-defaultplaybackrate
  23580. *
  23581. * @param {number} [rate]
  23582. * New default playback rate to set.
  23583. *
  23584. * @return {number|Player}
  23585. * - The default playback rate when getting or 1.0
  23586. * - the player when setting
  23587. */
  23588. ;
  23589. _proto.defaultPlaybackRate = function defaultPlaybackRate(rate) {
  23590. if (rate !== undefined) {
  23591. return this.techCall_('setDefaultPlaybackRate', rate);
  23592. }
  23593. if (this.tech_ && this.tech_.featuresPlaybackRate) {
  23594. return this.techGet_('defaultPlaybackRate');
  23595. }
  23596. return 1.0;
  23597. }
  23598. /**
  23599. * Gets or sets the audio flag
  23600. *
  23601. * @param {boolean} bool
  23602. * - true signals that this is an audio player
  23603. * - false signals that this is not an audio player
  23604. *
  23605. * @return {boolean}
  23606. * The current value of isAudio when getting
  23607. */
  23608. ;
  23609. _proto.isAudio = function isAudio(bool) {
  23610. if (bool !== undefined) {
  23611. this.isAudio_ = !!bool;
  23612. return;
  23613. }
  23614. return !!this.isAudio_;
  23615. }
  23616. /**
  23617. * A helper method for adding a {@link TextTrack} to our
  23618. * {@link TextTrackList}.
  23619. *
  23620. * In addition to the W3C settings we allow adding additional info through options.
  23621. *
  23622. * @see http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-addtexttrack
  23623. *
  23624. * @param {string} [kind]
  23625. * the kind of TextTrack you are adding
  23626. *
  23627. * @param {string} [label]
  23628. * the label to give the TextTrack label
  23629. *
  23630. * @param {string} [language]
  23631. * the language to set on the TextTrack
  23632. *
  23633. * @return {TextTrack|undefined}
  23634. * the TextTrack that was added or undefined
  23635. * if there is no tech
  23636. */
  23637. ;
  23638. _proto.addTextTrack = function addTextTrack(kind, label, language) {
  23639. if (this.tech_) {
  23640. return this.tech_.addTextTrack(kind, label, language);
  23641. }
  23642. }
  23643. /**
  23644. * Create a remote {@link TextTrack} and an {@link HTMLTrackElement}. It will
  23645. * automatically removed from the video element whenever the source changes, unless
  23646. * manualCleanup is set to false.
  23647. *
  23648. * @param {Object} options
  23649. * Options to pass to {@link HTMLTrackElement} during creation. See
  23650. * {@link HTMLTrackElement} for object properties that you should use.
  23651. *
  23652. * @param {boolean} [manualCleanup=true] if set to false, the TextTrack will be
  23653. *
  23654. * @return {HtmlTrackElement}
  23655. * the HTMLTrackElement that was created and added
  23656. * to the HtmlTrackElementList and the remote
  23657. * TextTrackList
  23658. *
  23659. * @deprecated The default value of the "manualCleanup" parameter will default
  23660. * to "false" in upcoming versions of Video.js
  23661. */
  23662. ;
  23663. _proto.addRemoteTextTrack = function addRemoteTextTrack(options, manualCleanup) {
  23664. if (this.tech_) {
  23665. return this.tech_.addRemoteTextTrack(options, manualCleanup);
  23666. }
  23667. }
  23668. /**
  23669. * Remove a remote {@link TextTrack} from the respective
  23670. * {@link TextTrackList} and {@link HtmlTrackElementList}.
  23671. *
  23672. * @param {Object} track
  23673. * Remote {@link TextTrack} to remove
  23674. *
  23675. * @return {undefined}
  23676. * does not return anything
  23677. */
  23678. ;
  23679. _proto.removeRemoteTextTrack = function removeRemoteTextTrack(obj) {
  23680. if (obj === void 0) {
  23681. obj = {};
  23682. }
  23683. var _obj = obj,
  23684. track = _obj.track;
  23685. if (!track) {
  23686. track = obj;
  23687. } // destructure the input into an object with a track argument, defaulting to arguments[0]
  23688. // default the whole argument to an empty object if nothing was passed in
  23689. if (this.tech_) {
  23690. return this.tech_.removeRemoteTextTrack(track);
  23691. }
  23692. }
  23693. /**
  23694. * Gets available media playback quality metrics as specified by the W3C's Media
  23695. * Playback Quality API.
  23696. *
  23697. * @see [Spec]{@link https://wicg.github.io/media-playback-quality}
  23698. *
  23699. * @return {Object|undefined}
  23700. * An object with supported media playback quality metrics or undefined if there
  23701. * is no tech or the tech does not support it.
  23702. */
  23703. ;
  23704. _proto.getVideoPlaybackQuality = function getVideoPlaybackQuality() {
  23705. return this.techGet_('getVideoPlaybackQuality');
  23706. }
  23707. /**
  23708. * Get video width
  23709. *
  23710. * @return {number}
  23711. * current video width
  23712. */
  23713. ;
  23714. _proto.videoWidth = function videoWidth() {
  23715. return this.tech_ && this.tech_.videoWidth && this.tech_.videoWidth() || 0;
  23716. }
  23717. /**
  23718. * Get video height
  23719. *
  23720. * @return {number}
  23721. * current video height
  23722. */
  23723. ;
  23724. _proto.videoHeight = function videoHeight() {
  23725. return this.tech_ && this.tech_.videoHeight && this.tech_.videoHeight() || 0;
  23726. }
  23727. /**
  23728. * The player's language code
  23729. * NOTE: The language should be set in the player options if you want the
  23730. * the controls to be built with a specific language. Changing the language
  23731. * later will not update controls text.
  23732. *
  23733. * @param {string} [code]
  23734. * the language code to set the player to
  23735. *
  23736. * @return {string}
  23737. * The current language code when getting
  23738. */
  23739. ;
  23740. _proto.language = function language(code) {
  23741. if (code === undefined) {
  23742. return this.language_;
  23743. }
  23744. this.language_ = String(code).toLowerCase();
  23745. }
  23746. /**
  23747. * Get the player's language dictionary
  23748. * Merge every time, because a newly added plugin might call videojs.addLanguage() at any time
  23749. * Languages specified directly in the player options have precedence
  23750. *
  23751. * @return {Array}
  23752. * An array of of supported languages
  23753. */
  23754. ;
  23755. _proto.languages = function languages() {
  23756. return mergeOptions(Player.prototype.options_.languages, this.languages_);
  23757. }
  23758. /**
  23759. * returns a JavaScript object reperesenting the current track
  23760. * information. **DOES not return it as JSON**
  23761. *
  23762. * @return {Object}
  23763. * Object representing the current of track info
  23764. */
  23765. ;
  23766. _proto.toJSON = function toJSON() {
  23767. var options = mergeOptions(this.options_);
  23768. var tracks = options.tracks;
  23769. options.tracks = [];
  23770. for (var i = 0; i < tracks.length; i++) {
  23771. var track = tracks[i]; // deep merge tracks and null out player so no circular references
  23772. track = mergeOptions(track);
  23773. track.player = undefined;
  23774. options.tracks[i] = track;
  23775. }
  23776. return options;
  23777. }
  23778. /**
  23779. * Creates a simple modal dialog (an instance of the {@link ModalDialog}
  23780. * component) that immediately overlays the player with arbitrary
  23781. * content and removes itself when closed.
  23782. *
  23783. * @param {string|Function|Element|Array|null} content
  23784. * Same as {@link ModalDialog#content}'s param of the same name.
  23785. * The most straight-forward usage is to provide a string or DOM
  23786. * element.
  23787. *
  23788. * @param {Object} [options]
  23789. * Extra options which will be passed on to the {@link ModalDialog}.
  23790. *
  23791. * @return {ModalDialog}
  23792. * the {@link ModalDialog} that was created
  23793. */
  23794. ;
  23795. _proto.createModal = function createModal(content, options) {
  23796. var _this14 = this;
  23797. options = options || {};
  23798. options.content = content || '';
  23799. var modal = new ModalDialog(this, options);
  23800. this.addChild(modal);
  23801. modal.on('dispose', function () {
  23802. _this14.removeChild(modal);
  23803. });
  23804. modal.open();
  23805. return modal;
  23806. }
  23807. /**
  23808. * Change breakpoint classes when the player resizes.
  23809. *
  23810. * @private
  23811. */
  23812. ;
  23813. _proto.updateCurrentBreakpoint_ = function updateCurrentBreakpoint_() {
  23814. if (!this.responsive()) {
  23815. return;
  23816. }
  23817. var currentBreakpoint = this.currentBreakpoint();
  23818. var currentWidth = this.currentWidth();
  23819. for (var i = 0; i < BREAKPOINT_ORDER.length; i++) {
  23820. var candidateBreakpoint = BREAKPOINT_ORDER[i];
  23821. var maxWidth = this.breakpoints_[candidateBreakpoint];
  23822. if (currentWidth <= maxWidth) {
  23823. // The current breakpoint did not change, nothing to do.
  23824. if (currentBreakpoint === candidateBreakpoint) {
  23825. return;
  23826. } // Only remove a class if there is a current breakpoint.
  23827. if (currentBreakpoint) {
  23828. this.removeClass(BREAKPOINT_CLASSES[currentBreakpoint]);
  23829. }
  23830. this.addClass(BREAKPOINT_CLASSES[candidateBreakpoint]);
  23831. this.breakpoint_ = candidateBreakpoint;
  23832. break;
  23833. }
  23834. }
  23835. }
  23836. /**
  23837. * Removes the current breakpoint.
  23838. *
  23839. * @private
  23840. */
  23841. ;
  23842. _proto.removeCurrentBreakpoint_ = function removeCurrentBreakpoint_() {
  23843. var className = this.currentBreakpointClass();
  23844. this.breakpoint_ = '';
  23845. if (className) {
  23846. this.removeClass(className);
  23847. }
  23848. }
  23849. /**
  23850. * Get or set breakpoints on the player.
  23851. *
  23852. * Calling this method with an object or `true` will remove any previous
  23853. * custom breakpoints and start from the defaults again.
  23854. *
  23855. * @param {Object|boolean} [breakpoints]
  23856. * If an object is given, it can be used to provide custom
  23857. * breakpoints. If `true` is given, will set default breakpoints.
  23858. * If this argument is not given, will simply return the current
  23859. * breakpoints.
  23860. *
  23861. * @param {number} [breakpoints.tiny]
  23862. * The maximum width for the "vjs-layout-tiny" class.
  23863. *
  23864. * @param {number} [breakpoints.xsmall]
  23865. * The maximum width for the "vjs-layout-x-small" class.
  23866. *
  23867. * @param {number} [breakpoints.small]
  23868. * The maximum width for the "vjs-layout-small" class.
  23869. *
  23870. * @param {number} [breakpoints.medium]
  23871. * The maximum width for the "vjs-layout-medium" class.
  23872. *
  23873. * @param {number} [breakpoints.large]
  23874. * The maximum width for the "vjs-layout-large" class.
  23875. *
  23876. * @param {number} [breakpoints.xlarge]
  23877. * The maximum width for the "vjs-layout-x-large" class.
  23878. *
  23879. * @param {number} [breakpoints.huge]
  23880. * The maximum width for the "vjs-layout-huge" class.
  23881. *
  23882. * @return {Object}
  23883. * An object mapping breakpoint names to maximum width values.
  23884. */
  23885. ;
  23886. _proto.breakpoints = function breakpoints(_breakpoints) {
  23887. // Used as a getter.
  23888. if (_breakpoints === undefined) {
  23889. return assign(this.breakpoints_);
  23890. }
  23891. this.breakpoint_ = '';
  23892. this.breakpoints_ = assign({}, DEFAULT_BREAKPOINTS, _breakpoints); // When breakpoint definitions change, we need to update the currently
  23893. // selected breakpoint.
  23894. this.updateCurrentBreakpoint_(); // Clone the breakpoints before returning.
  23895. return assign(this.breakpoints_);
  23896. }
  23897. /**
  23898. * Get or set a flag indicating whether or not this player should adjust
  23899. * its UI based on its dimensions.
  23900. *
  23901. * @param {boolean} value
  23902. * Should be `true` if the player should adjust its UI based on its
  23903. * dimensions; otherwise, should be `false`.
  23904. *
  23905. * @return {boolean}
  23906. * Will be `true` if this player should adjust its UI based on its
  23907. * dimensions; otherwise, will be `false`.
  23908. */
  23909. ;
  23910. _proto.responsive = function responsive(value) {
  23911. // Used as a getter.
  23912. if (value === undefined) {
  23913. return this.responsive_;
  23914. }
  23915. value = Boolean(value);
  23916. var current = this.responsive_; // Nothing changed.
  23917. if (value === current) {
  23918. return;
  23919. } // The value actually changed, set it.
  23920. this.responsive_ = value; // Start listening for breakpoints and set the initial breakpoint if the
  23921. // player is now responsive.
  23922. if (value) {
  23923. this.on('playerresize', this.updateCurrentBreakpoint_);
  23924. this.updateCurrentBreakpoint_(); // Stop listening for breakpoints if the player is no longer responsive.
  23925. } else {
  23926. this.off('playerresize', this.updateCurrentBreakpoint_);
  23927. this.removeCurrentBreakpoint_();
  23928. }
  23929. return value;
  23930. }
  23931. /**
  23932. * Get current breakpoint name, if any.
  23933. *
  23934. * @return {string}
  23935. * If there is currently a breakpoint set, returns a the key from the
  23936. * breakpoints object matching it. Otherwise, returns an empty string.
  23937. */
  23938. ;
  23939. _proto.currentBreakpoint = function currentBreakpoint() {
  23940. return this.breakpoint_;
  23941. }
  23942. /**
  23943. * Get the current breakpoint class name.
  23944. *
  23945. * @return {string}
  23946. * The matching class name (e.g. `"vjs-layout-tiny"` or
  23947. * `"vjs-layout-large"`) for the current breakpoint. Empty string if
  23948. * there is no current breakpoint.
  23949. */
  23950. ;
  23951. _proto.currentBreakpointClass = function currentBreakpointClass() {
  23952. return BREAKPOINT_CLASSES[this.breakpoint_] || '';
  23953. }
  23954. /**
  23955. * An object that describes a single piece of media.
  23956. *
  23957. * Properties that are not part of this type description will be retained; so,
  23958. * this can be viewed as a generic metadata storage mechanism as well.
  23959. *
  23960. * @see {@link https://wicg.github.io/mediasession/#the-mediametadata-interface}
  23961. * @typedef {Object} Player~MediaObject
  23962. *
  23963. * @property {string} [album]
  23964. * Unused, except if this object is passed to the `MediaSession`
  23965. * API.
  23966. *
  23967. * @property {string} [artist]
  23968. * Unused, except if this object is passed to the `MediaSession`
  23969. * API.
  23970. *
  23971. * @property {Object[]} [artwork]
  23972. * Unused, except if this object is passed to the `MediaSession`
  23973. * API. If not specified, will be populated via the `poster`, if
  23974. * available.
  23975. *
  23976. * @property {string} [poster]
  23977. * URL to an image that will display before playback.
  23978. *
  23979. * @property {Tech~SourceObject|Tech~SourceObject[]|string} [src]
  23980. * A single source object, an array of source objects, or a string
  23981. * referencing a URL to a media source. It is _highly recommended_
  23982. * that an object or array of objects is used here, so that source
  23983. * selection algorithms can take the `type` into account.
  23984. *
  23985. * @property {string} [title]
  23986. * Unused, except if this object is passed to the `MediaSession`
  23987. * API.
  23988. *
  23989. * @property {Object[]} [textTracks]
  23990. * An array of objects to be used to create text tracks, following
  23991. * the {@link https://www.w3.org/TR/html50/embedded-content-0.html#the-track-element|native track element format}.
  23992. * For ease of removal, these will be created as "remote" text
  23993. * tracks and set to automatically clean up on source changes.
  23994. *
  23995. * These objects may have properties like `src`, `kind`, `label`,
  23996. * and `language`, see {@link Tech#createRemoteTextTrack}.
  23997. */
  23998. /**
  23999. * Populate the player using a {@link Player~MediaObject|MediaObject}.
  24000. *
  24001. * @param {Player~MediaObject} media
  24002. * A media object.
  24003. *
  24004. * @param {Function} ready
  24005. * A callback to be called when the player is ready.
  24006. */
  24007. ;
  24008. _proto.loadMedia = function loadMedia(media, ready) {
  24009. var _this15 = this;
  24010. if (!media || typeof media !== 'object') {
  24011. return;
  24012. }
  24013. this.reset(); // Clone the media object so it cannot be mutated from outside.
  24014. this.cache_.media = mergeOptions(media);
  24015. var _this$cache_$media = this.cache_.media,
  24016. artwork = _this$cache_$media.artwork,
  24017. poster = _this$cache_$media.poster,
  24018. src = _this$cache_$media.src,
  24019. textTracks = _this$cache_$media.textTracks; // If `artwork` is not given, create it using `poster`.
  24020. if (!artwork && poster) {
  24021. this.cache_.media.artwork = [{
  24022. src: poster,
  24023. type: getMimetype(poster)
  24024. }];
  24025. }
  24026. if (src) {
  24027. this.src(src);
  24028. }
  24029. if (poster) {
  24030. this.poster(poster);
  24031. }
  24032. if (Array.isArray(textTracks)) {
  24033. textTracks.forEach(function (tt) {
  24034. return _this15.addRemoteTextTrack(tt, false);
  24035. });
  24036. }
  24037. this.ready(ready);
  24038. }
  24039. /**
  24040. * Get a clone of the current {@link Player~MediaObject} for this player.
  24041. *
  24042. * If the `loadMedia` method has not been used, will attempt to return a
  24043. * {@link Player~MediaObject} based on the current state of the player.
  24044. *
  24045. * @return {Player~MediaObject}
  24046. */
  24047. ;
  24048. _proto.getMedia = function getMedia() {
  24049. if (!this.cache_.media) {
  24050. var poster = this.poster();
  24051. var src = this.currentSources();
  24052. var textTracks = Array.prototype.map.call(this.remoteTextTracks(), function (tt) {
  24053. return {
  24054. kind: tt.kind,
  24055. label: tt.label,
  24056. language: tt.language,
  24057. src: tt.src
  24058. };
  24059. });
  24060. var media = {
  24061. src: src,
  24062. textTracks: textTracks
  24063. };
  24064. if (poster) {
  24065. media.poster = poster;
  24066. media.artwork = [{
  24067. src: media.poster,
  24068. type: getMimetype(media.poster)
  24069. }];
  24070. }
  24071. return media;
  24072. }
  24073. return mergeOptions(this.cache_.media);
  24074. }
  24075. /**
  24076. * Gets tag settings
  24077. *
  24078. * @param {Element} tag
  24079. * The player tag
  24080. *
  24081. * @return {Object}
  24082. * An object containing all of the settings
  24083. * for a player tag
  24084. */
  24085. ;
  24086. Player.getTagSettings = function getTagSettings(tag) {
  24087. var baseOptions = {
  24088. sources: [],
  24089. tracks: []
  24090. };
  24091. var tagOptions = getAttributes(tag);
  24092. var dataSetup = tagOptions['data-setup'];
  24093. if (hasClass(tag, 'vjs-fill')) {
  24094. tagOptions.fill = true;
  24095. }
  24096. if (hasClass(tag, 'vjs-fluid')) {
  24097. tagOptions.fluid = true;
  24098. } // Check if data-setup attr exists.
  24099. if (dataSetup !== null) {
  24100. // Parse options JSON
  24101. // If empty string, make it a parsable json object.
  24102. var _safeParseTuple = tuple(dataSetup || '{}'),
  24103. err = _safeParseTuple[0],
  24104. data = _safeParseTuple[1];
  24105. if (err) {
  24106. log.error(err);
  24107. }
  24108. assign(tagOptions, data);
  24109. }
  24110. assign(baseOptions, tagOptions); // Get tag children settings
  24111. if (tag.hasChildNodes()) {
  24112. var children = tag.childNodes;
  24113. for (var i = 0, j = children.length; i < j; i++) {
  24114. var child = children[i]; // Change case needed: http://ejohn.org/blog/nodename-case-sensitivity/
  24115. var childName = child.nodeName.toLowerCase();
  24116. if (childName === 'source') {
  24117. baseOptions.sources.push(getAttributes(child));
  24118. } else if (childName === 'track') {
  24119. baseOptions.tracks.push(getAttributes(child));
  24120. }
  24121. }
  24122. }
  24123. return baseOptions;
  24124. }
  24125. /**
  24126. * Determine whether or not flexbox is supported
  24127. *
  24128. * @return {boolean}
  24129. * - true if flexbox is supported
  24130. * - false if flexbox is not supported
  24131. */
  24132. ;
  24133. _proto.flexNotSupported_ = function flexNotSupported_() {
  24134. var elem = document.createElement('i'); // Note: We don't actually use flexBasis (or flexOrder), but it's one of the more
  24135. // common flex features that we can rely on when checking for flex support.
  24136. 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
  24137. 'msFlexOrder' in elem.style);
  24138. };
  24139. return Player;
  24140. }(Component);
  24141. /**
  24142. * Get the {@link VideoTrackList}
  24143. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist
  24144. *
  24145. * @return {VideoTrackList}
  24146. * the current video track list
  24147. *
  24148. * @method Player.prototype.videoTracks
  24149. */
  24150. /**
  24151. * Get the {@link AudioTrackList}
  24152. * @link https://html.spec.whatwg.org/multipage/embedded-content.html#audiotracklist
  24153. *
  24154. * @return {AudioTrackList}
  24155. * the current audio track list
  24156. *
  24157. * @method Player.prototype.audioTracks
  24158. */
  24159. /**
  24160. * Get the {@link TextTrackList}
  24161. *
  24162. * @link http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-texttracks
  24163. *
  24164. * @return {TextTrackList}
  24165. * the current text track list
  24166. *
  24167. * @method Player.prototype.textTracks
  24168. */
  24169. /**
  24170. * Get the remote {@link TextTrackList}
  24171. *
  24172. * @return {TextTrackList}
  24173. * The current remote text track list
  24174. *
  24175. * @method Player.prototype.remoteTextTracks
  24176. */
  24177. /**
  24178. * Get the remote {@link HtmlTrackElementList} tracks.
  24179. *
  24180. * @return {HtmlTrackElementList}
  24181. * The current remote text track element list
  24182. *
  24183. * @method Player.prototype.remoteTextTrackEls
  24184. */
  24185. ALL.names.forEach(function (name) {
  24186. var props = ALL[name];
  24187. Player.prototype[props.getterName] = function () {
  24188. if (this.tech_) {
  24189. return this.tech_[props.getterName]();
  24190. } // if we have not yet loadTech_, we create {video,audio,text}Tracks_
  24191. // these will be passed to the tech during loading
  24192. this[props.privateName] = this[props.privateName] || new props.ListClass();
  24193. return this[props.privateName];
  24194. };
  24195. });
  24196. /**
  24197. * Global enumeration of players.
  24198. *
  24199. * The keys are the player IDs and the values are either the {@link Player}
  24200. * instance or `null` for disposed players.
  24201. *
  24202. * @type {Object}
  24203. */
  24204. Player.players = {};
  24205. var navigator = window$1.navigator;
  24206. /*
  24207. * Player instance options, surfaced using options
  24208. * options = Player.prototype.options_
  24209. * Make changes in options, not here.
  24210. *
  24211. * @type {Object}
  24212. * @private
  24213. */
  24214. Player.prototype.options_ = {
  24215. // Default order of fallback technology
  24216. techOrder: Tech.defaultTechOrder_,
  24217. html5: {},
  24218. flash: {},
  24219. // default inactivity timeout
  24220. inactivityTimeout: 2000,
  24221. // default playback rates
  24222. playbackRates: [],
  24223. // Add playback rate selection by adding rates
  24224. // 'playbackRates': [0.5, 1, 1.5, 2],
  24225. liveui: false,
  24226. // Included control sets
  24227. children: ['mediaLoader', 'posterImage', 'textTrackDisplay', 'loadingSpinner', 'bigPlayButton', 'liveTracker', 'controlBar', 'errorDisplay', 'textTrackSettings', 'resizeManager'],
  24228. language: navigator && (navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language) || 'en',
  24229. // locales and their language translations
  24230. languages: {},
  24231. // Default message to show when a video cannot be played.
  24232. notSupportedMessage: 'No compatible source was found for this media.',
  24233. fullscreen: {
  24234. options: {
  24235. navigationUI: 'hide'
  24236. }
  24237. },
  24238. breakpoints: {},
  24239. responsive: false
  24240. };
  24241. [
  24242. /**
  24243. * Returns whether or not the player is in the "ended" state.
  24244. *
  24245. * @return {Boolean} True if the player is in the ended state, false if not.
  24246. * @method Player#ended
  24247. */
  24248. 'ended',
  24249. /**
  24250. * Returns whether or not the player is in the "seeking" state.
  24251. *
  24252. * @return {Boolean} True if the player is in the seeking state, false if not.
  24253. * @method Player#seeking
  24254. */
  24255. 'seeking',
  24256. /**
  24257. * Returns the TimeRanges of the media that are currently available
  24258. * for seeking to.
  24259. *
  24260. * @return {TimeRanges} the seekable intervals of the media timeline
  24261. * @method Player#seekable
  24262. */
  24263. 'seekable',
  24264. /**
  24265. * Returns the current state of network activity for the element, from
  24266. * the codes in the list below.
  24267. * - NETWORK_EMPTY (numeric value 0)
  24268. * The element has not yet been initialised. All attributes are in
  24269. * their initial states.
  24270. * - NETWORK_IDLE (numeric value 1)
  24271. * The element's resource selection algorithm is active and has
  24272. * selected a resource, but it is not actually using the network at
  24273. * this time.
  24274. * - NETWORK_LOADING (numeric value 2)
  24275. * The user agent is actively trying to download data.
  24276. * - NETWORK_NO_SOURCE (numeric value 3)
  24277. * The element's resource selection algorithm is active, but it has
  24278. * not yet found a resource to use.
  24279. *
  24280. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
  24281. * @return {number} the current network activity state
  24282. * @method Player#networkState
  24283. */
  24284. 'networkState',
  24285. /**
  24286. * Returns a value that expresses the current state of the element
  24287. * with respect to rendering the current playback position, from the
  24288. * codes in the list below.
  24289. * - HAVE_NOTHING (numeric value 0)
  24290. * No information regarding the media resource is available.
  24291. * - HAVE_METADATA (numeric value 1)
  24292. * Enough of the resource has been obtained that the duration of the
  24293. * resource is available.
  24294. * - HAVE_CURRENT_DATA (numeric value 2)
  24295. * Data for the immediate current playback position is available.
  24296. * - HAVE_FUTURE_DATA (numeric value 3)
  24297. * Data for the immediate current playback position is available, as
  24298. * well as enough data for the user agent to advance the current
  24299. * playback position in the direction of playback.
  24300. * - HAVE_ENOUGH_DATA (numeric value 4)
  24301. * The user agent estimates that enough data is available for
  24302. * playback to proceed uninterrupted.
  24303. *
  24304. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
  24305. * @return {number} the current playback rendering state
  24306. * @method Player#readyState
  24307. */
  24308. 'readyState'].forEach(function (fn) {
  24309. Player.prototype[fn] = function () {
  24310. return this.techGet_(fn);
  24311. };
  24312. });
  24313. TECH_EVENTS_RETRIGGER.forEach(function (event) {
  24314. Player.prototype["handleTech" + toTitleCase(event) + "_"] = function () {
  24315. return this.trigger(event);
  24316. };
  24317. });
  24318. /**
  24319. * Fired when the player has initial duration and dimension information
  24320. *
  24321. * @event Player#loadedmetadata
  24322. * @type {EventTarget~Event}
  24323. */
  24324. /**
  24325. * Fired when the player has downloaded data at the current playback position
  24326. *
  24327. * @event Player#loadeddata
  24328. * @type {EventTarget~Event}
  24329. */
  24330. /**
  24331. * Fired when the current playback position has changed *
  24332. * During playback this is fired every 15-250 milliseconds, depending on the
  24333. * playback technology in use.
  24334. *
  24335. * @event Player#timeupdate
  24336. * @type {EventTarget~Event}
  24337. */
  24338. /**
  24339. * Fired when the volume changes
  24340. *
  24341. * @event Player#volumechange
  24342. * @type {EventTarget~Event}
  24343. */
  24344. /**
  24345. * Reports whether or not a player has a plugin available.
  24346. *
  24347. * This does not report whether or not the plugin has ever been initialized
  24348. * on this player. For that, [usingPlugin]{@link Player#usingPlugin}.
  24349. *
  24350. * @method Player#hasPlugin
  24351. * @param {string} name
  24352. * The name of a plugin.
  24353. *
  24354. * @return {boolean}
  24355. * Whether or not this player has the requested plugin available.
  24356. */
  24357. /**
  24358. * Reports whether or not a player is using a plugin by name.
  24359. *
  24360. * For basic plugins, this only reports whether the plugin has _ever_ been
  24361. * initialized on this player.
  24362. *
  24363. * @method Player#usingPlugin
  24364. * @param {string} name
  24365. * The name of a plugin.
  24366. *
  24367. * @return {boolean}
  24368. * Whether or not this player is using the requested plugin.
  24369. */
  24370. Component.registerComponent('Player', Player);
  24371. /**
  24372. * The base plugin name.
  24373. *
  24374. * @private
  24375. * @constant
  24376. * @type {string}
  24377. */
  24378. var BASE_PLUGIN_NAME = 'plugin';
  24379. /**
  24380. * The key on which a player's active plugins cache is stored.
  24381. *
  24382. * @private
  24383. * @constant
  24384. * @type {string}
  24385. */
  24386. var PLUGIN_CACHE_KEY = 'activePlugins_';
  24387. /**
  24388. * Stores registered plugins in a private space.
  24389. *
  24390. * @private
  24391. * @type {Object}
  24392. */
  24393. var pluginStorage = {};
  24394. /**
  24395. * Reports whether or not a plugin has been registered.
  24396. *
  24397. * @private
  24398. * @param {string} name
  24399. * The name of a plugin.
  24400. *
  24401. * @return {boolean}
  24402. * Whether or not the plugin has been registered.
  24403. */
  24404. var pluginExists = function pluginExists(name) {
  24405. return pluginStorage.hasOwnProperty(name);
  24406. };
  24407. /**
  24408. * Get a single registered plugin by name.
  24409. *
  24410. * @private
  24411. * @param {string} name
  24412. * The name of a plugin.
  24413. *
  24414. * @return {Function|undefined}
  24415. * The plugin (or undefined).
  24416. */
  24417. var getPlugin = function getPlugin(name) {
  24418. return pluginExists(name) ? pluginStorage[name] : undefined;
  24419. };
  24420. /**
  24421. * Marks a plugin as "active" on a player.
  24422. *
  24423. * Also, ensures that the player has an object for tracking active plugins.
  24424. *
  24425. * @private
  24426. * @param {Player} player
  24427. * A Video.js player instance.
  24428. *
  24429. * @param {string} name
  24430. * The name of a plugin.
  24431. */
  24432. var markPluginAsActive = function markPluginAsActive(player, name) {
  24433. player[PLUGIN_CACHE_KEY] = player[PLUGIN_CACHE_KEY] || {};
  24434. player[PLUGIN_CACHE_KEY][name] = true;
  24435. };
  24436. /**
  24437. * Triggers a pair of plugin setup events.
  24438. *
  24439. * @private
  24440. * @param {Player} player
  24441. * A Video.js player instance.
  24442. *
  24443. * @param {Plugin~PluginEventHash} hash
  24444. * A plugin event hash.
  24445. *
  24446. * @param {boolean} [before]
  24447. * If true, prefixes the event name with "before". In other words,
  24448. * use this to trigger "beforepluginsetup" instead of "pluginsetup".
  24449. */
  24450. var triggerSetupEvent = function triggerSetupEvent(player, hash, before) {
  24451. var eventName = (before ? 'before' : '') + 'pluginsetup';
  24452. player.trigger(eventName, hash);
  24453. player.trigger(eventName + ':' + hash.name, hash);
  24454. };
  24455. /**
  24456. * Takes a basic plugin function and returns a wrapper function which marks
  24457. * on the player that the plugin has been activated.
  24458. *
  24459. * @private
  24460. * @param {string} name
  24461. * The name of the plugin.
  24462. *
  24463. * @param {Function} plugin
  24464. * The basic plugin.
  24465. *
  24466. * @return {Function}
  24467. * A wrapper function for the given plugin.
  24468. */
  24469. var createBasicPlugin = function createBasicPlugin(name, plugin) {
  24470. var basicPluginWrapper = function basicPluginWrapper() {
  24471. // We trigger the "beforepluginsetup" and "pluginsetup" events on the player
  24472. // regardless, but we want the hash to be consistent with the hash provided
  24473. // for advanced plugins.
  24474. //
  24475. // The only potentially counter-intuitive thing here is the `instance` in
  24476. // the "pluginsetup" event is the value returned by the `plugin` function.
  24477. triggerSetupEvent(this, {
  24478. name: name,
  24479. plugin: plugin,
  24480. instance: null
  24481. }, true);
  24482. var instance = plugin.apply(this, arguments);
  24483. markPluginAsActive(this, name);
  24484. triggerSetupEvent(this, {
  24485. name: name,
  24486. plugin: plugin,
  24487. instance: instance
  24488. });
  24489. return instance;
  24490. };
  24491. Object.keys(plugin).forEach(function (prop) {
  24492. basicPluginWrapper[prop] = plugin[prop];
  24493. });
  24494. return basicPluginWrapper;
  24495. };
  24496. /**
  24497. * Takes a plugin sub-class and returns a factory function for generating
  24498. * instances of it.
  24499. *
  24500. * This factory function will replace itself with an instance of the requested
  24501. * sub-class of Plugin.
  24502. *
  24503. * @private
  24504. * @param {string} name
  24505. * The name of the plugin.
  24506. *
  24507. * @param {Plugin} PluginSubClass
  24508. * The advanced plugin.
  24509. *
  24510. * @return {Function}
  24511. */
  24512. var createPluginFactory = function createPluginFactory(name, PluginSubClass) {
  24513. // Add a `name` property to the plugin prototype so that each plugin can
  24514. // refer to itself by name.
  24515. PluginSubClass.prototype.name = name;
  24516. return function () {
  24517. triggerSetupEvent(this, {
  24518. name: name,
  24519. plugin: PluginSubClass,
  24520. instance: null
  24521. }, true);
  24522. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  24523. args[_key] = arguments[_key];
  24524. }
  24525. var instance = _construct(PluginSubClass, [this].concat(args)); // The plugin is replaced by a function that returns the current instance.
  24526. this[name] = function () {
  24527. return instance;
  24528. };
  24529. triggerSetupEvent(this, instance.getEventHash());
  24530. return instance;
  24531. };
  24532. };
  24533. /**
  24534. * Parent class for all advanced plugins.
  24535. *
  24536. * @mixes module:evented~EventedMixin
  24537. * @mixes module:stateful~StatefulMixin
  24538. * @fires Player#beforepluginsetup
  24539. * @fires Player#beforepluginsetup:$name
  24540. * @fires Player#pluginsetup
  24541. * @fires Player#pluginsetup:$name
  24542. * @listens Player#dispose
  24543. * @throws {Error}
  24544. * If attempting to instantiate the base {@link Plugin} class
  24545. * directly instead of via a sub-class.
  24546. */
  24547. var Plugin =
  24548. /*#__PURE__*/
  24549. function () {
  24550. /**
  24551. * Creates an instance of this class.
  24552. *
  24553. * Sub-classes should call `super` to ensure plugins are properly initialized.
  24554. *
  24555. * @param {Player} player
  24556. * A Video.js player instance.
  24557. */
  24558. function Plugin(player) {
  24559. if (this.constructor === Plugin) {
  24560. throw new Error('Plugin must be sub-classed; not directly instantiated.');
  24561. }
  24562. this.player = player; // Make this object evented, but remove the added `trigger` method so we
  24563. // use the prototype version instead.
  24564. evented(this);
  24565. delete this.trigger;
  24566. stateful(this, this.constructor.defaultState);
  24567. markPluginAsActive(player, this.name); // Auto-bind the dispose method so we can use it as a listener and unbind
  24568. // it later easily.
  24569. this.dispose = bind(this, this.dispose); // If the player is disposed, dispose the plugin.
  24570. player.on('dispose', this.dispose);
  24571. }
  24572. /**
  24573. * Get the version of the plugin that was set on <pluginName>.VERSION
  24574. */
  24575. var _proto = Plugin.prototype;
  24576. _proto.version = function version() {
  24577. return this.constructor.VERSION;
  24578. }
  24579. /**
  24580. * Each event triggered by plugins includes a hash of additional data with
  24581. * conventional properties.
  24582. *
  24583. * This returns that object or mutates an existing hash.
  24584. *
  24585. * @param {Object} [hash={}]
  24586. * An object to be used as event an event hash.
  24587. *
  24588. * @return {Plugin~PluginEventHash}
  24589. * An event hash object with provided properties mixed-in.
  24590. */
  24591. ;
  24592. _proto.getEventHash = function getEventHash(hash) {
  24593. if (hash === void 0) {
  24594. hash = {};
  24595. }
  24596. hash.name = this.name;
  24597. hash.plugin = this.constructor;
  24598. hash.instance = this;
  24599. return hash;
  24600. }
  24601. /**
  24602. * Triggers an event on the plugin object and overrides
  24603. * {@link module:evented~EventedMixin.trigger|EventedMixin.trigger}.
  24604. *
  24605. * @param {string|Object} event
  24606. * An event type or an object with a type property.
  24607. *
  24608. * @param {Object} [hash={}]
  24609. * Additional data hash to merge with a
  24610. * {@link Plugin~PluginEventHash|PluginEventHash}.
  24611. *
  24612. * @return {boolean}
  24613. * Whether or not default was prevented.
  24614. */
  24615. ;
  24616. _proto.trigger = function trigger$1(event, hash) {
  24617. if (hash === void 0) {
  24618. hash = {};
  24619. }
  24620. return trigger(this.eventBusEl_, event, this.getEventHash(hash));
  24621. }
  24622. /**
  24623. * Handles "statechanged" events on the plugin. No-op by default, override by
  24624. * subclassing.
  24625. *
  24626. * @abstract
  24627. * @param {Event} e
  24628. * An event object provided by a "statechanged" event.
  24629. *
  24630. * @param {Object} e.changes
  24631. * An object describing changes that occurred with the "statechanged"
  24632. * event.
  24633. */
  24634. ;
  24635. _proto.handleStateChanged = function handleStateChanged(e) {}
  24636. /**
  24637. * Disposes a plugin.
  24638. *
  24639. * Subclasses can override this if they want, but for the sake of safety,
  24640. * it's probably best to subscribe the "dispose" event.
  24641. *
  24642. * @fires Plugin#dispose
  24643. */
  24644. ;
  24645. _proto.dispose = function dispose() {
  24646. var name = this.name,
  24647. player = this.player;
  24648. /**
  24649. * Signals that a advanced plugin is about to be disposed.
  24650. *
  24651. * @event Plugin#dispose
  24652. * @type {EventTarget~Event}
  24653. */
  24654. this.trigger('dispose');
  24655. this.off();
  24656. player.off('dispose', this.dispose); // Eliminate any possible sources of leaking memory by clearing up
  24657. // references between the player and the plugin instance and nulling out
  24658. // the plugin's state and replacing methods with a function that throws.
  24659. player[PLUGIN_CACHE_KEY][name] = false;
  24660. this.player = this.state = null; // Finally, replace the plugin name on the player with a new factory
  24661. // function, so that the plugin is ready to be set up again.
  24662. player[name] = createPluginFactory(name, pluginStorage[name]);
  24663. }
  24664. /**
  24665. * Determines if a plugin is a basic plugin (i.e. not a sub-class of `Plugin`).
  24666. *
  24667. * @param {string|Function} plugin
  24668. * If a string, matches the name of a plugin. If a function, will be
  24669. * tested directly.
  24670. *
  24671. * @return {boolean}
  24672. * Whether or not a plugin is a basic plugin.
  24673. */
  24674. ;
  24675. Plugin.isBasic = function isBasic(plugin) {
  24676. var p = typeof plugin === 'string' ? getPlugin(plugin) : plugin;
  24677. return typeof p === 'function' && !Plugin.prototype.isPrototypeOf(p.prototype);
  24678. }
  24679. /**
  24680. * Register a Video.js plugin.
  24681. *
  24682. * @param {string} name
  24683. * The name of the plugin to be registered. Must be a string and
  24684. * must not match an existing plugin or a method on the `Player`
  24685. * prototype.
  24686. *
  24687. * @param {Function} plugin
  24688. * A sub-class of `Plugin` or a function for basic plugins.
  24689. *
  24690. * @return {Function}
  24691. * For advanced plugins, a factory function for that plugin. For
  24692. * basic plugins, a wrapper function that initializes the plugin.
  24693. */
  24694. ;
  24695. Plugin.registerPlugin = function registerPlugin(name, plugin) {
  24696. if (typeof name !== 'string') {
  24697. throw new Error("Illegal plugin name, \"" + name + "\", must be a string, was " + typeof name + ".");
  24698. }
  24699. if (pluginExists(name)) {
  24700. log.warn("A plugin named \"" + name + "\" already exists. You may want to avoid re-registering plugins!");
  24701. } else if (Player.prototype.hasOwnProperty(name)) {
  24702. throw new Error("Illegal plugin name, \"" + name + "\", cannot share a name with an existing player method!");
  24703. }
  24704. if (typeof plugin !== 'function') {
  24705. throw new Error("Illegal plugin for \"" + name + "\", must be a function, was " + typeof plugin + ".");
  24706. }
  24707. pluginStorage[name] = plugin; // Add a player prototype method for all sub-classed plugins (but not for
  24708. // the base Plugin class).
  24709. if (name !== BASE_PLUGIN_NAME) {
  24710. if (Plugin.isBasic(plugin)) {
  24711. Player.prototype[name] = createBasicPlugin(name, plugin);
  24712. } else {
  24713. Player.prototype[name] = createPluginFactory(name, plugin);
  24714. }
  24715. }
  24716. return plugin;
  24717. }
  24718. /**
  24719. * De-register a Video.js plugin.
  24720. *
  24721. * @param {string} name
  24722. * The name of the plugin to be de-registered. Must be a string that
  24723. * matches an existing plugin.
  24724. *
  24725. * @throws {Error}
  24726. * If an attempt is made to de-register the base plugin.
  24727. */
  24728. ;
  24729. Plugin.deregisterPlugin = function deregisterPlugin(name) {
  24730. if (name === BASE_PLUGIN_NAME) {
  24731. throw new Error('Cannot de-register base plugin.');
  24732. }
  24733. if (pluginExists(name)) {
  24734. delete pluginStorage[name];
  24735. delete Player.prototype[name];
  24736. }
  24737. }
  24738. /**
  24739. * Gets an object containing multiple Video.js plugins.
  24740. *
  24741. * @param {Array} [names]
  24742. * If provided, should be an array of plugin names. Defaults to _all_
  24743. * plugin names.
  24744. *
  24745. * @return {Object|undefined}
  24746. * An object containing plugin(s) associated with their name(s) or
  24747. * `undefined` if no matching plugins exist).
  24748. */
  24749. ;
  24750. Plugin.getPlugins = function getPlugins(names) {
  24751. if (names === void 0) {
  24752. names = Object.keys(pluginStorage);
  24753. }
  24754. var result;
  24755. names.forEach(function (name) {
  24756. var plugin = getPlugin(name);
  24757. if (plugin) {
  24758. result = result || {};
  24759. result[name] = plugin;
  24760. }
  24761. });
  24762. return result;
  24763. }
  24764. /**
  24765. * Gets a plugin's version, if available
  24766. *
  24767. * @param {string} name
  24768. * The name of a plugin.
  24769. *
  24770. * @return {string}
  24771. * The plugin's version or an empty string.
  24772. */
  24773. ;
  24774. Plugin.getPluginVersion = function getPluginVersion(name) {
  24775. var plugin = getPlugin(name);
  24776. return plugin && plugin.VERSION || '';
  24777. };
  24778. return Plugin;
  24779. }();
  24780. /**
  24781. * Gets a plugin by name if it exists.
  24782. *
  24783. * @static
  24784. * @method getPlugin
  24785. * @memberOf Plugin
  24786. * @param {string} name
  24787. * The name of a plugin.
  24788. *
  24789. * @returns {Function|undefined}
  24790. * The plugin (or `undefined`).
  24791. */
  24792. Plugin.getPlugin = getPlugin;
  24793. /**
  24794. * The name of the base plugin class as it is registered.
  24795. *
  24796. * @type {string}
  24797. */
  24798. Plugin.BASE_PLUGIN_NAME = BASE_PLUGIN_NAME;
  24799. Plugin.registerPlugin(BASE_PLUGIN_NAME, Plugin);
  24800. /**
  24801. * Documented in player.js
  24802. *
  24803. * @ignore
  24804. */
  24805. Player.prototype.usingPlugin = function (name) {
  24806. return !!this[PLUGIN_CACHE_KEY] && this[PLUGIN_CACHE_KEY][name] === true;
  24807. };
  24808. /**
  24809. * Documented in player.js
  24810. *
  24811. * @ignore
  24812. */
  24813. Player.prototype.hasPlugin = function (name) {
  24814. return !!pluginExists(name);
  24815. };
  24816. /**
  24817. * Signals that a plugin is about to be set up on a player.
  24818. *
  24819. * @event Player#beforepluginsetup
  24820. * @type {Plugin~PluginEventHash}
  24821. */
  24822. /**
  24823. * Signals that a plugin is about to be set up on a player - by name. The name
  24824. * is the name of the plugin.
  24825. *
  24826. * @event Player#beforepluginsetup:$name
  24827. * @type {Plugin~PluginEventHash}
  24828. */
  24829. /**
  24830. * Signals that a plugin has just been set up on a player.
  24831. *
  24832. * @event Player#pluginsetup
  24833. * @type {Plugin~PluginEventHash}
  24834. */
  24835. /**
  24836. * Signals that a plugin has just been set up on a player - by name. The name
  24837. * is the name of the plugin.
  24838. *
  24839. * @event Player#pluginsetup:$name
  24840. * @type {Plugin~PluginEventHash}
  24841. */
  24842. /**
  24843. * @typedef {Object} Plugin~PluginEventHash
  24844. *
  24845. * @property {string} instance
  24846. * For basic plugins, the return value of the plugin function. For
  24847. * advanced plugins, the plugin instance on which the event is fired.
  24848. *
  24849. * @property {string} name
  24850. * The name of the plugin.
  24851. *
  24852. * @property {string} plugin
  24853. * For basic plugins, the plugin function. For advanced plugins, the
  24854. * plugin class/constructor.
  24855. */
  24856. /**
  24857. * @file extend.js
  24858. * @module extend
  24859. */
  24860. /**
  24861. * A combination of node inherits and babel's inherits (after transpile).
  24862. * Both work the same but node adds `super_` to the subClass
  24863. * and Bable adds the superClass as __proto__. Both seem useful.
  24864. *
  24865. * @param {Object} subClass
  24866. * The class to inherit to
  24867. *
  24868. * @param {Object} superClass
  24869. * The class to inherit from
  24870. *
  24871. * @private
  24872. */
  24873. var _inherits = function _inherits(subClass, superClass) {
  24874. if (typeof superClass !== 'function' && superClass !== null) {
  24875. throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
  24876. }
  24877. subClass.prototype = Object.create(superClass && superClass.prototype, {
  24878. constructor: {
  24879. value: subClass,
  24880. enumerable: false,
  24881. writable: true,
  24882. configurable: true
  24883. }
  24884. });
  24885. if (superClass) {
  24886. // node
  24887. subClass.super_ = superClass;
  24888. }
  24889. };
  24890. /**
  24891. * Used to subclass an existing class by emulating ES subclassing using the
  24892. * `extends` keyword.
  24893. *
  24894. * @function
  24895. * @example
  24896. * var MyComponent = videojs.extend(videojs.getComponent('Component'), {
  24897. * myCustomMethod: function() {
  24898. * // Do things in my method.
  24899. * }
  24900. * });
  24901. *
  24902. * @param {Function} superClass
  24903. * The class to inherit from
  24904. *
  24905. * @param {Object} [subClassMethods={}]
  24906. * Methods of the new class
  24907. *
  24908. * @return {Function}
  24909. * The new class with subClassMethods that inherited superClass.
  24910. */
  24911. var extend$1 = function extend(superClass, subClassMethods) {
  24912. if (subClassMethods === void 0) {
  24913. subClassMethods = {};
  24914. }
  24915. var subClass = function subClass() {
  24916. superClass.apply(this, arguments);
  24917. };
  24918. var methods = {};
  24919. if (typeof subClassMethods === 'object') {
  24920. if (subClassMethods.constructor !== Object.prototype.constructor) {
  24921. subClass = subClassMethods.constructor;
  24922. }
  24923. methods = subClassMethods;
  24924. } else if (typeof subClassMethods === 'function') {
  24925. subClass = subClassMethods;
  24926. }
  24927. _inherits(subClass, superClass); // Extend subObj's prototype with functions and other properties from props
  24928. for (var name in methods) {
  24929. if (methods.hasOwnProperty(name)) {
  24930. subClass.prototype[name] = methods[name];
  24931. }
  24932. }
  24933. return subClass;
  24934. };
  24935. /**
  24936. * @file video.js
  24937. * @module videojs
  24938. */
  24939. /**
  24940. * Normalize an `id` value by trimming off a leading `#`
  24941. *
  24942. * @private
  24943. * @param {string} id
  24944. * A string, maybe with a leading `#`.
  24945. *
  24946. * @return {string}
  24947. * The string, without any leading `#`.
  24948. */
  24949. var normalizeId = function normalizeId(id) {
  24950. return id.indexOf('#') === 0 ? id.slice(1) : id;
  24951. };
  24952. /**
  24953. * The `videojs()` function doubles as the main function for users to create a
  24954. * {@link Player} instance as well as the main library namespace.
  24955. *
  24956. * It can also be used as a getter for a pre-existing {@link Player} instance.
  24957. * However, we _strongly_ recommend using `videojs.getPlayer()` for this
  24958. * purpose because it avoids any potential for unintended initialization.
  24959. *
  24960. * Due to [limitations](https://github.com/jsdoc3/jsdoc/issues/955#issuecomment-313829149)
  24961. * of our JSDoc template, we cannot properly document this as both a function
  24962. * and a namespace, so its function signature is documented here.
  24963. *
  24964. * #### Arguments
  24965. * ##### id
  24966. * string|Element, **required**
  24967. *
  24968. * Video element or video element ID.
  24969. *
  24970. * ##### options
  24971. * Object, optional
  24972. *
  24973. * Options object for providing settings.
  24974. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  24975. *
  24976. * ##### ready
  24977. * {@link Component~ReadyCallback}, optional
  24978. *
  24979. * A function to be called when the {@link Player} and {@link Tech} are ready.
  24980. *
  24981. * #### Return Value
  24982. *
  24983. * The `videojs()` function returns a {@link Player} instance.
  24984. *
  24985. * @namespace
  24986. *
  24987. * @borrows AudioTrack as AudioTrack
  24988. * @borrows Component.getComponent as getComponent
  24989. * @borrows module:computed-style~computedStyle as computedStyle
  24990. * @borrows module:events.on as on
  24991. * @borrows module:events.one as one
  24992. * @borrows module:events.off as off
  24993. * @borrows module:events.trigger as trigger
  24994. * @borrows EventTarget as EventTarget
  24995. * @borrows module:extend~extend as extend
  24996. * @borrows module:fn.bind as bind
  24997. * @borrows module:format-time.formatTime as formatTime
  24998. * @borrows module:format-time.resetFormatTime as resetFormatTime
  24999. * @borrows module:format-time.setFormatTime as setFormatTime
  25000. * @borrows module:merge-options.mergeOptions as mergeOptions
  25001. * @borrows module:middleware.use as use
  25002. * @borrows Player.players as players
  25003. * @borrows Plugin.registerPlugin as registerPlugin
  25004. * @borrows Plugin.deregisterPlugin as deregisterPlugin
  25005. * @borrows Plugin.getPlugins as getPlugins
  25006. * @borrows Plugin.getPlugin as getPlugin
  25007. * @borrows Plugin.getPluginVersion as getPluginVersion
  25008. * @borrows Tech.getTech as getTech
  25009. * @borrows Tech.registerTech as registerTech
  25010. * @borrows TextTrack as TextTrack
  25011. * @borrows module:time-ranges.createTimeRanges as createTimeRange
  25012. * @borrows module:time-ranges.createTimeRanges as createTimeRanges
  25013. * @borrows module:url.isCrossOrigin as isCrossOrigin
  25014. * @borrows module:url.parseUrl as parseUrl
  25015. * @borrows VideoTrack as VideoTrack
  25016. *
  25017. * @param {string|Element} id
  25018. * Video element or video element ID.
  25019. *
  25020. * @param {Object} [options]
  25021. * Options object for providing settings.
  25022. * See: [Options Guide](https://docs.videojs.com/tutorial-options.html).
  25023. *
  25024. * @param {Component~ReadyCallback} [ready]
  25025. * A function to be called when the {@link Player} and {@link Tech} are
  25026. * ready.
  25027. *
  25028. * @return {Player}
  25029. * The `videojs()` function returns a {@link Player|Player} instance.
  25030. */
  25031. function videojs$1(id, options, ready) {
  25032. var player = videojs$1.getPlayer(id);
  25033. if (player) {
  25034. if (options) {
  25035. log.warn("Player \"" + id + "\" is already initialised. Options will not be applied.");
  25036. }
  25037. if (ready) {
  25038. player.ready(ready);
  25039. }
  25040. return player;
  25041. }
  25042. var el = typeof id === 'string' ? $('#' + normalizeId(id)) : id;
  25043. if (!isEl(el)) {
  25044. throw new TypeError('The element or ID supplied is not valid. (videojs)');
  25045. } // document.body.contains(el) will only check if el is contained within that one document.
  25046. // This causes problems for elements in iframes.
  25047. // Instead, use the element's ownerDocument instead of the global document.
  25048. // This will make sure that the element is indeed in the dom of that document.
  25049. // Additionally, check that the document in question has a default view.
  25050. // If the document is no longer attached to the dom, the defaultView of the document will be null.
  25051. if (!el.ownerDocument.defaultView || !el.ownerDocument.body.contains(el)) {
  25052. log.warn('The element supplied is not included in the DOM');
  25053. }
  25054. options = options || {};
  25055. videojs$1.hooks('beforesetup').forEach(function (hookFunction) {
  25056. var opts = hookFunction(el, mergeOptions(options));
  25057. if (!isObject(opts) || Array.isArray(opts)) {
  25058. log.error('please return an object in beforesetup hooks');
  25059. return;
  25060. }
  25061. options = mergeOptions(options, opts);
  25062. }); // We get the current "Player" component here in case an integration has
  25063. // replaced it with a custom player.
  25064. var PlayerComponent = Component.getComponent('Player');
  25065. player = new PlayerComponent(el, options, ready);
  25066. videojs$1.hooks('setup').forEach(function (hookFunction) {
  25067. return hookFunction(player);
  25068. });
  25069. return player;
  25070. }
  25071. /**
  25072. * An Object that contains lifecycle hooks as keys which point to an array
  25073. * of functions that are run when a lifecycle is triggered
  25074. *
  25075. * @private
  25076. */
  25077. videojs$1.hooks_ = {};
  25078. /**
  25079. * Get a list of hooks for a specific lifecycle
  25080. *
  25081. * @param {string} type
  25082. * the lifecyle to get hooks from
  25083. *
  25084. * @param {Function|Function[]} [fn]
  25085. * Optionally add a hook (or hooks) to the lifecycle that your are getting.
  25086. *
  25087. * @return {Array}
  25088. * an array of hooks, or an empty array if there are none.
  25089. */
  25090. videojs$1.hooks = function (type, fn) {
  25091. videojs$1.hooks_[type] = videojs$1.hooks_[type] || [];
  25092. if (fn) {
  25093. videojs$1.hooks_[type] = videojs$1.hooks_[type].concat(fn);
  25094. }
  25095. return videojs$1.hooks_[type];
  25096. };
  25097. /**
  25098. * Add a function hook to a specific videojs lifecycle.
  25099. *
  25100. * @param {string} type
  25101. * the lifecycle to hook the function to.
  25102. *
  25103. * @param {Function|Function[]}
  25104. * The function or array of functions to attach.
  25105. */
  25106. videojs$1.hook = function (type, fn) {
  25107. videojs$1.hooks(type, fn);
  25108. };
  25109. /**
  25110. * Add a function hook that will only run once to a specific videojs lifecycle.
  25111. *
  25112. * @param {string} type
  25113. * the lifecycle to hook the function to.
  25114. *
  25115. * @param {Function|Function[]}
  25116. * The function or array of functions to attach.
  25117. */
  25118. videojs$1.hookOnce = function (type, fn) {
  25119. videojs$1.hooks(type, [].concat(fn).map(function (original) {
  25120. var wrapper = function wrapper() {
  25121. videojs$1.removeHook(type, wrapper);
  25122. return original.apply(void 0, arguments);
  25123. };
  25124. return wrapper;
  25125. }));
  25126. };
  25127. /**
  25128. * Remove a hook from a specific videojs lifecycle.
  25129. *
  25130. * @param {string} type
  25131. * the lifecycle that the function hooked to
  25132. *
  25133. * @param {Function} fn
  25134. * The hooked function to remove
  25135. *
  25136. * @return {boolean}
  25137. * The function that was removed or undef
  25138. */
  25139. videojs$1.removeHook = function (type, fn) {
  25140. var index = videojs$1.hooks(type).indexOf(fn);
  25141. if (index <= -1) {
  25142. return false;
  25143. }
  25144. videojs$1.hooks_[type] = videojs$1.hooks_[type].slice();
  25145. videojs$1.hooks_[type].splice(index, 1);
  25146. return true;
  25147. }; // Add default styles
  25148. if (window$1.VIDEOJS_NO_DYNAMIC_STYLE !== true && isReal()) {
  25149. var style = $('.vjs-styles-defaults');
  25150. if (!style) {
  25151. style = createStyleElement('vjs-styles-defaults');
  25152. var head = $('head');
  25153. if (head) {
  25154. head.insertBefore(style, head.firstChild);
  25155. }
  25156. setTextContent(style, "\n .video-js {\n width: 300px;\n height: 150px;\n }\n\n .vjs-fluid {\n padding-top: 56.25%\n }\n ");
  25157. }
  25158. } // Run Auto-load players
  25159. // You have to wait at least once in case this script is loaded after your
  25160. // video in the DOM (weird behavior only with minified version)
  25161. autoSetupTimeout(1, videojs$1);
  25162. /**
  25163. * Current Video.js version. Follows [semantic versioning](https://semver.org/).
  25164. *
  25165. * @type {string}
  25166. */
  25167. videojs$1.VERSION = version;
  25168. /**
  25169. * The global options object. These are the settings that take effect
  25170. * if no overrides are specified when the player is created.
  25171. *
  25172. * @type {Object}
  25173. */
  25174. videojs$1.options = Player.prototype.options_;
  25175. /**
  25176. * Get an object with the currently created players, keyed by player ID
  25177. *
  25178. * @return {Object}
  25179. * The created players
  25180. */
  25181. videojs$1.getPlayers = function () {
  25182. return Player.players;
  25183. };
  25184. /**
  25185. * Get a single player based on an ID or DOM element.
  25186. *
  25187. * This is useful if you want to check if an element or ID has an associated
  25188. * Video.js player, but not create one if it doesn't.
  25189. *
  25190. * @param {string|Element} id
  25191. * An HTML element - `<video>`, `<audio>`, or `<video-js>` -
  25192. * or a string matching the `id` of such an element.
  25193. *
  25194. * @return {Player|undefined}
  25195. * A player instance or `undefined` if there is no player instance
  25196. * matching the argument.
  25197. */
  25198. videojs$1.getPlayer = function (id) {
  25199. var players = Player.players;
  25200. var tag;
  25201. if (typeof id === 'string') {
  25202. var nId = normalizeId(id);
  25203. var player = players[nId];
  25204. if (player) {
  25205. return player;
  25206. }
  25207. tag = $('#' + nId);
  25208. } else {
  25209. tag = id;
  25210. }
  25211. if (isEl(tag)) {
  25212. var _tag = tag,
  25213. _player = _tag.player,
  25214. playerId = _tag.playerId; // Element may have a `player` property referring to an already created
  25215. // player instance. If so, return that.
  25216. if (_player || players[playerId]) {
  25217. return _player || players[playerId];
  25218. }
  25219. }
  25220. };
  25221. /**
  25222. * Returns an array of all current players.
  25223. *
  25224. * @return {Array}
  25225. * An array of all players. The array will be in the order that
  25226. * `Object.keys` provides, which could potentially vary between
  25227. * JavaScript engines.
  25228. *
  25229. */
  25230. videojs$1.getAllPlayers = function () {
  25231. return (// Disposed players leave a key with a `null` value, so we need to make sure
  25232. // we filter those out.
  25233. Object.keys(Player.players).map(function (k) {
  25234. return Player.players[k];
  25235. }).filter(Boolean)
  25236. );
  25237. };
  25238. videojs$1.players = Player.players;
  25239. videojs$1.getComponent = Component.getComponent;
  25240. /**
  25241. * Register a component so it can referred to by name. Used when adding to other
  25242. * components, either through addChild `component.addChild('myComponent')` or through
  25243. * default children options `{ children: ['myComponent'] }`.
  25244. *
  25245. * > NOTE: You could also just initialize the component before adding.
  25246. * `component.addChild(new MyComponent());`
  25247. *
  25248. * @param {string} name
  25249. * The class name of the component
  25250. *
  25251. * @param {Component} comp
  25252. * The component class
  25253. *
  25254. * @return {Component}
  25255. * The newly registered component
  25256. */
  25257. videojs$1.registerComponent = function (name, comp) {
  25258. if (Tech.isTech(comp)) {
  25259. log.warn("The " + name + " tech was registered as a component. It should instead be registered using videojs.registerTech(name, tech)");
  25260. }
  25261. Component.registerComponent.call(Component, name, comp);
  25262. };
  25263. videojs$1.getTech = Tech.getTech;
  25264. videojs$1.registerTech = Tech.registerTech;
  25265. videojs$1.use = use;
  25266. /**
  25267. * An object that can be returned by a middleware to signify
  25268. * that the middleware is being terminated.
  25269. *
  25270. * @type {object}
  25271. * @property {object} middleware.TERMINATOR
  25272. */
  25273. Object.defineProperty(videojs$1, 'middleware', {
  25274. value: {},
  25275. writeable: false,
  25276. enumerable: true
  25277. });
  25278. Object.defineProperty(videojs$1.middleware, 'TERMINATOR', {
  25279. value: TERMINATOR,
  25280. writeable: false,
  25281. enumerable: true
  25282. });
  25283. /**
  25284. * A reference to the {@link module:browser|browser utility module} as an object.
  25285. *
  25286. * @type {Object}
  25287. * @see {@link module:browser|browser}
  25288. */
  25289. videojs$1.browser = browser;
  25290. /**
  25291. * Use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED} instead; only
  25292. * included for backward-compatibility with 4.x.
  25293. *
  25294. * @deprecated Since version 5.0, use {@link module:browser.TOUCH_ENABLED|browser.TOUCH_ENABLED instead.
  25295. * @type {boolean}
  25296. */
  25297. videojs$1.TOUCH_ENABLED = TOUCH_ENABLED;
  25298. videojs$1.extend = extend$1;
  25299. videojs$1.mergeOptions = mergeOptions;
  25300. videojs$1.bind = bind;
  25301. videojs$1.registerPlugin = Plugin.registerPlugin;
  25302. videojs$1.deregisterPlugin = Plugin.deregisterPlugin;
  25303. /**
  25304. * Deprecated method to register a plugin with Video.js
  25305. *
  25306. * @deprecated videojs.plugin() is deprecated; use videojs.registerPlugin() instead
  25307. *
  25308. * @param {string} name
  25309. * The plugin name
  25310. *
  25311. * @param {Plugin|Function} plugin
  25312. * The plugin sub-class or function
  25313. */
  25314. videojs$1.plugin = function (name, plugin) {
  25315. log.warn('videojs.plugin() is deprecated; use videojs.registerPlugin() instead');
  25316. return Plugin.registerPlugin(name, plugin);
  25317. };
  25318. videojs$1.getPlugins = Plugin.getPlugins;
  25319. videojs$1.getPlugin = Plugin.getPlugin;
  25320. videojs$1.getPluginVersion = Plugin.getPluginVersion;
  25321. /**
  25322. * Adding languages so that they're available to all players.
  25323. * Example: `videojs.addLanguage('es', { 'Hello': 'Hola' });`
  25324. *
  25325. * @param {string} code
  25326. * The language code or dictionary property
  25327. *
  25328. * @param {Object} data
  25329. * The data values to be translated
  25330. *
  25331. * @return {Object}
  25332. * The resulting language dictionary object
  25333. */
  25334. videojs$1.addLanguage = function (code, data) {
  25335. var _mergeOptions;
  25336. code = ('' + code).toLowerCase();
  25337. videojs$1.options.languages = mergeOptions(videojs$1.options.languages, (_mergeOptions = {}, _mergeOptions[code] = data, _mergeOptions));
  25338. return videojs$1.options.languages[code];
  25339. };
  25340. /**
  25341. * A reference to the {@link module:log|log utility module} as an object.
  25342. *
  25343. * @type {Function}
  25344. * @see {@link module:log|log}
  25345. */
  25346. videojs$1.log = log;
  25347. videojs$1.createLogger = createLogger$1;
  25348. videojs$1.createTimeRange = videojs$1.createTimeRanges = createTimeRanges;
  25349. videojs$1.formatTime = formatTime;
  25350. videojs$1.setFormatTime = setFormatTime;
  25351. videojs$1.resetFormatTime = resetFormatTime;
  25352. videojs$1.parseUrl = parseUrl;
  25353. videojs$1.isCrossOrigin = isCrossOrigin;
  25354. videojs$1.EventTarget = EventTarget;
  25355. videojs$1.on = on;
  25356. videojs$1.one = one;
  25357. videojs$1.off = off;
  25358. videojs$1.trigger = trigger;
  25359. /**
  25360. * A cross-browser XMLHttpRequest wrapper.
  25361. *
  25362. * @function
  25363. * @param {Object} options
  25364. * Settings for the request.
  25365. *
  25366. * @return {XMLHttpRequest|XDomainRequest}
  25367. * The request object.
  25368. *
  25369. * @see https://github.com/Raynos/xhr
  25370. */
  25371. videojs$1.xhr = xhr;
  25372. videojs$1.TextTrack = TextTrack;
  25373. videojs$1.AudioTrack = AudioTrack;
  25374. videojs$1.VideoTrack = VideoTrack;
  25375. ['isEl', 'isTextNode', 'createEl', 'hasClass', 'addClass', 'removeClass', 'toggleClass', 'setAttributes', 'getAttributes', 'emptyEl', 'appendContent', 'insertContent'].forEach(function (k) {
  25376. videojs$1[k] = function () {
  25377. log.warn("videojs." + k + "() is deprecated; use videojs.dom." + k + "() instead");
  25378. return Dom[k].apply(null, arguments);
  25379. };
  25380. });
  25381. videojs$1.computedStyle = computedStyle;
  25382. /**
  25383. * A reference to the {@link module:dom|DOM utility module} as an object.
  25384. *
  25385. * @type {Object}
  25386. * @see {@link module:dom|dom}
  25387. */
  25388. videojs$1.dom = Dom;
  25389. /**
  25390. * A reference to the {@link module:url|URL utility module} as an object.
  25391. *
  25392. * @type {Object}
  25393. * @see {@link module:url|url}
  25394. */
  25395. videojs$1.url = Url;
  25396. return videojs$1;
  25397. }));