Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1575)

Unified Diff: native_client_sdk/src/examples/api/messaging/example.js

Issue 781623002: [NaCl SDK] Messaging example (demonstrates postMessageAndAwaitResponse) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/examples/api/messaging/example.js
diff --git a/native_client_sdk/src/examples/api/messaging/example.js b/native_client_sdk/src/examples/api/messaging/example.js
new file mode 100644
index 0000000000000000000000000000000000000000..32275dd3e9f6dcf45deb66e20b209c9d5f682e5d
--- /dev/null
+++ b/native_client_sdk/src/examples/api/messaging/example.js
@@ -0,0 +1,35 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function attachListeners() {
+ var number1El = document.querySelector('#addend1');
+ var number2El = document.querySelector('#addend2');
+ var resultEl = document.querySelector('#result');
+
+ document.getElementById('addAsync').addEventListener('click', function() {
+ var value1 = parseInt(number1El.value);
+ var value2 = parseInt(number2El.value);
+ common.naclModule.postMessage([value1, value2]);
+
+ // The result is returned in handleMessage below.
+ });
+
+ document.getElementById('addSync').addEventListener('click', function() {
+ var value1 = parseInt(number1El.value);
+ var value2 = parseInt(number2El.value);
+ var result =
+ common.naclModule.postMessageAndAwaitResponse([value1, value2]);
+
+ // This is the result returned from the module synchronously (i.e. when the
+ // addSync button is pressed)
+ resultEl.textContent = result;
+ });
+}
+
+// Called by the common.js module.
+function handleMessage(message_event) {
+ // This is the result returned from the module asynchronously (i.e. when the
+ // addAsync button is pressed)
+ result.textContent = message_event.data;
+}
« no previous file with comments | « native_client_sdk/src/examples/api/messaging/example.dsc ('k') | native_client_sdk/src/examples/api/messaging/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698