├── .npmignore ├── .gitignore ├── example ├── assets │ └── logo.png ├── main.js ├── components │ └── MyComponent.vue └── App.vue ├── .babelrc ├── index.html ├── docker-compose.yml ├── LICENSE ├── Dockerfile ├── package.json ├── webpack.dev.config.js ├── README.md ├── webpack.build.config.js ├── src ├── index.js └── WebSocketBridge.js └── dist ├── vue-django-channels.js └── vue-django-channels.js.map /.npmignore: -------------------------------------------------------------------------------- 1 | build 2 | docs 3 | example 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | npm-debug.log 4 | yarn-error.log 5 | .idea/ 6 | -------------------------------------------------------------------------------- /example/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imoontech/vue-django-channels/HEAD/example/assets/logo.png -------------------------------------------------------------------------------- /example/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | new Vue({ 5 | el: '#app', 6 | render: h => h(App) 7 | }) 8 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "stage-1", 4 | ["latest", { 5 | "es2015": { "modules": false } 6 | }] 7 | ], 8 | "plugins": [ 9 | "transform-object-assign" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | vue-django-channels 6 | 7 | 8 |
9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | node: 5 | build: 6 | context: . 7 | dockerfile: ./Dockerfile 8 | image: vue-django-channels/node 9 | command: yarn run dev 10 | ports: 11 | - "8181:8181" 12 | volumes: 13 | - ./:/code/ 14 | - node-modules:/code/node_modules 15 | 16 | yarn: 17 | image: vue-django-channels/node 18 | command: yarn 19 | volumes: 20 | - ./:/code/ 21 | - node-modules:/code/node_modules 22 | - yarn-cache:/root/yarn-cache 23 | 24 | volumes: 25 | node-modules: 26 | driver: local 27 | yarn-cache: 28 | driver: local 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 imoontech 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:6 2 | 3 | # this method installs but requires a new shell to use it - not sure how to do that with docker 4 | #RUN curl -o- -L https://yarnpkg.com/install.sh | bash 5 | 6 | RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 7 | RUN echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list 8 | RUN apt-get update && apt-get install -y yarn net-tools 9 | 10 | RUN mkdir -p /code 11 | WORKDIR /code 12 | ADD ./package.json package.json 13 | 14 | # set the location of yarn-cache so we can mount it as a volume in docker-compose to benefit from yarn's caching 15 | # an to prevent having to rebuild this image 16 | RUN yarn config set cache-folder /root/yarn-cache 17 | 18 | # do all new package installs and updates from the yarn container with "docker-compose run yarn" 19 | # we don't want to run yarn here because it makes the image larger than necessary and any change to package.json would rebuild the image 20 | # to prevent this we mount yarn-cache as a docker-compose volume and use yarn.lock to take advantage of all that yarn has to offer 21 | # this means you have to run "docker-compose run yarn" before running "docker-compose up" for the first time 22 | # RUN yarn 23 | 24 | ENV DOCKER 1 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-django-channels", 3 | "description": "Django Channels WebSocketBridge handler for Vue.js", 4 | "version": "0.2.1", 5 | "homepage": "dist/index.js", 6 | "main": "dist/vue-django-channels.js", 7 | "author": "Steven Moon @stvnmoon", 8 | "license": "MIT", 9 | "scripts": { 10 | "dev": "cross-env NODE_ENV=development webpack-dev-server --config webpack.dev.config.js --hot --host 0.0.0.0 --port 8181", 11 | "build": "cross-env NODE_ENV=production webpack --config webpack.build.config.js --progress --hide-modules" 12 | }, 13 | "keywords": [ 14 | "vue", 15 | "django", 16 | "django-channels", 17 | "channels", 18 | "websocket" 19 | ], 20 | "repository": { 21 | "type": "git", 22 | "url": "https://github.com/imoontech/vue-django-channels.git" 23 | }, 24 | "files": [ 25 | "dist", 26 | "src" 27 | ], 28 | "dependencies": { 29 | "vue": "^2.2.1", 30 | "reconnecting-websocket": "^3.0.3" 31 | }, 32 | "devDependencies": { 33 | "babel-core": "^6.0.0", 34 | "babel-loader": "^6.0.0", 35 | "babel-preset-latest": "^6.0.0", 36 | "babel-preset-stage-0": "^6.16.0", 37 | "babel-plugin-transform-object-assign": "^6.8.0", 38 | "cross-env": "^3.0.0", 39 | "css-loader": "^0.25.0", 40 | "file-loader": "^0.9.0", 41 | "node-sass": "^4.5.1", 42 | "sass-loader": "^6.0.3", 43 | "vue-loader": "^11.1.4", 44 | "vue-style-loader": "^2.0.0", 45 | "vue-template-compiler": "^2.2.1", 46 | "webpack": "^2.2.0", 47 | "webpack-dev-server": "^2.2.0", 48 | "vue": "^2.2.1" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /webpack.dev.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var webpack = require('webpack') 3 | 4 | module.exports = { 5 | entry: './example/main.js', 6 | output: { 7 | path: path.resolve(__dirname, './dist'), 8 | publicPath: '/dist/', 9 | filename: 'index.js' 10 | }, 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.vue$/, 15 | loader: 'vue-loader', 16 | options: { 17 | loaders: { 18 | // Since sass-loader (weirdly) has SCSS as its default parse mode, we map 19 | // the "scss" and "sass" values for the lang attribute to the right configs here. 20 | // other preprocessors should work out of the box, no loader config like this necessary. 21 | 'scss': 'vue-style-loader!css-loader!sass-loader', 22 | 'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax' 23 | } 24 | // other vue-loader options go here 25 | } 26 | }, 27 | { 28 | test: /\.js$/, 29 | loader: 'babel-loader', 30 | exclude: /node_modules/ 31 | }, 32 | { 33 | test: /\.(png|jpg|gif|svg)$/, 34 | loader: 'file-loader', 35 | options: { 36 | name: '[name].[ext]?[hash]' 37 | } 38 | } 39 | ] 40 | }, 41 | resolve: { 42 | alias: { 43 | 'vue$': 'vue/dist/vue.esm.js' 44 | } 45 | }, 46 | devServer: { 47 | historyApiFallback: true, 48 | noInfo: true, 49 | // this is required when running in a docker env on a windows host for hot reloading to work 50 | watchOptions: { 51 | aggregateTimeout: 300, 52 | poll: 1000 53 | } 54 | }, 55 | performance: { 56 | hints: false 57 | }, 58 | devtool: '#eval-source-map' 59 | } 60 | -------------------------------------------------------------------------------- /example/components/MyComponent.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 53 | 54 | 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WIP 2 | Please do not use at this time 3 | 4 | # vue-django-channels 5 | 6 | > Django Channels WebSocketBridge handler for Vue.js 7 | 8 | Based on [vue-websocket](https://github.com/icebob/vue-websocket), a socket.io implementation for vue 9 | 10 | Scaffold generated with [vue-cli](https://github.com/vuejs/vue-cli) [webpack-simple](https://github.com/vuejs-templates/webpack-simple) template. 11 | 12 | I develop on Windows 10 so I do pretty much all of my development using Docker. 13 | 14 | ## Setup 15 | 16 | ##### ports 17 | This project uses 8181 for the dev-server port. I did this because the default 8080 confilcts with my primary dev 18 | configuration and just remapping in the compose file does not work because of CORS. 19 | 20 | To change the port, these files need updated with the port of your choosing: 21 | 22 | `package.json` 23 | ```json 24 | "dev": "cross-env NODE_ENV=development webpack-dev-server --hot --host 0.0.0.0 --port 8181", 25 | ``` 26 | `docker-compose.yml` 27 | ```yaml 28 | ports: 29 | - "8181:8181" 30 | ``` 31 | 32 | ##### build docker images 33 | ```commandline 34 | docker-compose build 35 | ``` 36 | ##### install node dependencies 37 | > see `Dockerfile` for why this is done here 38 | ```commandline 39 | docker-compose run yarn 40 | ``` 41 | For some reason, running yarn this way causes npm to fail to run the node-sass install script properly resulting in this error 42 | `ENOENT: no such file or directory, scandir '/code/node_modules/node-sass/vendor'`. 43 | This seems to happen every time I run yarn to update with new packages. This may be something with my current config so you may not get this error. 44 | 45 | To fix this, run bash in a yarn container and run the `install.js` script: 46 | ```bash 47 | vue-django-channels> docker-compose run yarn bash 48 | root@1071df0c4c5f:/code# node node_modules/node-sass/scripts/install.js 49 | Downloading binary from https://github.com/sass/node-sass/releases/download/v4.5.2/linux-x64-48_binding.node 50 | Download complete 51 | Binary saved to /code/node_modules/node-sass/vendor/linux-x64-48/binding.node 52 | ``` 53 | 54 | ## Build Setup 55 | 56 | ``` bash 57 | # install dependencies 58 | docker-compose run yarn 59 | 60 | # serve with hot reload at localhost:8181 61 | docker-compose up [-d] 62 | 63 | # build for production with minification 64 | docker-compose run yarn yarn build 65 | ``` 66 | 67 | For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader). 68 | -------------------------------------------------------------------------------- /webpack.build.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var webpack = require('webpack') 3 | 4 | var version = require("./package.json").version; 5 | var banner = "/**\n" + 6 | " * vue-django-channels v" + version + "\n" + 7 | " * https://github.com/imoontech/vue-django-channels\n" + 8 | " * Released under the MIT License.\n" + " */\n"; 9 | 10 | 11 | module.exports = { 12 | entry: { 13 | 'vue-django-channels': './src/index.js' 14 | }, 15 | output: { 16 | path: path.resolve(__dirname, './dist'), 17 | publicPath: '/dist/', 18 | filename: '[name].js', 19 | library: 'VueDjangoChannels', 20 | libraryTarget: 'umd' 21 | }, 22 | module: { 23 | rules: [ 24 | { 25 | test: /\.vue$/, 26 | loader: 'vue-loader', 27 | options: { 28 | loaders: { 29 | // Since sass-loader (weirdly) has SCSS as its default parse mode, we map 30 | // the "scss" and "sass" values for the lang attribute to the right configs here. 31 | // other preprocessors should work out of the box, no loader config like this necessary. 32 | 'scss': 'vue-style-loader!css-loader!sass-loader', 33 | 'sass': 'vue-style-loader!css-loader!sass-loader?indentedSyntax' 34 | } 35 | // other vue-loader options go here 36 | } 37 | }, 38 | { 39 | test: /\.js$/, 40 | loader: 'babel-loader', 41 | exclude: /node_modules/ 42 | }, 43 | { 44 | test: /\.(png|jpg|gif|svg)$/, 45 | loader: 'file-loader', 46 | options: { 47 | name: '[name].[ext]?[hash]' 48 | } 49 | } 50 | ] 51 | }, 52 | resolve: { 53 | alias: { 54 | 'vue$': 'vue/dist/vue.esm.js' 55 | } 56 | }, 57 | devtool: '#eval-source-map' 58 | } 59 | 60 | if (process.env.NODE_ENV === 'production') { 61 | module.exports.devtool = '#source-map' 62 | // http://vue-loader.vuejs.org/en/workflow/production.html 63 | module.exports.plugins = (module.exports.plugins || []).concat([ 64 | new webpack.DefinePlugin({ 65 | 'process.env': { 66 | NODE_ENV: '"production"' 67 | } 68 | }), 69 | new webpack.optimize.UglifyJsPlugin({ 70 | sourceMap: true, 71 | compress: { 72 | warnings: false 73 | } 74 | }), 75 | new webpack.LoaderOptionsPlugin({ 76 | minimize: true 77 | }), 78 | new webpack.BannerPlugin({ 79 | banner: banner, 80 | raw: true 81 | }) 82 | ]) 83 | } 84 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | // based on [vue-websocket](https://github.com/icebob/vue-websocket) 2 | 3 | import { WebSocketBridge } from './WebSocketBridge.js'; 4 | 5 | let VueDjangoChannels = { 6 | 7 | install(Vue, url, protocols, options) { 8 | 9 | let webSocketBridge = new WebSocketBridge() 10 | 11 | webSocketBridge.connect(url, protocols, options); 12 | webSocketBridge.listen(); 13 | 14 | Vue.prototype.$channels = webSocketBridge; 15 | 16 | let addListeners = function () { 17 | if (this.$options["channels"]) { 18 | let conf = this.$options.channels; 19 | 20 | if (conf.events) { 21 | let prefix = conf.prefix || ""; 22 | Object.keys(conf.events).forEach((key) => { 23 | let func = conf.events[key].bind(this); 24 | this.$channels.socket.addEventListener(prefix + key, func); 25 | conf.events[key].__binded = func; 26 | }); 27 | } 28 | } 29 | }; 30 | 31 | let removeListeners = function () { 32 | if (this.$options["channels"]) { 33 | let conf = this.$options.channels; 34 | 35 | if (conf.events) { 36 | let prefix = conf.prefix || ""; 37 | Object.keys(conf.events).forEach((key) => { 38 | this.$channels.socket.removeEventListener(prefix + key, conf.events[key].__binded); 39 | }); 40 | } 41 | 42 | // remove stream handlers 43 | if (conf.streams) { 44 | Object.keys(conf.streams).forEach((stream) => { 45 | this.$channels.removeStreamHandler(stream, conf.streams[stream].__binded); 46 | }); 47 | } 48 | } 49 | }; 50 | 51 | let addStreamHandlers = function () { 52 | if (this.$options["channels"]) { 53 | let conf = this.$options.channels; 54 | 55 | if (conf.streams) { 56 | Object.keys(conf.streams).forEach((stream) => { 57 | let func = conf.streams[stream].bind(this); 58 | this.$channels.demultiplex(stream, func); 59 | }); 60 | } 61 | } 62 | }; 63 | 64 | Vue.mixin({ 65 | // Vue v1.x 66 | beforeCompile: addListeners, 67 | // Vue v2.x 68 | beforeCreate: addListeners, 69 | 70 | created: addStreamHandlers, 71 | 72 | beforeDestroy: removeListeners 73 | }); 74 | } 75 | }; 76 | 77 | export default VueDjangoChannels; 78 | -------------------------------------------------------------------------------- /example/App.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 78 | 79 | 107 | -------------------------------------------------------------------------------- /src/WebSocketBridge.js: -------------------------------------------------------------------------------- 1 | import ReconnectingWebSocket from 'reconnecting-websocket'; 2 | 3 | 4 | /** 5 | * Bridge between Channels and plain javascript. 6 | * 7 | * @example 8 | * const webSocketBridge = new WebSocketBridge(); 9 | * webSocketBridge.connect(); 10 | * webSocketBridge.listen(function(action, stream) { 11 | * console.log(action, stream); 12 | * }); 13 | */ 14 | export class WebSocketBridge { 15 | constructor(options) { 16 | /** 17 | * The underlaying `ReconnectingWebSocket` instance. 18 | * 19 | * @type {ReconnectingWebSocket} 20 | */ 21 | this.socket = null; 22 | this.streams = {}; 23 | this.default_cb = null; 24 | this.options = {...options}; 25 | } 26 | 27 | /** 28 | * Connect to the websocket server 29 | * 30 | * @param {String} [url] The url of the websocket. Defaults to 31 | * `window.location.host` 32 | * @param {String[]|String} [protocols] Optional string or array of protocols. 33 | * @param {Object} options Object of options for [`reconnecting-websocket`](https://github.com/joewalnes/reconnecting-websocket#options-1). 34 | * @example 35 | * const webSocketBridge = new WebSocketBridge(); 36 | * webSocketBridge.connect(); 37 | */ 38 | connect(url, protocols, options) { 39 | let _url; 40 | // Use wss:// if running on https:// 41 | const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws'; 42 | const base_url = `${scheme}://${window.location.host}`; 43 | if (url === undefined) { 44 | _url = base_url; 45 | } else { 46 | // Support relative URLs 47 | if (url[0] == '/') { 48 | _url = `${base_url}${url}`; 49 | } else { 50 | _url = url; 51 | } 52 | } 53 | this.socket = new ReconnectingWebSocket(_url, protocols, options); 54 | } 55 | 56 | /** 57 | * Starts listening for messages on the websocket, demultiplexing if necessary. 58 | * 59 | * @param {Function} [cb] Callback to be execute when a message 60 | * arrives. The callback will receive `action` and `stream` parameters 61 | * 62 | * @example 63 | * const webSocketBridge = new WebSocketBridge(); 64 | * webSocketBridge.connect(); 65 | * webSocketBridge.listen(function(action, stream) { 66 | * console.log(action, stream); 67 | * }); 68 | */ 69 | listen(cb) { 70 | this.default_cb = cb; 71 | this.socket.onmessage = (event) => { 72 | const msg = JSON.parse(event.data); 73 | let action; 74 | let stream; 75 | 76 | if (msg.stream !== undefined) { 77 | action = msg.payload; 78 | stream = msg.stream; 79 | // this will call all registered callbacks for this stream 80 | if(Array.isArray(this.streams[stream])) { 81 | this.streams[stream].forEach(function(callback) { 82 | callback ? callback(action, stream) : null 83 | }) 84 | } 85 | } else { 86 | action = msg; 87 | stream = null; 88 | this.default_cb ? this.default_cb(action, stream) : null; 89 | } 90 | }; 91 | } 92 | 93 | /** 94 | * Adds a 'stream handler' callback. Messages coming from the specified stream 95 | * will call the specified callback. Streams can have multiple handlers that 96 | * will all be called in sequence on receiving a message on the websocket. 97 | * 98 | * @param {String} stream The stream name 99 | * @param {Function} cb Callback to be execute when a message 100 | * arrives. The callback will receive `action` and `stream` parameters. 101 | 102 | * @example 103 | * const webSocketBridge = new WebSocketBridge(); 104 | * webSocketBridge.connect(); 105 | * webSocketBridge.listen(); 106 | * webSocketBridge.demultiplex('mystream', function(action, stream) { 107 | * console.log(action, stream); 108 | * }); 109 | * webSocketBridge.demultiplex('myotherstream', function(action, stream) { 110 | * console.info(action, stream); 111 | * }); 112 | */ 113 | demultiplex(stream, cb) { 114 | if(Array.isArray(this.streams[stream])) { 115 | this.streams[stream].push(cb) 116 | } else { 117 | // add the first array element 118 | this.streams[stream] = [cb]; 119 | } 120 | } 121 | 122 | /** 123 | * Removes a 'stream handler' callback. 124 | * 125 | * @param {String} stream The stream name 126 | * @param {Function} cb Callback to be removed 127 | */ 128 | removeStreamHandler(stream, cb) { 129 | if(Array.isArray(this.streams[stream])) { 130 | this.streams[stream] = this.streams[stream].filter(function(callback) { 131 | return callback !== cb 132 | }) 133 | 134 | if (this.streams[stream].length === 0) { 135 | delete this.streams[stream] 136 | } 137 | } 138 | } 139 | 140 | /** 141 | * Sends a message to the reply channel. 142 | * 143 | * @param {Object} msg The message 144 | * 145 | * @example 146 | * webSocketBridge.send({prop1: 'value1', prop2: 'value1'}); 147 | */ 148 | send(msg) { 149 | this.socket.send(JSON.stringify(msg)); 150 | } 151 | 152 | /** 153 | * Returns an object to send messages to a specific stream 154 | * 155 | * @param {String} stream The stream name 156 | * @return {Object} convenience object to send messages to `stream`. 157 | * @example 158 | * webSocketBridge.stream('mystream').send({prop1: 'value1', prop2: 'value1'}) 159 | */ 160 | stream(stream) { 161 | return { 162 | send: (action) => { 163 | const msg = { 164 | stream, 165 | payload: action 166 | } 167 | this.socket.send(JSON.stringify(msg)); 168 | } 169 | } 170 | } 171 | 172 | } -------------------------------------------------------------------------------- /dist/vue-django-channels.js: -------------------------------------------------------------------------------- 1 | /** 2 | * vue-django-channels v0.2.1 3 | * https://github.com/imoontech/vue-django-channels 4 | * Released under the MIT License. 5 | */ 6 | 7 | !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.VueDjangoChannels=n():e.VueDjangoChannels=n()}(this,function(){return function(e){function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}var t={};return n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="/dist/",n(n.s=1)}([function(e,n,t){"use strict";function o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var r=t(2),i=t.n(r);t.d(n,"a",function(){return a});var s=Object.assign||function(e){for(var n=1;ne.maxReconnectionDelay?e.maxReconnectionDelay:t},u=["onopen","onclose","onmessage","onerror"],f=function(e,n,t){Object.keys(t).forEach(function(n){t[n].forEach(function(t){var o=t[0],r=t[1];e.addEventListener(n,o,r)})}),n&&u.forEach(function(t){e[t]=n[t]})},l=function(e,n,t){var r=this;void 0===t&&(t={});var u,v,d=0,h=0,m=!0,p=null,y={};if(!(this instanceof l))throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");var b=i();if(Object.keys(b).filter(function(e){return t.hasOwnProperty(e)}).forEach(function(e){return b[e]=t[e]}),!o(b.constructor))throw new TypeError("Invalid WebSocket constructor. Set `options.constructor`");var E=b.debug?function(){for(var e=[],n=0;nb.maxRetries)return void k("EHOSTDOWN","Too many failed connection attempts");d=d?a(b,d):c(b),E("reconnectDelay:",d),m&&setTimeout(O,d)},O=function(){E("connect");var t=u;u=new b.constructor(e,n),v=setTimeout(function(){E("timeout"),u.close(),k("ETIMEDOUT","Connection timeout")},b.connectionTimeout),E("bypass properties");for(var o in u)["addEventListener","removeEventListener","close","send"].indexOf(o)<0&&s(u,r,o);u.addEventListener("open",function(){clearTimeout(v),E("open"),d=c(b),E("reconnectDelay:",d),h=0}),u.addEventListener("close",w),f(u,t,y),u.onclose=u.onclose||p,p=null};E("init"),O(),this.close=function(e,n,t){void 0===e&&(e=1e3),void 0===n&&(n="");var o=void 0===t?{}:t,r=o.keepClosed,i=void 0!==r&&r,s=o.fastClose,c=void 0===s||s,a=o.delay,f=void 0===a?0:a;if(f&&(d=f),m=!i,u.close(e,n),c){var l={code:e,reason:n,wasClean:!0};w(),u.removeEventListener("close",w),Array.isArray(y.close)&&y.close.forEach(function(e){var n=e[0],t=e[1];n(l),u.removeEventListener("close",n,t)}),u.onclose&&(p=u.onclose,u.onclose(l),u.onclose=null)}},this.send=function(e){u.send(e)},this.addEventListener=function(e,n,t){Array.isArray(y[e])?y[e].some(function(e){return e[0]===n})||y[e].push([n,t]):y[e]=[[n,t]],u.addEventListener(e,n,t)},this.removeEventListener=function(e,n,t){Array.isArray(y[e])&&(y[e]=y[e].filter(function(e){return e[0]!==n})),u.removeEventListener(e,n,t)}};e.exports=l}])}); 8 | //# sourceMappingURL=vue-django-channels.js.map -------------------------------------------------------------------------------- /dist/vue-django-channels.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///vue-django-channels.js","webpack:///webpack/bootstrap 9d3a8f9bf2472ccb9b33","webpack:///./src/WebSocketBridge.js","webpack:///./src/index.js","webpack:///./~/reconnecting-websocket/dist/index.js"],"names":["root","factory","exports","module","define","amd","this","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","value","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","__webpack_exports__","_classCallCheck","instance","Constructor","TypeError","__WEBPACK_IMPORTED_MODULE_0_reconnecting_websocket__","__WEBPACK_IMPORTED_MODULE_0_reconnecting_websocket___default","WebSocketBridge","_extends","assign","target","arguments","length","source","key","_createClass","defineProperties","props","descriptor","writable","protoProps","staticProps","options","socket","streams","default_cb","url","protocols","_url","scheme","window","location","protocol","base_url","host","undefined","a","cb","_this","onmessage","event","msg","JSON","parse","data","action","stream","payload","Array","isArray","forEach","callback","push","filter","send","stringify","_this2","__WEBPACK_IMPORTED_MODULE_0__WebSocketBridge_js__","VueDjangoChannels","install","Vue","webSocketBridge","connect","listen","$channels","addListeners","$options","conf","channels","events","prefix","keys","func","bind","addEventListener","__binded","removeListeners","removeEventListener","removeStreamHandler","addStreamHandlers","_this3","demultiplex","mixin","beforeCompile","beforeCreate","created","beforeDestroy","isWebSocket","constructor","CLOSING","isGlobalWebSocket","WebSocket","getDefaultOptions","maxReconnectionDelay","minReconnectionDelay","reconnectionDelayGrowFactor","connectionTimeout","maxRetries","Infinity","debug","bypassProperty","src","dst","set","initReconnectionDelay","config","Math","random","updateReconnectionDelay","previousDelay","newDelay","LEVEL_0_EVENTS","reassignEventListeners","ws","oldWs","listeners","type","_a","listener","ReconnectingWebsocket","connectingTimeout","reconnectDelay","retriesCount","shouldRetry","savedOnClose","log","params","_i","console","apply","concat","emitError","code","setTimeout","err","Error","error","fn","onerror","handleClose","close","indexOf","clearTimeout","onclose","reason","_b","_c","keepClosed","_d","fastClose","_e","delay","fakeCloseEvent_1","wasClean","some"],"mappings":";;;;;;CAAA,SAAAA,EAAAC,GACA,gBAAAC,UAAA,gBAAAC,QACAA,OAAAD,QAAAD,IACA,kBAAAG,gBAAAC,IACAD,UAAAH,GACA,gBAAAC,SACAA,QAAA,kBAAAD,IAEAD,EAAA,kBAAAC,KACCK,KAAA,WACD,MCAgB,UAAUC,GCN1B,QAAAC,GAAAC,GAGA,GAAAC,EAAAD,GACA,MAAAC,GAAAD,GAAAP,OAGA,IAAAC,GAAAO,EAAAD,IACAE,EAAAF,EACAG,GAAA,EACAV,WAUA,OANAK,GAAAE,GAAAI,KAAAV,EAAAD,QAAAC,IAAAD,QAAAM,GAGAL,EAAAS,GAAA,EAGAT,EAAAD,QAvBA,GAAAQ,KA+DA,OAnCAF,GAAAM,EAAAP,EAGAC,EAAAO,EAAAL,EAGAF,EAAAG,EAAA,SAAAK,GAA2C,MAAAA,IAG3CR,EAAAS,EAAA,SAAAf,EAAAgB,EAAAC,GACAX,EAAAY,EAAAlB,EAAAgB,IACAG,OAAAC,eAAApB,EAAAgB,GACAK,cAAA,EACAC,YAAA,EACAC,IAAAN,KAMAX,EAAAkB,EAAA,SAAAvB,GACA,GAAAgB,GAAAhB,KAAAwB,WACA,WAA2B,MAAAxB,GAAA,SAC3B,WAAiC,MAAAA,GAEjC,OADAK,GAAAS,EAAAE,EAAA,IAAAA,GACAA,GAIAX,EAAAY,EAAA,SAAAQ,EAAAC,GAAsD,MAAAR,QAAAS,UAAAC,eAAAlB,KAAAe,EAAAC,IAGtDrB,EAAAwB,EAAA,SAGAxB,IAAAyB,EAAA,KDgBM,SAAU9B,EAAQ+B,EAAqB1B,GAE7C,YAQA,SAAS2B,GAAgBC,EAAUC,GAAe,KAAMD,YAAoBC,IAAgB,KAAM,IAAIC,WAAU,q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AC,GAAAD,EAAAC,GAAA/D,OAAA,SAAAgE,GAEA,MADAA,GAAA,KACAC,KAGAL,EAAApC,oBAAAuC,EAAAE,EAAAhG,IAGArD,GAAAD,QAAAuJ","file":"vue-django-channels.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"VueDjangoChannels\"] = factory();\n\telse\n\t\troot[\"VueDjangoChannels\"] = factory();\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"VueDjangoChannels\"] = factory();\n\telse\n\t\troot[\"VueDjangoChannels\"] = factory();\n})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// identity function for calling harmony imports with the correct context\n/******/ \t__webpack_require__.i = function(value) { return value; };\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"/dist/\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 1);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_reconnecting_websocket__ = __webpack_require__(2);\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_reconnecting_websocket___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_reconnecting_websocket__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"a\", function() { return WebSocketBridge; });\nvar _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\n\n\n/**\r\n * Bridge between Channels and plain javascript.\r\n *\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n * webSocketBridge.listen(function(action, stream) {\r\n * console.log(action, stream);\r\n * });\r\n */\n\nvar WebSocketBridge = function () {\n function WebSocketBridge(options) {\n _classCallCheck(this, WebSocketBridge);\n\n /**\r\n * The underlaying `ReconnectingWebSocket` instance.\r\n * \r\n * @type {ReconnectingWebSocket}\r\n */\n this.socket = null;\n this.streams = {};\n this.default_cb = null;\n this.options = _extends({}, options);\n }\n\n /**\r\n * Connect to the websocket server\r\n *\r\n * @param {String} [url] The url of the websocket. Defaults to\r\n * `window.location.host`\r\n * @param {String[]|String} [protocols] Optional string or array of protocols.\r\n * @param {Object} options Object of options for [`reconnecting-websocket`](https://github.com/joewalnes/reconnecting-websocket#options-1).\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n */\n\n\n _createClass(WebSocketBridge, [{\n key: 'connect',\n value: function connect(url, protocols, options) {\n var _url = void 0;\n // Use wss:// if running on https://\n var scheme = window.location.protocol === 'https:' ? 'wss' : 'ws';\n var base_url = scheme + '://' + window.location.host;\n if (url === undefined) {\n _url = base_url;\n } else {\n // Support relative URLs\n if (url[0] == '/') {\n _url = '' + base_url + url;\n } else {\n _url = url;\n }\n }\n this.socket = new __WEBPACK_IMPORTED_MODULE_0_reconnecting_websocket___default.a(_url, protocols, options);\n }\n\n /**\r\n * Starts listening for messages on the websocket, demultiplexing if necessary.\r\n *\r\n * @param {Function} [cb] Callback to be execute when a message\r\n * arrives. The callback will receive `action` and `stream` parameters\r\n *\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n * webSocketBridge.listen(function(action, stream) {\r\n * console.log(action, stream);\r\n * });\r\n */\n\n }, {\n key: 'listen',\n value: function listen(cb) {\n var _this = this;\n\n this.default_cb = cb;\n this.socket.onmessage = function (event) {\n var msg = JSON.parse(event.data);\n var action = void 0;\n var stream = void 0;\n\n if (msg.stream !== undefined) {\n action = msg.payload;\n stream = msg.stream;\n // this will call all registered callbacks for this stream\n if (Array.isArray(_this.streams[stream])) {\n _this.streams[stream].forEach(function (callback) {\n callback ? callback(action, stream) : null;\n });\n }\n } else {\n action = msg;\n stream = null;\n _this.default_cb ? _this.default_cb(action, stream) : null;\n }\n };\n }\n\n /**\r\n * Adds a 'stream handler' callback. Messages coming from the specified stream\r\n * will call the specified callback. Streams can have multiple handlers that\r\n * will all be called in sequence on receiving a message on the websocket.\r\n *\r\n * @param {String} stream The stream name\r\n * @param {Function} cb Callback to be execute when a message\r\n * arrives. The callback will receive `action` and `stream` parameters.\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n * webSocketBridge.listen();\r\n * webSocketBridge.demultiplex('mystream', function(action, stream) {\r\n * console.log(action, stream);\r\n * });\r\n * webSocketBridge.demultiplex('myotherstream', function(action, stream) {\r\n * console.info(action, stream);\r\n * });\r\n */\n\n }, {\n key: 'demultiplex',\n value: function demultiplex(stream, cb) {\n if (Array.isArray(this.streams[stream])) {\n this.streams[stream].push(cb);\n } else {\n // add the first array element\n this.streams[stream] = [cb];\n }\n }\n\n /**\r\n * Removes a 'stream handler' callback.\r\n *\r\n * @param {String} stream The stream name\r\n * @param {Function} cb Callback to be removed\r\n */\n\n }, {\n key: 'removeStreamHandler',\n value: function removeStreamHandler(stream, cb) {\n if (Array.isArray(this.streams[stream])) {\n this.streams[stream] = this.streams[stream].filter(function (callback) {\n return callback !== cb;\n });\n\n if (this.streams[stream].length === 0) {\n delete this.streams[stream];\n }\n }\n }\n\n /**\r\n * Sends a message to the reply channel.\r\n *\r\n * @param {Object} msg The message\r\n *\r\n * @example\r\n * webSocketBridge.send({prop1: 'value1', prop2: 'value1'});\r\n */\n\n }, {\n key: 'send',\n value: function send(msg) {\n this.socket.send(JSON.stringify(msg));\n }\n\n /**\r\n * Returns an object to send messages to a specific stream\r\n *\r\n * @param {String} stream The stream name\r\n * @return {Object} convenience object to send messages to `stream`.\r\n * @example\r\n * webSocketBridge.stream('mystream').send({prop1: 'value1', prop2: 'value1'})\r\n */\n\n }, {\n key: 'stream',\n value: function stream(_stream) {\n var _this2 = this;\n\n return {\n send: function send(action) {\n var msg = {\n stream: _stream,\n payload: action\n };\n _this2.socket.send(JSON.stringify(msg));\n }\n };\n }\n }]);\n\n return WebSocketBridge;\n}();\n\n\n\n/***/ }),\n/* 1 */\n/***/ (function(module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\nObject.defineProperty(__webpack_exports__, \"__esModule\", { value: true });\n/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__WebSocketBridge_js__ = __webpack_require__(0);\n// based on [vue-websocket](https://github.com/icebob/vue-websocket)\n\n\n\nvar VueDjangoChannels = {\n install: function install(Vue, url, protocols, options) {\n\n var webSocketBridge = new __WEBPACK_IMPORTED_MODULE_0__WebSocketBridge_js__[\"a\" /* WebSocketBridge */]();\n\n webSocketBridge.connect(url, protocols, options);\n webSocketBridge.listen();\n\n Vue.prototype.$channels = webSocketBridge;\n\n var addListeners = function addListeners() {\n var _this = this;\n\n if (this.$options[\"channels\"]) {\n var conf = this.$options.channels;\n\n if (conf.events) {\n var prefix = conf.prefix || \"\";\n Object.keys(conf.events).forEach(function (key) {\n var func = conf.events[key].bind(_this);\n _this.$channels.socket.addEventListener(prefix + key, func);\n conf.events[key].__binded = func;\n });\n }\n }\n };\n\n var removeListeners = function removeListeners() {\n var _this2 = this;\n\n if (this.$options[\"channels\"]) {\n var conf = this.$options.channels;\n\n if (conf.events) {\n var prefix = conf.prefix || \"\";\n Object.keys(conf.events).forEach(function (key) {\n _this2.$channels.socket.removeEventListener(prefix + key, conf.events[key].__binded);\n });\n }\n\n // remove stream handlers\n if (conf.streams) {\n Object.keys(conf.streams).forEach(function (stream) {\n _this2.$channels.removeStreamHandler(stream, conf.streams[stream].__binded);\n });\n }\n }\n };\n\n var addStreamHandlers = function addStreamHandlers() {\n var _this3 = this;\n\n if (this.$options[\"channels\"]) {\n var conf = this.$options.channels;\n\n if (conf.streams) {\n Object.keys(conf.streams).forEach(function (stream) {\n var func = conf.streams[stream].bind(_this3);\n _this3.$channels.demultiplex(stream, func);\n });\n }\n }\n };\n\n Vue.mixin({\n // Vue v1.x\n beforeCompile: addListeners,\n // Vue v2.x\n beforeCreate: addListeners,\n\n created: addStreamHandlers,\n\n beforeDestroy: removeListeners\n });\n }\n};\n\n/* harmony default export */ __webpack_exports__[\"default\"] = (VueDjangoChannels);\n\n/***/ }),\n/* 2 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\nvar isWebSocket = function (constructor) {\n return constructor && constructor.CLOSING === 2;\n};\nvar isGlobalWebSocket = function () {\n return typeof WebSocket !== 'undefined' && isWebSocket(WebSocket);\n};\nvar getDefaultOptions = function () { return ({\n constructor: isGlobalWebSocket() ? WebSocket : null,\n maxReconnectionDelay: 10000,\n minReconnectionDelay: 1500,\n reconnectionDelayGrowFactor: 1.3,\n connectionTimeout: 4000,\n maxRetries: Infinity,\n debug: false,\n}); };\nvar bypassProperty = function (src, dst, name) {\n Object.defineProperty(dst, name, {\n get: function () { return src[name]; },\n set: function (value) { src[name] = value; },\n enumerable: true,\n configurable: true,\n });\n};\nvar initReconnectionDelay = function (config) {\n return (config.minReconnectionDelay + Math.random() * config.minReconnectionDelay);\n};\nvar updateReconnectionDelay = function (config, previousDelay) {\n var newDelay = previousDelay * config.reconnectionDelayGrowFactor;\n return (newDelay > config.maxReconnectionDelay)\n ? config.maxReconnectionDelay\n : newDelay;\n};\nvar LEVEL_0_EVENTS = ['onopen', 'onclose', 'onmessage', 'onerror'];\nvar reassignEventListeners = function (ws, oldWs, listeners) {\n Object.keys(listeners).forEach(function (type) {\n listeners[type].forEach(function (_a) {\n var listener = _a[0], options = _a[1];\n ws.addEventListener(type, listener, options);\n });\n });\n if (oldWs) {\n LEVEL_0_EVENTS.forEach(function (name) { ws[name] = oldWs[name]; });\n }\n};\nvar ReconnectingWebsocket = function (url, protocols, options) {\n var _this = this;\n if (options === void 0) { options = {}; }\n var ws;\n var connectingTimeout;\n var reconnectDelay = 0;\n var retriesCount = 0;\n var shouldRetry = true;\n var savedOnClose = null;\n var listeners = {};\n // require new to construct\n if (!(this instanceof ReconnectingWebsocket)) {\n throw new TypeError(\"Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator\");\n }\n // Set config. Not using `Object.assign` because of IE11\n var config = getDefaultOptions();\n Object.keys(config)\n .filter(function (key) { return options.hasOwnProperty(key); })\n .forEach(function (key) { return config[key] = options[key]; });\n if (!isWebSocket(config.constructor)) {\n throw new TypeError('Invalid WebSocket constructor. Set `options.constructor`');\n }\n var log = config.debug ? function () {\n var params = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n params[_i - 0] = arguments[_i];\n }\n return console.log.apply(console, ['RWS:'].concat(params));\n } : function () { };\n /**\n * Not using dispatchEvent, otherwise we must use a DOM Event object\n * Deferred because we want to handle the close event before this\n */\n var emitError = function (code, msg) { return setTimeout(function () {\n var err = new Error(msg);\n err.code = code;\n if (Array.isArray(listeners.error)) {\n listeners.error.forEach(function (_a) {\n var fn = _a[0];\n return fn(err);\n });\n }\n if (ws.onerror) {\n ws.onerror(err);\n }\n }, 0); };\n var handleClose = function () {\n log('close');\n retriesCount++;\n log('retries count:', retriesCount);\n if (retriesCount > config.maxRetries) {\n emitError('EHOSTDOWN', 'Too many failed connection attempts');\n return;\n }\n if (!reconnectDelay) {\n reconnectDelay = initReconnectionDelay(config);\n }\n else {\n reconnectDelay = updateReconnectionDelay(config, reconnectDelay);\n }\n log('reconnectDelay:', reconnectDelay);\n if (shouldRetry) {\n setTimeout(connect, reconnectDelay);\n }\n };\n var connect = function () {\n log('connect');\n var oldWs = ws;\n ws = new config.constructor(url, protocols);\n connectingTimeout = setTimeout(function () {\n log('timeout');\n ws.close();\n emitError('ETIMEDOUT', 'Connection timeout');\n }, config.connectionTimeout);\n log('bypass properties');\n for (var key in ws) {\n // @todo move to constant\n if (['addEventListener', 'removeEventListener', 'close', 'send'].indexOf(key) < 0) {\n bypassProperty(ws, _this, key);\n }\n }\n ws.addEventListener('open', function () {\n clearTimeout(connectingTimeout);\n log('open');\n reconnectDelay = initReconnectionDelay(config);\n log('reconnectDelay:', reconnectDelay);\n retriesCount = 0;\n });\n ws.addEventListener('close', handleClose);\n reassignEventListeners(ws, oldWs, listeners);\n // because when closing with fastClose=true, it is saved and set to null to avoid double calls\n ws.onclose = ws.onclose || savedOnClose;\n savedOnClose = null;\n };\n log('init');\n connect();\n this.close = function (code, reason, _a) {\n if (code === void 0) { code = 1000; }\n if (reason === void 0) { reason = ''; }\n var _b = _a === void 0 ? {} : _a, _c = _b.keepClosed, keepClosed = _c === void 0 ? false : _c, _d = _b.fastClose, fastClose = _d === void 0 ? true : _d, _e = _b.delay, delay = _e === void 0 ? 0 : _e;\n if (delay) {\n reconnectDelay = delay;\n }\n shouldRetry = !keepClosed;\n ws.close(code, reason);\n if (fastClose) {\n var fakeCloseEvent_1 = {\n code: code,\n reason: reason,\n wasClean: true,\n };\n // execute close listeners soon with a fake closeEvent\n // and remove them from the WS instance so they\n // don't get fired on the real close.\n handleClose();\n ws.removeEventListener('close', handleClose);\n // run and remove level2\n if (Array.isArray(listeners.close)) {\n listeners.close.forEach(function (_a) {\n var listener = _a[0], options = _a[1];\n listener(fakeCloseEvent_1);\n ws.removeEventListener('close', listener, options);\n });\n }\n // run and remove level0\n if (ws.onclose) {\n savedOnClose = ws.onclose;\n ws.onclose(fakeCloseEvent_1);\n ws.onclose = null;\n }\n }\n };\n this.send = function (data) {\n ws.send(data);\n };\n this.addEventListener = function (type, listener, options) {\n if (Array.isArray(listeners[type])) {\n if (!listeners[type].some(function (_a) {\n var l = _a[0];\n return l === listener;\n })) {\n listeners[type].push([listener, options]);\n }\n }\n else {\n listeners[type] = [[listener, options]];\n }\n ws.addEventListener(type, listener, options);\n };\n this.removeEventListener = function (type, listener, options) {\n if (Array.isArray(listeners[type])) {\n listeners[type] = listeners[type].filter(function (_a) {\n var l = _a[0];\n return l !== listener;\n });\n }\n ws.removeEventListener(type, listener, options);\n };\n};\nmodule.exports = ReconnectingWebsocket;\n\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// vue-django-channels.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/dist/\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 9d3a8f9bf2472ccb9b33","import ReconnectingWebSocket from 'reconnecting-websocket';\r\n\r\n\r\n/**\r\n * Bridge between Channels and plain javascript.\r\n *\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n * webSocketBridge.listen(function(action, stream) {\r\n * console.log(action, stream);\r\n * });\r\n */\r\nexport class WebSocketBridge {\r\n constructor(options) {\r\n /**\r\n * The underlaying `ReconnectingWebSocket` instance.\r\n * \r\n * @type {ReconnectingWebSocket}\r\n */\r\n this.socket = null;\r\n this.streams = {};\r\n this.default_cb = null;\r\n this.options = {...options};\r\n }\r\n\r\n /**\r\n * Connect to the websocket server\r\n *\r\n * @param {String} [url] The url of the websocket. Defaults to\r\n * `window.location.host`\r\n * @param {String[]|String} [protocols] Optional string or array of protocols.\r\n * @param {Object} options Object of options for [`reconnecting-websocket`](https://github.com/joewalnes/reconnecting-websocket#options-1).\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n */\r\n connect(url, protocols, options) {\r\n let _url;\r\n // Use wss:// if running on https://\r\n const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws';\r\n const base_url = `${scheme}://${window.location.host}`;\r\n if (url === undefined) {\r\n _url = base_url;\r\n } else {\r\n // Support relative URLs\r\n if (url[0] == '/') {\r\n _url = `${base_url}${url}`;\r\n } else {\r\n _url = url;\r\n }\r\n }\r\n this.socket = new ReconnectingWebSocket(_url, protocols, options);\r\n }\r\n\r\n /**\r\n * Starts listening for messages on the websocket, demultiplexing if necessary.\r\n *\r\n * @param {Function} [cb] Callback to be execute when a message\r\n * arrives. The callback will receive `action` and `stream` parameters\r\n *\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n * webSocketBridge.listen(function(action, stream) {\r\n * console.log(action, stream);\r\n * });\r\n */\r\n listen(cb) {\r\n this.default_cb = cb;\r\n this.socket.onmessage = (event) => {\r\n const msg = JSON.parse(event.data);\r\n let action;\r\n let stream;\r\n\r\n if (msg.stream !== undefined) {\r\n action = msg.payload;\r\n stream = msg.stream;\r\n // this will call all registered callbacks for this stream\r\n if(Array.isArray(this.streams[stream])) {\r\n this.streams[stream].forEach(function(callback) {\r\n callback ? callback(action, stream) : null\r\n })\r\n }\r\n } else {\r\n action = msg;\r\n stream = null;\r\n this.default_cb ? this.default_cb(action, stream) : null;\r\n }\r\n };\r\n }\r\n\r\n /**\r\n * Adds a 'stream handler' callback. Messages coming from the specified stream\r\n * will call the specified callback. Streams can have multiple handlers that\r\n * will all be called in sequence on receiving a message on the websocket.\r\n *\r\n * @param {String} stream The stream name\r\n * @param {Function} cb Callback to be execute when a message\r\n * arrives. The callback will receive `action` and `stream` parameters.\r\n\r\n * @example\r\n * const webSocketBridge = new WebSocketBridge();\r\n * webSocketBridge.connect();\r\n * webSocketBridge.listen();\r\n * webSocketBridge.demultiplex('mystream', function(action, stream) {\r\n * console.log(action, stream);\r\n * });\r\n * webSocketBridge.demultiplex('myotherstream', function(action, stream) {\r\n * console.info(action, stream);\r\n * });\r\n */\r\n demultiplex(stream, cb) {\r\n if(Array.isArray(this.streams[stream])) {\r\n this.streams[stream].push(cb)\r\n } else {\r\n // add the first array element\r\n this.streams[stream] = [cb];\r\n }\r\n }\r\n\r\n /**\r\n * Removes a 'stream handler' callback.\r\n *\r\n * @param {String} stream The stream name\r\n * @param {Function} cb Callback to be removed\r\n */\r\n removeStreamHandler(stream, cb) {\r\n if(Array.isArray(this.streams[stream])) {\r\n this.streams[stream] = this.streams[stream].filter(function(callback) {\r\n return callback !== cb\r\n })\r\n\r\n if (this.streams[stream].length === 0) {\r\n \tdelete this.streams[stream]\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sends a message to the reply channel.\r\n *\r\n * @param {Object} msg The message\r\n *\r\n * @example\r\n * webSocketBridge.send({prop1: 'value1', prop2: 'value1'});\r\n */\r\n send(msg) {\r\n this.socket.send(JSON.stringify(msg));\r\n }\r\n\r\n /**\r\n * Returns an object to send messages to a specific stream\r\n *\r\n * @param {String} stream The stream name\r\n * @return {Object} convenience object to send messages to `stream`.\r\n * @example\r\n * webSocketBridge.stream('mystream').send({prop1: 'value1', prop2: 'value1'})\r\n */\r\n stream(stream) {\r\n return {\r\n send: (action) => {\r\n const msg = {\r\n stream,\r\n payload: action\r\n }\r\n this.socket.send(JSON.stringify(msg));\r\n }\r\n }\r\n }\r\n\r\n}\n\n\n// WEBPACK FOOTER //\n// ./src/WebSocketBridge.js","// based on [vue-websocket](https://github.com/icebob/vue-websocket)\r\n\r\nimport { WebSocketBridge } from './WebSocketBridge.js';\r\n\r\nlet VueDjangoChannels = {\r\n\r\n install(Vue, url, protocols, options) {\r\n\r\n let webSocketBridge = new WebSocketBridge()\r\n\r\n webSocketBridge.connect(url, protocols, options);\r\n webSocketBridge.listen();\r\n\r\n Vue.prototype.$channels = webSocketBridge;\r\n\r\n let addListeners = function () {\r\n if (this.$options[\"channels\"]) {\r\n let conf = this.$options.channels;\r\n\r\n if (conf.events) {\r\n let prefix = conf.prefix || \"\";\r\n Object.keys(conf.events).forEach((key) => {\r\n let func = conf.events[key].bind(this);\r\n this.$channels.socket.addEventListener(prefix + key, func);\r\n conf.events[key].__binded = func;\r\n });\r\n }\r\n }\r\n };\r\n\r\n let removeListeners = function () {\r\n if (this.$options[\"channels\"]) {\r\n let conf = this.$options.channels;\r\n\r\n if (conf.events) {\r\n let prefix = conf.prefix || \"\";\r\n Object.keys(conf.events).forEach((key) => {\r\n this.$channels.socket.removeEventListener(prefix + key, conf.events[key].__binded);\r\n });\r\n }\r\n\r\n // remove stream handlers\r\n if (conf.streams) {\r\n Object.keys(conf.streams).forEach((stream) => {\r\n this.$channels.removeStreamHandler(stream, conf.streams[stream].__binded);\r\n });\r\n }\r\n }\r\n };\r\n\r\n let addStreamHandlers = function () {\r\n if (this.$options[\"channels\"]) {\r\n let conf = this.$options.channels;\r\n\r\n if (conf.streams) {\r\n Object.keys(conf.streams).forEach((stream) => {\r\n let func = conf.streams[stream].bind(this);\r\n this.$channels.demultiplex(stream, func);\r\n });\r\n }\r\n }\r\n };\r\n\r\n Vue.mixin({\r\n // Vue v1.x\r\n beforeCompile: addListeners,\r\n // Vue v2.x\r\n beforeCreate: addListeners,\r\n\r\n created: addStreamHandlers,\r\n\r\n beforeDestroy: removeListeners\r\n });\r\n }\r\n};\r\n\r\nexport default VueDjangoChannels;\r\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.js","\"use strict\";\nvar isWebSocket = function (constructor) {\n return constructor && constructor.CLOSING === 2;\n};\nvar isGlobalWebSocket = function () {\n return typeof WebSocket !== 'undefined' && isWebSocket(WebSocket);\n};\nvar getDefaultOptions = function () { return ({\n constructor: isGlobalWebSocket() ? WebSocket : null,\n maxReconnectionDelay: 10000,\n minReconnectionDelay: 1500,\n reconnectionDelayGrowFactor: 1.3,\n connectionTimeout: 4000,\n maxRetries: Infinity,\n debug: false,\n}); };\nvar bypassProperty = function (src, dst, name) {\n Object.defineProperty(dst, name, {\n get: function () { return src[name]; },\n set: function (value) { src[name] = value; },\n enumerable: true,\n configurable: true,\n });\n};\nvar initReconnectionDelay = function (config) {\n return (config.minReconnectionDelay + Math.random() * config.minReconnectionDelay);\n};\nvar updateReconnectionDelay = function (config, previousDelay) {\n var newDelay = previousDelay * config.reconnectionDelayGrowFactor;\n return (newDelay > config.maxReconnectionDelay)\n ? config.maxReconnectionDelay\n : newDelay;\n};\nvar LEVEL_0_EVENTS = ['onopen', 'onclose', 'onmessage', 'onerror'];\nvar reassignEventListeners = function (ws, oldWs, listeners) {\n Object.keys(listeners).forEach(function (type) {\n listeners[type].forEach(function (_a) {\n var listener = _a[0], options = _a[1];\n ws.addEventListener(type, listener, options);\n });\n });\n if (oldWs) {\n LEVEL_0_EVENTS.forEach(function (name) { ws[name] = oldWs[name]; });\n }\n};\nvar ReconnectingWebsocket = function (url, protocols, options) {\n var _this = this;\n if (options === void 0) { options = {}; }\n var ws;\n var connectingTimeout;\n var reconnectDelay = 0;\n var retriesCount = 0;\n var shouldRetry = true;\n var savedOnClose = null;\n var listeners = {};\n // require new to construct\n if (!(this instanceof ReconnectingWebsocket)) {\n throw new TypeError(\"Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator\");\n }\n // Set config. Not using `Object.assign` because of IE11\n var config = getDefaultOptions();\n Object.keys(config)\n .filter(function (key) { return options.hasOwnProperty(key); })\n .forEach(function (key) { return config[key] = options[key]; });\n if (!isWebSocket(config.constructor)) {\n throw new TypeError('Invalid WebSocket constructor. Set `options.constructor`');\n }\n var log = config.debug ? function () {\n var params = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n params[_i - 0] = arguments[_i];\n }\n return console.log.apply(console, ['RWS:'].concat(params));\n } : function () { };\n /**\n * Not using dispatchEvent, otherwise we must use a DOM Event object\n * Deferred because we want to handle the close event before this\n */\n var emitError = function (code, msg) { return setTimeout(function () {\n var err = new Error(msg);\n err.code = code;\n if (Array.isArray(listeners.error)) {\n listeners.error.forEach(function (_a) {\n var fn = _a[0];\n return fn(err);\n });\n }\n if (ws.onerror) {\n ws.onerror(err);\n }\n }, 0); };\n var handleClose = function () {\n log('close');\n retriesCount++;\n log('retries count:', retriesCount);\n if (retriesCount > config.maxRetries) {\n emitError('EHOSTDOWN', 'Too many failed connection attempts');\n return;\n }\n if (!reconnectDelay) {\n reconnectDelay = initReconnectionDelay(config);\n }\n else {\n reconnectDelay = updateReconnectionDelay(config, reconnectDelay);\n }\n log('reconnectDelay:', reconnectDelay);\n if (shouldRetry) {\n setTimeout(connect, reconnectDelay);\n }\n };\n var connect = function () {\n log('connect');\n var oldWs = ws;\n ws = new config.constructor(url, protocols);\n connectingTimeout = setTimeout(function () {\n log('timeout');\n ws.close();\n emitError('ETIMEDOUT', 'Connection timeout');\n }, config.connectionTimeout);\n log('bypass properties');\n for (var key in ws) {\n // @todo move to constant\n if (['addEventListener', 'removeEventListener', 'close', 'send'].indexOf(key) < 0) {\n bypassProperty(ws, _this, key);\n }\n }\n ws.addEventListener('open', function () {\n clearTimeout(connectingTimeout);\n log('open');\n reconnectDelay = initReconnectionDelay(config);\n log('reconnectDelay:', reconnectDelay);\n retriesCount = 0;\n });\n ws.addEventListener('close', handleClose);\n reassignEventListeners(ws, oldWs, listeners);\n // because when closing with fastClose=true, it is saved and set to null to avoid double calls\n ws.onclose = ws.onclose || savedOnClose;\n savedOnClose = null;\n };\n log('init');\n connect();\n this.close = function (code, reason, _a) {\n if (code === void 0) { code = 1000; }\n if (reason === void 0) { reason = ''; }\n var _b = _a === void 0 ? {} : _a, _c = _b.keepClosed, keepClosed = _c === void 0 ? false : _c, _d = _b.fastClose, fastClose = _d === void 0 ? true : _d, _e = _b.delay, delay = _e === void 0 ? 0 : _e;\n if (delay) {\n reconnectDelay = delay;\n }\n shouldRetry = !keepClosed;\n ws.close(code, reason);\n if (fastClose) {\n var fakeCloseEvent_1 = {\n code: code,\n reason: reason,\n wasClean: true,\n };\n // execute close listeners soon with a fake closeEvent\n // and remove them from the WS instance so they\n // don't get fired on the real close.\n handleClose();\n ws.removeEventListener('close', handleClose);\n // run and remove level2\n if (Array.isArray(listeners.close)) {\n listeners.close.forEach(function (_a) {\n var listener = _a[0], options = _a[1];\n listener(fakeCloseEvent_1);\n ws.removeEventListener('close', listener, options);\n });\n }\n // run and remove level0\n if (ws.onclose) {\n savedOnClose = ws.onclose;\n ws.onclose(fakeCloseEvent_1);\n ws.onclose = null;\n }\n }\n };\n this.send = function (data) {\n ws.send(data);\n };\n this.addEventListener = function (type, listener, options) {\n if (Array.isArray(listeners[type])) {\n if (!listeners[type].some(function (_a) {\n var l = _a[0];\n return l === listener;\n })) {\n listeners[type].push([listener, options]);\n }\n }\n else {\n listeners[type] = [[listener, options]];\n }\n ws.addEventListener(type, listener, options);\n };\n this.removeEventListener = function (type, listener, options) {\n if (Array.isArray(listeners[type])) {\n listeners[type] = listeners[type].filter(function (_a) {\n var l = _a[0];\n return l !== listener;\n });\n }\n ws.removeEventListener(type, listener, options);\n };\n};\nmodule.exports = ReconnectingWebsocket;\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/reconnecting-websocket/dist/index.js\n// module id = 2\n// module chunks = 0"],"sourceRoot":""} --------------------------------------------------------------------------------