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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
body {
|
| 2 |
+
margin: 0;
|
| 3 |
+
padding: 0;
|
| 4 |
+
font-family: Arial, sans-serif;
|
| 5 |
+
background-color: #f0f0f0;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
.header {
|
| 9 |
+
text-align: center;
|
| 10 |
+
padding: 20px;
|
| 11 |
+
background-color: #3498db;
|
| 12 |
+
color: #ffffff;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.app {
|
| 16 |
+
position: relative;
|
| 17 |
+
padding: 20px;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
.message-container {
|
| 21 |
+
position: relative;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.message-container textarea {
|
| 25 |
+
width: 100%;
|
| 26 |
+
padding: 10px;
|
| 27 |
+
border: 1px solid #ccc;
|
| 28 |
+
background-color: #ffffff;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.message-input {
|
| 32 |
+
background-color: transparent;
|
| 33 |
+
width: 100%;
|
| 34 |
+
height: 175px;
|
| 35 |
+
/*border: 1px solid #ccc;*/
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
.message-box {
|
| 40 |
+
position: relative;
|
| 41 |
+
width: calc(33% + 100px);
|
| 42 |
+
height: auto;
|
| 43 |
+
padding: calc(4% + 20px);
|
| 44 |
+
border-radius: 5px;
|
| 45 |
+
font-size: 24pt;
|
| 46 |
+
margin: 0 0 20px 20px;
|
| 47 |
+
white-space: pre;
|
| 48 |
+
white-space: pre-line;
|
| 49 |
+
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
@media (orientation: portrait) {
|
| 53 |
+
.message-box {
|
| 54 |
+
margin-bottom: 100px;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/* Styles pour le mode paysage */
|
| 59 |
+
@media (orientation: landscape) {
|
| 60 |
+
.message-box {
|
| 61 |
+
margin-bottom: 80px;
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
.message-box.sent {
|
| 65 |
+
width: calc(88% - 50px);
|
| 66 |
+
background-color: #d3d3d3;/*#20efbb; */
|
| 67 |
+
left: 0%;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.message-box.received {
|
| 71 |
+
width: 85%;
|
| 72 |
+
background-color: #fff;/*#3498db;*/
|
| 73 |
+
|
| 74 |
+
}
|
| 75 |
+
.message-box.received a {
|
| 76 |
+
color: #2A58E2;
|
| 77 |
+
font-size: 18pt;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
#message-input {
|
| 81 |
+
position: fixed;
|
| 82 |
+
bottom: 10px;
|
| 83 |
+
left: calc(10% + 40px);
|
| 84 |
+
background-color: transparent;
|
| 85 |
+
border: solid #000;
|
| 86 |
+
opacity: 85%;
|
| 87 |
+
width: calc(70% - 40px);
|
| 88 |
+
height: calc(3% + 35px);
|
| 89 |
+
border-radius: 30px;
|
| 90 |
+
font-size: 32pt;
|
| 91 |
+
z-index: 9;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#message-input:hover {
|
| 95 |
+
color: #000;
|
| 96 |
+
background: #d3d3d3;
|
| 97 |
+
border: solid #3498db;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
#send-button:hover {
|
| 101 |
+
color: #fff;
|
| 102 |
+
background: #20efbb;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
#send-button {
|
| 106 |
+
position: fixed;
|
| 107 |
+
bottom: 12px;
|
| 108 |
+
left: 84%;
|
| 109 |
+
background-color: transparent;
|
| 110 |
+
border: solid #20efbb;
|
| 111 |
+
width: 150px;
|
| 112 |
+
height: calc(3% + 50px);
|
| 113 |
+
border-radius: 20px;
|
| 114 |
+
font-size: 24pt;
|
| 115 |
+
z-index: 9;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
#upload-files {
|
| 120 |
+
position: fixed;
|
| 121 |
+
bottom: 0px;
|
| 122 |
+
left: 1%;
|
| 123 |
+
background-color: transparent;
|
| 124 |
+
border: solid #20efbb;
|
| 125 |
+
width: 100px;
|
| 126 |
+
height: calc(3% + 50px);
|
| 127 |
+
border-radius: 20px;
|
| 128 |
+
font-size: 18pt;
|
| 129 |
+
z-index: 9;
|
| 130 |
+
overflow: hidden;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
#custom-upload {
|
| 134 |
+
display: inline-block;
|
| 135 |
+
background: transparent;
|
| 136 |
+
cursor: pointer;
|
| 137 |
+
position: fixed;
|
| 138 |
+
bottom: 12px;
|
| 139 |
+
left: calc(4% - 10px);
|
| 140 |
+
background-color: transparent;
|
| 141 |
+
width: calc(100px);
|
| 142 |
+
/*height: calc(3% + 50px);*/
|
| 143 |
+
border-radius: 20px;
|
| 144 |
+
font-size: 18pt;
|
| 145 |
+
z-index: 4;
|
| 146 |
+
overflow: hidden;
|
| 147 |
+
}
|
| 148 |
+
#upload-files {
|
| 149 |
+
display: none;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
#upload-files:hover {
|
| 153 |
+
color: #fff;
|
| 154 |
+
background: #20efbb;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
#user-id-input {
|
| 158 |
+
position: fixed;
|
| 159 |
+
top: 80px;
|
| 160 |
+
left: calc(10% + 40px);
|
| 161 |
+
background-color: transparent;
|
| 162 |
+
border: solid #000;
|
| 163 |
+
opacity: 5%;
|
| 164 |
+
width: calc(70% - 40px);
|
| 165 |
+
height: 50px;
|
| 166 |
+
border-radius: 30px;
|
| 167 |
+
font-size: 24pt;
|
| 168 |
+
z-index: 9;
|
| 169 |
+
display: block;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
#user-id-input:hover {
|
| 173 |
+
color: #000;
|
| 174 |
+
opacity: 80%;
|
| 175 |
+
background: #d3d3d3;
|
| 176 |
+
border: solid #3498db;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
#menu-button {
|
| 188 |
+
position: fixed;
|
| 189 |
+
left: 0;
|
| 190 |
+
top: 0;
|
| 191 |
+
width: 50px;
|
| 192 |
+
height: 100%;
|
| 193 |
+
background-color: #3498db;
|
| 194 |
+
color: #ffffff;
|
| 195 |
+
text-align: center;
|
| 196 |
+
line-height: 50px;
|
| 197 |
+
cursor: pointer;
|
| 198 |
+
z-index: 9999;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
#menu {
|
| 202 |
+
position: fixed;
|
| 203 |
+
left: -150px;
|
| 204 |
+
top: 0px;
|
| 205 |
+
width: 150px;
|
| 206 |
+
height: 100%;
|
| 207 |
+
background-color: #ffffff;
|
| 208 |
+
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
|
| 209 |
+
transition: left 0.3s ease-in-out;
|
| 210 |
+
overflow-y: auto;
|
| 211 |
+
padding-top: 45px;
|
| 212 |
+
padding-left: 20px;
|
| 213 |
+
padding-right: 20px;
|
| 214 |
+
z-index: 9997;
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
.menu-item {
|
| 218 |
+
margin-bottom: 10px;
|
| 219 |
+
z-index: 9999;
|
| 220 |
+
cursor: pointer;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.menu-item a {
|
| 224 |
+
color: #0d66e3;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
#add-button {
|
| 228 |
+
cursor: pointer;
|
| 229 |
+
z-index: 9999;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
#input-container {
|
| 233 |
+
display: none;
|
| 234 |
+
margin-top: 10px;
|
| 235 |
+
z-index: 9998;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
#toggle-menu-button {
|
| 239 |
+
position: fixed;
|
| 240 |
+
left: 5px;
|
| 241 |
+
top: 10px;
|
| 242 |
+
width: 30px;
|
| 243 |
+
height: 30px;
|
| 244 |
+
background-color: #3498db;
|
| 245 |
+
color: #ffffff;
|
| 246 |
+
text-align: center;
|
| 247 |
+
line-height: 30px;
|
| 248 |
+
cursor: pointer;
|
| 249 |
+
z-index: 9999;
|
| 250 |
+
font-size: 14pt;
|
| 251 |
+
border: none;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
#add-button {
|
| 255 |
+
position: fixed;
|
| 256 |
+
left: 50px;
|
| 257 |
+
bottom: 20px;
|
| 258 |
+
transform: translateX(-50%);
|
| 259 |
+
width: 40px;
|
| 260 |
+
height: 40px;
|
| 261 |
+
background-color: #3498db;
|
| 262 |
+
color: #ffffff;
|
| 263 |
+
text-align: center;
|
| 264 |
+
line-height: 40px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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var socket = io.connect('http://' + document.domain + ':' + location.port); // change by https:// if your use https proxy like replit
|
| 2 |
+
var uid = "{{ username }}";//document.cookie;//Math.floor(Math.random() * 1000000000);
|
| 3 |
+
var iid = 0;
|
| 4 |
+
var roomID = $('#user-id-input').val();
|
| 5 |
+
var menuVisible = false;
|
| 6 |
+
var addButton = $('#add-button');
|
| 7 |
+
var inputContainer = $('#input-container');
|
| 8 |
+
|
| 9 |
+
function sendnew(roomid) {
|
| 10 |
+
roomID = roomid;
|
| 11 |
+
socket.emit('message', {
|
| 12 |
+
data: JSON.stringify({
|
| 13 |
+
message: 'Connected!',
|
| 14 |
+
usid: uid,
|
| 15 |
+
roomID: roomid,
|
| 16 |
+
cookies: document.cookie
|
| 17 |
+
})
|
| 18 |
+
});
|
| 19 |
+
$('#mmsg2').empty();
|
| 20 |
+
$('#user-id-input').val(roomid);
|
| 21 |
+
document.getElementById("message-input").placeholder = "Message a envoyer dans " + roomid + "...";
|
| 22 |
+
menuVisible = !menuVisible;
|
| 23 |
+
var leftValue = menuVisible ? '0' : '-150px';
|
| 24 |
+
$('#menu').css('left', leftValue);
|
| 25 |
+
if (!menuVisible) {
|
| 26 |
+
addButton.css('display', 'none');
|
| 27 |
+
$('#toggle-menu-button').css('width', '30px');
|
| 28 |
+
} else {
|
| 29 |
+
addButton.css('display', 'inline');
|
| 30 |
+
$('#toggle-menu-button').css('width', '180px');
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
$(document).ready(function() {
|
| 34 |
+
|
| 35 |
+
addButton.css('display', 'none');
|
| 36 |
+
$('#menu-button').on('click', function() {
|
| 37 |
+
menuVisible = !menuVisible;
|
| 38 |
+
var leftValue = menuVisible ? '0' : '-150px';
|
| 39 |
+
$('#menu').css('left', leftValue);
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
addButton.on('click', function() {
|
| 43 |
+
inputContainer.show();
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
+
$('#ok-button').on('click', function() {
|
| 47 |
+
var itemName = $('#item-name').val();
|
| 48 |
+
var itemId = $('#item-id').val();
|
| 49 |
+
if (itemName && itemId) {
|
| 50 |
+
var newItem = $('<div class="menu-item" onclick="sendnew(\'' + itemId + '\');">' + itemName + ' (' + itemId + ')</div>');
|
| 51 |
+
$('#menu').append(newItem);
|
| 52 |
+
inputContainer.hide();
|
| 53 |
+
$('#item-name').val('');
|
| 54 |
+
$('#item-id').val('');
|
| 55 |
+
}
|
| 56 |
+
});
|
| 57 |
+
|
| 58 |
+
$('#toggle-menu-button').on('click', function() {
|
| 59 |
+
menuVisible = !menuVisible;
|
| 60 |
+
var leftValue = menuVisible ? '0' : '-150px';
|
| 61 |
+
$('#menu').css('left', leftValue);
|
| 62 |
+
if (!menuVisible) {
|
| 63 |
+
addButton.css('display', 'none');
|
| 64 |
+
$('#toggle-menu-button').css('width', '30px');
|
| 65 |
+
} else {
|
| 66 |
+
addButton.css('display', 'inline');
|
| 67 |
+
$('#toggle-menu-button').css('width', '180px');
|
| 68 |
+
}
|
| 69 |
+
});
|
| 70 |
+
});
|
| 71 |
+
|
| 72 |
+
function formatMessage(message, usid) {
|
| 73 |
+
message = "<" + usid + ">: \n" + message;
|
| 74 |
+
const words = message.split(" ");
|
| 75 |
+
const container = document.createElement("div");
|
| 76 |
+
for (const word of words) {
|
| 77 |
+
const wordNode = document.createTextNode(word + " ");
|
| 78 |
+
|
| 79 |
+
if (word.startsWith("@")) {
|
| 80 |
+
const username = word.substring(1);
|
| 81 |
+
const strongNode = document.createElement("strong");
|
| 82 |
+
strongNode.textContent = "@" + username + " ";
|
| 83 |
+
container.appendChild(strongNode);
|
| 84 |
+
} else if (word.match(/^https?:\/\/[^\s/$.?#].[^\s]*$/i)) {
|
| 85 |
+
const urlNode = document.createElement("a");
|
| 86 |
+
urlNode.href = word;
|
| 87 |
+
urlNode.textContent = word + " ";
|
| 88 |
+
urlNode.target = "_blank";
|
| 89 |
+
container.appendChild(urlNode);
|
| 90 |
+
} else {
|
| 91 |
+
container.appendChild(wordNode);
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return container;
|
| 96 |
+
}
|
| 97 |
+
document.addEventListener("keydown", KeyCheck);
|
| 98 |
+
|
| 99 |
+
function KeyCheck(event) {
|
| 100 |
+
var KeyID = event.keyCode;
|
| 101 |
+
switch (KeyID) {
|
| 102 |
+
case 13:
|
| 103 |
+
var message = $('#message-input').val();
|
| 104 |
+
if (message !== '' && message.startsWith("/change-chat-room") === false) {
|
| 105 |
+
socket.emit('message', {
|
| 106 |
+
data: JSON.stringify({
|
| 107 |
+
message: message,
|
| 108 |
+
usid: uid,
|
| 109 |
+
roomID: roomID,
|
| 110 |
+
cookies: document.cookie
|
| 111 |
+
})
|
| 112 |
+
});
|
| 113 |
+
$('#message-input').val('');
|
| 114 |
+
window.scrollTo(0, document.body.scrollHeight);
|
| 115 |
+
$('#mmsg2').append($('<div class="message-box sent">').text('Moi : \n' + message));
|
| 116 |
+
} else if (message !== '') {
|
| 117 |
+
if (message.endsWith(';')) {
|
| 118 |
+
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
break;
|
| 122 |
+
default:
|
| 123 |
+
break;
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
$('#user-id-input').on('change', function() {
|
| 128 |
+
var userInput = $(this).val();
|
| 129 |
+
if (userInput.endsWith(';')) {
|
| 130 |
+
roomID = userInput;
|
| 131 |
+
socket.emit('message', {
|
| 132 |
+
data: JSON.stringify({
|
| 133 |
+
message: 'Connected!',
|
| 134 |
+
usid: uid,
|
| 135 |
+
roomID: roomID,
|
| 136 |
+
cookies: document.cookie
|
| 137 |
+
})
|
| 138 |
+
});
|
| 139 |
+
}
|
| 140 |
+
});
|
| 141 |
+
|
| 142 |
+
var userIdInput = $('#user-id-input');
|
| 143 |
+
var isScrolling = false;
|
| 144 |
+
var fadeTimeout;
|
| 145 |
+
|
| 146 |
+
function hideUserIdInput() {
|
| 147 |
+
userIdInput.animate({
|
| 148 |
+
opacity: 0.01
|
| 149 |
+
}, 200);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
function showUserIdInput() {
|
| 153 |
+
userIdInput.animate({
|
| 154 |
+
opacity: 0.85
|
| 155 |
+
}, 200);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
$(window).on('scroll', function() {
|
| 159 |
+
if (!isScrolling) {
|
| 160 |
+
showUserIdInput();
|
| 161 |
+
isScrolling = true;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
clearTimeout(fadeTimeout);
|
| 165 |
+
|
| 166 |
+
fadeTimeout = setTimeout(function() {
|
| 167 |
+
hideUserIdInput();
|
| 168 |
+
isScrolling = false;
|
| 169 |
+
}, 300);
|
| 170 |
+
});
|
| 171 |
+
$('#user-id-input').on('click', function() {
|
| 172 |
+
showUserIdInput();
|
| 173 |
+
fadeTimeout = setTimeout(function() {
|
| 174 |
+
hideUserIdInput();
|
| 175 |
+
}, 1000);
|
| 176 |
+
});
|
| 177 |
+
|
| 178 |
+
$('#user-id-input').on('over', function() {
|
| 179 |
+
showUserIdInput();
|
| 180 |
+
fadeTimeout = setTimeout(function() {
|
| 181 |
+
hideUserIdInput();
|
| 182 |
+
}, 200);
|
| 183 |
+
});
|
| 184 |
+
|
| 185 |
+
$(document).ready(function() {
|
| 186 |
+
|
| 187 |
+
socket.on('connect', function() {
|
| 188 |
+
socket.emit('message', {
|
| 189 |
+
data: JSON.stringify({
|
| 190 |
+
message: 'Connected!',
|
| 191 |
+
usid: uid,
|
| 192 |
+
roomID: roomID,
|
| 193 |
+
cookies: document.cookie
|
| 194 |
+
})
|
| 195 |
+
});
|
| 196 |
+
});
|
| 197 |
+
|
| 198 |
+
socket.on('message', function(data) {
|
| 199 |
+
var message = data.data;
|
| 200 |
+
var msg = JSON.parse(message)['message'];
|
| 201 |
+
try {
|
| 202 |
+
if (JSON.parse(message)['message'] != 'Connected!' && JSON.parse(message)['usid'] != uid && JSON.parse(message)['message'].toString() != 'undefined') {
|
| 203 |
+
|
| 204 |
+
var usid = JSON.parse(message)['usid'];
|
| 205 |
+
if(usid === JSON.parse(message)['message']) {
|
| 206 |
+
usid = uid;
|
| 207 |
+
}
|
| 208 |
+
const messageContainer = formatMessage(msg, usid);
|
| 209 |
+
const messageBox = $('<div class="message-box received">');
|
| 210 |
+
messageBox.html('<p>').append(messageContainer);
|
| 211 |
+
$('#mmsg2').append(messageBox);
|
| 212 |
+
if(JSON.parse(message)['stat'] != 'restoreHistory') {
|
| 213 |
+
socket.emit('save', {
|
| 214 |
+
data: JSON.stringify({
|
| 215 |
+
message: usid + ": \n" + msg,
|
| 216 |
+
donotsend: 'true',
|
| 217 |
+
usid: uid,
|
| 218 |
+
cookies: document.cookie.toString(),
|
| 219 |
+
roomID: roomID
|
| 220 |
+
})
|
| 221 |
+
});
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
iid++;
|
| 226 |
+
|
| 227 |
+
}
|
| 228 |
+
} catch {
|
| 229 |
+
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
const imageExtensions = [
|
| 234 |
+
'jpg',
|
| 235 |
+
'jpeg',
|
| 236 |
+
'png',
|
| 237 |
+
'gif',
|
| 238 |
+
'bmp',
|
| 239 |
+
'webp',
|
| 240 |
+
'svg',
|
| 241 |
+
'apng',
|
| 242 |
+
'JPG',
|
| 243 |
+
'JPEG',
|
| 244 |
+
'PNG',
|
| 245 |
+
'GIF',
|
| 246 |
+
'BMP',
|
| 247 |
+
'WEBP',
|
| 248 |
+
'SVG',
|
| 249 |
+
'APNG'
|
| 250 |
+
];
|
| 251 |
+
var usid = JSON.parse(message)['usid'].split(" ")[0].replace("username=", "");
|
| 252 |
+
|
| 253 |
+
if (imageExtensions.includes(JSON.parse(message)['ext']) && usid != uid && JSON.parse(message)['file'].toString() != 'undefined') {
|
| 254 |
+
console.log(usid);
|
| 255 |
+
$('#mmsg2').append($('<div class="message-box received">').html('' + usid + ' : \n<img src="data:image/' + JSON.parse(message)['ext'] + ';base64,' + JSON.parse(message)['file'] + '" width="90%">'));
|
| 256 |
+
}
|
| 257 |
+
var messageContainer = document.getElementById('mmsg2');
|
| 258 |
+
messageContainer.scrollTop = messageContainer.scrollHeight;
|
| 259 |
+
window.scrollTo(0, document.body.scrollHeight);
|
| 260 |
+
});
|
| 261 |
+
|
| 262 |
+
$('#send-button').click(function() {
|
| 263 |
+
var message = $('#message-input').val();
|
| 264 |
+
if (message !== '') {
|
| 265 |
+
socket.emit('message', {
|
| 266 |
+
data: JSON.stringify({
|
| 267 |
+
message: message,
|
| 268 |
+
usid: uid,
|
| 269 |
+
roomID: roomID,
|
| 270 |
+
cookies: document.cookie
|
| 271 |
+
})
|
| 272 |
+
});
|
| 273 |
+
$('#message-input').val('');
|
| 274 |
+
window.scrollTo(0, document.body.scrollHeight);
|
| 275 |
+
$('#mmsg2').append($('<div class="message-box sent">').text('Moi: \n' + message));
|
| 276 |
+
}
|
| 277 |
+
});
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
$('#upload-files').on('change', function() {
|
| 281 |
+
var selectedFile = this.files[0];
|
| 282 |
+
while (this.files[0].toString() === 'undefined') {
|
| 283 |
+
setTimeout(function() {
|
| 284 |
+
console.log('Fin');
|
| 285 |
+
}, 2000);
|
| 286 |
+
}
|
| 287 |
+
if (selectedFile) {
|
| 288 |
+
var reader = new FileReader();
|
| 289 |
+
reader.onload = function(event) {
|
| 290 |
+
var fileContent = event.target.result.split(',')[1];
|
| 291 |
+
var fileExtension = selectedFile.name.split('.').pop();
|
| 292 |
+
var bufs = 1000;
|
| 293 |
+
var mille = fileContent.slice(0, bufs);
|
| 294 |
+
var pos = bufs;
|
| 295 |
+
while (fileContent.length != pos) {
|
| 296 |
+
socket.emit('image', {
|
| 297 |
+
data: JSON.stringify({
|
| 298 |
+
buf: mille,
|
| 299 |
+
ext: fileExtension,
|
| 300 |
+
usid: uid,
|
| 301 |
+
endded: 'false',
|
| 302 |
+
roomID: roomID,
|
| 303 |
+
cookies: document.cookie
|
| 304 |
+
})
|
| 305 |
+
});
|
| 306 |
+
mille = fileContent.slice(pos, pos + bufs);
|
| 307 |
+
pos += mille.length;
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
}
|
| 311 |
+
socket.emit('image', {
|
| 312 |
+
data: JSON.stringify({
|
| 313 |
+
buf: mille,
|
| 314 |
+
ext: fileExtension,
|
| 315 |
+
usid: uid,
|
| 316 |
+
endded: 'false',
|
| 317 |
+
roomID: roomID,
|
| 318 |
+
cookies: document.cookie
|
| 319 |
+
})
|
| 320 |
+
});
|
| 321 |
+
pos = fileContent.length;
|
| 322 |
+
if (fileContent != 'undefined') {
|
| 323 |
+
try {
|
| 324 |
+
$('#mmsg2').append($('<div class="message-box sent">').html('Moi: ' + '<img src="data:image/' + fileExtension + ';base64,' + fileContent + '" width="90%">'));
|
| 325 |
+
var messageContainer = document.getElementById('mmsg2');
|
| 326 |
+
messageContainer.scrollTop = messageContainer.scrollHeight;
|
| 327 |
+
window.scrollTo(0, document.body.scrollHeight);
|
| 328 |
+
} catch (error) {
|
| 329 |
+
console.log(error);
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
}
|
| 333 |
+
socket.emit('image', {
|
| 334 |
+
data: JSON.stringify({
|
| 335 |
+
buf: '',
|
| 336 |
+
ext: fileExtension,
|
| 337 |
+
usid: uid,
|
| 338 |
+
endded: 'true',
|
| 339 |
+
type: fileExtension,
|
| 340 |
+
roomID: roomID,
|
| 341 |
+
cookies: document.cookie
|
| 342 |
+
})
|
| 343 |
+
});
|
| 344 |
+
$('#upload-files').val('');
|
| 345 |
+
window.scrollTo(0, document.body.scrollHeight);
|
| 346 |
+
};
|
| 347 |
+
reader.readAsDataURL(selectedFile);
|
| 348 |
+
$('#mmsg2').append($('<div class="message-box sent">').text("Fichier en cours d'envoie..."));
|
| 349 |
+
}
|
| 350 |
+
});
|
| 351 |
+
});
|