-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
44 lines (44 loc) · 1.97 KB
/
index.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
<!-- Realtime Golang WebAssembly chat app using PubNub in a minimal amount of code -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" type="image/png" href="icon.png">
<meta name="description" content="Example of a chat app using PubNub Go SDK with WebAssembly.">
<meta name="keywords" content="JavaScript,PubNub,Chat,chat-room,chatting,SDK,PubSub-sdk,tutorial,WebAssembly,golang">
<meta name="author" content="Chandler Mayo">
<title>Go WebAssembly Chat | PubNub</title>
</head>
<body>
<p><a href="https://www.pubnub.com/?devrel_pbpn=go-wasm-chat"><img src="https://d2c805weuec6z7.cloudfront.net/Powered_By_PubNub.png" alt="Powered By PubNub" width="150"></a></p>
<p>Enter chat and click send.</p>
<input id="input" placeholder="Your Message Here"/>
<button id="send" type="button" style="background: lightgray; cursor: pointer;">Send</button>
<p>Chat Output:<p>
<div id="box"></div>
<!-- https://github.com/golang/go/blob/master/misc/wasm/wasm_exec.js -->
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
let mod, inst;
WebAssembly.instantiateStreaming(
fetch("main.wasm", {cache: 'no-cache'}), go.importObject).then((result) => {
mod = result.module;
inst = result.instance;
run();
});
async function run() {
await go.run(inst);
};
(function(){
input.addEventListener('keypress', function (e) {
if (e.keyCode == 13) { // Enter was pressed.
e.preventDefault();
// Trigger the send button.
document.getElementById("send").click();
};
});
})();</script>
</body>
</html>