-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
195 lines (159 loc) · 5.92 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
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XirSys PHP demo</title>
<link href="css/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="css/main.css" rel="stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="js/xrtc-1.5.0.js"></script>
<script src="js/manyToMany.js"></script>
</head>
<body>
<p>Link this demo to yourself or a friend: <a href="http://xirsys.com/demo" target="_blank">http://xirsys.com/demo</a><br>
Fork it on <a href="https://github.com/xirsys/php" target="_blank">GitHub</a>!
</p><br>
<div id="form-join">
<form class="form-horizontal">
<div class="control-group">
<label for="room" class="control-label">Room</label>
<div class="controls">
<input type="text" id="room" name="room" value="default"/>
</div>
</div>
<div class="control-group">
<label for="username" class="control-label">Username</label>
<div class="controls">
<input type="text" id="username" name="username"/>
</div>
</div>
<br>
</form>
<button id="button-join" class="btn btn-primary btn-large">Join</button>
</div>
<div id="form-connect">
<form class="form-horizontal">
<div class="control-group">
<label for="userlist" class="control-label">Other users in this room</label>
<div class="controls">
<ul id="userlist">
</ul>
</div>
</div>
<button id="connect" class="btn btn-primary btn-large">Connect</button>
</form>
<br>
<!-- Video chat -->
<div id="video-slots">
</div>
<!-- Text chat -->
<div id="container-text" class="text-chat">
<div id="chatwindow-outer" class="text-chat">
<div id="chatwindow" class="text-chat">
</div>
</div>
<div id="bottom" class="text-chat">
<input id="message" type="text" name="input" class="text-chat"></input><button id="send" class="btn btn-success btn-large text-chat">Send</button>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
// Initially hide connect form
$('#form-connect').hide()
// Randomize username in form
$("#username").val(randomizeUsername());
// Initialize manyToMany object
manyToMany.init();
$("#button-join").click(function(e) {
e.preventDefault();
// Create room on XirSys if it doesn't exist yet
$.ajax({
url: 'addRoom.php',
type: 'post',
data: {'room': $('#room').val()},
success: (function(data) {
console.log('room created');
})
});
// Success and fail handlers for user's local video / audio stream allocation
var getMediaSuccess = function (stream) {
manyToMany.addVideo({ stream: stream, isLocalStream: true, userId: $('#username').val() });
manyToMany.localMediaStream( stream );
};
var getMediaFailed = function (err) {
console.log('Get media stream error. ', err);
};
// Requests the local video and audio stream
// Comment this out if you don't want a microphone / webcam request
manyToMany.getUserMedia(
{ video: true, audio: true },
getMediaSuccess,
getMediaFailed
);
// Room information object / container
var roomInfo = {
name: $('#room').val()
};
// Create the XirSys objects needed to initialize a room
manyToMany.room( new xRtc.Room(roomInfo) );
// Assign events for updating the room's users list
manyToMany.room().on( xRtc.Room.events.usersUpdated, manyToMany.refreshRoom )
.on( xRtc.Room.events.userConnected, manyToMany.refreshRoom )
.on( xRtc.Room.events.userDisconnected, manyToMany.refreshRoom )
.on( xRtc.Room.events.connectionDeclined, manyToMany.refreshRoom )
// More events for accepting a call and handling connection creation
.on( xRtc.Room.events.incomingConnection, manyToMany.acceptCall )
.on( xRtc.Room.events.connectionCreated, manyToMany.connectionCreated )
.on( xRtc.Room.events.enter, manyToMany.enterRoom );
// Map all other default events
manyToMany.subscribe( manyToMany.room(), xRtc.Room.events );
// Enter / open room
manyToMany.room().enter($("#username").val(), { autoReply: false });
manyToMany.username($("#username").val());
// Hide join form and button
$('#form-join').hide()
$('#form-connect').show()
});
// Handles connect button click
$("#connect").click(function (e) {
e.preventDefault();
// Grab room participants from list
var participants = [];
$('li.participant').each(function(i, elem) {
participants.push($(elem).text());
});
console.log('Connecting to participants');
// Connect to remote peer
for (var i = 0; i < participants.length; i++) {
manyToMany.preConnect(participants[i], { createDataChannel: 'auto' });
}
});
// Sends a message
$("#send").click(function (e) {
e.preventDefault();
if ($("#message").val() != "") {
manyToMany.sendMessage($("#message").val());
$("#message").val("");
}
});
// Hitting enter sends message if not empty
$("#message").keyup(function(event){
if(event.keyCode == 13){
if (this.value != "") {
manyToMany.sendMessage($("#message").val());
this.value = "";
}
}
});
});
// Randomizes username for form
function randomizeUsername() {
var username = "";
var possible = "abcdefghijklmnopqrstuvwxyz";
for( var i=0; i < 5; i++ )
username += possible.charAt(Math.floor(Math.random() * possible.length));
return username;
}
</script>
</body>
</html>