Created
April 3, 2018 23:18
-
-
Save yomete/f5cad6ec8881109a32727a1d2c70a1a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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