-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
78 lines (63 loc) · 2.44 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
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src='https://cdn.firebase.com/v0/firebase.js'></script>
<script src='https://cdn.firebase.com/v0/firebase-simple-login.js'> </script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<title>dClicker</title>
<div id="boxDiv"></div>
<script>
var boxNum = -1;
var queueRef = new Firebase('https://cs290b.firebaseio.com/queue');
mycallback = function(){
queueRef.push({box: boxNum, mark: $(this).val()});
};
var usersRef = new Firebase('https://cs290b.firebaseio.com/users');
var auth = new FirebaseSimpleLogin(usersRef, function(error, user) {
if (error) {
// an error occurred while attempting login
console.log(error);
} else if (user) {
// user authenticated with Firebase
console.log('User ID: ' + user.id + ', Provider: ' + user.provider);
usersRef.transaction(function(users) {
if (users != null) {
var c_users = users;
for (var i = 0; i < 9; i++) {
if (c_users[i] == 0) {
c_users[i] = user.id;
boxNum = i;
usersRef.child(i).onDisconnect().set(0);
return c_users;
};
};
return;
};
return users;
}, function(err, committed, snapshot) {
if (committed && !err) {
// Joined room successfully.
var html = '<p>' + (boxNum+1) + '</p>'
html += '<form action=""><input class="clicker" type="radio" name="marker" value="c">clear<br><input class="clicker" type="radio" name="marker" value="x">X<br><input class="clicker" type="radio" name="marker" value="o">O</form>';
var div = document.getElementById('boxDiv');
div.innerHTML = html;
$('.clicker').click(mycallback);
} else {
// Could not join room because it was full.
var html = '<p>Refresh to try for a square.</p>'
var div = document.getElementById('boxDiv');
div.innerHTML = html;
}
});
} else {
console.log('other');
// user is logged out
}
});
auth.login('anonymous');
</script>
</body>
</html>