-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathsampleoverlay.html
290 lines (254 loc) · 8.4 KB
/
sampleoverlay.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!--
Development Notes:
- It's important that the IFRAME logic stay intact, as it is how we receieve messages
- This code is in vanilla Javascript designed for web browsers without compiling
- Details of the incoming message structure can be found here: https://github.com/steveseguin/social_stream/blob/main/README.md#message-structure
!-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat Overlay</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap">
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap');
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-color: rgba(10, 22, 40, 0.8); /* Dark, semi-transparent background */
font-family: 'Roboto', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #0000;
}
#chat-container {
padding: 25px;
max-width: 350px;
margin: auto;
}
.message {
background: linear-gradient(145deg, #1a2a48, #162238);
padding: 20px;
margin-bottom: 20px;
border-radius: 15px;
border: 1px solid #2e3b55;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
color: #e4e6eb;
transition: transform 0.2s ease-in-out;
opacity: 0;
transform: translateY(-20px);
animation: slideFadeIn 0.5s ease forwards;
position: relative;
overflow: hidden;
}
@keyframes slideFadeIn {
to {
opacity: 1;
transform: translateY(0);
}
}
#chat-container .message + .message {
transition: transform 0.5s ease;
}
.name {
color: white;
font-size: 1.2em;
font-weight: 700;
}
.text {
font-size: 0.95em;
line-height: 1.4;
margin: 8px 0;
}
.text img {
max-width:100px;
max-height: 24px;
vertical-align: bottom;
}
.donation {
color: #4cd137;
font-weight: 600;
}
.message:after {
content: "";
display: table;
clear: both;
}
.separator {
height: 2px;
background: linear-gradient(to right, #4ab8f9, #4cd137);
margin: 20px 0;
}
.name-bg {
background-color: #4a6fa5;
padding: 5px 10px;
border-radius: 5px;
display: inline-block;
vertical-align: middle;
}
.membership-status {
color: #ffd700;
font-weight: 700;
font-size: 0.9em;
margin-bottom: 5px;
}
.large-image {
max-width: 100%;
height: auto;
margin-top: 10px;
border-radius: 10px;
}
.avatar-wrapper {
width: 60px;
height: 60px;
border-radius: 50%;
display: inline-block;
margin-right: 15px;
position: relative;
overflow: hidden;
background: linear-gradient(45deg, #4ab8f9, #4cd137);
padding: 3px;
vertical-align: middle;
}
.avatar {
width: 100%;
height: 100%;
border-radius: 50%;
background: url('https://somdomain.com/avatar.png') no-repeat center center;
background-size: cover;
position: relative;
}
.avatar-wrapper::after {
content: '';
position: absolute;
top: -5px; right: -5px; bottom: -5px; left: -5px;
background: linear-gradient(45deg, #4ab8f9, #4cd137);
border-radius: 50%;
z-index: -1;
}
.source-icon {
width: 20px;
height: 20px;
vertical-align: middle;
position: relative;
}
.badge {
display: inline-block;
height: 1em;
margin-left: 5px;
vertical-align: middle;
}
</style>
</head>
<body>
<div id="chat-container"></div>
<script>
var urlParams = new URLSearchParams(window.location.search);
var roomID = "iWWnKL28tQ";
if (urlParams.has("session")){
roomID = urlParams.get("session");
}
var password = "false";
var featuredMode = false; // featured == selected messages only. not featured == all messages.
const chatContainer = document.getElementById('chat-container');
function addMessageToOverlay(data) {
const messageDiv = document.createElement('div');
messageDiv.classList.add('message');
if (data.mid){messageDiv.id = data.mid;}
data.sourceicon = "https://socialstream.ninja/sources/images/"+data.type+".png";
console.log(data.chatbadges);
var chatbadges = "";
if (data.chatbadges) {
data.chatbadges.forEach(badge => {
if (typeof badge === "object") {
if (badge.type === "img" && badge.src) {
chatbadges += `<img class='badge' src='${badge.src}' />`;
} else if (badge.type === "svg" && badge.html) {
chatbadges += `<span class='badge svg'>${badge.html}</span>`;
}
} else {
chatbadges += `<img class='badge' src='${badge}' />`;
}
});
}
messageDiv.innerHTML = `
${data.chatimg ? `<div class="avatar-wrapper"><div class="avatar" style="background-image: url('${data.chatimg}');"></div></div>` : ''}
${data.chatname ? `<div class="name-bg"><div class="name" ${data.nameColor ? `style="text-shadow: 0 0 3px ${data.nameColor}"` : ''}>${data.chatname}</div></div>` : ''}
${data.sourceicon ? `<img src="${data.sourceicon}" alt="Channel Source" class="source-icon">` : ''}
${chatbadges}
${data.membership ? `<div class="membership-status">${data.membership}</div>` : ''}
<div class="text" ${data.event ? 'style="font-style: italic;"' : ''}>${data.chatmessage ? data.chatmessage : ''}</div>
${data.hasDonation ? `<div class="donation">${data.hasDonation}</div>` : ''}
${data.contentimg ? `<img src="${data.contentimg}" alt="Large Content" class="large-image" onerror="this.style.display='none';">` : ''}
`;
Array.from(chatContainer.children).forEach(child => {
child.style.transform = 'translateY(' + messageDiv.offsetHeight + 'px)';
});
chatContainer.prepend(messageDiv);
// Auto-scroll to the latest message
chatContainer.scrollTop = chatContainer.scrollHeight;
while (chatContainer.children.length > 20) {
chatContainer.removeChild(chatContainer.lastChild);
}
setTimeout(() => {
Array.from(chatContainer.children).forEach(child => {
child.style.transform = '';
});
}, 500);
}
// The IFrame allows for peer to peer mode; used by default. It may have issues if self-hosting this page though while using OBS v31 due to same-origin strict policies in CEF
var iframe = document.createElement("iframe");
if (featuredMode){
iframe.src = `https://vdo.socialstream.ninja/?ln&password=${password}&salt=vdo.ninja&label=overlay&exclude=${roomID}&scene&novideo&noaudio&cleanoutput&room=${roomID}`;
} else {
iframe.src = "https://vdo.socialstream.ninja/?ln&salt=vdo.ninja&password="+password+"&push&label=dock&vd=0&ad=0&novideo&noaudio&autostart&cleanoutput&room="+roomID;
}
iframe.style.cssText = "width: 0px; height: 0px; position: fixed; left: -100px; top: -100px;";
document.body.appendChild(iframe);
window.addEventListener("message", function (e) {
if (e.source != iframe.contentWindow) return;
if (e.data.dataReceived && e.data.dataReceived.overlayNinja) {
addMessageToOverlay(e.data.dataReceived.overlayNinja);
}
});
// The Websocket mode is an alternative to using p2p mode; useful if your OBS or system refuses to use IFrames/P2P.
var conCon = 1;
var socketserver = false;
// localserver mode can be used via the stand-alone app; file-> enable local server, or use the publicly hosted one.
var serverURL = urlParams.has("localserver") ? "ws://127.0.0.1:3000" : "wss://io.socialstream.ninja";
function setupSocket(){
socketserver.onclose = function (){
setTimeout(function(){
conCon+=1;
socketserver = new WebSocket(serverURL);
setupSocket();
},100*conCon);
};
socketserver.onopen = function (){
conCon = 1;
socketserver.send(JSON.stringify({"join":roomID, "out":3, "in":4}));
};
socketserver.addEventListener('message', function (event) {
var resp = false
if (event.data){
var data = JSON.parse(event.data);
addMessageToOverlay(data);
if (data.get){
var ret = {};
ret.callback = {};
ret.callback.get = data.get
ret.callback.result = true;
socketserver.send(JSON.stringify(ret));
}
}
});
}
if (urlParams.has("server") || urlParams.has("server2")){ // opt-in to use. Must also be enabled in the menu as well.
serverURL = urlParams.get("server") || urlParams.get("server2") || serverURL;
socketserver = new WebSocket(serverURL);
setupSocket();
}
</script>
</body>
</html>