This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ <h1>Examples</h1>
1616 < li > < a href ="counting.html "> Counting Tasks</ a > </ li >
1717 < li > < a href ="profiling.html "> Profiling Across Tasks</ a > </ li >
1818 < li > < a href ="throttle.html "> Throttle</ a > </ li >
19+ < li > < a href ="web-socket.html "> WebSocket</ a > </ li >
1920 < li > < a href ="xml-http-request.html "> XMLHttpRequest</ a > </ li >
2021 </ ol >
2122
Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 ">
5+ < title > WebSockets with Zones</ title >
6+ < link rel ="stylesheet " href ="style.css ">
7+ < script src ="../zone.js "> </ script >
8+ </ head >
9+ < body >
10+
11+ < p >
12+ Ensure that you started < code > node test/ws-server.js</ code > before loading
13+ this page. Then check console output.
14+ </ p >
15+
16+ < script >
17+
18+ var ws = new WebSocket ( 'ws://localhost:8001' ) ;
19+
20+ ws . onopen = function ( ) {
21+ console . log ( 'Setting secret payload in the current zone (id: %d)' , zone . $id ) ;
22+ zone . secretPayload = 'bah!' ;
23+
24+ ws . onmessage = function ( event ) {
25+ if ( ! zone . hasOwnProperty ( 'secretPayload' ) &&
26+ zone . parent . hasOwnProperty ( 'secretPayload' ) &&
27+ zone . secretPayload === 'bah!' ) {
28+ console . log ( "The current zone (id: %d) doesn't have secretPayload, but parent (id: %d) does. Zones are working!" ,
29+ zone . $id , zone . parent . $id ) ;
30+ } else {
31+ console . error ( 'Secret payload not found where expected! Zones are not working! :-(' ) ;
32+ }
33+ } ;
34+ ws . send ( 'hello!' ) ;
35+ } ;
36+
37+ </ script >
38+ </ body >
39+ </ html >
You can’t perform that action at this time.
0 commit comments