-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (101 loc) · 2.55 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sparrow</title>
<!-- for mobile screens -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- stylesheets are conveniently separated into components -->
<link rel="stylesheet" media="all" href="styles/setup.css">
<link rel="stylesheet" media="all" href="styles/says.css">
<link rel="stylesheet" media="all" href="styles/reply.css">
<link rel="stylesheet" media="all" href="styles/typing.css">
<link rel="stylesheet" media="all" href="styles/input.css">
<style>
body {
background: #dcdde0;
}
.bubble-container {
height: 100vh;
}
.bubble-container .input-wrap textarea {
margin: 0;
width: calc(100% - 30px);
}
</style>
</head>
<body>
<div id="chat"></div>
<script src="Bubbles.js"></script>
<script>
var msgcount=0;
var username = null;
const messageSet = new Set([]);
// var server = "http://35ee3617.ngrok.io/";
var server = "http://192.168.4.1";
var chatWindow = new Bubbles(document.getElementById("chat"), "chatWindow", {
inputCallbackFn: function(o) {
if (msgcount==0){
username = o.input;
msgcount = msgcount+1;
console.log(username);
}
else{
var d = new Date();
var ts = d.getTime();
var xhr = new XMLHttpRequest();
var url = server + "/send";
var data = JSON.stringify({
"key":"sparrow:"+username+'_'+ts,
"userID":"sparrow:"+username,
"timeStamp":ts,
"destination":"sparrow",
"message": o.input
});
var formData = new FormData();
formData.append('data', data);
var req = new Request(url, {
method: 'post',
body: formData
});
fetch(req);
}
}
})
setInterval(function() {
fetch(server + '/receive', {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*"
},
})
.then(r => r.json())
.then(r => {
r.forEach(message => {
var currentUserID = message['userID'];
var messageContent = message['message'];
var messageKey = message['key'];
var destination = message['destination'];
if (!messageSet.has(messageKey) && ("sparrow:"+username == destination)){
messageSet.add(messageKey);
var convoNew = {
ice: {
says: [messageContent],
}
};
chatWindow.talk(convoNew);
}
});
});
}, 10 * 1000);
var initiateConversation = {
ice: {
says: ["Hi", "Whats your username?"],
}
}
chatWindow.talk(initiateConversation)
</script>
</body>