-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
86 lines (72 loc) · 2.32 KB
/
js.js
File metadata and controls
86 lines (72 loc) · 2.32 KB
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
/*
===================================
ASSIGNMENT
===================================
1. remove all useless comments (old code, obvious comments)
2. remove all useless console(log)s - the more you log, the less your logs mean.
3. go through and make fixes in accordance with my comments in the file
4. fix (listen, myEmitter) functions to send and listen to events on our websocket
5. to get an idea if your code is working, expect to see your own event logged in console
when clicking the button
*/
user = {
userName: 'hi',
password: 'he',
imgUrl: 'https://new.com'
}
let locStorage = window.localStorage;
function saveUserProperty(property) {
user[property] = property;
}
function authenticate() {
console.log('authenticated')
return true
}
// form submittion event will save all input values in local storage and pass them to user object
document.addEventListener("submit", () => {
//get all input elements
const inputs = document.getElementsByTagName("input");
//authenticate
authenticate();
//save each input to the corresponding property
for (const input of inputs) {
saveUserProperty(input.value);
}
//save all input user data to localstorage for future use
locStorage.setItem("username", (user.userName));
locStorage.setItem("isAuthenticated", (true));
locStorage.setItem("imgUrl", (user.imgUrl));
const form = document.getElementById("login");
form.hidden = true
createButton();
login()
})
function createButton() {
const newButton = document.getElementById('emitter')
newButton.innerHTML = `<button id="emitter">Click Here to Emit</button>`
newButton.addEventListener('click', () => {
emitButton();
})
}
function login(){
console.log("hello")
// const spotIMServer = "https://spotim-demo-chat-server.herokuapp.com"
// const socket = io.connect(spotIMServer);
// const room = "/spotim/chat";
// socket.on('connect',room,()=>{
// console.log('hello')
// })
}
function emitButton() {
socket.emit('message',room,(data)=>{
console.log(data)
})}
function sendMessage(){
emissionObject ={
currentName:user.userName,
currentImg:user.imgUrl,
date:new Date().getTime,
message:"hello world"
}
socket.emit(emissionObject)
}