From 684ddfd78d0a7370a6efd34020dbf6fd4cc2ffbc Mon Sep 17 00:00:00 2001 From: Philip Marais Date: Wed, 26 Sep 2018 07:25:25 +0200 Subject: [PATCH 1/4] Added connection variable for manual-connect Added the option to connect to a connection other than the connections dictated in the instantiation. Can be used as usual with `this.$connect()`, or alternatively `this.$connect('ws://localhost:port/foo/')` to specify a different socket endpoint/channel. --- src/Main.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Main.js b/src/Main.js index 53ab66d..11812d2 100755 --- a/src/Main.js +++ b/src/Main.js @@ -13,7 +13,10 @@ export default { } if (opts.connectManually) { - Vue.prototype.$connect = () => { + Vue.prototype.$connect = (connectionAlternative) => { + if (connectionAlternative) { + connection = connectionAlternative + } observer = new Observer(connection, opts) Vue.prototype.$socket = observer.WebSocket } From 3ea1a54c77fb2176053edaa35d5c20c7fd983f83 Mon Sep 17 00:00:00 2001 From: Philip Marais Date: Wed, 26 Sep 2018 07:28:03 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7ced2a9..f517249 100755 --- a/README.md +++ b/README.md @@ -67,7 +67,10 @@ Vue.use(VueNativeSock, 'ws://localhost:9090', { connectManually: true, }) const vm = new Vue() +// Connect to the websocket target specified in the configuration vm.$connect() +// Connect to an alternative websocket URI +vm.$connect('ws://localhost:9090/alternative/connection/') // do stuff with WebSockets vm.$disconnect() ``` From 94c131ecfef538bb2efb5a94cbcb76dcc41aa606 Mon Sep 17 00:00:00 2001 From: Philip Marais Date: Wed, 26 Sep 2018 11:28:34 +0200 Subject: [PATCH 3/4] Connection URL/Opts update with default values Added the `connectionUrl` & `connectionOpts` parameters with default values, to the manual `connect` function --- src/Main.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Main.js b/src/Main.js index 11812d2..dffa89b 100755 --- a/src/Main.js +++ b/src/Main.js @@ -13,11 +13,8 @@ export default { } if (opts.connectManually) { - Vue.prototype.$connect = (connectionAlternative) => { - if (connectionAlternative) { - connection = connectionAlternative - } - observer = new Observer(connection, opts) + Vue.prototype.$connect = (connectionUrl = connection, connectionOpts = opts) => { + observer = new Observer(connectionUrl, connectionOpts) Vue.prototype.$socket = observer.WebSocket } From 0ec586b4d5a07ac427933bb77d45174285554bd4 Mon Sep 17 00:00:00 2001 From: Philip Marais Date: Wed, 26 Sep 2018 11:31:41 +0200 Subject: [PATCH 4/4] Readme update for manual connect `vm.$connect(connectionURL, connectionOpts)` example in the `Readme` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f517249..84864f3 100755 --- a/README.md +++ b/README.md @@ -69,8 +69,8 @@ Vue.use(VueNativeSock, 'ws://localhost:9090', { const vm = new Vue() // Connect to the websocket target specified in the configuration vm.$connect() -// Connect to an alternative websocket URI -vm.$connect('ws://localhost:9090/alternative/connection/') +// Connect to an alternative websocket URL and Options e.g. +vm.$connect('ws://localhost:9090/alternative/connection/', { format: 'json' }) // do stuff with WebSockets vm.$disconnect() ```