Skip to content

Commit d3de2c5

Browse files
committed
fixup: adjust index.html in websocket example
Signed-off-by: Lance Ball <[email protected]>
1 parent 000ba75 commit d3de2c5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

examples/websocket/index.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
<html>
33
<head>
44
<title>CloudEvent Example</title>
5-
<script src="../../bundles/cloudevents-sdk.js"></script>
5+
<script src="../../_bundles/cloudevents-sdk.js"></script>
66
<script>
77
const CloudEvent = window['cloudevents-sdk'].CloudEvent;
8+
const Version = window['cloudevents-sdk'].Version;
89
const socket = new WebSocket("ws://localhost:8080");
910

1011
function print(weather) {
11-
const data = JSON.parse(weather);
12+
const data = weather;
1213
const summary = `
1314
<h2>Current weather for ${data.name}: ${data.weather[0].main}</h2>
1415
<hr/>
@@ -23,7 +24,7 @@ <h2>Current weather for ${data.name}: ${data.weather[0].main}</h2>
2324

2425
function initialize() {
2526
socket.onmessage = function(message) {
26-
console.log(message.data)
27+
console.log(message.data);
2728
const event = new CloudEvent(JSON.parse(message.data));
2829
if (event.type === "weather.error") {
2930
console.error(`Error: ${event.data}`);
@@ -37,11 +38,13 @@ <h2>Current weather for ${data.name}: ${data.weather[0].main}</h2>
3738
input.addEventListener("keyup", function(event) {
3839
if (event.keyCode === 13) {
3940
event.preventDefault();
40-
socket.send(new CloudEvent({
41+
const ce = new CloudEvent({
4142
type: "weather.query",
4243
source: "/weather.client",
43-
data: input.value
44-
}).toString());
44+
data: { zip: input.value }
45+
});
46+
console.log(ce);
47+
socket.send(JSON.stringify(ce));
4548
}
4649
});
4750

0 commit comments

Comments
 (0)