-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuchat.php
138 lines (118 loc) · 4.55 KB
/
uchat.php
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
<?php
$chatId = (isset($_GET['id']) && !empty($_GET['id'])) ? $_GET['id'] : '';
$chatId = htmlspecialchars(html_entity_decode($chatId));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="/css/chat.css">
<script src="/js/jquery.min.js"></script>
<script src="/js/api.js"></script>
<script src="/js/google.api.youtube.js"></script>
<script src="/js/OAuthHelper.js"></script>
<title>Chat</title>
</head>
<script>
let SnippetObj = null;
let MessageObj = null;
document.addEventListener("DOMContentLoaded", function () {
SnippetObj = new StreamSnippet(ID_SNIPPED_DATA_CONTAINER);
MessageObj = new StreamMessages('chat-container-id');
});
videoId = '<?=$chatId?>';
/**
* Sample JavaScript code for youtube.liveChatMessages.list
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
async function authenticate() {
return await GoogleAuth
.signIn({scope: "https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.readonly"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.youtube.liveBroadcasts.list(LiveStreamRequest)
.then(function(response) {
// Handle the results here (response.result has the parsed body).
responseStore.data = response;
console.log('ok');
},
function(err) {
console.log('error');
responseStore.error = err
});
}
gapi.load("client:auth2", function() {
gapi.auth2.init({
client_id: "325464991668-7td1mt49jrtos3h88i7ierh8e9f8tvv3.apps.googleusercontent.com",
ux_mode: "redirect"
}).then(function () {
GoogleAuth = gapi.auth2.getAuthInstance();
// Listen for sign-in state changes.
GoogleAuth.isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
if(isAuthorized){
loadClient().then(function () {
initChat();
});
}else{
authenticate().then(function () {
initChat();
});
}
console.log( 'Is auth: ' + isAuthorized);
});
});
function initChat() {
loadClient().then(function () {
getBroadcastList().then(function () {
if (videoId !== '' && videoId !== null) {
console.log(' id:' + videoId);
MessageObj.readNewMessages();
MessageObj.initClearMessageInterval();
MessageObj.initNewMessageInterval();
MessageObj.initHideEmptyChatIterval();
}
});
});
}
</script>
<body>
<div class="chat-container" id="chat-container-id">
</div>
<script>
let chatId = '<?=$chatId?>';
(function($) {
$.fn.isOverflowHeight = function() {
return this.each(function() {
var el = $(this);
if (el.css("overflow") == "hidden") {
var text = el.html();
var t = $(this.cloneNode(true)).hide().css('position', 'absolute').css('overflow', 'visible').height('auto').width(el.width());
el.after(t);
function height() {
return t.height() > el.height();
};
if(height())
{
let comments = $('.comment');
if(comments.length > 5){
comments[0].remove();
}
}
}
});
};
})(jQuery);
</script>
</body>
</html>