GUI -- Added ability to define an alternate port for WS - used to connect to moc…
…k web-socket server. Topo view can use query string '?wsport=8123' for example. Change-Id: Ie34d557b9580d58239380010e8d58233998a78ca
Showing
4 changed files
with
32 additions
and
20 deletions
... | @@ -33,25 +33,25 @@ | ... | @@ -33,25 +33,25 @@ |
33 | return secure ? protocol + 's' : protocol; | 33 | return secure ? protocol + 's' : protocol; |
34 | } | 34 | } |
35 | 35 | ||
36 | - function urlBase(protocol) { | 36 | + function urlBase(protocol, port) { |
37 | return matchSecure(protocol) + '://' + | 37 | return matchSecure(protocol) + '://' + |
38 | - $loc.host() + ':' + $loc.port(); | 38 | + $loc.host() + ':' + (port || $loc.port()); |
39 | } | 39 | } |
40 | 40 | ||
41 | function httpPrefix(suffix) { | 41 | function httpPrefix(suffix) { |
42 | return urlBase('http') + suffix; | 42 | return urlBase('http') + suffix; |
43 | } | 43 | } |
44 | 44 | ||
45 | - function wsPrefix(suffix) { | 45 | + function wsPrefix(suffix, wsport) { |
46 | - return urlBase('ws') + suffix; | 46 | + return urlBase('ws', wsport) + suffix; |
47 | } | 47 | } |
48 | 48 | ||
49 | function rsUrl(path) { | 49 | function rsUrl(path) { |
50 | return httpPrefix(rsSuffix) + path; | 50 | return httpPrefix(rsSuffix) + path; |
51 | } | 51 | } |
52 | 52 | ||
53 | - function wsUrl(path) { | 53 | + function wsUrl(path, wsport) { |
54 | - return wsPrefix(wsSuffix) + path; | 54 | + return wsPrefix(wsSuffix, wsport) + path; |
55 | } | 55 | } |
56 | 56 | ||
57 | return { | 57 | return { | ... | ... |
... | @@ -23,15 +23,17 @@ | ... | @@ -23,15 +23,17 @@ |
23 | var fs; | 23 | var fs; |
24 | 24 | ||
25 | angular.module('onosRemote') | 25 | angular.module('onosRemote') |
26 | - .factory('WebSocketService', ['$location', 'UrlFnService', 'FnService', | 26 | + .factory('WebSocketService', |
27 | - function ($loc, ufs, _fs_) { | 27 | + ['$log', '$location', 'UrlFnService', 'FnService', |
28 | + | ||
29 | + function ($log, $loc, ufs, _fs_) { | ||
28 | fs = _fs_; | 30 | fs = _fs_; |
29 | 31 | ||
30 | // creates a web socket for the given path, returning a "handle". | 32 | // creates a web socket for the given path, returning a "handle". |
31 | - // cb is the callbacks block. | 33 | + // opts contains the event handler callbacks. |
32 | - function createWebSocket(path, cb) { | 34 | + function createWebSocket(path, opts) { |
33 | - //var fullUrl = ufs.wsUrl(path), | 35 | + var wsport = opts && opts.wsport, |
34 | - var fullUrl = 'ws://localhost:8123/foo', | 36 | + fullUrl = ufs.wsUrl(path, wsport), |
35 | ws = new WebSocket(fullUrl), | 37 | ws = new WebSocket(fullUrl), |
36 | api = { | 38 | api = { |
37 | meta: { path: fullUrl, ws: ws }, | 39 | meta: { path: fullUrl, ws: ws }, |
... | @@ -39,9 +41,11 @@ | ... | @@ -39,9 +41,11 @@ |
39 | close: close | 41 | close: close |
40 | }; | 42 | }; |
41 | 43 | ||
42 | - ws.onopen = (cb && cb.onOpen) || null; | 44 | + $log.debug('Attempting to open websocket to: ' + fullUrl); |
43 | - ws.onmessage = (cb && cb.onMessage) || null; | 45 | + |
44 | - ws.onclose = (cb && cb.onClose) || null; | 46 | + ws.onopen = (opts && opts.onOpen) || null; |
47 | + ws.onmessage = (opts && opts.onMessage) || null; | ||
48 | + ws.onclose = (opts && opts.onClose) || null; | ||
45 | 49 | ||
46 | function send(msg) { | 50 | function send(msg) { |
47 | if (msg) { | 51 | if (msg) { | ... | ... |
... | @@ -147,11 +147,14 @@ | ... | @@ -147,11 +147,14 @@ |
147 | 147 | ||
148 | } | 148 | } |
149 | 149 | ||
150 | - function setUpWebSocket() { | 150 | + // wsport indicates web-socket-server port other than the default. |
151 | + // Used for testing with the mock-web-socket-server. | ||
152 | + function setUpWebSocket(wsport) { | ||
151 | var wsHandle = wss.createWebSocket('topology', { | 153 | var wsHandle = wss.createWebSocket('topology', { |
152 | onOpen: onWsOpen, | 154 | onOpen: onWsOpen, |
153 | onMessage: onWsMessage, | 155 | onMessage: onWsMessage, |
154 | - onClose: onWsClose | 156 | + onClose: onWsClose, |
157 | + wsport: wsport | ||
155 | }); | 158 | }); |
156 | 159 | ||
157 | // TODO: handle "guiSuccessor" functionality (replace host) | 160 | // TODO: handle "guiSuccessor" functionality (replace host) |
... | @@ -168,11 +171,11 @@ | ... | @@ -168,11 +171,11 @@ |
168 | angular.module('ovTopo', moduleDependencies) | 171 | angular.module('ovTopo', moduleDependencies) |
169 | 172 | ||
170 | .controller('OvTopoCtrl', [ | 173 | .controller('OvTopoCtrl', [ |
171 | - '$scope', '$log', | 174 | + '$scope', '$log', '$location', |
172 | 'KeyService', 'ZoomService', 'GlyphService', 'MapService', | 175 | 'KeyService', 'ZoomService', 'GlyphService', 'MapService', |
173 | 'WebSocketService', | 176 | 'WebSocketService', |
174 | 177 | ||
175 | - function ($scope, _$log_, _ks_, _zs_, _gs_, _ms_, _wss_) { | 178 | + function ($scope, _$log_, $loc, _ks_, _zs_, _gs_, _ms_, _wss_) { |
176 | var self = this; | 179 | var self = this; |
177 | $log = _$log_; | 180 | $log = _$log_; |
178 | ks = _ks_; | 181 | ks = _ks_; |
... | @@ -200,7 +203,7 @@ | ... | @@ -200,7 +203,7 @@ |
200 | setUpDefs(); | 203 | setUpDefs(); |
201 | setUpZoom(); | 204 | setUpZoom(); |
202 | setUpMap(); | 205 | setUpMap(); |
203 | - setUpWebSocket(); | 206 | + setUpWebSocket($loc.search().wsport); |
204 | 207 | ||
205 | $log.log('OvTopoCtrl has been created'); | 208 | $log.log('OvTopoCtrl has been created'); |
206 | }]); | 209 | }]); | ... | ... |
... | @@ -76,4 +76,9 @@ describe('factory: fw/remote/urlfn.js', function () { | ... | @@ -76,4 +76,9 @@ describe('factory: fw/remote/urlfn.js', function () { |
76 | setLoc('https', 'foo', '123'); | 76 | setLoc('https', 'foo', '123'); |
77 | expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/ws/path'); | 77 | expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/ws/path'); |
78 | }); | 78 | }); |
79 | + | ||
80 | + it('should allow us to define an alternate WS port', function () { | ||
81 | + setLoc('http', 'foo', '123'); | ||
82 | + expect(ufs.wsUrl('xyyzy', 456)).toEqual('ws://foo:456/onos/ui/ws/xyyzy'); | ||
83 | + }); | ||
79 | }); | 84 | }); | ... | ... |
-
Please register or login to post a comment