pusher-plugin

0.0.5 • Public • Published

##Vue Pusher Plugin

Simple plugin for managing channels and events within vue utilising pusher-js

##Usage

Import as plugin in your main.js file

//main.js
import Vue from 'vue'
import Pusher from 'pusher-plugin'

Vue.use(Pusher, {
    pusherKey: "yourPublicPusherKey", 
    forceTLS: true, 
    cluster: "eu"
})

Use available methods in components

  • subscribeToPusherChannel(channel)
  • unsubscribeFromPusherChannel(channel)
  • bindEventToPusherChannel(channel, event, callback)
  • unbindEventFromPusherChannel(channel, event, callback = false)
//Hello.vue
<template>
    {{pusherData}}
</template>
<script>
export default {
    data: () => ({
        pusherData: {}
    }),
    created () {
      const vm = this
      vm.subscribeToPusherChannel('test_channel')
      vm.bindEventToPusherChannel('test_event', (data) => {
        vm.pusherData = data
      })
    },
    destroyed () {
      const vm = this
      vm.unbindEventFromPusherChannel('test_event')
      vm.unsubscribeFromPusherChannel('test_channel')
    }
}
</script>

Readme

Keywords

Package Sidebar

Install

npm i pusher-plugin

Weekly Downloads

1

Version

0.0.5

License

MIT

Unpacked Size

88.4 kB

Total Files

9

Last publish

Collaborators

  • ajanes93