This repository was archived by the owner on Apr 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathfacebook-login.html
More file actions
172 lines (128 loc) · 4.8 KB
/
facebook-login.html
File metadata and controls
172 lines (128 loc) · 4.8 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PubNub ChatEngine</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
body {
margin: 30px auto;
}
</style>
</head>
<body>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="../node_modules/chat-engine/dist/chat-engine.js" type="text/javascript"></script>
<script type="text/javascript">
// WARNING: PUBNUB KEYS REQUIRED FOR EXAMPLE TO FUNCTION
const PUBLISH_KEY = '';
const SUBSCRIBE_KEY = '';
// just making sure you're paying attention
if (PUBLISH_KEY === '' || SUBSCRIBE_KEY === '') {
throw new Error('You forgot to enter your keys')
}
const ChatEngine = ChatEngineCore.create({
publishKey: PUBLISH_KEY,
subscribeKey: SUBSCRIBE_KEY
}, {
debug: true,
globalChannel: 'chat-engine-demo-facebook'
});
ChatEngine.on('$.ready', (data) => {
let me = data.me;
FB.api("/" + data.me.state.id + "/picture?redirect=false", function(response) {
if (response && !response.error) {
me.update({
avatar: response.data.url
});
}
});
$('#chat-input').submit(() => {
ChatEngine.global.emit('message', {
text: $('#message').val()
});
$('#message').val('');
return false;
});
ChatEngine.global.on('message', (payload) => {
$('#chat').append($('<p><img src="' + payload.sender.state.avatar + '" style="border-radius: 50%; width: 20px; height: 20px; display: inline-block;"/> <strong>' + payload.sender.state.name + ':</strong> ' + payload.data.text + '</p>'));
});
});
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
function buildChatEngine(fbMe, fbAccessToken) {
ChatEngine.connect(fbMe.id, fbMe, fbAccessToken);
// ChatEngine.connect(fbMe.id, fbMe);
};
function startUp(auth) {
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Logged in as ' + response.name + '!';
buildChatEngine(response, auth.authResponse.accessToken);
});
};
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(auth) {
console.log('success', auth.status)
if (auth.status === 'connected') {
// Logged into your app and Facebook.
startUp(auth);
} else if (auth.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
window.fbAsyncInit = function() {
FB.init({
appId: '305450936585628',
xfbml: true,
version: 'v2.8'
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="container">
<div class="col-sm-6 offset-sm-3">
<div class="card">
<div class="card-header">
Chat
</div>
<div class="card-block">
<div id="chat" class="log">
</div>
<form id="chat-input">
<div class="input-group">
<input type="text" class="form-control message" placeholder="Your Message..." id="message"> <span class="input-group-btn"><button class="btn btn-primary" type="submit" id="submit">Send</button></span></div>
</form>
<div id="status">
</div>
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
</div>
</div>
</div>
</body>
</html>