-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.html
118 lines (113 loc) · 5.23 KB
/
window.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Ruto</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Reddit+Mono:[email protected]&display=swap" rel="stylesheet" />
<style>
body {
font-family: 'Reddit Mono', monospace;
}
</style>
<link rel="stylesheet" href="style.css" />
</head>
<body style="overflow-x: hidden">
<div class="p-1">
<div class="col-lg-12 px-0">
<div class="row">
<div class="col-12 chat-root">
<div class="row chat-content">
<div class="col-12">
<h4>Window</h4>
</div>
<div class="col-12 p-0">
<div class="chat" style="height: 80vh" id="mymessage"></div>
</div>
<div class="col-12 mt-4">
<form class="row" onsubmit="event.preventDefault(); sendMessage();">
<div class="col-8">
<label for="message" class="visually-hidden">Message</label>
<input type="text" class="form-control" id="message" placeholder="message" required />
</div>
<div class="col-4">
<button type="submit" class="btn btn-primary mb-3 w-100">SEND</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="dist/ruto.min.js"></script>
<script>
function GetUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
ruto.receive('/parent-to-window/popup', window.opener, function (response, message) {
const id = GetUUID();
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
$('#mymessage').append(
`<div class="message" id="${id}">
<div class="his sent">
<div class="bubble">
➔ ${message}
</div>
</div>
</div>`,
);
const newMessage = `MY Response to ${message} is ${GetUUID()}`;
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
$('#' + id).append(
`<div class="his received">
<div class="bubble">
${newMessage} ➔
</div>
</div>`,
);
return response.send(newMessage);
//response.send(`MY Response to ${message} is ${GetUUID()}`)
});
function sendMessage() {
const id = GetUUID();
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
$('#mymessage').append(
`<div class="message" id="${id}">
<div class="mine sent">
<div class="bubble">
${$('#message').val()} ➔
</div>
</div>
</div>`,
);
ruto.send(window.location.origin + '/window-to-parent/purple', window.opener, $('#message').val()).then(
function (message) {
//document.getElementById("statuses").innerHTML = document.getElementById("statuses").innerHTML + "ó Parent: " + message + "<hr>";
$('#' + id).append(
`<div class="mine received">
<div class="bubble">
➔ ${message}
</div>
</div>`,
);
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
},
function (error) {
console.log('Error:', error);
},
);
$('#message').val('');
}
</script>
</body>
</html>