0.2.1 • Published 8 months ago

@phantasweng/vue-echo v0.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Intro

Vue Laravel Echo - Simply import Laravel Echo to Vue instance

Install

yarn add @phantasweng/vue-echo

or

npm install @phantasweng/vue-echo

main.js

import VueEcho from '@/plugins/vue-echo'

Vue.use(VueEcho, {
  broadcaster: 'pusher',
  key: process.env.VUE_APP_ECHO_KEY,
  wsHost: process.env.VUE_APP_ECHO_HOST,
  wsPort: process.env.VUE_APP_ECHO_PORT,
  forceTLS: false,
  disableStats: true,
  authEndpoint: process.env.VUE_APP_ECHO_AUTH,
  auth: { headers: { Authorization: 'Bearer ' + Cookies.get('my_access_token') } }
}, store)

Usage

In instance

this.$echo.join(channelName, { isPrivate: true })
this.$echo.subscribe(channelName, eventName, (e) => {...})
this.$echo.unsubscribe(channelName, eventName)

In router

import { Echo } from '@/plugins/vue-echo'

Echo.join(channelName, { isPrivate: true })

Echo.subscribe(channelName, eventName, (e) => {...})
Echo.unsubscribe(channelName, eventName)

In Vuex

import { Echo } from '@/plugins/vue-echo'
Echo.join(...)

// OR

this._vm.$echo.join(...)

API

NameDescription
join加入 Channelfunction (channelName, { isPrivate })
leave離開 Channelfunction (channelName)
subscribe訂閱 Eventfunction (channelName, eventName, callback)
unsubscribe取消訂閱 Eventfunction (channelName, eventName)
getChannels取得已加入 Channelsfunction
getEvents取得已訂閱 Eventsfunction 取得全部 OR function (channelName) 取得特定 Channel
onChangeChannel, Event 變動傳入 function,當變動時執行 Hook
0.2.1

8 months ago

0.2.0

1 year ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago