Skip to content

Commit

Permalink
fix: pass UTC time in chat msgs
Browse files Browse the repository at this point in the history
Resolves #363
  • Loading branch information
hi-liang committed Feb 16, 2022
1 parent 0f08157 commit 651d859
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export class ARENAChat {
jitsiStatsCallback = (e) => {
const id = e.detail.id;
const stats = e.detail.stats;
//console.log('jitsiStatsCallback', id, stats);
// console.log('jitsiStatsCallback', id, stats);
if (id === this.settings.userid) {
this.settings.stats = stats;
}
Expand Down Expand Up @@ -622,14 +622,16 @@ export class ARENAChat {
* @param {*} msgTxt The message text.
*/
sendMsg(msgTxt) {
const now = new Date();
const msg = {
object_id: uuidv4(),
type: 'chat',
to_uid: this.toSel.value,
from_uid: this.settings.userid,
from_un: this.settings.username,
from_scene: this.settings.scene,
from_desc: `${decodeURI(this.settings.username)} (${this.toSel.options[this.toSel.selectedIndex].text}) ${new Date().toLocaleTimeString()}`,
from_desc: `${decodeURI(this.settings.username)} (${this.toSel.options[this.toSel.selectedIndex].text})`,
from_time: now.toJSON(),
cameraid: this.settings.cameraid,
text: msgTxt,
};
Expand All @@ -639,7 +641,7 @@ export class ARENAChat {
this.settings.publishPrivateTopic.replace('{to_uid}', this.toSel.value);
// console.log("sending", msg, "to", dstTopic);
this.mqttc.send(dstTopic, JSON.stringify(msg), 0, false);
this.txtAddMsg(msg.text, msg.from_desc, 'self');
this.txtAddMsg(msg.text, msg.from_desc + ' ' + now.toLocaleTimeString(), 'self');
}

/**
Expand Down Expand Up @@ -725,13 +727,13 @@ export class ARENAChat {
// drop messages to scenes different from our scene
if (msg.to_uid === 'scene' && msg.from_scene != this.settings.scene) return;

this.txtAddMsg(msg.text, msg.from_desc, 'other');
this.txtAddMsg(msg.text, msg.from_desc + ' ' + new Date(msg.from_time).toLocaleTimeString(), 'other');

this.unreadMsgs++;
this.chatDot.textContent = this.unreadMsgs < 100 ? this.unreadMsgs : '...';

// check if chat is visible
if (this.chatPopup.style.display == 'none') {
if (this.chatPopup.style.display === 'none') {
const msgText = (msg.text.length > 15) ? msg.text.substring(0, 15) + '...' : msg.text;
this.displayAlert(`New message from ${msg.from_un}: ${msgText}.`, 3000);
this.chatDot.style.display = 'block';
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ import './aframe-mods/'; // AFRAME modifications
import './systems/'; // custom AFRAME systems
import './components/'; // custom AFRAME components
import './webxr/'; // spedial handler for webxr devices

0 comments on commit 651d859

Please sign in to comment.