Compare commits
4 Commits
c288c45138
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 07b739e293 | |||
| 0e95d01786 | |||
| 8324597a84 | |||
| 9bf372b972 |
@@ -109,7 +109,7 @@ newgrp docker
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||||
sudo chmod +x /usr/local/bin/docker-compose
|
sudo ф
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Установка Nginx и Certbot
|
### 4. Установка Nginx и Certbot
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pycparser==2.22
|
|||||||
pypng==0.20220715.0
|
pypng==0.20220715.0
|
||||||
python-decouple==3.8
|
python-decouple==3.8
|
||||||
pytz==2025.2
|
pytz==2025.2
|
||||||
|
psutil==7.0.0
|
||||||
qrcode==7.4.2
|
qrcode==7.4.2
|
||||||
redis==5.0.1
|
redis==5.0.1
|
||||||
sqlparse==0.5.3
|
sqlparse==0.5.3
|
||||||
|
|||||||
@@ -557,12 +557,12 @@ const callStartTime = ref(null)
|
|||||||
const callDuration = ref(0)
|
const callDuration = ref(0)
|
||||||
const localVideoSize = ref('medium')
|
const localVideoSize = ref('medium')
|
||||||
const showShareModal = ref(false)
|
const showShareModal = ref(false)
|
||||||
const showStats = ref(false)
|
const showStats = ref(true) // false
|
||||||
const showMenu = ref(false)
|
const showMenu = ref(true) // false
|
||||||
const roomCodeCopied = ref(false)
|
const roomCodeCopied = ref(false)
|
||||||
const roomLinkCopied = ref(false)
|
const roomLinkCopied = ref(false)
|
||||||
const shouldMirrorLocal = ref(true)
|
const shouldMirrorLocal = ref(true)
|
||||||
const showVideoInfo = ref(false)
|
const showVideoInfo = ref(true) //false
|
||||||
const showConnectionQuality = ref(true)
|
const showConnectionQuality = ref(true)
|
||||||
const isConnecting = ref(false)
|
const isConnecting = ref(false)
|
||||||
const connectingMessage = ref('Connecting...')
|
const connectingMessage = ref('Connecting...')
|
||||||
|
|||||||
@@ -55,14 +55,13 @@ export const mediaService = {
|
|||||||
// Default constraints
|
// Default constraints
|
||||||
let constraints = {
|
let constraints = {
|
||||||
video: {
|
video: {
|
||||||
width: { ideal: 1280, max: 1920 },
|
width: { ideal: 640, max: 1280 },
|
||||||
height: { ideal: 720, max: 1080 },
|
height: { ideal: 480, max: 720 },
|
||||||
frameRate: { ideal: 30, max: 60 },
|
frameRate: { ideal: 15, max: 30 }
|
||||||
},
|
},
|
||||||
audio: {
|
audio: {
|
||||||
echoCancellation: true,
|
echoCancellation: true,
|
||||||
noiseSuppression: true,
|
noiseSuppression: true,
|
||||||
autoGainControl: true,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,408 @@
|
|||||||
// src/services/webrtc.js - WebRTC utility functions
|
// // // src/services/webrtc.js - WebRTC utility functions
|
||||||
|
// // export const webrtcService = {
|
||||||
|
// // /**
|
||||||
|
// // * Get STUN/TURN server configuration
|
||||||
|
// // */
|
||||||
|
// // getIceServerConfig() {
|
||||||
|
// // return {
|
||||||
|
// // iceServers: [
|
||||||
|
// // { urls: 'stun:stun.l.google.com:19302' },
|
||||||
|
// // { urls: 'stun:stun1.l.google.com:19302' },
|
||||||
|
// // { urls: 'stun:stun2.l.google.com:19302' },
|
||||||
|
// // // Add TURN servers for production
|
||||||
|
// // // {
|
||||||
|
// // // urls: 'turn:your-turn-server.com:3478',
|
||||||
|
// // // username: 'username',
|
||||||
|
// // // credential: 'password'
|
||||||
|
// // // }
|
||||||
|
// // ],
|
||||||
|
// // iceCandidatePoolSize: 10,
|
||||||
|
// // }
|
||||||
|
// // },
|
||||||
|
|
||||||
|
// // /**
|
||||||
|
// // * Test WebRTC support
|
||||||
|
// // */
|
||||||
|
// // isWebRTCSupported() {
|
||||||
|
// // return !!(
|
||||||
|
// // window.RTCPeerConnection ||
|
||||||
|
// // window.webkitRTCPeerConnection ||
|
||||||
|
// // window.mozRTCPeerConnection
|
||||||
|
// // )
|
||||||
|
// // },
|
||||||
|
|
||||||
|
// // /**
|
||||||
|
// // * Get WebRTC statistics
|
||||||
|
// // */
|
||||||
|
// // async getConnectionStats(peerConnection) {
|
||||||
|
// // if (!peerConnection) return null
|
||||||
|
|
||||||
|
// // try {
|
||||||
|
// // const stats = await peerConnection.getStats()
|
||||||
|
// // const result = {
|
||||||
|
// // video: {},
|
||||||
|
// // audio: {},
|
||||||
|
// // connection: {},
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // stats.forEach((report) => {
|
||||||
|
// // if (report.type === 'inbound-rtp' && report.mediaType === 'video') {
|
||||||
|
// // result.video.inbound = {
|
||||||
|
// // bytesReceived: report.bytesReceived,
|
||||||
|
// // packetsReceived: report.packetsReceived,
|
||||||
|
// // packetsLost: report.packetsLost,
|
||||||
|
// // frameWidth: report.frameWidth,
|
||||||
|
// // frameHeight: report.frameHeight,
|
||||||
|
// // framesPerSecond: report.framesPerSecond,
|
||||||
|
// // }
|
||||||
|
// // } else if (report.type === 'outbound-rtp' && report.mediaType === 'video') {
|
||||||
|
// // result.video.outbound = {
|
||||||
|
// // bytesSent: report.bytesSent,
|
||||||
|
// // packetsSent: report.packetsSent,
|
||||||
|
// // frameWidth: report.frameWidth,
|
||||||
|
// // frameHeight: report.frameHeight,
|
||||||
|
// // framesPerSecond: report.framesPerSecond,
|
||||||
|
// // }
|
||||||
|
// // } else if (report.type === 'candidate-pair' && report.state === 'succeeded') {
|
||||||
|
// // result.connection = {
|
||||||
|
// // currentRoundTripTime: report.currentRoundTripTime,
|
||||||
|
// // availableOutgoingBitrate: report.availableOutgoingBitrate,
|
||||||
|
// // bytesReceived: report.bytesReceived,
|
||||||
|
// // bytesSent: report.bytesSent,
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// // })
|
||||||
|
|
||||||
|
// // return result
|
||||||
|
// // } catch (error) {
|
||||||
|
// // console.error('Failed to get connection stats:', error)
|
||||||
|
// // return null
|
||||||
|
// // }
|
||||||
|
// // },
|
||||||
|
|
||||||
|
// // /**
|
||||||
|
// // * Monitor connection quality
|
||||||
|
// // */
|
||||||
|
// // createQualityMonitor(peerConnection, callback, interval = 5000) {
|
||||||
|
// // if (!peerConnection || typeof callback !== 'function') {
|
||||||
|
// // return null
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // const monitor = setInterval(async () => {
|
||||||
|
// // try {
|
||||||
|
// // const stats = await this.getConnectionStats(peerConnection)
|
||||||
|
// // if (stats) {
|
||||||
|
// // const quality = this.calculateQuality(stats)
|
||||||
|
// // callback(quality, stats)
|
||||||
|
// // }
|
||||||
|
// // } catch (error) {
|
||||||
|
// // console.error('Quality monitoring error:', error)
|
||||||
|
// // }
|
||||||
|
// // }, interval)
|
||||||
|
|
||||||
|
// // return monitor
|
||||||
|
// // },
|
||||||
|
|
||||||
|
// // /**
|
||||||
|
// // * Calculate connection quality score (0-100)
|
||||||
|
// // */
|
||||||
|
// // calculateQuality(stats) {
|
||||||
|
// // let score = 100
|
||||||
|
|
||||||
|
// // // Reduce score based on packet loss
|
||||||
|
// // if (stats.video.inbound?.packetsLost && stats.video.inbound?.packetsReceived) {
|
||||||
|
// // const lossRate = stats.video.inbound.packetsLost / stats.video.inbound.packetsReceived
|
||||||
|
// // score -= lossRate * 50 // Up to 50 points for packet loss
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // // Reduce score based on round trip time
|
||||||
|
// // if (stats.connection?.currentRoundTripTime) {
|
||||||
|
// // const rtt = stats.connection.currentRoundTripTime * 1000 // Convert to ms
|
||||||
|
// // if (rtt > 150) {
|
||||||
|
// // score -= Math.min(30, (rtt - 150) / 10) // Up to 30 points for high latency
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // // Reduce score based on low frame rate
|
||||||
|
// // if (stats.video.inbound?.framesPerSecond) {
|
||||||
|
// // const fps = stats.video.inbound.framesPerSecond
|
||||||
|
// // if (fps < 15) {
|
||||||
|
// // score -= (15 - fps) * 2 // Up to 30 points for low FPS
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // return Math.max(0, Math.min(100, Math.round(score)))
|
||||||
|
// // },
|
||||||
|
// // }
|
||||||
|
|
||||||
|
|
||||||
|
// // src/services/webrtc.js - WebRTC utility functions
|
||||||
|
// export const webrtcService = {
|
||||||
|
// /**
|
||||||
|
// * Get STUN/TURN server configuration (оптимизировано)
|
||||||
|
// */
|
||||||
|
// getIceServerConfig() {
|
||||||
|
// return {
|
||||||
|
// iceServers: [
|
||||||
|
// { urls: 'stun:stun.l.google.com:19302' },
|
||||||
|
// // Добавьте TURN сервер только при необходимости
|
||||||
|
// // {
|
||||||
|
// // urls: 'turn:your-turn-server.com:3478',
|
||||||
|
// // username: 'username',
|
||||||
|
// // credential: 'password'
|
||||||
|
// // }
|
||||||
|
// ],
|
||||||
|
// iceCandidatePoolSize: 0, // Уменьшено для экономии ресурсов
|
||||||
|
// bundlePolicy: 'max-bundle', // Объединение каналов
|
||||||
|
// rtcpMuxPolicy: 'require' // Объединение RTCP и RTP
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Get optimized media constraints
|
||||||
|
// */
|
||||||
|
// getOptimizedConstraints() {
|
||||||
|
// return {
|
||||||
|
// video: {
|
||||||
|
// width: { ideal: 640, max: 1280 },
|
||||||
|
// height: { ideal: 480, max: 720 },
|
||||||
|
// frameRate: { ideal: 15, max: 30 }
|
||||||
|
// },
|
||||||
|
// audio: {
|
||||||
|
// sampleRate: 10000,
|
||||||
|
// channelCount: 1,
|
||||||
|
// echoCancellation: true,
|
||||||
|
// noiseSuppression: true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Apply optimized parameters to video sender
|
||||||
|
// */
|
||||||
|
// optimizeVideoSender(sender, quality = 'medium') {
|
||||||
|
// if (!sender || sender.track?.kind !== 'video') return;
|
||||||
|
|
||||||
|
// const presets = {
|
||||||
|
// low: {
|
||||||
|
// maxBitrate: 150_000,
|
||||||
|
// scaleResolutionDownBy: 4.0,
|
||||||
|
// maxFramerate: 10
|
||||||
|
// },
|
||||||
|
// medium: {
|
||||||
|
// maxBitrate: 400_000,
|
||||||
|
// scaleResolutionDownBy: 2.0,
|
||||||
|
// maxFramerate: 15
|
||||||
|
// },
|
||||||
|
// high: {
|
||||||
|
// maxBitrate: 1_000_000,
|
||||||
|
// scaleResolutionDownBy: 1.0,
|
||||||
|
// maxFramerate: 30
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const params = sender.getParameters();
|
||||||
|
// params.encodings = [presets[quality] || presets.medium];
|
||||||
|
// sender.setParameters(params);
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Apply simulcast for better quality adaptation
|
||||||
|
// */
|
||||||
|
// enableSimulcast(sender) {
|
||||||
|
// if (!sender || sender.track?.kind !== 'video') return;
|
||||||
|
|
||||||
|
// const params = sender.getParameters();
|
||||||
|
// params.encodings = [
|
||||||
|
// { rid: 'low', active: true, maxBitrate: 150_000, scaleResolutionDownBy: 4.0, maxFramerate: 10 },
|
||||||
|
// { rid: 'medium', active: true, maxBitrate: 400_000, scaleResolutionDownBy: 2.0, maxFramerate: 15 },
|
||||||
|
// { rid: 'high', active: true, maxBitrate: 1_000_000, scaleResolutionDownBy: 1.0, maxFramerate: 30 }
|
||||||
|
// ];
|
||||||
|
// sender.setParameters(params);
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Prefer specific codec in SDP
|
||||||
|
// */
|
||||||
|
// preferCodec(sdp, codec) {
|
||||||
|
// const codecInfo = this.extractCodecInfo(sdp, codec);
|
||||||
|
// if (!codecInfo) return sdp;
|
||||||
|
|
||||||
|
// const { payload, rtpmap } = codecInfo;
|
||||||
|
// const lines = sdp.split('\r\n');
|
||||||
|
// const mLineIndex = lines.findIndex(line => line.startsWith('m=video'));
|
||||||
|
|
||||||
|
// if (mLineIndex === -1) return sdp;
|
||||||
|
|
||||||
|
// // Изменяем порядок кодеков в m-line
|
||||||
|
// const mLineParts = lines[mLineIndex].split(' ');
|
||||||
|
// const payloads = mLineParts.slice(3);
|
||||||
|
// const newPayloads = [payload, ...payloads.filter(p => p !== payload)];
|
||||||
|
// lines[mLineIndex] = [...mLineParts.slice(0, 3), ...newPayloads].join(' ');
|
||||||
|
|
||||||
|
// return lines.join('\r\n');
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Extract codec information from SDP
|
||||||
|
// */
|
||||||
|
// extractCodecInfo(sdp, codecName) {
|
||||||
|
// const lines = sdp.split('\r\n');
|
||||||
|
// for (let i = 0; i < lines.length; i++) {
|
||||||
|
// if (lines[i].includes(`a=rtpmap:`) && lines[i].toLowerCase().includes(codecName.toLowerCase())) {
|
||||||
|
// const payload = lines[i].split(' ')[0].split(':')[1];
|
||||||
|
// return { payload, rtpmap: lines[i] };
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Test WebRTC support
|
||||||
|
// */
|
||||||
|
// isWebRTCSupported() {
|
||||||
|
// return !!(
|
||||||
|
// window.RTCPeerConnection ||
|
||||||
|
// window.webkitRTCPeerConnection ||
|
||||||
|
// window.mozRTCPeerConnection
|
||||||
|
// )
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Get WebRTC statistics (оптимизировано)
|
||||||
|
// */
|
||||||
|
// async getConnectionStats(peerConnection) {
|
||||||
|
// if (!peerConnection) return null
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const stats = await peerConnection.getStats()
|
||||||
|
// const result = {
|
||||||
|
// video: {},
|
||||||
|
// audio: {},
|
||||||
|
// connection: {},
|
||||||
|
// }
|
||||||
|
|
||||||
|
// stats.forEach((report) => {
|
||||||
|
// if (report.type === 'inbound-rtp' && report.mediaType === 'video') {
|
||||||
|
// result.video.inbound = {
|
||||||
|
// bytesReceived: report.bytesReceived || 0,
|
||||||
|
// packetsReceived: report.packetsReceived || 0,
|
||||||
|
// packetsLost: report.packetsLost || 0,
|
||||||
|
// frameWidth: report.frameWidth || 0,
|
||||||
|
// frameHeight: report.frameHeight || 0,
|
||||||
|
// framesPerSecond: report.framesPerSecond || 0,
|
||||||
|
// }
|
||||||
|
// } else if (report.type === 'outbound-rtp' && report.mediaType === 'video') {
|
||||||
|
// result.video.outbound = {
|
||||||
|
// bytesSent: report.bytesSent || 0,
|
||||||
|
// packetsSent: report.packetsSent || 0,
|
||||||
|
// frameWidth: report.frameWidth || 0,
|
||||||
|
// frameHeight: report.frameHeight || 0,
|
||||||
|
// framesPerSecond: report.framesPerSecond || 0,
|
||||||
|
// }
|
||||||
|
// } else if (report.type === 'candidate-pair' && report.state === 'succeeded') {
|
||||||
|
// result.connection = {
|
||||||
|
// currentRoundTripTime: report.currentRoundTripTime || 0,
|
||||||
|
// availableOutgoingBitrate: report.availableOutgoingBitrate || 0,
|
||||||
|
// bytesReceived: report.bytesReceived || 0,
|
||||||
|
// bytesSent: report.bytesSent || 0,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
|
// return result
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error('Failed to get connection stats:', error)
|
||||||
|
// return null
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Monitor connection quality (увеличен интервал)
|
||||||
|
// */
|
||||||
|
// createQualityMonitor(peerConnection, callback, interval = 10000) {
|
||||||
|
// if (!peerConnection || typeof callback !== 'function') {
|
||||||
|
// return null
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const monitor = setInterval(async () => {
|
||||||
|
// try {
|
||||||
|
// const stats = await this.getConnectionStats(peerConnection)
|
||||||
|
// if (stats) {
|
||||||
|
// const quality = this.calculateQuality(stats)
|
||||||
|
// callback(quality, stats)
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error('Quality monitoring error:', error)
|
||||||
|
// }
|
||||||
|
// }, interval)
|
||||||
|
|
||||||
|
// return monitor
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Calculate connection quality score (0-100)
|
||||||
|
// */
|
||||||
|
// calculateQuality(stats) {
|
||||||
|
// let score = 100
|
||||||
|
|
||||||
|
// // Reduce score based on packet loss
|
||||||
|
// if (stats.video.inbound?.packetsLost && stats.video.inbound?.packetsReceived) {
|
||||||
|
// const lossRate = stats.video.inbound.packetsLost / Math.max(1, stats.video.inbound.packetsReceived)
|
||||||
|
// score -= Math.min(50, lossRate * 100) // Up to 50 points for packet loss
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Reduce score based on round trip time
|
||||||
|
// if (stats.connection?.currentRoundTripTime) {
|
||||||
|
// const rtt = stats.connection.currentRoundTripTime * 1000 // Convert to ms
|
||||||
|
// if (rtt > 150) {
|
||||||
|
// score -= Math.min(30, (rtt - 150) / 10) // Up to 30 points for high latency
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Reduce score based on low frame rate
|
||||||
|
// if (stats.video.inbound?.framesPerSecond) {
|
||||||
|
// const fps = stats.video.inbound.framesPerSecond
|
||||||
|
// if (fps < 10) {
|
||||||
|
// score -= (10 - fps) * 3 // Up to 30 points for very low FPS
|
||||||
|
// } else if (fps < 15) {
|
||||||
|
// score -= (15 - fps) * 2
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return Math.max(0, Math.min(100, Math.round(score)))
|
||||||
|
// },
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Adaptive quality control based on network conditions
|
||||||
|
// */
|
||||||
|
// async adaptQuality(peerConnection, qualityCallback) {
|
||||||
|
// if (!peerConnection) return;
|
||||||
|
|
||||||
|
// const senders = peerConnection.getSenders();
|
||||||
|
// const videoSender = senders.find(sender => sender.track?.kind === 'video');
|
||||||
|
|
||||||
|
// if (!videoSender) return;
|
||||||
|
|
||||||
|
// const stats = await this.getConnectionStats(peerConnection);
|
||||||
|
// if (!stats) return;
|
||||||
|
|
||||||
|
// const quality = this.calculateQuality(stats);
|
||||||
|
// qualityCallback(quality);
|
||||||
|
|
||||||
|
// // Адаптивное управление качеством
|
||||||
|
// if (quality < 30) {
|
||||||
|
// this.optimizeVideoSender(videoSender, 'low');
|
||||||
|
// } else if (quality < 60) {
|
||||||
|
// this.optimizeVideoSender(videoSender, 'medium');
|
||||||
|
// } else {
|
||||||
|
// this.optimizeVideoSender(videoSender, 'high');
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// src/services/webrtc.js - WebRTC utility functions with forced AV1 codec
|
||||||
|
|
||||||
export const webrtcService = {
|
export const webrtcService = {
|
||||||
/**
|
/**
|
||||||
* Get STUN/TURN server configuration
|
* Get STUN/TURN server configuration
|
||||||
@@ -7,19 +411,140 @@ export const webrtcService = {
|
|||||||
return {
|
return {
|
||||||
iceServers: [
|
iceServers: [
|
||||||
{ urls: 'stun:stun.l.google.com:19302' },
|
{ urls: 'stun:stun.l.google.com:19302' },
|
||||||
{ urls: 'stun:stun1.l.google.com:19302' },
|
|
||||||
{ urls: 'stun:stun2.l.google.com:19302' },
|
|
||||||
// Add TURN servers for production
|
|
||||||
// {
|
|
||||||
// urls: 'turn:your-turn-server.com:3478',
|
|
||||||
// username: 'username',
|
|
||||||
// credential: 'password'
|
|
||||||
// }
|
|
||||||
],
|
],
|
||||||
iceCandidatePoolSize: 10,
|
iceCandidatePoolSize: 0,
|
||||||
|
bundlePolicy: 'max-bundle',
|
||||||
|
rtcpMuxPolicy: 'require'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get optimized media constraints for AV1
|
||||||
|
*/
|
||||||
|
async getOptimizedConstraints() {
|
||||||
|
return {
|
||||||
|
video: {
|
||||||
|
width: { ideal: 640, max: 1280 },
|
||||||
|
height: { ideal: 480, max: 720 },
|
||||||
|
frameRate: { ideal: 15, max: 30 }
|
||||||
|
},
|
||||||
|
audio: {
|
||||||
|
sampleRate: 10000,
|
||||||
|
channelCount: 1,
|
||||||
|
echoCancellation: true,
|
||||||
|
noiseSuppression: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply optimized parameters to video sender
|
||||||
|
*/
|
||||||
|
optimizeVideoSender(sender, quality = 'medium') {
|
||||||
|
if (!sender || sender.track?.kind !== 'video') return;
|
||||||
|
|
||||||
|
const presets = {
|
||||||
|
low: {
|
||||||
|
maxBitrate: 150_000,
|
||||||
|
scaleResolutionDownBy: 2.0,
|
||||||
|
maxFramerate: 15
|
||||||
|
},
|
||||||
|
medium: {
|
||||||
|
maxBitrate: 400_000,
|
||||||
|
scaleResolutionDownBy: 1.5,
|
||||||
|
maxFramerate: 25
|
||||||
|
},
|
||||||
|
high: {
|
||||||
|
maxBitrate: 1_000_000,
|
||||||
|
scaleResolutionDownBy: 1.0,
|
||||||
|
maxFramerate: 30
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const params = sender.getParameters();
|
||||||
|
params.encodings = [presets[quality] || presets.high];
|
||||||
|
sender.setParameters(params);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force AV1 codec in SDP
|
||||||
|
*/
|
||||||
|
forceAV1Codec(sdp) {
|
||||||
|
// Найдем AV1 payload type
|
||||||
|
const av1Payload = this.findAV1Payload(sdp);
|
||||||
|
if (!av1Payload) {
|
||||||
|
console.warn('AV1 codec not found in SDP, falling back to default codecs');
|
||||||
|
return sdp;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines = sdp.split('\r\n');
|
||||||
|
const mLineIndex = lines.findIndex(line => line.startsWith('m=video'));
|
||||||
|
|
||||||
|
if (mLineIndex === -1) return sdp;
|
||||||
|
|
||||||
|
// Переставим AV1 на первое место в m-line
|
||||||
|
const mLineParts = lines[mLineIndex].split(' ');
|
||||||
|
const payloads = mLineParts.slice(3);
|
||||||
|
const newPayloads = [av1Payload, ...payloads.filter(p => p !== av1Payload)];
|
||||||
|
lines[mLineIndex] = [...mLineParts.slice(0, 3), ...newPayloads].join(' ');
|
||||||
|
|
||||||
|
// Удалим ненужные кодеки (опционально)
|
||||||
|
const filteredLines = this.removeUnwantedCodecs(lines, av1Payload);
|
||||||
|
|
||||||
|
return filteredLines.join('\r\n');
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find AV1 payload type in SDP
|
||||||
|
*/
|
||||||
|
findAV1Payload(sdp) {
|
||||||
|
const lines = sdp.split('\r\n');
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.includes('a=rtpmap:') && line.toLowerCase().includes('av1')) {
|
||||||
|
const match = line.match(/a=rtpmap:(\d+) av1/i);
|
||||||
|
if (match) {
|
||||||
|
return match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove unwanted codecs from SDP (keep only AV1)
|
||||||
|
*/
|
||||||
|
removeUnwantedCodecs(lines, av1Payload) {
|
||||||
|
const filteredLines = [];
|
||||||
|
let skipNext = false;
|
||||||
|
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
const line = lines[i];
|
||||||
|
|
||||||
|
// Пропускаем описания других кодеков
|
||||||
|
if (line.startsWith('a=rtpmap:') && !line.includes(`a=rtpmap:${av1Payload}`)) {
|
||||||
|
skipNext = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.startsWith('a=rtcp-fb:') && !line.includes(`a=rtcp-fb:${av1Payload}`)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.startsWith('a=fmtp:') && !line.includes(`a=fmtp:${av1Payload}`)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skipNext && line.startsWith('a=')) {
|
||||||
|
skipNext = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredLines.push(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredLines;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test WebRTC support
|
* Test WebRTC support
|
||||||
*/
|
*/
|
||||||
@@ -31,6 +556,55 @@ export const webrtcService = {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create peer connection with AV1 support
|
||||||
|
*/
|
||||||
|
async createPeerConnection(onIceCandidate, onTrack) {
|
||||||
|
const config = this.getIceServerConfig();
|
||||||
|
const peerConnection = new RTCPeerConnection(config);
|
||||||
|
|
||||||
|
peerConnection.onicecandidate = (event) => {
|
||||||
|
if (event.candidate) {
|
||||||
|
onIceCandidate(event.candidate);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
peerConnection.ontrack = (event) => {
|
||||||
|
onTrack(event);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Принудительно применяем AV1 к исходящим потокам
|
||||||
|
peerConnection.onnegotiationneeded = async () => {
|
||||||
|
try {
|
||||||
|
const offer = await peerConnection.createOffer();
|
||||||
|
offer.sdp = this.forceAV1Codec(offer.sdp);
|
||||||
|
await peerConnection.setLocalDescription(offer);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error forcing AV1 codec:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return peerConnection;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create offer with forced AV1
|
||||||
|
*/
|
||||||
|
async createOfferWithAV1(peerConnection) {
|
||||||
|
const offer = await peerConnection.createOffer();
|
||||||
|
offer.sdp = this.forceAV1Codec(offer.sdp);
|
||||||
|
return offer;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create answer with forced AV1
|
||||||
|
*/
|
||||||
|
async createAnswerWithAV1(peerConnection) {
|
||||||
|
const answer = await peerConnection.createAnswer();
|
||||||
|
answer.sdp = this.forceAV1Codec(answer.sdp);
|
||||||
|
return answer;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get WebRTC statistics
|
* Get WebRTC statistics
|
||||||
*/
|
*/
|
||||||
@@ -48,27 +622,38 @@ export const webrtcService = {
|
|||||||
stats.forEach((report) => {
|
stats.forEach((report) => {
|
||||||
if (report.type === 'inbound-rtp' && report.mediaType === 'video') {
|
if (report.type === 'inbound-rtp' && report.mediaType === 'video') {
|
||||||
result.video.inbound = {
|
result.video.inbound = {
|
||||||
bytesReceived: report.bytesReceived,
|
bytesReceived: report.bytesReceived || 0,
|
||||||
packetsReceived: report.packetsReceived,
|
packetsReceived: report.packetsReceived || 0,
|
||||||
packetsLost: report.packetsLost,
|
packetsLost: report.packetsLost || 0,
|
||||||
frameWidth: report.frameWidth,
|
frameWidth: report.frameWidth || 0,
|
||||||
frameHeight: report.frameHeight,
|
frameHeight: report.frameHeight || 0,
|
||||||
framesPerSecond: report.framesPerSecond,
|
framesPerSecond: report.framesPerSecond || 0,
|
||||||
|
codecId: report.codecId || '',
|
||||||
}
|
}
|
||||||
} else if (report.type === 'outbound-rtp' && report.mediaType === 'video') {
|
} else if (report.type === 'outbound-rtp' && report.mediaType === 'video') {
|
||||||
result.video.outbound = {
|
result.video.outbound = {
|
||||||
bytesSent: report.bytesSent,
|
bytesSent: report.bytesSent || 0,
|
||||||
packetsSent: report.packetsSent,
|
packetsSent: report.packetsSent || 0,
|
||||||
frameWidth: report.frameWidth,
|
frameWidth: report.frameWidth || 0,
|
||||||
frameHeight: report.frameHeight,
|
frameHeight: report.frameHeight || 0,
|
||||||
framesPerSecond: report.framesPerSecond,
|
framesPerSecond: report.framesPerSecond || 0,
|
||||||
|
codecId: report.codecId || '',
|
||||||
}
|
}
|
||||||
} else if (report.type === 'candidate-pair' && report.state === 'succeeded') {
|
} else if (report.type === 'candidate-pair' && report.state === 'succeeded') {
|
||||||
result.connection = {
|
result.connection = {
|
||||||
currentRoundTripTime: report.currentRoundTripTime,
|
currentRoundTripTime: report.currentRoundTripTime || 0,
|
||||||
availableOutgoingBitrate: report.availableOutgoingBitrate,
|
availableOutgoingBitrate: report.availableOutgoingBitrate || 0,
|
||||||
bytesReceived: report.bytesReceived,
|
bytesReceived: report.bytesReceived || 0,
|
||||||
bytesSent: report.bytesSent,
|
bytesSent: report.bytesSent || 0,
|
||||||
|
}
|
||||||
|
} else if (report.type === 'codec') {
|
||||||
|
// Получаем информацию о кодеке
|
||||||
|
if (report.id === result.video.inbound?.codecId || report.id === result.video.outbound?.codecId) {
|
||||||
|
result.video.codec = {
|
||||||
|
mimeType: report.mimeType,
|
||||||
|
clockRate: report.clockRate,
|
||||||
|
sdpFmtpLine: report.sdpFmtpLine
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -109,17 +694,24 @@ export const webrtcService = {
|
|||||||
calculateQuality(stats) {
|
calculateQuality(stats) {
|
||||||
let score = 100
|
let score = 100
|
||||||
|
|
||||||
|
// Проверяем, используется ли AV1
|
||||||
|
if (stats.video.codec && stats.video.codec.mimeType) {
|
||||||
|
if (stats.video.codec.mimeType.toLowerCase().includes('av1')) {
|
||||||
|
score += 10; // Бонус за использование AV1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reduce score based on packet loss
|
// Reduce score based on packet loss
|
||||||
if (stats.video.inbound?.packetsLost && stats.video.inbound?.packetsReceived) {
|
if (stats.video.inbound?.packetsLost && stats.video.inbound?.packetsReceived) {
|
||||||
const lossRate = stats.video.inbound.packetsLost / stats.video.inbound.packetsReceived
|
const lossRate = stats.video.inbound.packetsLost / Math.max(1, stats.video.inbound.packetsReceived)
|
||||||
score -= lossRate * 50 // Up to 50 points for packet loss
|
score -= Math.min(50, lossRate * 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reduce score based on round trip time
|
// Reduce score based on round trip time
|
||||||
if (stats.connection?.currentRoundTripTime) {
|
if (stats.connection?.currentRoundTripTime) {
|
||||||
const rtt = stats.connection.currentRoundTripTime * 1000 // Convert to ms
|
const rtt = stats.connection.currentRoundTripTime * 1000
|
||||||
if (rtt > 150) {
|
if (rtt > 150) {
|
||||||
score -= Math.min(30, (rtt - 150) / 10) // Up to 30 points for high latency
|
score -= Math.min(30, (rtt - 150) / 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,10 +719,37 @@ export const webrtcService = {
|
|||||||
if (stats.video.inbound?.framesPerSecond) {
|
if (stats.video.inbound?.framesPerSecond) {
|
||||||
const fps = stats.video.inbound.framesPerSecond
|
const fps = stats.video.inbound.framesPerSecond
|
||||||
if (fps < 15) {
|
if (fps < 15) {
|
||||||
score -= (15 - fps) * 2 // Up to 30 points for low FPS
|
score -= (15 - fps) * 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.max(0, Math.min(100, Math.round(score)))
|
return Math.max(0, Math.min(100, Math.round(score)))
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Adaptive quality control with AV1
|
||||||
|
*/
|
||||||
|
async adaptQuality(peerConnection, qualityCallback) {
|
||||||
|
if (!peerConnection) return;
|
||||||
|
|
||||||
|
const senders = peerConnection.getSenders();
|
||||||
|
const videoSender = senders.find(sender => sender.track?.kind === 'video');
|
||||||
|
|
||||||
|
if (!videoSender) return;
|
||||||
|
|
||||||
|
const stats = await this.getConnectionStats(peerConnection);
|
||||||
|
if (!stats) return;
|
||||||
|
|
||||||
|
const quality = this.calculateQuality(stats);
|
||||||
|
qualityCallback(quality);
|
||||||
|
|
||||||
|
// Адаптивное управление качеством
|
||||||
|
if (quality < 30) {
|
||||||
|
this.optimizeVideoSender(videoSender, 'low');
|
||||||
|
} else if (quality < 60) {
|
||||||
|
this.optimizeVideoSender(videoSender, 'medium');
|
||||||
|
} else {
|
||||||
|
this.optimizeVideoSender(videoSender, 'high');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,10 +21,10 @@ export const useWebRTCStore = defineStore('webrtc', () => {
|
|||||||
// Media constraints
|
// Media constraints
|
||||||
const mediaConstraints = ref({
|
const mediaConstraints = ref({
|
||||||
video: {
|
video: {
|
||||||
width: { ideal: 1280, max: 1920 },
|
width: { ideal: 640, max: 1280 },
|
||||||
height: { ideal: 720, max: 1080 },
|
height: { ideal: 480, max: 720 },
|
||||||
frameRate: { ideal: 30, max: 60 },
|
frameRate: { ideal: 15, max: 30 }
|
||||||
},
|
},
|
||||||
audio: {
|
audio: {
|
||||||
echoCancellation: true,
|
echoCancellation: true,
|
||||||
noiseSuppression: true,
|
noiseSuppression: true,
|
||||||
@@ -43,10 +43,9 @@ export const useWebRTCStore = defineStore('webrtc', () => {
|
|||||||
const rtcConfiguration = {
|
const rtcConfiguration = {
|
||||||
iceServers: [
|
iceServers: [
|
||||||
{ urls: 'stun:stun.l.google.com:19302' },
|
{ urls: 'stun:stun.l.google.com:19302' },
|
||||||
{ urls: 'stun:stun1.l.google.com:19302' },
|
|
||||||
// Add TURN servers here for production
|
// Add TURN servers here for production
|
||||||
],
|
],
|
||||||
iceCandidatePoolSize: 10,
|
iceCandidatePoolSize: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|||||||
Reference in New Issue
Block a user