Skip to content
Permalink
cd8dac4a30
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
68 lines (46 sloc) 1.68 KB
// Register a service worker, this one located in serviceworker.js
// A service worker is a piece of code the browser runs behind the scenes.
if ('serviceWorker' in navigator) {
console.log('CLIENT: service worker registration in progress.');
navigator.serviceWorker.register('sw.js').then(function() {
console.log('CLIENT: service worker registration complete.');
}, function() {
console.log('CLIENT: service worker registration failure.');
});
} else {
console.log('CLIENT: service workers are not supported.');
}
var sampleMessage = {
sentBy:"Meira",
dateStamp:"02/20/2020 at 2:50",
text:"Hello,this is a message."
}
let allMessages = [];
let chatBox = document.querySelector("#chatBox")
allMessages.push(sampleMessage);
console.log(allMessages);
function makeAndDisplaymMessage(sender,dateStamp,text){
var newMessage = {
sentBy: sender,
dateStamp: dateStamp,
text:text
}
//display message
var newMsgP = document.createElement("p");
newMsgP.innerText = sender + ": " + text;
chatBox.appendChild(newMsgP);
allMessages.push(newMessage);
console.log(allMessages);
}
document.querySelector("#sendBtn").addEventListener('click', function(){
makeAndDisplaymMessage("me","now", document.querySelector("#newMsg").value);
document.querySelector("#newMsg").value = "";
document.querySelector("#newMsg").focus();
let src = 'img/soothing_flute.mp3';
let audio = new Audio(src);
audio.play();
window.navigator.vibrate(200);
let curr_date = new Date();
let month = curr_date.getMonth() + 1;
let date_str = month.toString() + "/" + curr_date.getDate().toString() + "/" + curr_date.getFullYear().toString();
});