alexeyinkin commented on code in PR #22959: URL: https://github.com/apache/beam/pull/22959#discussion_r958445269
########## playground/frontend/lib/utils/javascript_post_message.dart: ########## @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import 'dart:convert'; +import 'dart:html' as html; + +/// Sends the [message] repeatedly 30 times with the interval of one second. +/// +/// Call this to send [message] to a newly opened window when it is unknown +/// if it is interactive yet. +/// +/// The receiver should be idempotent or be able to ignore repeated messages +/// after it handles the first one. +void javaScriptPostMessageRepeated( + html.WindowBase window, + dynamic message, +) async { + final messageString = jsonEncode(message); + + for (int i = 30; --i >= 0; ) { + window.postMessage(messageString, '*'); + await Future.delayed(const Duration(seconds: 1)); Review Comment: This seems like nasty workaround, but this is the only thing we can think of to send a message to an unreliable recipient without introducing any contract for response from them. A response expectation would be a worse solution since response messages can interfere with the JS of any 3rd party HTML pages embedding this iframe. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
