-
Notifications
You must be signed in to change notification settings - Fork 6
/
conference.html
134 lines (123 loc) · 4.59 KB
/
conference.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
134
<!DOCTYPE html>
<head>
<title>JS sandbox - FHIRCast conferencing</title>
</head>
<body>
<div class="conference" id="conferenceStop">
<p id="status"> </p>
<p id="userList"> </p>
<button id="stop" onclick="stopConference(user)">Stop conference</button>
</div>
<div class="conference" id="conferenceStart">
<table>
<tr>
<td>Title</td>
<td>
<select id="name" name="Name" >
<option value="Tumor board" selected>Tumor board</option>
<option value="Resident teaching">Resident teaching</option>
<option value="Pathology weekly" >Pathology weekly</option>
</select>
</td>
</tr>
<tr>
<td>Invitees</td>
<td><select id="conferenceUsers" name="conferenceUsers" multiple></select></td>
</tr>
<tr>
<td></td>
<td>
<button onclick="startConference(document.getElementById('name').value,user,topics)">Start conference</button>
</td>
</tr>
</table>
</div>
<script>
document.getElementById('conferenceStop').style.visibility = 'hidden';
var topics={};
var parser=document.createElement('a'); // use link tag as a url parser
parser.href=window.location;
var xhr=new XMLHttpRequest();
xhr.open('POST',parser.protocol+'//' + parser.host + '/mode');
xhr.send();
xhr.onloadend = function() {
var env=JSON.parse(this.responseText);
document.body.style.backgroundColor = env.backgroundColor;
};
var user = getUrlParameter("user");
var xhr=new XMLHttpRequest();
xhr.open('GET',parser.protocol+'//' + parser.host + '/conference');
xhr.send();
xhr.onloadend = function() {
conferences=JSON.parse(this.responseText);
conferences.forEach(conference => {
if (user===conference.user) {
// conference is running for this user
document.getElementById('conferenceStart').style.visibility = 'collapse';
document.getElementById('conferenceStop').style.visibility = 'visible';
document.getElementById('status').innerText=conference.title+' conference is in progress with users:';
document.getElementById('userList').innerText=conference.topics;
}
else if (conference.topics.includes(user)) {
document.getElementById('stop').innerText='Exit conference';
document.getElementById('conferenceStart').style.visibility = 'collapse';
document.getElementById('conferenceStop').style.visibility = 'visible';
}
});
};
var select=document.getElementById('conferenceUsers');
var xhr=new XMLHttpRequest();
xhr.open('GET',parser.protocol+'//' + parser.host + '/topics');
xhr.send();
xhr.onloadend = function() {
topics=JSON.parse(this.responseText);
topics.forEach(topic => {
if (user!==topic) {
option = document.createElement('option');
option.setAttribute('value', topic);
option.setAttribute('label', topic);
option.selected=true;
select.add(option);
}
});
};
function startConference(title,user,topics){
var xhr=new XMLHttpRequest();
xhr.open('POST',parser.protocol+'//' + parser.host + '/conference');
xhr.setRequestHeader('Content-Type','application/json');
var conference={};
conference.user=user;
conference.title=title;
conference.topics=[];
for(var option of document.getElementById('conferenceUsers').options) {
if(option.selected) {
conference.topics.push(option.value);
}
}
xhr.send(JSON.stringify(conference));
location.reload();
return;
}
function stopConference(user){
var xhr=new XMLHttpRequest();
xhr.open('DELETE',parser.protocol+'//' + parser.host + '/conference');
xhr.setRequestHeader('Content-Type','application/json');
xhr.send('{"user": "'+user +'"}');
location.reload();
return;
}
function getUrlParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
var res = sParameterName[1].replace(/\+/g, '%20');
return decodeURIComponent(res);
}
}
}
</script>
</body>