|
| 1 | +(function (exports, LaravelEcho) { |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } |
| 5 | + |
| 6 | + var LaravelEcho__default = /*#__PURE__*/_interopDefaultLegacy(LaravelEcho); |
| 7 | + |
| 8 | + function getChannel(channels, channelName) { |
| 9 | + const target = Object.keys(channels).find(channel => channels[channel].name.replace('private-', '') === channelName); |
| 10 | + return channels[target]; |
| 11 | + } |
| 12 | + |
| 13 | + function join(channelName, options) { |
| 14 | + const { |
| 15 | + isPrivate |
| 16 | + } = options; |
| 17 | + console.debug('[Echo] joinChannel -', isPrivate ? 'private-' + channelName : channelName); |
| 18 | + isPrivate ? this.private(channelName) : this.channel(channelName); |
| 19 | + } |
| 20 | + function leave(channelName) { |
| 21 | + const targetChannel = getChannel(this.connector.channels, channelName); |
| 22 | + console.debug('[Echo] leaveChannel -', targetChannel.name); |
| 23 | + this.leave(channelName); |
| 24 | + } |
| 25 | + function subscribe(channelName, eventName, callback) { |
| 26 | + const targetChannel = getChannel(this.connector.channels, channelName); |
| 27 | + targetChannel.listen(eventName, res => { |
| 28 | + if (callback) callback(res); |
| 29 | + }); |
| 30 | + console.debug('[Echo] subscribeEvent -', targetChannel.name, eventName); |
| 31 | + } |
| 32 | + function unsubscribe(channelName, eventName) { |
| 33 | + const targetChannel = getChannel(this.connector.channels, channelName); |
| 34 | + targetChannel.stopListening(eventName); |
| 35 | + console.debug('[Echo] unsubscribeEvent -', targetChannel.name, eventName); |
| 36 | + } |
| 37 | + function getChannels() { |
| 38 | + return this.connector.channels; |
| 39 | + } |
| 40 | + function getEvents(channelName) { |
| 41 | + const channel = Object.keys(this.connector.channels).find(key => key.includes(channelName)); |
| 42 | + |
| 43 | + if (channel) { |
| 44 | + return this.connector.channels[channel].subscription.callbacks._callbacks; |
| 45 | + } else { |
| 46 | + const channels = this.connector.channels; |
| 47 | + let events = {}; |
| 48 | + |
| 49 | + for (const channel of Object.keys(channels)) { |
| 50 | + events = { ...events, |
| 51 | + ...channels[channel].subscription.callbacks._callbacks |
| 52 | + }; |
| 53 | + } |
| 54 | + |
| 55 | + return events; |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + window.Pusher = require('pusher-js'); |
| 60 | + const defaultOptions = { |
| 61 | + broadcaster: 'pusher', |
| 62 | + forceTLS: true |
| 63 | + }; |
| 64 | + exports.Echo = void 0; |
| 65 | + const Plugin = { |
| 66 | + install(Vue, options = {}, store) { |
| 67 | + if (this.installed) { |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + this.installed = true; |
| 72 | + const config = Vue.util.mergeOptions(defaultOptions, options || {}); |
| 73 | + const laravelEcho = new LaravelEcho__default['default'](config); |
| 74 | + Vue.prototype.$echo = exports.Echo = { ...laravelEcho |
| 75 | + }; |
| 76 | + Object.setPrototypeOf(exports.Echo, { |
| 77 | + join: join.bind(laravelEcho), |
| 78 | + leave: leave.bind(laravelEcho), |
| 79 | + subscribe: subscribe.bind(laravelEcho), |
| 80 | + unsubscribe: unsubscribe.bind(laravelEcho), |
| 81 | + getChannels: getChannels.bind(laravelEcho), |
| 82 | + getEvents: getEvents.bind(laravelEcho) |
| 83 | + }); |
| 84 | + Vue.mixin({ |
| 85 | + mounted() {} |
| 86 | + |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + }; // This exports the plugin object. |
| 91 | + |
| 92 | + exports.default = Plugin; |
| 93 | + |
| 94 | + Object.defineProperty(exports, '__esModule', { value: true }); |
| 95 | + |
| 96 | + return exports; |
| 97 | + |
| 98 | +}({}, LaravelEcho)); |
0 commit comments