-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo.php
331 lines (278 loc) · 11 KB
/
video.php
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
include "include/session.php";
include "include/config.php";
if(isset($_GET["oid"])&&isset($_GET["rid"])){
$ourid=$_GET["oid"];
$remoteid=$_GET["rid"];
}
?>
<?php
if($_SESSION["seeker"]){
$sql=$conn->prepare("SELECT r.r_name,s.s_name FROM st_details AS s,rc_details AS r WHERE s.s_id=? AND r.r_id=?");
$sql->bindParam(1,$ourid);
$sql->bindParam(2,$remoteid);
$sql->execute();
$row=$sql->fetch(PDO::FETCH_ASSOC);
?>
<div class="">
<div>
<h1 class="title text-center">Welcome to Qualifind Live Meet</h1>
<div class="inline">
<input class="text-center ft id" value="" id="show-peer" disabled/>
<div class="text-center copy">copy it manually and send to seeker</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 mt-3 mb-3 " >
<div class="card main" style="background: transparent;">
<div class="card-body cb">
<h5 class="card-title"><?php echo $row["s_name"] ?></h5>
<div id="ourVideo"></div>
</div>
</div>
</div>
<div class="col-sm-6 mt-3 mb-3 ">
<div class="card main" style="background: transparent;">
<div class="card-body cb">
<h5 class="card-title"><?php echo $row["r_name"] ?></h5>
<div id="remoteVideo"></div>
</div>
</div>
</div>
</div>
</div>
<div class="inline">
<h3 class="text-center" id="">Find Your Qualifind</h3>
</div>
</div>
<div class="meetfooter">
<div class="row">
<div class="col text-center">
<input class="bottominput ft" id="peerID" placeholder="peer ID">
<button class="btn button" id="call-peer">Call Peer</button>
<button class="btn button1" id="shareScreen">Share Screen</button>
<button class="btn button1" id="endcall">end</button>
</div>
</div>
</div>
<?php }elseif($_SESSION["recruiter"]){
$sql=$conn->prepare("SELECT r.r_name,s.s_name FROM st_details AS s,rc_details AS r WHERE s.s_id=? AND r.r_id=?");
$sql->bindParam(1,$remoteid);
$sql->bindParam(2,$ourid);
$sql->execute();
$row=$sql->fetch(PDO::FETCH_ASSOC);
?>
<div class="">
<div>
<h1 class="title text-center">Welcome to Qualifind Live Meet</h1>
<div class="inline">
<input class="text-center ft id" value="" id="show-peer" disabled/>
<div class="text-center copy">copy it manually and send to seeker</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 mt-3 mb-3 " >
<div class="card main" style="background: transparent;">
<div class="card-body cb">
<h5 class="card-title"><?php echo $row["r_name"] ?></h5>
<div id="ourVideo"></div>
</div>
</div>
</div>
<div class="col-sm-6 mt-3 mb-3 ">
<div class="card main" style="background: transparent;">
<div class="card-body cb">
<h5 class="card-title"><?php echo $row["s_name"] ?></h5>
<div id="remoteVideo"></div>
</div>
</div>
</div>
</div>
</div>
<div class="inline">
<h3 class="text-center" id="">Find Your Qualifind</h3>
</div>
</div>
<div class="meetfooter">
<div class="row">
<div class="col text-center">
<input class="bottominput ft" id="peerID" placeholder="peer ID">
<button class="btn button" id="call-peer">Call Peer</button>
<button class="btn button1" id="shareScreen">Share Screen</button>
<button class="btn button1" id="endcall">end</button>
</div>
</div>
</div>
<?php }else{
?>
<h1>Haltino tha</h1>
<?php }?>
<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>
<script>
//on load page
window.addEventListener('load', (e) => {
var peer = new Peer();
var curPeer;
var myStream;
var peerList = [];
let conn;
//different id generate
peer.on('open', function (id) {
document.getElementById('show-peer').value = id
})
//call function
peer.on("call", function (call) {
var answerCall = confirm("Do you want to answer?");
console.log(answerCall)
if (answerCall) {
try{
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then((stream) => {
myStream = stream
addOurVideo(stream)
call.answer(stream)
call.on('stream', function (remoteStream) {
if (!peerList.includes(call.peer)) {
addRemoteVideo(remoteStream)
curPeer = call.peerConnection
peerList.push(call.peer)
}
})
call.on("close", function(){
console.log("call closed up")
})
}).catch((err) => {
console.log(err + "unable to get media")
})
}catch(err){
console.log("here it is"+err);
alert("your permission for camera must be on!");
}
} else {
console.log("call denied");
}
})
//disconnect fn
peer.on('disconnected',function(disconnect){
var answerCall = confirm("Do you want end call?");
if(answerCall){
myStream.getTracks().forEach(track => track.stop());
peer.removeAllListeners();
peer.destroy();
location.reload();
}
})
//call-peer click event
document.getElementById('call-peer').addEventListener('click', (e) => {
let remotePeerId = document.getElementById("peerID").value;
let myID=document.getElementById('show-peer').value ;
if(remotePeerId==myID || remotePeerId==""){
alert("you can not call to yourself!!!");
}else{
document.getElementById('show-peer').innerHTML = "connected " + remotePeerId;
callPeer(remotePeerId);
}
})
//endcall click event
document.getElementById("endcall").addEventListener("click",(e)=>{
let remotePeerId = document.getElementById("peerID").value;
document.getElementById('show-peer').innerHTML = "disconnected " + remotePeerId;
var vidTrack = myStream.getVideoTracks();
vidTrack.forEach(track => track.enabled = false);
let sender = curPeer.getSenders().find(function (s) {
return s.track.kind=="video"
});
sender.replaceTrack(vidTrack)
peer.disconnect()
location.reload();
})
//shareScreen click event
document.getElementById('shareScreen').addEventListener('click', (e) => {
navigator.mediaDevices.getDisplayMedia({
video: {
cursor: "always"
},
audio: {
echoCancellation: true,
noiseSuppression: true
}
}).then((stream) => {
let videoTrack = stream.getVideoTracks()[0];
videoTrack.onended = function () {
stopScreenShare();
}
let sender = curPeer.getSenders().find(function (s) {
return s.track.kind == videoTrack.kind
});
sender.replaceTrack(videoTrack)
}).catch((err) => {
console.log(err + "unable to get d media")
})
})
function removecall(id){
let stream=null;
let call=peer.disconnect(id,stream);
}
function callPeer(id) {
try{
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
}).then((stream) => {
myStream = stream
let videoTrack = stream.getVideoTracks()[0];
addOurVideo(stream)
let call = peer.call(id, stream)
call.on('stream', function (remoteStream) {
if (!peerList.includes(call.peer)) {
addRemoteVideo(remoteStream)
curPeer = call.peerConnection
peerList.push(call.peer)
}
})
call.on("close",function(){
// console.log(id);
console.log("call closed down")
})
}).catch((err) => {
console.log(err + "unable to get media")
})
}catch(err){
alert("try again later!!")
}
}
function stopScreenShare() {
let videoTrack = myStream.getVideoTracks()[0];
var sender = curPeer.getSenders().find(function (s) {
return s.track.kind == videoTrack.kind;
})
sender.replaceTrack(videoTrack)
}
function addRemoteVideo(stream) {
let video = document.createElement("video");
video.classList.add('video')
video.srcObject = stream;
video.controls=true;
video.onended=function () {
video.pause();
}
video.play();
document.getElementById('remoteVideo').append(video)
}
function addOurVideo(stream) {
let video = document.createElement("video");
video.classList.add('video')
video.srcObject = stream;
video.onended=function () {
video.pause();
}
video.muted = true;
video.play()
document.getElementById('ourVideo').append(video)
}
})
</script>