Skip to content

Commit

Permalink
Further improvements on sockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
RakhithaRR committed Mar 10, 2018
1 parent 0627d86 commit cbbe6d7
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 54 deletions.
67 changes: 34 additions & 33 deletions .idea/workspace.xml

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

34 changes: 22 additions & 12 deletions Client/src/components/Projects/ViewProjects.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,15 @@
<v-list two-line>
<template v-for="(item, index) in messages">
<v-list-tile
@click="toggle(index)"
:key="item.title"
:key="index"
>
<v-list-tile-content>
<v-list-tile-title>{{ item.title }}</v-list-tile-title>
<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.subtitle }}</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>{{ item.action }}</v-list-tile-action-text>
<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>
Expand All @@ -189,12 +188,15 @@
<div class="layout row">
<v-flex md11>
<v-text-field
v-model="textMessage"
label="Enter your message here"
></v-text-field>
</v-flex>
<v-flex md1>
<div class="text-xs-right">
<v-btn>Send</v-btn>
<v-btn
@click="startConnection"
>Send</v-btn>
</div>
</v-flex>
</div>
Expand All @@ -220,6 +222,7 @@
date1: new Date(Date.now()).toISOString().slice(0, 10),
events: [],
textMessage: '',
messages: []
}
Expand Down Expand Up @@ -307,22 +310,29 @@
this.events.push(obj.deadline);
}
}
},
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]);
});
}
},
mounted() {
this.getProject();
const socket = io('http://localhost:3000');
socket.on('hello', (data) => {
console.log(data);
socket.emit('my other event', {my: 'data'})
});
this.startConnection();
},
computed: {}
computed: {
}
}
</script>
Expand Down
22 changes: 13 additions & 9 deletions Server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ app.use(bodyParser.json());
const io = socketIO(server);

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

socket.on('my other event', function (data) {
console.log(data);
});
Expand All @@ -33,22 +37,22 @@ io.on('connection',(socket)=>{
const users = require('./routes/user');
const project = require('./routes/project');

app.use('/users',users);
app.use('/users', users);
app.use('/project', project);


app.get('/',(req,res) => {
app.get('/', (req, res) => {
res.send("Invalid Endpoint");
});


//firebase connection check
var fireConnection = firebase.database.ref('.info/connected');
fireConnection.on("value", (con) =>{
if(con.val() === true){
fireConnection.on("value", (con) => {
if (con.val() === true) {
console.log("Connected to Firebase...");
}
else{
else {
console.log("Not connected to Firebase!");
}
});
Expand Down

0 comments on commit cbbe6d7

Please sign in to comment.