]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - public/javascripts/index.js
4910e454078f665a5bf946c6523b89f1d6d71175
4 var $ = require('jquery')
5 require('blueimp-file-upload')
7 var WebTorrent
= require('webtorrent')
8 var client
= new WebTorrent({ dht: false })
10 var $content
= $('#ajax_load')
13 client
.on('error', function (err
) {
17 client
.on('warning', function (err
) {
21 // Events of the panel
22 $('#panel_get_videos').on('click', function () {
26 $('#panel_upload_video').on('click', function () {
30 $('#panel_make_friends').on('click', function () {
34 $('#panel_quit_friends').on('click', function () {
38 $('#search-video').on('keyup', function (e
) {
39 var search
= $(this).val()
41 if (search
=== '') return
43 if (e
.keyCode
=== 13) {
45 url: '/api/v1/videos/search/' + search
,
48 success: function (videos
) {
56 function makeFriends () {
58 url: '/api/v1/pods/makefriends',
63 alert('Already made friends.')
66 success: function () {
67 alert('Made friends!')
72 function quitFriends () {
74 url: '/api/v1/pods/quitfriends',
77 success: function () {
78 alert('Quit friends!')
83 function printVideos (videos
) {
86 if (videos
.length
=== 0) {
87 $content
.text('There is no videos.')
90 videos
.forEach(function (video
) {
91 var $video
= $('<div></div>').addClass('video')
93 var $video_name
= $('<span></span>').addClass('video_name').text(video
.name
)
94 var $video_pod
= $('<span></span>').addClass('video_pod_url').text(video
.podUrl
)
95 var $header
= $('<div></div>').append([ $video_name
, $video_pod
])
97 if (video
.namePath
!== null) {
98 var $remove
= $('<span></span>').addClass('span_action glyphicon glyphicon-remove')
101 $remove
.on('click', function () {
102 if (!confirm('Are you sure ?')) return
107 $header
.append($remove
)
110 var $video_description
= $('<div></div>').addClass('video_description').text(video
.description
)
113 $video_name
.on('click', function () {
117 if (!video
.magnetUri
) {
118 $remove
.css('display', 'none')
121 $video
.append([ $header
, $video_description
])
122 $content
.append($video
)
126 // Upload the video, the server will seed it
127 function uploadVideo () {
128 // Creating all the elements
129 var $video_label
= $('<label></label>').attr('for', 'name').text('Video name')
130 var $video_name
= $('<input></input>').addClass('form-control').attr({
134 var $video_block
= $('<div></div>').addClass('form-group').append([ $video_label
, $video_name
])
136 var $title
= $('<h3></h3>').text('Upload a video')
138 var $button_text
= $('<span></span>').text('Select the video...')
139 var $input_video
= $('<input></input>').attr({
144 var $button
= $('<div></div>').addClass('btn btn-default btn-file').append([ $button_text
, $input_video
])
146 var $description_label
= $('<label></label>').attr('for', 'description').text('Description')
147 var $description_text
= $('<textarea></textarea>').addClass('form-control').attr({
150 placeholder: 'Description...'
152 var $description
= $('<div></div>').addClass('form-group').append([ $description_label
, $description_text
])
154 var $bar
= $('<progress></progress').attr('value', '0').css('display', 'none')
155 var $progress_bar
= $('<div><div>').attr('id', 'progress').append($bar
)
157 var $input_submit
= $('<input></input>').addClass('btn btn-default').attr({
163 var $form_video
= $('<form></form>').append([ $video_block
, $button
, $progress_bar
, $description
, $input_submit
])
164 $form_video
.fileupload({
165 singleFileUploads: true,
167 url: '/api/v1/videos',
169 add: function (e
, data
) {
170 var $text
= $('<span></span>').addClass('name_file').text(data
['files'][0]['name'])
171 $text
.insertAfter($button
)
172 $input_submit
.off('click').on('click', function () {
173 $bar
.css('display', 'block')
174 data
.formData
= $form_video
.serializeArray()
178 progressall: function (e
, data
) {
184 done: function (e
, data
) {
185 // Print all the videos once it's finished
191 $content
.append([ $title
, $form_video
])
194 // Print the list of all the videos
195 function getVideos () {
197 url: '/api/v1/videos/',
200 success: function (videos
) {
206 function removeVideo (video
) {
208 url: '/api/v1/videos/' + video
._id
,
210 success: function (response
, status
) {
216 // Get the video: add the torrent file and stream it into a video tag
217 function getVideo (video
) {
218 var $waiting
= $('<img></img>').addClass('center-block loading').attr('src', '/images/loading.gif')
220 $content
.append($waiting
)
222 console
.log('Getting ' + video
)
223 client
.add(video
.magnetUri
, function (torrent
) {
224 var $embed
= $('<div></div>').addClass('embed-responsive embed-responsive-16by9')
227 $content
.append($embed
)
229 // Got torrent metadata!
230 console
.log('Torrent info hash:', torrent
.infoHash
)
232 // Let's say the first file is a webm (vp8) or mp4 (h264) video...
233 var file
= torrent
.files
[0]
235 file
.appendTo($embed
.get(0), function (err
) {
237 alert('Cannot append the file.')