forked from FirebaseExtended/firechat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
152 lines (129 loc) · 4.78 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!-- jQuery -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap-modal.min.js"></script>
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.0.2/firebase.js"></script>
<!-- Firechat -->
<link rel="stylesheet" href="dist/firechat.min.css" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" />
<script src="dist/firechat.min.js"></script>
<!-- Custom CSS -->
<style>
#firechat-wrapper {
height: 475px;
/*max-width: 325px;*/
padding: 10px;
border: 1px solid #ccc;
background-color: #fff;
margin: 50px auto;
text-align: center;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: 0 5px 25px #666;
-moz-box-shadow: 0 5px 25px #666;
box-shadow: 0 5px 25px #666;
}
</style>
</head>
<!--
Example: Anonymous Authentication
This example uses Firebase Simple Login to create "anonymous" user sessions in Firebase,
meaning that user credentials are not required, though a user has a valid Firebase
authentication token and security rules still apply.
Requirements: in order to use this example with your own Firebase, you'll need to do the following:
1. Apply the security rules at https://github.com/firebase/firechat/blob/master/rules.json
2. Enable the "Anonymous" authentication provider in Forge
3. Update the URL below to reference your Firebase
4. Update the room id for auto-entry with a public room you have created
-->
<body>
<div id="firechat-wrapper">
</div>
<div class="row">
<div class="span12">
<div id="firechat-container" class="clearfix"></div>
<div id="user-info">
Logged in as <span id="user-name">.</span>
<a href="javascript:logout();">Logout</a>
</div>
</div>
</div>
<div class="header-content">
<div class="container text-center">
<div id="auth-modal" class="modal hide fade" tabindex="-1" role="dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 id="myModalLabel">Authenticate to continue</h4>
</div>
<div class="modal-body text-center">
<p>
<a id="twitter-signin" href="javascript:login('twitter');">
<img id="twitter-signin-btn" src="assets/img/twitterButton.png">
</a>
<a id="facebook-signin" href="javascript:login('facebook');">
<img id="facebook-signin-btn" src="assets/img/twitterButton.png">
</a>
</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var chatRef = new Firebase("https://uit-chat.firebaseio.com");
var target = document.getElementById("firechat-wrapper");
var authModal = $('#auth-modal').modal( {show : false} );
var chat = new FirechatUI(chatRef, target);
chat.on('auth-required', function() {
authModal.modal('show');
return false;
});
chatRef.onAuth(function(authData) {
if (authData) {
var userId = authData.uid,
username = authData[authData.provider].displayName;
chat.setUser(userId, username);
$('#user-name').text(username);
$('#user-info').show();
setTimeout(function() {
chat._chat.enterRoom('-Iy1N3xs4kN8iALHV0QA')
}, 500);
} else {
$('#user-info').hide();
chat._chat.enterRoom('-Iy1N3xs4kN8iALHV0QA')
}
});
function login(provider) {
authModal.modal('hide');
chatRef.authWithOAuthPopup(provider, function(error, authData) {
if (error) {
console.log(error);
}
});
}
function logout() {
chatRef.unauth();
location.reload();
}
// chatRef.onAuth(function(authData) {
// if (authData) {
// chat.setUser(authData.uid, "Anonymous" + authData.uid.substr(10, 8));
// } else {
// chatRef.authAnonymously(function(error, authData) {
// if (error) {
// console.log(error);
// }
// });
// }
// });
</script>
</body>
</html>