Skip to content

Instantly share code, notes, and snippets.

@yomete
Created April 3, 2018 23:18
Show Gist options
  • Save yomete/f5cad6ec8881109a32727a1d2c70a1a2 to your computer and use it in GitHub Desktop.
Save yomete/f5cad6ec8881109a32727a1d2c70a1a2 to your computer and use it in GitHub Desktop.
<script>
import Pusher from 'pusher-js'
const pusher = new Pusher('APP_KEY', {
cluster: 'YOUR_CLUSTER',
encrypted: true,
authEndpoint: 'http://localhost:5000/pusher/auth'
})
export default ({
getPresenceID () {
// This function checks the address bar of the browser for params
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
}
// Appends 'presence' to the result
let id = getQueryString('id')
id = 'presence-' + id
return id
},
subscribeToPusher () {
let presenceid = this.getPresenceID()
let channel = pusher.subscribe(presenceid)
return channel
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment