Skip to content

Commit

Permalink
Still working on the chat.
Browse files Browse the repository at this point in the history
  • Loading branch information
RakhithaRR committed Mar 12, 2018
1 parent cbbe6d7 commit 491468c
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 72 deletions.
92 changes: 53 additions & 39 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 39 additions & 25 deletions Client/src/components/Projects/ViewProjects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,19 @@
>
<div>
<v-list two-line>
<template v-for="(item, index) in messages">
<v-list-tile
:key="index"
>
<v-list-tile-content>
<v-list-tile-title>{{ item.username }}</v-list-tile-title>
<v-list-tile-sub-title class="text--primary">{{ item.headline }}</v-list-tile-sub-title>
<v-list-tile-sub-title>{{ item.text }}</v-list-tile-sub-title>
</v-list-tile-content>
<v-list-tile-action>
<v-list-tile-action-text>{{ }}</v-list-tile-action-text>
</v-list-tile-action>
</v-list-tile>
<v-divider v-if="index + 1 < messages.length" :key="index"></v-divider>
</template>
<v-list-tile
v-for="(item,index) in messages"
:key="`${index}`"
>
<v-list-tile-content>
<v-list-tile-title>{{index}} - {{ item.username }}</v-list-tile-title>
<v-list-tile-sub-title class="text--primary">{{ item.headline }}</v-list-tile-sub-title>
<v-list-tile-sub-title>{{ item.text }}</v-list-tile-sub-title>
</v-list-tile-content>
<v-list-tile-action>
<v-list-tile-action-text>{{(new Date()).toDateString()}}</v-list-tile-action-text>
</v-list-tile-action>
</v-list-tile>
</v-list>
</div>
</v-container>
Expand All @@ -195,7 +193,7 @@
<v-flex md1>
<div class="text-xs-right">
<v-btn
@click="startConnection"
@click="sendMessage"
>Send</v-btn>
</div>
</v-flex>
Expand All @@ -210,6 +208,7 @@
<script>
import axios from 'axios';
import io from 'socket.io-client';
const socket = io.connect('http://localhost:3000');
export default {
Expand All @@ -223,7 +222,7 @@
events: [],
textMessage: '',
messages: []
messages: [{username: 'System', text: 'Project created.'}]
}
},
Expand Down Expand Up @@ -312,26 +311,41 @@
}
},
startConnection() {
const socket = io('http://localhost:3000');
socket.emit('my other event', {username: this.cUser.Username, text: this.textMessage});
socket.on('hello', (data) => {
console.log(data.messages[0]);
this.messages.push(data.messages[0]);
});
sendMessage() {
console.log("CLICKED");
socket.emit('chat', {username: this.cUser.Name, text: this.textMessage});
}
},
mounted() {
this.getProject();
this.startConnection();
// this.startConnection();
},
computed: {
receiveMessage(){
socket.on('chat', (data) => {
console.log(data);
console.log(this.messages);
this.messages.push(data);
return this.messages
// console.log(data.messages);
// for(var i in data.messages){
// if(data.messages.hasOwnProperty(i)){
// var obj = data.messages[i]
// this.messages.push(obj)
// }
// }
});
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions Server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ const io = socketIO(server);

//socket.io connection
io.on('connection', (socket) => {
var projRef = firebase.database.ref('/messages');
projRef.once("value", (snapshot) => {
socket.emit('hello', {
messages: snapshot.val()
})
// var projRef = firebase.database.ref('/messages');
// projRef.once("value", (snapshot) => {
// socket.emit('hello', {
// messages: snapshot.val()
// })
// });
socket.on('chat', (msg) => {
console.log(msg)
io.emit('chat', msg)
});

socket.on('my other event', function (data) {
console.log(data);
});
// socket.on('my other event', function (data) {
// console.log(data);
// });
});

//routes
Expand Down

0 comments on commit 491468c

Please sign in to comment.