forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb-socket.html
More file actions
42 lines (39 loc) · 1.26 KB
/
Copy pathweb-socket.html
File metadata and controls
42 lines (39 loc) · 1.26 KB
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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>WebSockets with Zones</title>
<link rel="stylesheet" href="css/style.css" />
<script src="../dist/zone.js"></script>
</head>
<body>
<p>
Ensure that you started <code>node test/ws-server.js</code> before loading this page. Then
check console output.
</p>
<script>
var ws = new WebSocket('ws://localhost:8001');
ws.onopen = function () {
Zone.current
.fork({properties: {secretPayload: 'bah!'}, name: 'secrete-zone'})
.run(function () {
ws.onmessage = function (eventListener) {
if (Zone.current.get('secretPayload') === 'bah!') {
console.log(
'The current zone (id: %s) has secretPayload. Zones are working!',
Zone.current.name,
);
} else {
console.error(
'Secret payload not found where expected! Zones are not working! :-(',
Zone.current.name,
);
}
};
console.log('Setting secret payload in the current zone (id: %s)', Zone.current.name);
});
ws.send('hello!');
};
</script>
</body>
</html>