-
Notifications
You must be signed in to change notification settings - Fork 0
/
pong.html
74 lines (70 loc) · 2.84 KB
/
pong.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!--
Copyright (c) 2011 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.
-->
<head>
<title>Pong</title>
<script type="text/javascript">
var pong = null;
var paintInterval = null;
// Handle a message coming from the NaCl module. The message payload is
// assumed to contain the current game score. Update the score text
// display with this value.
// Note that errors are also sent to this handler. A message starting
// with 'ERROR' is considered an error, all other strings are assumed
// to be scores.
function handleMessage(message_event) {
if (message_event.data.indexOf('ERROR') == 0) {
document.getElementById('error_log').innerHTML = message_event.data;
} else {
document.getElementById('score').innerHTML = message_event.data;
}
}
function pageDidUnload() {
clearInterval(paintInterval);
}
function resetScore() {
pong = document.getElementById('pong');
pong.postMessage("resetScore");
}
</script>
</head>
<body id="bodyId" onunload="pageDidUnload()">
<h1>Pong</h1>
<!-- Load the published .nexe. This includes the 'src' attribute which
shows how to load multi-architecture modules. Each entry in the "nexes"
object in the .nmf manifest file is a key-value pair: the key is the
runtime ('x86-32', 'x86-64', etc.); the value is a URL for the desired NaCl
module. To load the debug versions of your .nexes, set the 'src'
attribute to the _dbg.nmf version of the manifest file.
Note: The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
and a 'message' event listener attached. This wrapping method is used
instead of attaching the event listeners directly to the <EMBED> element to
ensure that the listeners are active before the NaCl module 'load' event
fires. This also allows you to use PPB_Messaging.PostMessage() (in C) or
pp::Instance.PostMessage() (in C++) from within the initialization code in
your NaCl module.
-->
<div id="listener">
<script type="text/javascript">
window.webkitStorageInfo.requestQuota(PERSISTENT, 1024);
var listener = document.getElementById('listener')
listener.addEventListener('message', handleMessage, true);
</script>
<embed name="nacl_module"
id="pong"
width=1000 height=800
src="pong.nmf"
type="application/x-nacl" />
</div>
<br />
<p id="score">
</p>
<button onclick="resetScore()">Reset score</button>
<p id="error_log"></p>
</body>
</html>