-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
186 lines (173 loc) · 4.66 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<html>
<meta charset="utf-8">
<head>
<script src="build/syncplay.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet" />
</head>
<body>
<style>
body {
background: black;
}
#node {
width: 100%; height: 100%;
margin: 0; padding: 0;
}
#fpicker {
display: none;
}
#fpicker-div {
background: grey;
width: 98%; height: 96%;
position: fixed;
color: wheat;
text-align: center;
cursor: pointer;
border: 15px dashed wheat;
margin: -10px;
}
#fpicker-div > label {
position: absolute;
text-align: center;
font-size: 4em;
width: 100%;
top: 40%;
display: block;
cursor: pointer;
}
#float {
position: fixed;
margin: 10px;
display: none;
}
.file {
font-size: smaller;
margin-top: 4px;
opacity: 0.6;
}
</style>
<input id="fpicker" type="file" accept="video/*,audio/*" />
<div id="fpicker-div" onclick="pick();"><label>Click here to pick a file</label></div>
<button id="float">_</button>
<video id="node" controls="true" style="display: none;"></video>
<script>
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": true,
"progressBar": true,
"positionClass": "toast-top-right",
"preventDuplicates": true,
"showDuration": "30",
"hideDuration": "1000",
"timeOut": "2000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
function pick() {
$("#fpicker").click();
}
var vid_player = $("#node")[0];
var username = null;
while(username == null) {
username = prompt("Pick a name", "Guest_" + Math.ceil(Math.random()*1000));
}
document.title = username;
$("#fpicker").change(function(e) {
$("#node").attr("src", window.URL.createObjectURL($("#fpicker")[0].files[0]));
window.filename = $("#fpicker")[0].files[0].name;
window.filesize = $("#fpicker")[0].files[0].size;
});
vid_player.volume = 0.3;
$(vid_player).on("loadeddata", function(e) {
$("#fpicker-div").hide();
$("#node").show();
function onconnect(e) {
if (e.connected) {
toastr.success("Connected!");
syncplayjs.set_file(filename, vid_player.duration, filesize);
}
}
window.syncplayjs = new SyncPlay({
name: username,
room: document.location.hash || "test",
url: "127.0.0.1:9000"
}, onconnect, vid_player);
var getterFn = {
is_paused: function(vid_player) {
return vid_player.paused;
},
get_position: function(vid_player) {
return vid_player.currentTime;
}
};
syncplayjs.setStateGetters(getterFn, vid_player);
syncplayjs.connect();
});
$(vid_player).on("listusers", function(e) {
syncplayjs.seeked();
for (var i = 0; i < Object.keys(e.detail).length; i++) {
var user = Object.keys(e.detail)[i];
if (user == username) {
continue;
}
var filename = e.detail[user].file.name;
var filesize = e.detail[user].file.size; // bytes
var file_duration = e.detail[user].file.duration; // seconds
}
});
$(vid_player).on("userlist", function(e) {
var user = e.detail.user;
var user_event = e.detail.evt;
toastr.info("'" + user + "' " + user_event);
});
window.seekFromEvent = false;
$(vid_player).on("seeked", function(e) {
if (!window.seekFromEvent) {
syncplayjs.seeked();
}
window.seekFromEvent = false;
});
$(vid_player).on("fileupdate", function(e) {
var username = Object.keys(e.detail.user);
var duration = e.detail.user[username].file.duration; // seconds
var filename = e.detail.user[username].file.name;
var filesize = e.detail.user[username].file.size; // bytes
});
$(vid_player).on("userevent", function(e) {
var username = e.detail.setBy;
var position = e.detail.position;
var paused = e.detail.paused;
var doSeek = e.detail.doSeek
if (!paused && vid_player.paused) {
var message = "'" + username + "' resumes at " + position;
vid_player.currentTime = e.detail.position;
vid_player.play();
toastr.info(message);
}
if (paused && !vid_player.paused) {
var message = "'" + username + "' paused at " + position;
vid_player.pause();
toastr.info(message);
}
if (doSeek == true) {
var message = "'" + username + "' seeked to " + position;
window.seekFromEvent = true;
vid_player.currentTime = e.detail.position;
toastr.warning(message);
}
});
$(vid_player).on("play", function(e) {
syncplayjs.playPause();
});
$(vid_player).on("pause", function(e) {
syncplayjs.playPause();
});
</script>
</body>
</html>