OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library unittest.runner.browser.host; | 5 library unittest.runner.browser.host; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:html'; | 9 import 'dart:html'; |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 print("$error\n${new Trace.from(stackTrace).terse}"); | 77 print("$error\n${new Trace.from(stackTrace).terse}"); |
78 }); | 78 }); |
79 } | 79 } |
80 | 80 |
81 /// Creates a [MultiChannel] connection to the server, using a [WebSocket] as | 81 /// Creates a [MultiChannel] connection to the server, using a [WebSocket] as |
82 /// the underlying protocol. | 82 /// the underlying protocol. |
83 MultiChannel _connectToServer() { | 83 MultiChannel _connectToServer() { |
84 // The `managerUrl` query parameter contains the WebSocket URL of the remote | 84 // The `managerUrl` query parameter contains the WebSocket URL of the remote |
85 // [BrowserManager] with which this communicates. | 85 // [BrowserManager] with which this communicates. |
86 var currentUrl = Uri.parse(window.location.href); | 86 var currentUrl = Uri.parse(window.location.href); |
87 var webSocketUrl = currentUrl | 87 var webSocket = new WebSocket(currentUrl.queryParameters['managerUrl']); |
88 .resolve(currentUrl.queryParameters['managerUrl']) | |
89 .replace(scheme: 'ws'); | |
90 var webSocket = new WebSocket(webSocketUrl.toString()); | |
91 | 88 |
92 var inputController = new StreamController(sync: true); | 89 var inputController = new StreamController(sync: true); |
93 webSocket.onMessage.listen( | 90 webSocket.onMessage.listen( |
94 (message) => inputController.add(JSON.decode(message.data))); | 91 (message) => inputController.add(JSON.decode(message.data))); |
95 | 92 |
96 var outputController = new StreamController(sync: true); | 93 var outputController = new StreamController(sync: true); |
97 outputController.stream.listen( | 94 outputController.stream.listen( |
98 (message) => webSocket.send(JSON.encode(message))); | 95 (message) => webSocket.send(JSON.encode(message))); |
99 | 96 |
100 return new MultiChannel(inputController.stream, outputController.sink); | 97 return new MultiChannel(inputController.stream, outputController.sink); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 message.stopPropagation(); | 129 message.stopPropagation(); |
133 inputController.add(message.data["data"]); | 130 inputController.add(message.data["data"]); |
134 }); | 131 }); |
135 | 132 |
136 outputController.stream.listen((message) => | 133 outputController.stream.listen((message) => |
137 iframe.contentWindow.postMessage(message, window.location.origin)); | 134 iframe.contentWindow.postMessage(message, window.location.origin)); |
138 }); | 135 }); |
139 | 136 |
140 return new StreamChannel(inputController.stream, outputController.sink); | 137 return new StreamChannel(inputController.stream, outputController.sink); |
141 } | 138 } |
OLD | NEW |