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 import 'dart:convert'; | |
6 import 'dart:html'; | 5 import 'dart:html'; |
7 | 6 |
8 import 'package:stream_channel/stream_channel.dart'; | 7 import 'package:stream_channel/stream_channel.dart'; |
9 | 8 |
10 /// Constructs a [StreamChannel] wrapping `postMessage` communication with the | 9 /// Constructs a [StreamChannel] wrapping `postMessage` communication with the |
11 /// host page. | 10 /// host page. |
12 StreamChannel postMessageChannel() { | 11 StreamChannel postMessageChannel() { |
13 var controller = new StreamChannelController(sync: true); | 12 var controller = new StreamChannelController(sync: true); |
14 | 13 |
15 window.onMessage.listen((message) { | 14 window.onMessage.listen((message) { |
(...skipping 18 matching lines...) Expand all Loading... |
34 | 33 |
35 // Send a ready message once we're listening so the host knows it's safe to | 34 // Send a ready message once we're listening so the host knows it's safe to |
36 // start sending events. | 35 // start sending events. |
37 window.parent.postMessage({ | 36 window.parent.postMessage({ |
38 "href": window.location.href, | 37 "href": window.location.href, |
39 "ready": true | 38 "ready": true |
40 }, window.location.origin); | 39 }, window.location.origin); |
41 | 40 |
42 return controller.foreign; | 41 return controller.foreign; |
43 } | 42 } |
OLD | NEW |