-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
sample_wss_source.html
80 lines (69 loc) · 2.11 KB
/
sample_wss_source.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
<html lang="en">
<body>
<script>
var conCon = 1;
var socketserver = false;
var roomID = "test";
(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);
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 if (window.location.protocol=="file:"){
roomID = prompt("Enter your session ID here, or add it to the URL.");
}
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":1, "in":3}));
};
socketserver.addEventListener('message', function (event) {
console.log(event.data);
});
}
var serverURL = "wss://io.socialstream.ninja";
socketserver = new WebSocket(serverURL);
setupSocket();
function sendTest(){
var data = {};
data.chatname = "steve";
data.chatbadges = "";
data.backgroundColor = "";
data.textColor = "";
data.chatmessage = "Some test message here. 🥷";
data.chatimg = "https://socialstream.ninja/sources/images/unknown.png";
data.hasDonation = "$100";
data.membership = "";;
data.contentimg = "";
data.type = "zoom";
data.textonly = true;
data.id = Date.now() + parseInt(Math.random()*1000000); // not required, but useful for keeping track of order or assigning message uniquiness
socketserver.send(JSON.stringify(data));
}
</script>
<button onclick="sendTest();">TEST MESSAGE</button>
</body>
</html>