| #!mojo mojo:js_content_handler |
| // A JavaScript version of the C++ echo example. Connect to the echo_server.js |
| // application, call it's echoString() method, and then quit. To run this |
| // application with mojo_shell, set DIR to be the absolute path for this |
| // mojo_shell "file://$DIR/echo_client.js" |
| "mojo/services/public/js/application", |
| "examples/echo/echo.mojom", |
| ], function(console, application, echo) { |
| const Application = application.Application; |
| class EchoClientApp extends Application { |
| // The URL of this application is saved by the Application constructor. |
| // Assume that the echo_server.js URL is a sibling of echo_client.js. |
| // Note also: we could also connect to to the C++ echo service with: |
| // var echoServerURL = "mojo:echo_server"; |
| this.url.replace("echo_client.js", "echo_server.js"); |
| this.shell.connectToService(echoServerURL, Echo); |
| var echoServerApp = this; |
| echoServer.echoString("Hello World").then(function(response) { |
| console.log("Response: " + response.value); |