Skip to content

Commit

Permalink
Active users working
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaydixit20 authored Jul 6, 2020
1 parent ff79fd2 commit d62ec24
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ io.on('connection', socket => {

socket.on('switch_room', (room) => {
const oldRoom = currentUser(socket.id).room;
console.log(oldRoom);
const u = userSwitch(socket.id, room);
socket.leaveAll();
socket.join(u.room);
Expand Down
45 changes: 44 additions & 1 deletion public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const url = require('url');
const { app, BrowserWindow, ipcMain } = electron;
const isDev = require('electron-is-dev');
const { Menu, globalShortcut } = require('electron');

let mainWindow;

Expand All @@ -16,6 +17,10 @@ function createWindow() {
});
mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, 'index.html')}`);
mainWindow.on('closed', () => mainWindow = null);
globalShortcut.register('CmdOrCtrl+Q', () => app.quit());

const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
}

ipcMain.on('userLogin', (e, user) => {
Expand All @@ -36,4 +41,42 @@ app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
});

const menuTemplate = [
{
label: 'Chat',
submenu: [
{
label: 'Quit',
click() {
app.quit();
}
},
{
type: 'separator'
},
{
role: 'reload'
}
]
}
]

if(isDev) {
menuTemplate.push({
label: 'DevTools',
submenu: [
{
label: 'DevTools',
click(item, focusedWindow) {
focusedWindow.toggleDevTools();
}
}
]
})
}

if(process.platform == 'darwin') {
menuTemplate.unshift();
}
11 changes: 0 additions & 11 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ <h1>ChatApp</h1>
required
/>
</div>
<!-- <div class="form-control">
<label for="room">Room</label>
<select name="room" id="room">
<option value="JavaScript">JavaScript</option>
<option value="Python">Python</option>
<option value="PHP">PHP</option>
<option value="C#">C#</option>
<option value="Ruby">Ruby</option>
<option value="Java">Java</option>
</select>
</div> -->
<button type="submit" class="btn">Join Chat</button>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ register.addEventListener('submit', (e) => {
}
console.log(regUser);
axios.post('http://localhost:3000/user/register', regUser)
.then(res => alert(res.data));
.then(res => console.log(res.data));

e.target.elements.username.value = '';
e.target.elements.password.value = '';
Expand Down
4 changes: 3 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const socket = io(); //new connection
const electron = require('electron');
const moment = require('moment');
const { ipcRenderer } = electron;
const chatForm = document.getElementById('chat-form');
const chatMessages = document.querySelector('.chat-messages');
Expand Down Expand Up @@ -35,7 +36,7 @@ socket.on('loadMsgs', user => {
const message = {
username: msg.from,
text: msg.body,
time: 0
time: moment(msg.updatedAt).format('DD-MM h:mm a')
}
outputMessage(message);
})
Expand All @@ -49,6 +50,7 @@ roomList.addEventListener('click', (e) => {
console.log(e.target.innerHTML);
const room = e.target.innerHTML;
if(room !== currentRoom) {

currentRoom = room;

socket.emit('switch_room', room);
Expand Down

0 comments on commit d62ec24

Please sign in to comment.