-
Notifications
You must be signed in to change notification settings - Fork 17
/
chat.html
221 lines (171 loc) · 5.11 KB
/
chat.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link href="chat.css" rel="stylesheet" type="text/css" />
<style>
input[type="text"] {
border: 1px solid black;
}
.videoDialog {
display:none;
}
.videoDialog div {
padding:0;
background-color:#fff;
font-family:"lucida grande",tahoma,verdana,arial,sans-serif
width:400px;
border:5px solid #666;
border:5px solid rgba(232, 232, 232, 0.8);
-moz-border-radius: 0 0 8px 8px;
-webkit-border-radius:0 0 8px 8px;
border-top: 0px;
margin-bottom:-5px;
}
.videoDialog:hover div {
border-color:rgba(82, 82, 82, 0.8);
}
.videoDialog h2 {
margin-top: 0px;
margin-bottom:0px;
color:#fff;
background-color:rgb(232, 232, 232);
padding:5px 10px;
-moz-border-radius:8px 8px 0 0;
-webkit-border-radius:8px 8px 0 0;
font-size:20px;
filter:alpha(opacity=80);
opacity: 0.8;
-moz-opacity:0.8;
color: gray;
}
.videoDialog:hover h2 {
color: white;
background-color:rgb(82, 82, 82);
}
</style>
<script>
$(document).ready(function() {
$(".videoDialog").draggable();
});
var content;
var Signaling = top.Signaling;
var localStream;
window.onload = function() {
content = document.getElementById('content');
chatHistory = document.getElementById('chatHistory');
chatMessage = document.getElementById('chatMessage');
selfView = document.getElementById('selfView');
peerView = document.getElementById('peerView');
addButton = document.getElementById('addButton');
removeButton = document.getElementById('removeButton');
removeButton.disabled = true;
}
function startChat() {
content.hidden = false;
Signaling.Peer.onmessage = receiveChatMessage;
Signaling.Peer.onaddstream = receiveVideoStream;
Signaling.Peer.onremovestream = removeRemoteStream;
}
/* -------------------------------------------------------------------------
* Instant messaging
* ------------------------------------------------------------------------- */
var chatHistory;
var chatMessage;
function receiveChatMessage(e) {
console.log("chat message received");
chatHistory.value += "["+ new Date().toLocaleTimeString() +"] Zdalny: " + e.data + "\n";
}
function sendChatMessage() {
chatHistory.value += "["+ new Date().toLocaleTimeString() +"] Ja: " + chatMessage.value + "\n";
Signaling.Peer.send(chatMessage.value);
chatMessage.value = "";
}
/* -------------------------------------------------------------------------
* Voice & video
* ------------------------------------------------------------------------- */
var selfView;
var peerView;
var addButton;
function requestSelfVideo() {
console.log("requestSelfVideo");
navigator.webkitGetUserMedia('audio,video user', function(stream) {
console.log("got self stream");
localStream = stream;
selfView.src = webkitURL.createObjectURL(stream);
Signaling.Peer.addStream(stream);
$(".local").slideDown(500);
});
addButton.disabled = true;
removeButton.disabled = false;
}
function receiveVideoStream(e) {
console.log("onaddstream event: receiveVideoStream");
peerView.src = webkitURL.createObjectURL(e.stream);
$(".remote").slideDown(500);
}
function stopSelfVideo() {
selfView.src = 0;
try {
Signaling.Peer.removeStream(localStream);
} catch (err) { console.log(err); }
addButton.disabled = false;
removeButton.disabled = true;
$(".local").slideUp(500);
}
function removeRemoteStream() {
console.log("Remote Stream removed")
peerView.src = 0;
$(".remote").slideUp(500);
}
</script>
<body>
<div id="content">
<form id="videoForm">
<div id="videos"></div>
<table align=center>
<tr height="240">
<td width="320">
<div class="videoDialog local">
<h2>Local camera</h2>
<div>
<video id="selfView" width="320" height="240" autoplay controls></video>
</div>
</div>
</td>
<td width="320">
<div class="videoDialog remote">
<h2>Remote camera</h2>
<div>
<video id="peerView" width="320" height="240" autoplay controls></video>
</div>
</div>
</td>
</tr>
<tr><td>
<input id="addButton"
type="button"
value="Turn on webcam"
onclick="requestSelfVideo();">
<input id="removeButton"
type="button"
value="Turn off webcam"
onclick="stopSelfVideo();">
</td>
<td>
</td>
</tr>
</table>
</form>
<div id="chat">
<textarea id="chatHistory" readonly cols="80" rows="6"></textarea>
<form id="chatForm" action="javascript:sendChatMessage();">
<input id="chatMessage" type="text" size="74" >
<input type="submit" value="Send">
</form>
</div>
<div id="footer">Author: Karol Domagala, based on Web RTC <a href="http://labs.ericsson.com/apis/web-real-time-communication">Ericsson Labs</a>.
</div>
</body>
</html>