[html5] r7082 - [e] (0) add websocket onmessage example Fixing https://www.w3.org/Bugs/Public/sh [...]

whatwg at whatwg.org whatwg at whatwg.org
Wed May 2 12:50:01 PDT 2012


Author: ianh
Date: 2012-05-02 12:49:59 -0700 (Wed, 02 May 2012)
New Revision: 7082

Modified:
   complete.html
   index
   source
Log:
[e] (0) add websocket onmessage example
Fixing https://www.w3.org/Bugs/Public/show_bug.cgi?id=16134
Affected topics: WebSocket API

Modified: complete.html
===================================================================
--- complete.html	2012-04-28 04:01:44 UTC (rev 7081)
+++ complete.html	2012-05-02 19:49:59 UTC (rev 7082)
@@ -240,7 +240,7 @@
 
   <header class=head id=head><p><a class=logo href=http://www.whatwg.org/><img alt=WHATWG height=101 src=/images/logo width=101></a></p>
    <hgroup><h1 class=allcaps>HTML</h1>
-    <h2 class="no-num no-toc">Living Standard — Last Updated 28 April 2012</h2>
+    <h2 class="no-num no-toc">Living Standard — Last Updated 2 May 2012</h2>
    </hgroup><dl><dt><strong>Web developer edition:</strong></dt>
     <dd><strong><a href=http://developers.whatwg.org/>http://developers.whatwg.org/</a></strong></dd>
     <dt>Multiple-page version:</dt>
@@ -81632,6 +81632,24 @@
   data back to RAM before running this <a href=#concept-task title=concept-task>task</a> so as to avoid stalling the main
   thread while it created the <code><a href=#arraybuffer>ArrayBuffer</a></code> object.</p>
 
+  <div class=example>
+
+   <p>Here is an example of how to define a handler for the <code title=event-message><a href=#event-message>message</a></code> event in the case of text
+   frames:</p>
+
+   <pre>mysocket.onmessage = function (event) {
+  if (event.data == 'on') {
+    turnLampOn();
+  } else if (event.data == 'off') {
+    turnLampOff();
+  }
+};</pre>
+
+   <p>The protocol here is a trivial one, with the server just sending
+   "on" or "off" messages.</p>
+
+  </div>
+
   <hr><p>When <i><a href=#the-websocket-closing-handshake-is-started>the WebSocket closing handshake is started</a></i>, the user
   agent must <a href=#queue-a-task>queue a task</a> to change the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's value
   to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2). (If the

Modified: index
===================================================================
--- index	2012-04-28 04:01:44 UTC (rev 7081)
+++ index	2012-05-02 19:49:59 UTC (rev 7082)
@@ -240,7 +240,7 @@
 
   <header class=head id=head><p><a class=logo href=http://www.whatwg.org/><img alt=WHATWG height=101 src=/images/logo width=101></a></p>
    <hgroup><h1 class=allcaps>HTML</h1>
-    <h2 class="no-num no-toc">Living Standard — Last Updated 28 April 2012</h2>
+    <h2 class="no-num no-toc">Living Standard — Last Updated 2 May 2012</h2>
    </hgroup><dl><dt><strong>Web developer edition:</strong></dt>
     <dd><strong><a href=http://developers.whatwg.org/>http://developers.whatwg.org/</a></strong></dd>
     <dt>Multiple-page version:</dt>
@@ -81632,6 +81632,24 @@
   data back to RAM before running this <a href=#concept-task title=concept-task>task</a> so as to avoid stalling the main
   thread while it created the <code><a href=#arraybuffer>ArrayBuffer</a></code> object.</p>
 
+  <div class=example>
+
+   <p>Here is an example of how to define a handler for the <code title=event-message><a href=#event-message>message</a></code> event in the case of text
+   frames:</p>
+
+   <pre>mysocket.onmessage = function (event) {
+  if (event.data == 'on') {
+    turnLampOn();
+  } else if (event.data == 'off') {
+    turnLampOff();
+  }
+};</pre>
+
+   <p>The protocol here is a trivial one, with the server just sending
+   "on" or "off" messages.</p>
+
+  </div>
+
   <hr><p>When <i><a href=#the-websocket-closing-handshake-is-started>the WebSocket closing handshake is started</a></i>, the user
   agent must <a href=#queue-a-task>queue a task</a> to change the <code title=dom-WebSocket-readyState><a href=#dom-websocket-readystate>readyState</a></code> attribute's value
   to <code title=dom-WebSocket-CLOSING><a href=#dom-websocket-closing>CLOSING</a></code> (2). (If the

Modified: source
===================================================================
--- source	2012-04-28 04:01:44 UTC (rev 7081)
+++ source	2012-05-02 19:49:59 UTC (rev 7082)
@@ -94906,6 +94906,25 @@
   title="concept-task">task</span> so as to avoid stalling the main
   thread while it created the <code>ArrayBuffer</code> object.</p>
 
+  <div class="example">
+
+   <p>Here is an example of how to define a handler for the <code
+   title="event-message">message</code> event in the case of text
+   frames:</p>
+
+   <pre>mysocket.onmessage = function (event) {
+  if (event.data == 'on') {
+    turnLampOn();
+  } else if (event.data == 'off') {
+    turnLampOff();
+  }
+};</pre>
+
+   <p>The protocol here is a trivial one, with the server just sending
+   "on" or "off" messages.</p>
+
+  </div>
+
   <hr>
 
   <p>When <i>the WebSocket closing handshake is started</i>, the user




More information about the Commit-Watchers mailing list