[mirotalk] - refactoring comments
This commit is contained in:
@@ -73,13 +73,13 @@
|
||||
- https://mirotalk.up.railway.app/join?room=test&name=mirotalk&audio=0&video=0¬ify=0
|
||||
- https://mirotalk.herokuapp.com/join?room=test&name=mirotalk&audio=0&video=0¬ify=0
|
||||
|
||||
| Params | Type | Description |
|
||||
| ------ | ------- | ---------------- |
|
||||
| room | string | room Id |
|
||||
| name | string | user name |
|
||||
| audio | boolean | audio stream |
|
||||
| video | boolean | video stream |
|
||||
| notify | boolean | welcome message |
|
||||
| Params | Type | Description |
|
||||
| ------ | ------- | --------------- |
|
||||
| room | string | room Id |
|
||||
| name | string | user name |
|
||||
| audio | boolean | audio stream |
|
||||
| video | boolean | video stream |
|
||||
| notify | boolean | welcome message |
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
@@ -7,27 +7,61 @@ module.exports = class Logger {
|
||||
this.debugOn = debugOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Console debug logs
|
||||
* @param {string} msg message
|
||||
* @param {object} op optional params
|
||||
* @returns
|
||||
*/
|
||||
debug(msg, op = '') {
|
||||
if (this.debugOn === false) return;
|
||||
console.debug('[' + this.getDataTime() + '] [' + this.appName + '] ' + msg, op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Console logs
|
||||
* @param {string} msg message
|
||||
* @param {object} op optional params
|
||||
* @returns
|
||||
*/
|
||||
log(msg, op = '') {
|
||||
console.log('[' + this.getDataTime() + '] [' + this.appName + '] ' + msg, op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Console info logs
|
||||
* @param {string} msg message
|
||||
* @param {object} op optional params
|
||||
* @returns
|
||||
*/
|
||||
info(msg, op = '') {
|
||||
console.info('[' + this.getDataTime() + '] [' + this.appName + '] ' + msg, op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Console warning logs
|
||||
* @param {string} msg message
|
||||
* @param {object} op optional params
|
||||
* @returns
|
||||
*/
|
||||
warn(msg, op = '') {
|
||||
console.warn('[' + this.getDataTime() + '] [' + this.appName + '] ' + msg, op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Console error logs
|
||||
* @param {string} msg message
|
||||
* @param {object} op optional params
|
||||
* @returns
|
||||
*/
|
||||
error(msg, op = '') {
|
||||
console.error('[' + this.getDataTime() + '] [' + this.appName + '] ' + msg, op);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date time
|
||||
* @returns {string} date to ISO string
|
||||
*/
|
||||
getDataTime() {
|
||||
return new Date().toISOString().replace(/T/, ' ').replace(/Z/, '');
|
||||
}
|
||||
|
||||
+10
-10
@@ -425,8 +425,8 @@ io.sockets.on('connect', (socket) => {
|
||||
channels[channel][socket.id] = socket;
|
||||
socket.channels[channel] = channel;
|
||||
|
||||
// Send to peer how many peers are connected in the same room
|
||||
sendToPeer(socket.id, sockets, 'peersCount', { peers_count: Object.keys(peers[channel]).length });
|
||||
// Send some server info to joined peer
|
||||
sendToPeer(socket.id, sockets, 'serverInfo', { peers_count: Object.keys(peers[channel]).length });
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -746,10 +746,10 @@ io.sockets.on('connect', (socket) => {
|
||||
|
||||
/**
|
||||
* Send async data to all peers in the same room except yourself
|
||||
* @param {*} room_id id of the room to send data
|
||||
* @param {*} socket_id socket id of peer that send data
|
||||
* @param {*} msg message to send to the peers in the same room
|
||||
* @param {*} config JSON data to send to the peers in the same room
|
||||
* @param {string} room_id id of the room to send data
|
||||
* @param {string} socket_id socket id of peer that send data
|
||||
* @param {string} msg message to send to the peers in the same room
|
||||
* @param {object} config JSON data to send to the peers in the same room
|
||||
*/
|
||||
async function sendToRoom(room_id, socket_id, msg, config = {}) {
|
||||
for (let peer_id in channels[room_id]) {
|
||||
@@ -763,10 +763,10 @@ async function sendToRoom(room_id, socket_id, msg, config = {}) {
|
||||
|
||||
/**
|
||||
* Send async data to specified peer
|
||||
* @param {*} peer_id id of the peer to send data
|
||||
* @param {*} sockets all peers connections
|
||||
* @param {*} msg message to send to the peer in the same room
|
||||
* @param {*} config JSON data to send to the peer in the same room
|
||||
* @param {string} peer_id id of the peer to send data
|
||||
* @param {object} sockets all peers connections
|
||||
* @param {string} msg message to send to the peer in the same room
|
||||
* @param {object} config JSON data to send to the peer in the same room
|
||||
*/
|
||||
async function sendToPeer(peer_id, sockets, msg, config = {}) {
|
||||
if (peer_id in sockets) {
|
||||
|
||||
+202
-205
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Start audio pitch detection
|
||||
* @param {object} stream media stream audio
|
||||
*/
|
||||
function startPitchDetection(stream) {
|
||||
pitchDetectionStatus = true;
|
||||
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
@@ -8,6 +12,14 @@ function startPitchDetection(stream) {
|
||||
mediaStreamSource.connect(meter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create audio mixer
|
||||
* @param {object} audioContext audio context
|
||||
* @param {decimal} clipLevel optional
|
||||
* @param {decimal} averaging optional
|
||||
* @param {integer} clipLag optional
|
||||
* @returns
|
||||
*/
|
||||
function createAudioMeter(audioContext, clipLevel, averaging, clipLag) {
|
||||
const processor = audioContext.createScriptProcessor(512);
|
||||
processor.onaudioprocess = volumeAudioProcess;
|
||||
@@ -40,6 +52,10 @@ function createAudioMeter(audioContext, clipLevel, averaging, clipLag) {
|
||||
return processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Volume audio process
|
||||
* @param {object} event audio volume event
|
||||
*/
|
||||
function volumeAudioProcess(event) {
|
||||
const buf = event.inputBuffer.getChannelData(0);
|
||||
const bufLength = buf.length;
|
||||
|
||||
@@ -142,6 +142,9 @@ let speed = 100;
|
||||
|
||||
typeWriter();
|
||||
|
||||
/**
|
||||
* Set room name
|
||||
*/
|
||||
function typeWriter() {
|
||||
if (i < txt.length) {
|
||||
document.getElementById('roomName').value += txt.charAt(i);
|
||||
|
||||
@@ -161,7 +161,7 @@ function handleRecognitionLanguages() {
|
||||
|
||||
/**
|
||||
* Start or Stop speech recognition
|
||||
* @param {*} config
|
||||
* @param {object} config data
|
||||
*/
|
||||
function startSpeech(config) {
|
||||
if (isWebkitSpeechRecognitionSupported) {
|
||||
|
||||
@@ -8,18 +8,35 @@ let aspect = 2;
|
||||
|
||||
let ratio = getAspectRatio();
|
||||
|
||||
/**
|
||||
* Get aspect ratio
|
||||
* @returns {integer} aspect ratio
|
||||
*/
|
||||
function getAspectRatio() {
|
||||
customRatio = aspect == 0 ? true : false;
|
||||
var ratio = ratios[aspect].split(':');
|
||||
return ratio[1] / ratio[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set aspect ratio
|
||||
* @param {integer} i ratios index
|
||||
*/
|
||||
function setAspectRatio(i) {
|
||||
aspect = i;
|
||||
ratio = getAspectRatio();
|
||||
resizeVideoMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate area
|
||||
* @param {integer} Increment
|
||||
* @param {integer} Count
|
||||
* @param {integer} Width
|
||||
* @param {integer} Height
|
||||
* @param {integer} Margin
|
||||
* @returns
|
||||
*/
|
||||
function Area(Increment, Count, Width, Height, Margin = 10) {
|
||||
ratio = customRatio ? 0.75 : ratio;
|
||||
let i = 0;
|
||||
@@ -37,6 +54,9 @@ function Area(Increment, Count, Width, Height, Margin = 10) {
|
||||
else return Increment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize video elements
|
||||
*/
|
||||
function resizeVideoMedia() {
|
||||
let Margin = 3;
|
||||
let videoMediaContainer = getId('videoMediaContainer');
|
||||
@@ -65,6 +85,15 @@ function resizeVideoMedia() {
|
||||
setWidth(videoMediaContainer, Cameras, max, bigWidth, Margin, Height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Width
|
||||
* @param {object} videoMediaContainer
|
||||
* @param {object} Cameras
|
||||
* @param {integer} width
|
||||
* @param {integer} bigWidth
|
||||
* @param {integer} margin
|
||||
* @param {integer} maxHeight
|
||||
*/
|
||||
function setWidth(videoMediaContainer, Cameras, width, bigWidth, margin, maxHeight) {
|
||||
ratio = customRatio ? 0.68 : ratio;
|
||||
let isOneVideoElement = videoMediaContainer.childElementCount == 1 ? true : false;
|
||||
@@ -81,6 +110,9 @@ function setWidth(videoMediaContainer, Cameras, width, bigWidth, margin, maxHeig
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle window event listener
|
||||
*/
|
||||
window.addEventListener(
|
||||
'load',
|
||||
function (event) {
|
||||
|
||||
Reference in New Issue
Block a user