forked from steveseguin/social_stream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.html
More file actions
569 lines (507 loc) · 20 KB
/
Copy pathactions.html
File metadata and controls
569 lines (507 loc) · 20 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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Actions Overlay - Social Stream Ninja</title>
<style>
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: transparent; /* Already set to transparent */
display: flex;
justify-content: center;
align-items: center;
font-family: Arial, sans-serif;
}
.fullscreen-media-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.8); /* Optional: dim background */
display: none; /* Hidden by default */
justify-content: center;
align-items: center;
z-index: 9999;
}
#status-message {
color: rgba(204, 204, 204, 0.5); /* Make semi-transparent */
font-size: 18px;
background-color: transparent;
}
.fullscreen-media-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: transparent; /* Changed from rgba(0, 0, 0, 0.8) to transparent */
display: none; /* Hidden by default */
justify-content: center;
align-items: center;
z-index: 9999;
overflow: hidden;
}
.fullscreen-media-container iframe {
width: 100%;
height: 100%;
border: none;
overflow: hidden;
background-color: transparent;
}
.fullscreen-media-container img {
max-width: 95%;
max-height: 95%;
border: none;
}
/* Modal styles */
.modal {
display: none;
position: fixed;
z-index: 10000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
justify-content: center;
align-items: center;
}
.modal-content {
background-color: #fefefe;
padding: 30px;
border: 1px solid #888;
border-radius: 8px;
width: 90%;
max-width: 400px;
text-align: center;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
.modal-content h2 {
margin-top: 0;
margin-bottom: 20px;
color: #333;
}
.modal-content input[type="text"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box;
}
.modal-content button {
background-color: #4CAF50;
color: white;
padding: 12px 24px;
margin: 10px 5px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
.modal-content button:hover {
background-color: #45a049;
}
.modal-content button.cancel {
background-color: #f44336;
}
.modal-content button.cancel:hover {
background-color: #da190b;
}
.modal-content p {
color: #666;
margin: 10px 0;
}
}
</style>
</head>
<body>
<div id="status-message"></div>
<div id="fullscreen-media-container" class="fullscreen-media-container"></div>
<!-- Session ID Modal -->
<div id="sessionModal" class="modal">
<div class="modal-content">
<h2>Session ID Required</h2>
<p>Please enter your session ID to continue:</p>
<input type="text" id="sessionIdInput" placeholder="Enter session ID" autofocus>
<div>
<button onclick="submitSessionId()">Submit</button>
<button class="cancel" onclick="cancelSessionId()">Cancel</button>
</div>
</div>
</div>
<script>
window.onerror = function backupErr(errorMsg, url=false, lineNumber=false) {
console.error(errorMsg);
console.error(lineNumber);
console.error("Unhandled Error occurred");
return false;
};
function getById(id) {
var el = document.getElementById(id);
if (!el) {
el = document.createElement("span");
}
return el;
}
(function (w) {
w.URLSearchParams = w.URLSearchParams || function (searchString) {
var self = this;
self.searchString = searchString;
self.get = function (name) {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(self.searchString);
if (results == null) {
return null;
} else {
return decodeURI(results[1]) || 0;
}
};
};
})(window);
var urlParams = new URLSearchParams(window.location.search);
var iframe = null;
var roomID = "test";
var password = "false";
var mediaContainer = document.getElementById('fullscreen-media-container');
var statusMessage = document.getElementById('status-message');
var obsStudio = null;
var audioContext = new (window.AudioContext || window.webkitAudioContext)();
// Attempt to connect to OBS Studio API if available
if (window.obsstudio) {
obsStudio = window.obsstudio;
console.log('OBS Studio API found.');
}
// Function to show session ID modal
function showSessionModal() {
var modal = document.getElementById('sessionModal');
modal.style.display = 'flex';
document.getElementById('sessionIdInput').focus();
}
// Function to submit session ID
function submitSessionId() {
var sessionIdInput = document.getElementById('sessionIdInput');
var sessionId = sessionIdInput.value.trim();
if (sessionId) {
roomID = sessionId;
var href = window.location.href;
var arr = href.split('?');
var newurl;
if (arr.length > 1 && arr[1] !== '') {
newurl = href + '&session=' + roomID;
} else {
newurl = href + '?session=' + roomID;
}
window.history.pushState({path: newurl.toString()}, '', newurl.toString());
// Hide modal
document.getElementById('sessionModal').style.display = 'none';
// Continue with initialization
initializeWithSessionId();
} else {
alert("Please enter a valid session ID");
}
}
// Function to cancel session ID entry
function cancelSessionId() {
document.getElementById('sessionModal').style.display = 'none';
if (window.location.protocol == "file:") {
alert("You need to provide your extension's session ID for this page to work");
} else {
window.location.href = "https://github.com/steveseguin/social_stream#readme";
}
}
// Make functions globally available
window.submitSessionId = submitSessionId;
window.cancelSessionId = cancelSessionId;
// Handle Enter key in input
document.addEventListener('DOMContentLoaded', function() {
var sessionIdInput = document.getElementById('sessionIdInput');
if (sessionIdInput) {
sessionIdInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
submitSessionId();
}
});
}
});
// Get session/room ID from URL parameters
var needsSessionId = false;
if (urlParams.has("session")) {
roomID = urlParams.get("session");
} else if (urlParams.has("s")) {
roomID = urlParams.get("s");
} else if (urlParams.has("id")) {
roomID = urlParams.get("id");
} else {
needsSessionId = true;
}
// Get password from URL parameters
if (urlParams.has("password")) {
password = urlParams.get("password") || "false";
}
// Function to initialize after session ID is available
function initializeWithSessionId() {
// Fix for electron dragging
try {
if ((window.ninjafy || window.electronApi)) {
document.body.style.width = "95%";
setTimeout(function() {
document.body.style.width = "100%";
}, 1000);
setTimeout(function() {
document.body.style.width = "98%";
}, 2000);
setTimeout(function() {
document.body.style.width = "100%";
}, 5000);
}
} catch(e) {}
// Load CSS if provided
if (urlParams.has('css')) {
var cssURL = urlParams.get('css');
cssURL = decodeURI(cssURL);
var cssStylesheet = document.createElement('link');
cssStylesheet.rel = 'stylesheet';
cssStylesheet.type = 'text/css';
cssStylesheet.media = 'screen';
cssStylesheet.href = cssURL;
document.getElementsByTagName('head')[0].appendChild(cssStylesheet);
}
// Load Base64 CSS if provided
if (urlParams.has("base64css") || urlParams.has("b64css") || urlParams.has("cssbase64") || urlParams.has("cssb64")) {
try {
var base64Css = urlParams.get("base64css") || urlParams.get("b64css") || urlParams.get("cssbase64") || urlParams.get("cssb64");
var css = decodeURIComponent(atob(base64Css));
var cssStyleSheet = document.createElement("style");
cssStyleSheet.innerText = css;
document.querySelector("head").appendChild(cssStyleSheet);
} catch(e) {
console.error(e);
}
}
// Load JavaScript if provided
if (urlParams.has('js')) {
console.warn("Third-party JavaScript has been injected into the code. Security cannot be ensured.");
var jsURL = urlParams.get('js');
jsURL = decodeURI(jsURL);
console.log(jsURL);
var externalJavaascript = document.createElement('script');
externalJavaascript.type = 'text/javascript';
externalJavaascript.crossorigin = 'anonymous';
externalJavaascript.src = jsURL;
externalJavaascript.onerror = function() {
console.warn("Third-party JavaScript failed to load");
};
externalJavaascript.onload = function() {
console.log("Third-party JavaScript loaded");
};
document.head.appendChild(externalJavaascript);
}
// Setup WebSocket if server parameter is provided
if (urlParams.has("server") || urlParams.has("server2")) {
serverURL = urlParams.get("server") || urlParams.get("server2") || serverURL;
socketserver = new WebSocket(serverURL);
setupSocket();
}
// Create iframe for receiving WebRTC data channel messages
iframe = document.createElement("iframe");
iframe.src = "https://vdo.socialstream.ninja/?ln&salt=vdo.ninja&password=" + password +
"&solo&view=" + roomID + "&novideo&noaudio&label=actions&cleanoutput&room=" + roomID;
iframe.style.width = "0px";
iframe.style.height = "0px";
iframe.style.position = "fixed";
iframe.style.left = "-100px";
iframe.style.top = "-100px";
iframe.id = "frame1";
document.body.appendChild(iframe);
console.log("Actions page initialized with session ID:", roomID);
}
// WebSocket connection setup
var conCon = 1;
var socketserver = false;
var serverURL = urlParams.has("localserver") ? "ws://127.0.0.1:3000" : "wss://io.socialstream.ninja/extension";
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": 5, "in": 6}));
};
socketserver.addEventListener('message', function(event) {
var resp = false;
if (event.data) {
try {
var data = JSON.parse(event.data);
processInput(data);
if (data.get) {
var ret = {};
ret.callback = {};
ret.callback.get = data.get;
ret.callback.result = true;
socketserver.send(JSON.stringify(ret));
}
} catch(e) {
console.error("Error processing WebSocket message:", e);
}
}
});
}
function processInput(data) {
console.log("Processing input:", data);
if (data.actionType) {
// Handle direct action object
handleAction(data);
} else if (data.action) {
handleAction(data.action);
} else if (data.content && data.content.action) {
handleAction(data.content.action);
} else if (data.overlayNinja) {
handleAction(data.overlayNinja);
} else if (data.dataReceived && data.dataReceived.overlayNinja) {
// Handle WebRTC data channel format
processInput(data.dataReceived.overlayNinja);
}
}
// Function to handle different action types
function handleAction(payload) {
if (!payload || !payload.actionType) {
console.warn("Received an empty or invalid payload:", payload);
return;
}
statusMessage.style.display = 'none'; // Hide status message when an action is received
switch (payload.actionType) {
case 'play_media':
if (payload.url) {
playMediaFullscreen(payload.url, payload.mediaType || 'iframe', payload.duration || 10000);
} else {
console.warn("Play media action received without a URL.");
}
break;
case 'obs_scene_change':
if (obsStudio && payload.sceneName) {
console.log(`Attempting to change OBS scene to: ${payload.sceneName}`);
obsStudio.setCurrentScene(payload.sceneName)
.then(() => console.log(`OBS Scene changed to ${payload.sceneName}`))
.catch(err => console.error("Error changing OBS scene:", err));
} else if (!obsStudio) {
console.warn("OBS API not available to change scene.");
} else {
console.warn("OBS scene change action received without a scene name.");
}
break;
case 'play_audio':
if (payload.audioUrl) {
playAudio(payload.audioUrl, payload.volume);
} else {
console.warn("Play audio action received without an audio URL.");
}
break;
default:
console.warn("Unknown action type received:", payload.actionType);
}
}
// Function to play media in fullscreen
function playMediaFullscreen(url, mediaType, duration = 10000) {
mediaContainer.innerHTML = ''; // Clear previous media
let mediaElement;
if (mediaType === 'image') {
mediaElement = document.createElement('img');
mediaElement.src = url;
} else { // Default to iframe for videos/gifs
mediaElement = document.createElement('iframe');
mediaElement.src = url;
mediaElement.setAttribute('allow', 'autoplay; fullscreen');
mediaElement.setAttribute('frameborder', '0');
mediaElement.setAttribute('allowtransparency', 'true');
mediaElement.style.width = '100%';
mediaElement.style.height = '100%';
mediaElement.style.overflow = 'hidden';
mediaElement.style.backgroundColor = 'transparent';
}
mediaContainer.appendChild(mediaElement);
mediaContainer.style.display = 'flex';
// Hide after specified duration
setTimeout(() => {
mediaContainer.style.display = 'none';
mediaContainer.innerHTML = ''; // Clean up
statusMessage.style.display = 'block'; // Show status message again
}, duration);
}
// Function to play audio
async function playAudio(audioUrl, volume = 1.0) {
try {
if (audioContext.state === 'suspended') {
await audioContext.resume();
}
const audio = new Audio(audioUrl);
audio.volume = parseFloat(volume);
await audio.play();
console.log("Playing audio:", audioUrl);
} catch (e) {
console.error("Error playing audio:", e);
}
}
// Listen for messages from the iframe
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message";
eventer(messageEvent, function(e) {
// Check if the message is from our iframe
if (iframe && e.source == iframe.contentWindow) {
// Process data from the WebRTC data channel
if (e.data && e.data.dataReceived) {
if (e.data.dataReceived.overlayNinja) {
processInput(e.data.dataReceived.overlayNinja);
} else {
// Handle direct action object in dataReceived
processInput(e.data.dataReceived);
}
} else if (e.data && e.data.actionType) {
// Handle direct action object
processInput(e.data);
}
}
});
// Handle audio context for browsers that require user interaction
document.addEventListener('click', () => {
if (audioContext.state === 'suspended') {
audioContext.resume().then(() => {
console.log('AudioContext resumed successfully');
}).catch(error => {
console.error('Failed to resume AudioContext:', error);
});
}
});
function testAction(actionData) {
processInput(actionData);
}
window.testAction = testAction;
// Initialize or show modal based on whether session ID is needed
if (needsSessionId) {
// Wait for DOM to be ready before showing modal
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
showSessionModal();
});
} else {
showSessionModal();
}
} else {
// Session ID is already available, initialize immediately
initializeWithSessionId();
}
</script>
</body>
</html>