This repository has been archived by the owner on May 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
room.html
209 lines (187 loc) · 7.47 KB
/
room.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<meta charset="UTF-8">
<html>
<head>
<title>SIDEKICK</title>
<link rel="stylesheet" type="text/css" href="css/room.css">
<script src="flashphoner_api/flashphoner.js"></script>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="full.js"></script>
<style>
.button {
background-color: #555555; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
</style>
<script>
function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var user_name = getUrlParameter("user_name")
if (!user_name) {
user_name = getUrlParameter("first_name") + " " + getUrlParameter("last_name");
}
var query_string = "?name=" + getUrlParameter("room")
$.get("https://sidekick.online:81/room/" + query_string, function (result) {
console.log(result);
$("#stream-video").attr("src", result.yt_src);
$("#home-title").html(result.home + "(1000 ₽)" );
$("#guest-title").html(result.guest + "(1214 ₽)");
});
$.get('https://sidekick.online:81/room/register' + query_string + "&user_name=" + user_name, function(result) {});
$( window ).on("unload", function() {
$.get('https://sidekick.online:81/room/unregister' + query_string + "&user_name=" + user_name, function(result) {});
});
$.get("https://sidekick.online:81/room/chat" + query_string, function (result) {
console.log(result);
for (var i = 0; i < result.messages.length; ++i) {
$("#chat").append(`
<div class="message">
<div class="message-author">${result.messages[i].name}</div>
<div class="message-body">${result.messages[i].body}</div>
</div>
`)
}
});
var updateWatchers = function() {
$.get("https://sidekick.online:81/room/watchers" + query_string, function(result) {
var new_friends_id_list = new Set();
console.log(result);
for (var i = 0; i < result.watchers.length; ++i) {
//if (!new_friends_id_list.includes(result.watchers[i])) {
// new_friends_id_list.push(result.watchers[i].name)
// $(`.watcher:eq(${i})`).show()
// console.log("ok");
//}
new_friends_id_list.add(result.watchers[i].name);
}
if (new_friends_id_list.size != friends_id_list.size) {
friends_id_list = new_friends_id_list;
update_friends();
}
});
}
var updateBets = function() {
$.get("https://sidekick.online:81/room/bets" + query_string, function(result) {
$("#home").html("")
$("#guest").html("")
for (var i = 0; i < result.bets.length; ++i) {
if (result.bets[i].name == user_name) {
$("#set-home").hide();
$("#set-guest").hide();
}
}
});
}
/*$.get("https://sidekick.online:81/room/watchers" + query_string, function(result) {
for (var i = 0; i < result.watchers.length; ++i) {
$("#watchers").append(`
`);
}
});*/
var updateBets = function () {
$.get("https://sidekick.online:81/room/bets" + query_string, function (result) {
var total = 0;
$("#home").html("")
$("#guest").html("")
for (var i = 0; i < result.bets.length; ++i) {
if (result.bets[i].value == "home") total += 1000;
else total += 1214
if (result.bets[i].name == user_name) {
$("#set-home").hide();
$("#set-guest").hide();
}
var element = $("#" + result.bets[i].value);
element.append(`
<div class="bet">
${result.bets[i].name}
</div>
`);
}
$("#bet-amount").html(total + "₽")
});
}
var postBet = function (side) {
var query_string = "?room_name=" + getUrlParameter("room") + "&name=" + user_name + "&value=" + side
$.get("https://sidekick.online:81/room/put_bet" + query_string, function (result) {
updateBets()
});
}
$("document").ready(function() {
$("#set-home").click(function() { postBet("home") });
$("#set-guest").click(function() { postBet("guest") });
$("#join").click(function() { init(); start_stream(); });
$("#update").click(function() { update_friends() });
$("#invite").val("https://sidekick.online/invite.html?room=" + getUrlParameter("room"))
$("#streamer_id").val(user_name);
setInterval(updateBets, 1000);
setInterval(updateWatchers, 10000);
});
setTimeout(function() {
console.log("123");
$("#bets").html(`
<div style="text-align: center; font-size: 2em;">Матч окончен</div>
<div style="text-align: center; font-size: 4em;">2:4</div>
<div style="text-align: center; font-size: 2em;">Михаил Маликов: <span style="color: #CC0000">-1000₽</span></div>
<div style="text-align: center; font-size: 2em;">Матвей Волков: <span style="color: #669966">+900₽</span></div>
`,)
}, 60000)
</script>
</head>
<body>
<div class="row">
<div id="stream" class="col-6">
<iframe id="stream-video" frameborder="0" allow="autoplay; encrypted-media"></iframe>
</div>
<div class="col-1"></div>
<div id="bets" class="col-5">
<div id="bet-amount"></div>
<div class="bet-side" style="left: 0">
<div id="home-title"></div>
<div id="home"></div>
<button class="button" id="set-home">Сделать ставку</button>
</div>
<div class="bet-side" style="right: 0">
<div id="guest-title"></div>
<div id="guest"></div>
<button class="button" id="set-guest">Сделать ставку</button>
</div>
</div>
</div>
<button class="button" id="join">присоединиться к чату</button>
<button style="text-size: 2.2em" class="button" id="update">обновить</button>
<input type="text" id="invite" style="height:3.5em;"/>
<div id="watchers" class="row">
<div id="fakeVideo" style="display:none"></div>
<input id="streamer_id" type=hidden value="stream1">
<div id="localVideo" style="display: block; float: left; padding: 15px;">
</div>
<div class="watcher col-3" id="remoteVideo1" style="display:none">
</div>
<div class="watcher col-3" id="remoteVideo2" style="display:none">
</div>
<div class="watcher col-3" id="remoteVideo3" style="display:none">
</div>
<div class="watcher col-3" id="remoteVideo4" style="display:none">
</div>
</div>
</div>
</body>
</html>