- }
-
- var url = window.location.origin + '/api/v1/videos/' + videoId
- xhttp.open('GET', url, true)
- xhttp.send()
- }
-
- function loadVideoTorrent (magnetUri) {
- console.log('Loading video ' + videoId)
- var client = new window.WebTorrent()
-
- console.log('Adding magnet ' + magnetUri)
- client.add(magnetUri, function (torrent) {
- var file = torrent.files[0]
-
- file.renderTo('video', { autoplay: true })
- })
- }
-
- var urlParts = window.location.href.split('/')
- var videoId = urlParts[urlParts.length - 1]
-
- loadVideoInfos(videoId, function (videoInfos) {
- var magnetUri = videoInfos.magnetUri
- var videoContainer = document.getElementById('video-container')
- var previewUrl = window.location.protocol + '//' + videoInfos.podHost + videoInfos.previewPath
- videoContainer.poster = previewUrl
-
- videojs('video-container', { controls: true, autoplay: false }, function () {
- var player = this
-
- var Button = videojs.getComponent('Button')
- var peertubeLinkButton = videojs.extend(Button, {
- constructor: function () {
- Button.apply(this, arguments)
- },
-
- createEl: function () {
- var link = document.createElement('a')
- link.href = window.location.href.replace('embed', 'watch')
- link.innerHTML = 'PeerTube'
- link.title = 'Go to the video page'
- link.className = 'vjs-peertube-link'
- link.target = '_blank'
-
- return link
- },
-
- handleClick: function () {
- player.pause()
- }
- })
- videojs.registerComponent('PeerTubeLinkButton', peertubeLinkButton)
-
- var controlBar = player.getChild('controlBar')
- var addedLink = controlBar.addChild('PeerTubeLinkButton', {})
- controlBar.el().insertBefore(addedLink.el(), controlBar.fullscreenToggle.el())
-
- player.dock({
- title: videoInfos.name
- })
-
- document.querySelector('.vjs-big-play-button').addEventListener('click', function () {
- loadVideoTorrent(magnetUri)
-
- player.play()
- }, false)
- })
- })
-
- </script>