Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomi Eluwande committed Jul 7, 2017
1 parent 44e444e commit 824f8be
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 283 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'no-unneeded-ternary': 0
}
}
15 changes: 2 additions & 13 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const bodyParser = require("body-parser");
const app = express();
const Pusher = require('pusher');
const crypto = require("crypto");

const pusher = new Pusher({
appId: '351311',
Expand Down Expand Up @@ -31,18 +32,6 @@ app.use( (req, res, next) => {

app.set('port', (process.env.PORT || 5000));

function generateUUID () {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}

let user_id = generateUUID()

app.get('/', (req,res) => {
res.send('Welcome')
})
Expand All @@ -51,7 +40,7 @@ app.post('/pusher/auth', (req, res) => {
let socketId = req.body.socket_id;
let channel = req.body.channel_name;
let presenceData = {
user_id: user_id
user_id: crypto.randomBytes(16).toString("hex")
};
let auth = pusher.authenticate(socketId, channel, presenceData);
res.send(auth);
Expand Down
27 changes: 27 additions & 0 deletions src/components/ChannelDetails.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script>
import Pusher from 'pusher-js'
const pusher = new Pusher('26b7d8fa6aa64488853b', {
cluster: 'eu',
encrypted: true,
authEndpoint: 'http://localhost:5000/pusher/auth'
})
export default ({
getPresenceID () {
let getQueryString = (field, url) => {
let href = url ? url : window.location.href
let reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i')
let string = reg.exec(href)
return string ? string[1] : null
}
let id = getQueryString('id')
id = 'presence-' + id
return id
},
subscribeToPusher () {
let presenceid = this.getPresenceID()
let channel = pusher.subscribe(presenceid)
return channel
}
})
</script>
Loading

0 comments on commit 824f8be

Please sign in to comment.