forked from steveseguin/social_stream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampleapi.html
More file actions
529 lines (483 loc) · 22.5 KB
/
sampleapi.html
File metadata and controls
529 lines (483 loc) · 22.5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Social Stream API Sandbox</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
<style>
:root {
--bg-color: #1a1a1a;
--text-color: #e0e0e0;
--primary-color: #4a90e2;
--tertiary-color: #38393a;
--secondary-color: #283037;
--accent-color: #e74c3c;
--success-color: #2ecc71;
--warning-color: #f39c12;
--info-color: #3498db;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding: 20px;
line-height: 1.6;
}
.container {
max-width: 1200px;
}
h1, h2 {
color: var(--primary-color);
margin-bottom: 20px;
}
.section {
background-color: var(--tertiary-color);
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
}
.section:hover {
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2);
transform: translateY(-2px);
}
#incoming_messages {
height: 300px;
overflow-y: auto;
background-color: rgba(255, 255, 255, 0.05);
padding: 10px;
border-radius: 5px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.inbound {
background-color: rgba(255, 255, 255, 0.1);
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
border-left: 3px solid var(--primary-color);
}
.btn {
margin: 5px;
transition: all 0.3s ease;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.btn-primary {
background-color: var(--primary-color);
border-color: var(--primary-color);
}
.btn-secondary {
background-color: var(--secondary-color);
border-color: var(--secondary-color);
}
.btn-success {
background-color: var(--success-color);
border-color: var(--success-color);
}
.btn-warning {
background-color: var(--warning-color);
border-color: var(--warning-color);
}
.btn-info {
background-color: var(--info-color);
border-color: var(--info-color);
}
.form-control {
background-color: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.2);
color: var(--text-color);
}
.form-control:focus {
background-color: rgba(255, 255, 255, 0.15);
border-color: var(--primary-color);
box-shadow: 0 0 0 0.2rem rgba(74, 144, 226, 0.25);
color: var(--text-color);
}
#connectionStatus {
font-weight: bold;
}
.connected {
color: var(--success-color);
}
.disconnected {
color: var(--accent-color);
}
.note {
font-size: 0.9em;
font-style: italic;
color: var(--info-color);
margin-top: 10px;
}
#testMessageForm .form-group {
margin-bottom: 10px;
}
#testMessageForm label {
color: var(--text-color);
}
</style>
</head>
<body>
<div class="container">
<h1 class="mb-4">Social Stream API Sandbox</h1>
<div class="container mt-3">
<p class="lead">
This Social Stream API Sandbox is a comprehensive tool for developers to test and interact with the Social Stream Ninja API. It provides a user-friendly interface to experiment with various API features, including message generation, user management, and channel-specific communications. For full API documentation, please visit <a href="https://socialstream.ninja/api" target="_blank">socialstream.ninja/api</a>.
</p>
</div>
<style>
.lead {
font-size: 1.1rem;
color: #e0e0e0;
background-color: rgba(255, 255, 255, 0.1);
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.lead a {
color: #4a90e2;
text-decoration: none;
}
.lead a:hover {
text-decoration: underline;
}
</style>
<div class="section">
<h2>Connection Settings</h2>
<div class="mb-3">
<label for="sessionID" class="form-label">Session ID:</label>
<input type="text" id="sessionID" class="form-control" placeholder="Enter session ID">
</div>
<button id="connectButton" class="btn btn-primary">Connect</button>
<button id="disconnectButton" class="btn btn-danger">Disconnect</button>
<span id="connectionStatus" class="ms-3"></span>
<p class="note">Note: The connection will automatically attempt to reconnect if disconnected. The session ID for the API needs to match the session ID provided by the extension; this should correspond to the ?session value found on the dock.html and featured.html links.</p>
</div>
<div class="section">
<h2>General Commands</h2>
<div class="btn-group" role="group">
<button class="btn btn-secondary" onclick="sendCommand('clearOverlay')">Clear Overlay</button>
<button class="btn btn-secondary" onclick="sendCommand('clearAll')">Clear All Messages</button>
<button class="btn btn-secondary" onclick="sendCommand('feature')">Feature Next Unfeatured</button>
<button class="btn btn-secondary" onclick="sendCommand('autoShow', 'toggle')">Toggle Auto-show</button>
<button class="btn btn-secondary" onclick="sendCommand('nextInQueue')">Next in Queue</button>
<button class="btn btn-secondary" onclick="sendCommand('getQueueSize')">Get Queue Size</button>
</div>
<p class="note">These commands control the general behavior of the overlay and message queue.</p>
</div>
<div class="section">
<h2>TTS Controls</h2>
<div class="btn-group" role="group">
<button class="btn btn-info" onclick="sendCommand('tts', 'on', 1)">Turn TTS On (via Dock)</button>
<button class="btn btn-info" onclick="sendCommand('tts', 'off', 1)">Turn TTS Off (via Dock)</button>
<button class="btn btn-info" onclick="sendCommand('tts', 'on', 2)">Turn TTS On (via Featured)</button>
<button class="btn btn-info" onclick="sendCommand('tts', 'off', 2)">Turn TTS Off (via Featured)</button>
</div>
<p class="note">TTS (Text-to-Speech) can be controlled separately for the dock and featured messages. Make sure to enable the &server mode for the target you wish to directly interact with.</p>
</div>
<div class="section">
<h2>Send Simple Message</h2>
<div class="mb-3">
<input type="text" id="customMessage" class="form-control" placeholder="Enter custom message">
</div>
<div class="btn-group" role="group">
<button class="btn btn-success" onclick="sendCustomMessage('sendChat')">Send via WSS</button>
<button class="btn btn-success" onclick="sendCustomMessage('sendEncodedChat', true)">Send via HTTPS GET</button>
<button class="btn btn-success" onclick="sendCustomMessage('sendChat', false, true)">Send via HTTPS POST</button>
</div>
<p class="note">Custom messages can be sent using different methods: WebSocket (WSS), HTTPS GET, or HTTPS POST.</p>
</div>
<div class="section">
<h2>Advanced Message Generator</h2>
<form id="testMessageForm">
<div class="form-group">
<label for="chatname">Username:</label>
<input type="text" class="form-control" id="chatname" placeholder="Enter username">
</div>
<div class="form-group">
<label for="chatmessage">Message:</label>
<input type="text" class="form-control" id="chatmessage" placeholder="Enter message">
</div>
<div class="form-group">
<label for="type">Platform:</label>
<select class="form-control" id="type">
<option value="twitch">Twitch</option>
<option value="youtube">YouTube</option>
<option value="facebook">Facebook</option>
<option value="discord">Discord</option>
<option value="slack">Slack</option>
<option value="zoom">Zoom</option>
</select>
</div>
<div class="form-group">
<label for="hasDonation">Donation Amount:</label>
<input type="text" class="form-control" id="hasDonation" placeholder="Enter donation amount (optional)">
</div>
<div class="form-group">
<label for="membership">Membership:</label>
<input type="text" class="form-control" id="membership" placeholder="Enter membership status (optional)">
</div>
<div class="form-group">
<label for="chatimg">Avatar URL:</label>
<input type="text" class="form-control" id="chatimg" placeholder="Enter avatar URL (optional)">
</div>
<div class="form-group">
<label for="nameColor">Name Color:</label>
<input type="color" class="form-control" id="nameColor">
</div>
<div class="form-group">
<label for="contentimg">Content Image URL:</label>
<input type="text" class="form-control" id="contentimg" placeholder="Enter content image URL (optional)">
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="isQuestion">
<label class="form-check-label" for="isQuestion">Mark as Question</label>
</div>
<button type="button" class="btn btn-primary" onclick="sendTestMessage()">Send Test Message</button>
<button type="button" class="btn btn-secondary" onclick="generateRandomMessage()">Generate Random Message</button>
</form>
<p class="note">Generate custom test messages to simulate different platforms and scenarios.</p>
</div>
<div class="section">
<h2>Channel-Specific Messaging</h2>
<div class="mb-3">
<input type="text" id="channelMessage" class="form-control" placeholder="Enter channel-specific message">
<select id="channelSelect" class="form-control mt-2">
<option value="1">Channel 1</option>
<option value="2">Channel 2</option>
<option value="3">Channel 3</option>
<option value="4">Channel 4</option>
<option value="5">Channel 5</option>
<option value="6">Channel 6</option>
<option value="7">Channel 7</option>
</select>
</div>
<button class="btn btn-primary" onclick="sendChannelMessage()">Send Channel Message</button>
<p class="note">Send messages to specific channels for more granular control.</p>
</div>
<div class="section">
<h2>Waitlist Commands</h2>
<div class="btn-group" role="group">
<button class="btn btn-warning" onclick="sendCommand('removefromwaitlist', 1)">Remove First from Waitlist</button>
<button class="btn btn-warning" onclick="sendCommand('highlightwaitlist', 1)">Highlight First in Waitlist</button>
<button class="btn btn-warning" onclick="sendCommand('resetwaitlist')">Reset Waitlist</button>
<button class="btn btn-warning" onclick="sendCommand('downloadwaitlist')">Download Waitlist</button>
<button class="btn btn-warning" onclick="sendCommand('selectwinner')">Select Winner</button>
<button class="btn btn-warning" onclick="sendCommand('stopentries')">Stop Entries</button>
<button class="btn btn-warning" onclick="sendCommand('waitlistmessage', 'Custom waitlist message')">Set Waitlist Message</button>
</div>
<p class="note">These commands manage the waitlist functionality, useful for giveaways or queue management.</p>
</div>
<div class="section">
<h2>User Management</h2>
<div class="btn-group" role="group">
<button class="btn btn-danger" onclick="blockUser()">Block User</button>
<button class="btn btn-success" onclick="toggleVIPUser()">Toggle VIP User</button>
<button class="btn btn-info" onclick="getUserHistory()">Get User History</button>
</div>
<p class="note">Manage users, including blocking, VIP status, and viewing history.</p>
</div>
<div class="section">
<h2>Incoming Messages</h2>
<div id="incoming_messages"></div>
<p class="note">This area displays incoming messages from the server.</p>
</div>
</div>
<script>
let socket;
let sessionID;
let quick = true;
function getSessionIdFromURL() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('session');
}
function updateConnectionStatus(status) {
const statusElement = document.getElementById('connectionStatus');
statusElement.textContent = status;
statusElement.className = status === 'Connected' ? 'connected' : 'disconnected';
}
function connect() {
sessionID = document.getElementById('sessionID').value;
if (!sessionID) {
alert('Please enter a session ID');
return;
}
socket = new WebSocket('wss://io.socialstream.ninja:443');
socket.onopen = function() {
socket.send(JSON.stringify({"join": sessionID, "out": 1, "in": 2}));
updateConnectionStatus('Connected');
document.getElementById('connectButton').disabled = true;
document.getElementById('disconnectButton').disabled = false;
quick = true;
};
socket.onmessage = function(event) {
const messageDiv = document.createElement('div');
messageDiv.className = 'inbound';
messageDiv.textContent = event.data;
document.getElementById('incoming_messages').prepend(messageDiv);
};
socket.onclose = function() {
updateConnectionStatus('Disconnected');
document.getElementById('connectButton').disabled = false;
document.getElementById('disconnectButton').disabled = true;
if (quick) {
quick = false;
connect();
} else {
setTimeout(function() {
connect();
}, 5000);
}
};
}
function disconnect() {
if (socket) {
socket.close();
}
}
function sendCommand(action, value = null, channel = null) {
if (!socket || socket.readyState !== WebSocket.OPEN) {
alert('Please connect first');
return;
}
const message = {
action: action,
apiid: sessionID
};
if (value !== null) message.value = value;
if (channel !== null) message.out = channel;
socket.send(JSON.stringify(message));
}
function sendCustomMessage(action, isEncodedGet = false, isPost = false) {
const message = document.getElementById('customMessage').value;
if (!message) {
alert('Please enter a message');
return;
}
if (isEncodedGet) {
const encodedMessage = encodeURIComponent(message);
fetch(`https://io.socialstream.ninja/${sessionID}/${action}/null/${encodedMessage}`)
.then(response => response.text())
.then(data => alert('Message sent via HTTPS GET'));
} else if (isPost) {
fetch(`https://io.socialstream.ninja/${sessionID}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({action: action, value: message, apiid: sessionID}),
})
.then(response => response.text())
.then(data => alert('Message sent via HTTPS POST'));
} else {
sendCommand(action, message);
}
}
function sendTestMessage() {
const testMessage = {
chatname: document.getElementById('chatname').value,
chatmessage: document.getElementById('chatmessage').value,
type: document.getElementById('type').value,
hasDonation: document.getElementById('hasDonation').value,
membership: document.getElementById('membership').value,
chatimg: document.getElementById('chatimg').value,
nameColor: document.getElementById('nameColor').value,
contentimg: document.getElementById('contentimg').value,
question: document.getElementById('isQuestion').checked
};
sendCommand('extContent', JSON.stringify(testMessage));
}
function generateRandomMessage() {
const randomData = {
chatname: "User" + Math.floor(Math.random() * 1000),
chatmessage: "Random message " + Math.random().toString(36).substring(7),
type: ["twitch", "youtube", "facebook", "discord", "slack", "zoom"][Math.floor(Math.random() * 6)],
hasDonation: Math.random() > 0.7 ? "$" + (Math.random() * 100).toFixed(2) : "",
membership: Math.random() > 0.8 ? "Premium Member" : "",
chatimg: "https://picsum.photos/50/50?random=" + Math.random(),
nameColor: '#' + Math.floor(Math.random()*16777215).toString(16),
contentimg: Math.random() > 0.9 ? "https://picsum.photos/200/200?random=" + Math.random() : "",
question: Math.random() > 0.8
};
Object.keys(randomData).forEach(key => {
const element = document.getElementById(key);
if (element) {
if (element.type === 'checkbox') {
element.checked = randomData[key];
} else if (element.tagName === 'SELECT') {
const option = Array.from(element.options).find(opt => opt.value === randomData[key]);
if (option) option.selected = true;
} else {
element.value = randomData[key];
}
}
});
}
function blockUser() {
const username = document.getElementById('chatname').value;
const platform = document.getElementById('type').value;
if (!username || !platform) {
alert('Please enter a username and select a platform');
return;
}
sendCommand('blockUser', { chatname: username, type: platform });
}
function toggleVIPUser() {
const username = document.getElementById('chatname').value;
const platform = document.getElementById('type').value;
if (!username || !platform) {
alert('Please enter a username and select a platform');
return;
}
sendCommand('toggleVIPUser', { chatname: username, type: platform });
}
function getUserHistory() {
const username = document.getElementById('chatname').value;
const platform = document.getElementById('type').value;
if (!username || !platform) {
alert('Please enter a username and select a platform');
return;
}
sendCommand('getUserHistory', { chatname: username, type: platform });
}
function sendChannelMessage() {
const message = document.getElementById('channelMessage').value;
const channel = document.getElementById('channelSelect').value;
if (!message) {
alert('Please enter a message');
return;
}
sendCommand('content' + channel, message);
}
// Event listeners
document.getElementById('connectButton').addEventListener('click', connect);
document.getElementById('disconnectButton').addEventListener('click', disconnect);
// Auto-connect if session ID is provided in URL
window.addEventListener('load', function() {
const urlSessionId = getSessionIdFromURL();
if (urlSessionId) {
document.getElementById('sessionID').value = urlSessionId;
connect();
}
});
// Developer Notes
console.log(`
Developer Notes:
1. The WebSocket server is at wss://io.socialstream.ninja:443
2. Session ID is crucial for connecting to the correct room
3. Use channel 1 for general communication, channel 2 for dock.html, etc.
4. The 'extContent' action is used to send simulated messages from various platforms
5. Custom actions can be added using a custom.js file in your project
6. MIDI hotkey support is available for predefined chat messages
7. The API supports both WebSocket and HTTP (GET/POST) methods
8. Use the 'target' field in messages for specific instance targeting
9. Error handling and reconnection logic is implemented for robustness
10. Experiment with different message types and actions to understand the full capabilities of the API
`);
</script>
</body>
</html>