-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.html
More file actions
810 lines (691 loc) · 22.5 KB
/
Copy pathviewer.html
File metadata and controls
810 lines (691 loc) · 22.5 KB
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Ekran Yansıt - İzleyici</title>
<script src="https://unpkg.com/peerjs@1.5.2/dist/peerjs.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
overflow: hidden;
background: #000;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#video {
width: 100%;
height: 100%;
object-fit: contain;
display: none;
}
.start-screen {
text-align: center;
color: white;
padding: 40px;
}
.start-screen h1 {
font-size: 28px;
margin-bottom: 15px;
}
.start-screen p {
opacity: 0.7;
margin-bottom: 30px;
font-size: 16px;
}
.btn {
padding: 18px 50px;
font-size: 17px;
font-weight: 500;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 14px;
cursor: pointer;
background: rgba(255, 255, 255, 0.1);
color: white;
transition: all 0.2s ease;
backdrop-filter: blur(10px);
}
.btn:hover {
background: rgba(255, 255, 255, 0.15);
transform: translateY(-2px);
}
.btn:active {
transform: translateY(0);
background: rgba(255, 255, 255, 0.2);
}
.status {
margin-top: 24px;
padding: 12px 24px;
border-radius: 10px;
font-size: 14px;
backdrop-filter: blur(10px);
}
.status.connecting {
background: rgba(255, 255, 255, 0.08);
border: 1px solid rgba(255, 255, 255, 0.15);
color: rgba(255, 255, 255, 0.7);
}
.status.connected {
background: rgba(56, 239, 125, 0.15);
border: 1px solid rgba(56, 239, 125, 0.3);
color: #38ef7d;
}
.status.error {
background: rgba(239, 83, 80, 0.15);
border: 1px solid rgba(239, 83, 80, 0.3);
color: #ef5350;
}
/* PIN Giriş Ekranı */
.pin-screen {
text-align: center;
color: white;
padding: 40px;
}
.pin-screen h2 {
font-size: 22px;
margin-bottom: 10px;
}
.pin-screen p {
opacity: 0.7;
margin-bottom: 25px;
font-size: 14px;
}
.pin-input-container {
display: flex;
justify-content: center;
gap: 12px;
margin-bottom: 25px;
}
.pin-input {
width: 55px;
height: 65px;
text-align: center;
font-size: 28px;
font-weight: 700;
border: 2px solid rgba(255, 255, 255, 0.2);
border-radius: 12px;
background: rgba(255, 255, 255, 0.1);
color: white;
outline: none;
transition: all 0.2s ease;
}
.pin-input:focus {
border-color: #38ef7d;
background: rgba(56, 239, 125, 0.1);
box-shadow: 0 0 20px rgba(56, 239, 125, 0.3);
}
.pin-input.error {
border-color: #ef5350;
background: rgba(239, 83, 80, 0.1);
animation: shake 0.5s ease;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-8px); }
75% { transform: translateX(8px); }
}
.pin-error {
color: #ef5350;
font-size: 14px;
margin-bottom: 15px;
min-height: 20px;
}
.hidden {
display: none !important;
}
.fullscreen-hint {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 10px 20px;
border-radius: 8px;
font-size: 14px;
opacity: 0;
transition: opacity 0.3s;
pointer-events: none;
}
.fullscreen-hint.show {
opacity: 1;
}
/* iPad için kontroller */
.controls {
position: fixed;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 12px;
opacity: 0.5;
transition: opacity 0.3s;
}
body:hover .controls,
body:active .controls,
.controls:active {
opacity: 1;
}
/* Tablet'te her zaman görünür */
@media (hover: none) {
.controls {
opacity: 1;
}
}
.control-btn {
width: 52px;
height: 52px;
border-radius: 50%;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.1);
color: white;
font-size: 20px;
cursor: pointer;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
}
.control-btn:hover {
background: rgba(255, 255, 255, 0.2);
transform: scale(1.08);
}
.control-btn:active {
transform: scale(0.95);
background: rgba(255, 255, 255, 0.25);
}
/* Switch camera button - varsayilan gizli */
#switchCamBtn {
display: none;
}
#switchCamBtn.visible {
display: flex;
}
/* Aktif durumlar */
.control-btn.camera-active {
background: rgba(100, 181, 246, 0.4);
border-color: rgba(100, 181, 246, 0.6);
box-shadow: 0 0 15px rgba(100, 181, 246, 0.4);
}
.control-btn.talking {
background: rgba(239, 83, 80, 0.5);
border-color: rgba(239, 83, 80, 0.7);
animation: pulse 1s ease-in-out infinite;
box-shadow: 0 0 15px rgba(239, 83, 80, 0.4);
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.08); }
}
</style>
</head>
<body>
<div id="startScreen" class="start-screen">
<h1>📺 Ekran Yansıt</h1>
<p>Bilgisayardan gelen yayını izleyin</p>
<button id="connectBtn" class="btn">
▶️ İzlemeye Başla
</button>
<div id="status" class="status hidden"></div>
</div>
<!-- PIN Giriş Ekranı -->
<div id="pinScreen" class="pin-screen hidden">
<h2>🔐 Güvenlik PIN'i</h2>
<p>Bilgisayarda görünen 4 haneli PIN'i girin</p>
<div class="pin-input-container">
<input type="tel" class="pin-input" maxlength="1" data-index="0" inputmode="numeric" pattern="[0-9]*">
<input type="tel" class="pin-input" maxlength="1" data-index="1" inputmode="numeric" pattern="[0-9]*">
<input type="tel" class="pin-input" maxlength="1" data-index="2" inputmode="numeric" pattern="[0-9]*">
<input type="tel" class="pin-input" maxlength="1" data-index="3" inputmode="numeric" pattern="[0-9]*">
</div>
<div id="pinError" class="pin-error"></div>
<button id="verifyPinBtn" class="btn">
✓ Doğrula
</button>
</div>
<video id="video" autoplay playsinline></video>
<div id="controls" class="controls hidden">
<button class="control-btn" id="fullscreenBtn">⛶</button>
<button class="control-btn" id="pauseBtn">⏸</button>
<button class="control-btn" id="muteBtn">🔊</button>
<button class="control-btn" id="talkBtn">🎤</button>
<button class="control-btn" id="cameraBtn">📷</button>
<button class="control-btn" id="switchCamBtn">🔄</button>
</div>
<div id="fullscreenHint" class="fullscreen-hint">
Tam ekran için çift dokunun
</div>
<script>
// DOM elementleri
const startScreen = document.getElementById('startScreen');
const pinScreen = document.getElementById('pinScreen');
const connectBtn = document.getElementById('connectBtn');
const statusDiv = document.getElementById('status');
const video = document.getElementById('video');
const controls = document.getElementById('controls');
const fullscreenBtn = document.getElementById('fullscreenBtn');
const pauseBtn = document.getElementById('pauseBtn');
const muteBtn = document.getElementById('muteBtn');
const talkBtn = document.getElementById('talkBtn');
const cameraBtn = document.getElementById('cameraBtn');
const switchCamBtn = document.getElementById('switchCamBtn');
const fullscreenHint = document.getElementById('fullscreenHint');
const pinInputs = document.querySelectorAll('.pin-input');
const verifyPinBtn = document.getElementById('verifyPinBtn');
const pinError = document.getElementById('pinError');
// URL'den peer ID al
const urlParams = new URLSearchParams(window.location.search);
const hostPeerId = urlParams.get('peerId');
let peer = null;
let dataConn = null;
let micStream = null;
let isTalking = false;
let remoteAudio = null; // Bilgisayardan gelen ses için
let cameraStream = null;
let isCameraOn = false;
let currentFacingMode = 'user'; // 'user' = ön kamera, 'environment' = arka kamera
// PIN input kontrolü - otomatik geçiş
pinInputs.forEach((input, index) => {
input.addEventListener('input', (e) => {
const value = e.target.value;
// Sadece rakam kabul et
if (!/^\d*$/.test(value)) {
e.target.value = '';
return;
}
// Sonraki input'a geç
if (value && index < pinInputs.length - 1) {
pinInputs[index + 1].focus();
}
// Hata stilini kaldır
input.classList.remove('error');
pinError.textContent = '';
// 4 hane doluysa otomatik doğrula
const pin = getEnteredPin();
if (pin.length === 4) {
verifyPin();
}
});
input.addEventListener('keydown', (e) => {
// Backspace ile önceki input'a geç
if (e.key === 'Backspace' && !e.target.value && index > 0) {
pinInputs[index - 1].focus();
}
});
// Paste desteği
input.addEventListener('paste', (e) => {
e.preventDefault();
const pastedData = e.clipboardData.getData('text').slice(0, 4);
if (/^\d+$/.test(pastedData)) {
pastedData.split('').forEach((char, i) => {
if (pinInputs[i]) {
pinInputs[i].value = char;
}
});
if (pastedData.length === 4) {
verifyPin();
}
}
});
});
// Girilen PIN'i al
function getEnteredPin() {
return Array.from(pinInputs).map(input => input.value).join('');
}
// PIN doğrulama butonu
verifyPinBtn.addEventListener('click', verifyPin);
// PIN doğrula
function verifyPin() {
const pin = getEnteredPin();
if (pin.length !== 4) {
showPinError('4 haneli PIN girin');
return;
}
verifyPinBtn.disabled = true;
verifyPinBtn.textContent = '⏳ Doğrulanıyor...';
// PIN'i bilgisayara gönder
dataConn.send({ type: 'verify-pin', pin: pin });
}
// PIN hatası göster
function showPinError(message) {
pinError.textContent = message;
pinInputs.forEach(input => {
input.classList.add('error');
input.value = '';
});
pinInputs[0].focus();
}
// Başlat butonuna tıklama
connectBtn.addEventListener('click', () => {
if (!hostPeerId) {
showStatus('Bağlantı bilgisi bulunamadı', 'error');
return;
}
connectToHost();
});
// Host'a bağlan
function connectToHost() {
showStatus('Bağlanıyor...', 'connecting');
connectBtn.disabled = true;
connectBtn.textContent = '⏳ Bağlanıyor...';
// Rastgele viewer ID
const viewerId = 'viewer-' + Math.random().toString(36).substr(2, 6);
peer = new Peer(viewerId, {
debug: 2
});
peer.on('open', () => {
console.log('Peer açıldı, host\'a bağlanılıyor:', hostPeerId);
// Host'u ara (video stream iste)
const call = peer.call(hostPeerId, null); // Boş stream gönder, karşılık bekle
// Aslında doğrusu: host'tan stream almak için ona bağlanmak
// PeerJS'de call yapan taraf stream gönderir, alan taraf alır
// Bu durumda viewer call yapmalı ama stream yok
// Çözüm: Data connection ile "stream iste" mesajı gönder
dataConn = peer.connect(hostPeerId);
dataConn.on('open', () => {
console.log('Data bağlantısı kuruldu');
// PIN ekranını göster
startScreen.classList.add('hidden');
pinScreen.classList.remove('hidden');
pinInputs[0].focus();
});
// Bilgisayardan gelen mesajları dinle
dataConn.on('data', (data) => {
console.log('Bilgisayardan mesaj:', data);
// PIN doğrulama cevabı
if (data.type === 'pin-verified') {
if (data.success) {
// PIN doğru, stream iste
console.log('PIN doğrulandı!');
pinScreen.classList.add('hidden');
dataConn.send({ type: 'request-stream' });
} else {
// PIN yanlış
showPinError('Yanlış PIN! Tekrar deneyin.');
verifyPinBtn.disabled = false;
verifyPinBtn.textContent = '✓ Doğrula';
}
return;
}
// Hata mesajı
if (data.type === 'error') {
console.error('Hata:', data.message);
return;
}
if (data.type === 'open-camera') {
// Kamerayı aç (bilgisayardan uzaktan açma)
if (!isCameraOn) {
startCamera();
}
}
if (data.type === 'switch-camera') {
// Kamera değiştir
if (isCameraOn) {
switchCamera();
}
}
if (data.type === 'close-camera') {
// Kamerayı kapat
if (isCameraOn) {
stopCamera();
}
}
});
});
// Gelen arama (host stream gönderdiğinde)
peer.on('call', (call) => {
console.log('Gelen arama!');
call.answer(); // Boş cevap ver, sadece al
call.on('stream', (remoteStream) => {
console.log('Stream alındı!');
// Video stream mi ses stream mi kontrol et
const hasVideo = remoteStream.getVideoTracks().length > 0;
if (hasVideo) {
// Video stream - ana ekrana göster
video.srcObject = remoteStream;
video.play();
// UI güncelle
startScreen.classList.add('hidden');
pinScreen.classList.add('hidden');
video.style.display = 'block';
controls.classList.remove('hidden');
// Fullscreen hint göster
showFullscreenHint();
} else {
// Sadece ses stream - bilgisayardan gelen konuşma
console.log('Bilgisayardan ses geliyor!');
if (!remoteAudio) {
remoteAudio = document.createElement('audio');
remoteAudio.autoplay = true;
document.body.appendChild(remoteAudio);
}
remoteAudio.srcObject = remoteStream;
}
});
call.on('error', (err) => {
console.error('Call error:', err);
showStatus('Yayın hatası: ' + err, 'error');
});
});
peer.on('error', (error) => {
console.error('Peer error:', error);
showStatus('Bağlantı hatası: ' + error.type, 'error');
connectBtn.disabled = false;
connectBtn.textContent = '▶️ Tekrar Dene';
});
// 10 saniye timeout
setTimeout(() => {
if (!video.srcObject) {
showStatus('Bağlantı zaman aşımı. Tekrar deneyin.', 'error');
connectBtn.disabled = false;
connectBtn.textContent = '▶️ Tekrar Dene';
}
}, 10000);
}
function showStatus(message, type) {
statusDiv.textContent = message;
statusDiv.className = 'status ' + type;
statusDiv.classList.remove('hidden');
}
function showFullscreenHint() {
fullscreenHint.classList.add('show');
setTimeout(() => {
fullscreenHint.classList.remove('show');
}, 3000);
}
// Fullscreen toggle
fullscreenBtn.addEventListener('click', toggleFullscreen);
video.addEventListener('dblclick', toggleFullscreen);
function toggleFullscreen() {
if (!document.fullscreenElement && !document.webkitFullscreenElement) {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen();
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}
// Pause toggle
pauseBtn.addEventListener('click', () => {
if (video.paused) {
video.play();
pauseBtn.textContent = '⏸';
} else {
video.pause();
pauseBtn.textContent = '▶️';
}
});
// Mute toggle
muteBtn.addEventListener('click', () => {
video.muted = !video.muted;
muteBtn.textContent = video.muted ? '🔇' : '🔊';
});
// Push-to-talk: Basılı tut ve konuş
let previousVolume = 1;
async function startTalking() {
if (isTalking) return;
isTalking = true;
talkBtn.classList.add('talking');
// Video sesini kıs (konuşurken karışmasın)
previousVolume = video.volume;
video.volume = 0.1;
try {
// Mikrofon izni al
micStream = await navigator.mediaDevices.getUserMedia({ audio: true });
// Bilgisayara ses gönder
const call = peer.call(hostPeerId, micStream);
console.log('Ses gönderiliyor...');
} catch (err) {
console.error('Mikrofon hatası:', err);
isTalking = false;
talkBtn.classList.remove('talking');
video.volume = previousVolume;
}
}
function stopTalking() {
if (!isTalking) return;
isTalking = false;
talkBtn.classList.remove('talking');
// Video sesini geri aç
video.volume = previousVolume;
// Mikrofonu kapat
if (micStream) {
micStream.getTracks().forEach(track => track.stop());
micStream = null;
}
}
// Mouse events (bilgisayar)
talkBtn.addEventListener('mousedown', startTalking);
talkBtn.addEventListener('mouseup', stopTalking);
talkBtn.addEventListener('mouseleave', stopTalking);
// Touch events (tablet/telefon)
talkBtn.addEventListener('touchstart', (e) => {
e.preventDefault();
startTalking();
});
talkBtn.addEventListener('touchend', (e) => {
e.preventDefault();
stopTalking();
});
// Kamera toggle
cameraBtn.addEventListener('click', toggleCamera);
async function toggleCamera() {
if (isCameraOn) {
// Kamerayı kapat
stopCamera();
} else {
// Kamerayı aç
await startCamera();
}
}
async function startCamera(facingMode = null) {
try {
// Önce kamera izni durumunu kontrol et
const permissionStatus = await navigator.permissions.query({ name: 'camera' }).catch(() => null);
if (permissionStatus && permissionStatus.state === 'denied') {
alert('Kamera izni engellendi. Lütfen tarayıcı ayarlarından izin verin:\n\n1. Adres çubuğundaki kilit ikonuna tıklayın\n2. Kamera iznini "İzin Ver" olarak değiştirin\n3. Sayfayı yenileyin');
return;
}
// Hangi kamerayı kullanacağız
const useMode = facingMode || currentFacingMode;
// Kamerayı aç
cameraStream = await navigator.mediaDevices.getUserMedia({
video: { facingMode: useMode },
audio: false
});
currentFacingMode = useMode;
isCameraOn = true;
cameraBtn.classList.add('camera-active');
cameraBtn.textContent = '📹';
switchCamBtn.classList.add('visible');
// Bilgisayara kamera stream'i gönder
const call = peer.call(hostPeerId, cameraStream);
console.log('Kamera stream gönderiliyor... (', useMode === 'user' ? 'ön' : 'arka', 'kamera)');
// Data connection ile kamera açıldığını bildir
if (dataConn && dataConn.open) {
dataConn.send({ type: 'camera-started', facingMode: useMode });
}
} catch (err) {
console.error('Kamera hatası:', err);
if (err.name === 'NotAllowedError') {
alert('Kamera izni reddedildi.\n\nİzin vermek için:\n1. Adres çubuğundaki kilit/kamera ikonuna tıklayın\n2. Kamera iznini açın\n3. Sayfayı yenileyin');
} else if (err.name === 'NotFoundError') {
alert('Kamera bulunamadı. Cihazınızda kamera olduğundan emin olun.');
} else if (err.name === 'NotReadableError') {
alert('Kamera başka bir uygulama tarafından kullanılıyor olabilir.');
} else if (err.name === 'OverconstrainedError') {
// Arka kamera yoksa ön kameraya geri dön
if (currentFacingMode === 'environment') {
currentFacingMode = 'user';
await startCamera('user');
} else {
alert('Kamera açılamadı: ' + err.message);
}
} else {
alert('Kamera açılamadı: ' + err.message);
}
}
}
function stopCamera() {
if (cameraStream) {
cameraStream.getTracks().forEach(track => track.stop());
cameraStream = null;
}
isCameraOn = false;
cameraBtn.classList.remove('camera-active');
cameraBtn.textContent = '📷';
switchCamBtn.classList.remove('visible');
// Data connection ile kamera kapandığını bildir
if (dataConn && dataConn.open) {
dataConn.send({ type: 'camera-stopped' });
}
}
// Kamera değiştir (ön/arka)
switchCamBtn.addEventListener('click', switchCamera);
async function switchCamera() {
if (!isCameraOn) return;
// Mevcut kamerayı kapat
if (cameraStream) {
cameraStream.getTracks().forEach(track => track.stop());
cameraStream = null;
}
// Diğer kameraya geç
currentFacingMode = currentFacingMode === 'user' ? 'environment' : 'user';
// Yeni kamerayı aç
await startCamera(currentFacingMode);
}
// Sayfa kapanırken temizlik
window.addEventListener('beforeunload', () => {
if (micStream) {
micStream.getTracks().forEach(track => track.stop());
}
if (cameraStream) {
cameraStream.getTracks().forEach(track => track.stop());
}
if (peer) {
peer.destroy();
}
});
</script>
</body>
</html>