Chat updates (#92)

* Send PONG responses to PINGs

* Split out client IDs for viewer counts vs. websocket IDs

* WIP username change event

* Display username changes

* Revert commented out code

* Add support for building from the current branch

* Fix PONG

* Make username changes have a unique ID

* Add a version param to js to cachebust
This commit is contained in:
Gabe Kangas
2020-07-28 21:30:03 -07:00
committed by GitHub
parent 87636a4183
commit d9509f5606
9 changed files with 161 additions and 47 deletions

View File

@@ -142,6 +142,7 @@ class MessagingInterface {
}
handleUpdateUsername() {
const oldName = this.username;
var newValue = this.inputChangeUserName.value;
newValue = newValue.trim();
// do other string cleanup?
@@ -154,6 +155,10 @@ class MessagingInterface {
setLocalStorage(KEY_AVATAR, this.imgUsernameAvatar.src);
}
this.handleHideChangeNameForm();
if (oldName !== newValue) {
this.sendUsernameChange(oldName, newValue, this.imgUsernameAvatar.src);
}
}
handleUsernameKeydown(event) {
@@ -164,6 +169,19 @@ class MessagingInterface {
}
}
sendUsernameChange(oldName, newName, image) {
const nameChange = {
type: SOCKET_MESSAGE_TYPES.NAME_CHANGE,
oldName: oldName,
newName: newName,
image: image,
};
const jsonMessage = JSON.stringify(nameChange);
this.websocket.send(jsonMessage)
}
handleMessageInputKeydown(event) {
var okCodes = [37,38,39,40,16,91,18,46,8];
var value = this.formMessageInput.value.trim();
@@ -213,6 +231,7 @@ class MessagingInterface {
body: content,
author: this.username,
image: this.imgUsernameAvatar.src,
type: SOCKET_MESSAGE_TYPES.CHAT,
});
const messageJSON = JSON.stringify(message);
if (this.websocket) {