| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of repositories; | 5 part of repositories; |
| 6 | 6 |
| 7 class TargetChangeEvent implements M.TargetChangeEvent { | 7 class TargetChangeEvent implements M.TargetChangeEvent { |
| 8 final TargetRepository repository; | 8 final TargetRepository repository; |
| 9 final bool disconnected; | 9 final bool disconnected; |
| 10 TargetChangeEvent(this.repository, [this.disconnected = false]); | 10 TargetChangeEvent(this.repository, [this.disconnected = false]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 factory TargetRepository() { | 23 factory TargetRepository() { |
| 24 var controller = new StreamController<TargetChangeEvent>(); | 24 var controller = new StreamController<TargetChangeEvent>(); |
| 25 var stream = controller.stream.asBroadcastStream(); | 25 var stream = controller.stream.asBroadcastStream(); |
| 26 return new TargetRepository._(controller, stream); | 26 return new TargetRepository._(controller, stream); |
| 27 } | 27 } |
| 28 | 28 |
| 29 TargetRepository._(this._onChange, this.onChange) { | 29 TargetRepository._(this._onChange, this.onChange) { |
| 30 _restore(); | 30 _restore(); |
| 31 // Add the default address if it doesn't already exist. | 31 // Add the default address if it doesn't already exist. |
| 32 if (_find(_networkAddressOfDefaultTarget()) == null) { | 32 if (find(_networkAddressOfDefaultTarget()) == null) { |
| 33 add(_networkAddressOfDefaultTarget()); | 33 add(_networkAddressOfDefaultTarget()); |
| 34 } | 34 } |
| 35 // Set the current target to the default target. | 35 // Set the current target to the default target. |
| 36 current = _find(_networkAddressOfDefaultTarget()); | 36 current = find(_networkAddressOfDefaultTarget()); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void add(String address) { | 39 void add(String address) { |
| 40 if (_find(address) != null) { | 40 if (find(address) != null) { |
| 41 return; | 41 return; |
| 42 } | 42 } |
| 43 _list.insert(0, new SC.WebSocketVMTarget(address)); | 43 _list.insert(0, new SC.WebSocketVMTarget(address)); |
| 44 _onChange.add(new TargetChangeEvent(this)); | 44 _onChange.add(new TargetChangeEvent(this)); |
| 45 _store(); | 45 _store(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 Iterable<SC.WebSocketVMTarget> list() => _list; | 48 Iterable<SC.WebSocketVMTarget> list() => _list; |
| 49 | 49 |
| 50 void setCurrent(M.Target t) { | 50 void setCurrent(M.Target t) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return b.lastConnectionTime.compareTo(a.lastConnectionTime); | 84 return b.lastConnectionTime.compareTo(a.lastConnectionTime); |
| 85 }); | 85 }); |
| 86 } | 86 } |
| 87 | 87 |
| 88 /// After making a change, update settings. | 88 /// After making a change, update settings. |
| 89 void _store() { | 89 void _store() { |
| 90 _settings.set(_historyKey, _list); | 90 _settings.set(_historyKey, _list); |
| 91 } | 91 } |
| 92 | 92 |
| 93 /// Find by networkAddress. | 93 /// Find by networkAddress. |
| 94 SC.WebSocketVMTarget _find(String networkAddress) { | 94 SC.WebSocketVMTarget find(String networkAddress) { |
| 95 for (SC.WebSocketVMTarget item in _list) { | 95 for (SC.WebSocketVMTarget item in _list) { |
| 96 if (item.networkAddress == networkAddress) { | 96 if (item.networkAddress == networkAddress) { |
| 97 return item; | 97 return item; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 return null; | 100 return null; |
| 101 } | 101 } |
| 102 | 102 |
| 103 static String _networkAddressOfDefaultTarget() { | 103 static String _networkAddressOfDefaultTarget() { |
| 104 if (Utils.runningInJavaScript()) { | 104 Uri serverAddress = Uri.parse(window.location.toString()); |
| 105 // We are running as JavaScript, use the same host that Observatory has | 105 return 'ws://${serverAddress.authority}${serverAddress.path}ws'; |
| 106 // been loaded from. | |
| 107 return 'ws://${window.location.host}/ws'; | |
| 108 } else { | |
| 109 // Otherwise, assume we are running from Dart Editor and want to connect | |
| 110 // to the default host. | |
| 111 return 'ws://localhost:8181/ws'; | |
| 112 } | |
| 113 } | 106 } |
| 114 } | 107 } |
| OLD | NEW |