fetchPeers / Peer count

This commit is contained in:
Yasin İLKAYA 2023-06-02 17:36:37 +03:00
parent 38cc4ab073
commit df792f40cd
10 changed files with 2244 additions and 33 deletions

1
.htaccess Normal file
View File

@ -0,0 +1 @@
# Please fill in the URLrewrite rules or custom Apache config here

View File

@ -0,0 +1 @@
xldcAYGIOnxW2yiX6KDZUW44-JTev8gg7r3kzrwY34k.PZDupKjVmMf0TNd3vLGxHErgeolq5CbdlHehVDWziwE

View File

@ -64,6 +64,27 @@ Client.prototype.peerRequest = function(client){
},'request/pair']);
};
Client.prototype.match = function(filterObject){
let keys = Object.keys(filterObject);
let size = keys.length;
if(size > this.info.size)
{
return false
}
for (const key of keys)
{
if(this.info.has(key))
{
if(this.info.get(key) != filterObject[key])
{
return false
}
}else{
return false
}
};
return true
};
/**
* @param {Client|string} client

View File

@ -82,6 +82,19 @@ Room.prototype.publish = function(room){
ROOM_CREATED(this);
termoutput && term.green("Room Published ").white(this.name," in ").yellow(this.clients.size).white(" clients")('\n');
};
/**
* @return {Client[]}
*/
Room.prototype.filterPeers = function(optiJson){
let peers = [];
this.clients.forEach(client => {
if(client.match(optiJson))
{
peers.push(client);
}
});
return peers;
};
Room.prototype.toJSON = function(detailed){
let obj = {};
obj.id = this.id;
@ -251,14 +264,29 @@ addService(({
break;
}
case 'room-peers':{
let {roomId} = message;
let {roomId,filter} = message;
if(Room.rooms.has(roomId))
{
let filteredPeers = Room.rooms.get(roomId).filterPeers(filter || {});
end({
status: 'success',
peers: [
...Room.rooms.get(roomId).clients.values()
].map(i => i.id)
peers: filteredPeers.map(i => i.id)
});
}else{
end({
status: 'fail'
})
}
break;
}
case 'room/peer-count':{
let {roomId,filter} = message;
if(Room.rooms.has(roomId))
{
let filteredPeers = Room.rooms.get(roomId).filterPeers(filter || {});
end({
status: 'success',
count: filteredPeers.length
});
}else{
end({

View File

@ -113,10 +113,21 @@ export default class Room extends EventTarget
wom
});
}
async fetchPeers(){
async fetchPeers(filter?:{[key:string]:any}, onlyNumber:boolean = false) : Promise<Number | Peer[]>
{
if(onlyNumber)
{
let {count} = await this.mwse.EventPooling.request({
type:'room/peer-count',
roomId: this.roomId,
filter: filter || {}
}) as {count:Number};
return count;
}else{
let {status, peers} = await this.mwse.EventPooling.request({
type:'room-peers',
roomId: this.roomId
type:'room/peer-count',
roomId: this.roomId,
filter: filter || {}
}) as {status:"success"|"fail", peers: string[]};
let cup : Peer[] = [];
@ -133,4 +144,12 @@ export default class Room extends EventTarget
};
return cup;
}
}
async peerCount(){
let {count} = await this.mwse.EventPooling.request({
type:'room/peer-count',
roomId: this.roomId
}) as {count:Number};
return count;
}
}

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html lang="tr">
<head>
<base href="/stream/">
@ -19,6 +20,6 @@
</div>
</div>
<script src="index.js?v=6"></script>
<script src="index.js?v=16"></script>
</body>
</html>

View File

@ -162,7 +162,7 @@ window.addEventListener("load", () => {
async function startOutgoingWebcam()
{
outgoingStream = await navigator.mediaDevices.getUserMedia({
video: true/*{
video: true,/*{
advanced: [
{ width: { exact: 1024 } },
{ width: { exact: 900 } },
@ -171,7 +171,7 @@ async function startOutgoingWebcam()
{ width: { exact: 320 } },
{ width: { exact: 240 } }
]
}*/,
}*/
audio: false
});
outgoingStreamOnlyVideo = new MediaStream(outgoingStream);
@ -270,7 +270,7 @@ setInterval(()=>{
getStats()
}, 1000)
/*
setInterval(() => {
if(activePeer?.turboBitrate == 0)
{
@ -279,19 +279,19 @@ setInterval(() => {
if(videoSender)
{
const parameters = videoSender.getParameters();
parameters.encodings[0].maxBitrate = 200000;
parameters.encodings[0].maxBitrate = 3_000_000;
videoSender.setParameters(parameters).then(() => {
console.log('Bitrate değiştirildi.');
// console.log('Bitrate değiştirildi.');
activePeer.turboBitrate = 1;
})
.catch(error => {
console.error('Bitrate değiştirilirken bir hata oluştu:', error);
// console.error('Bitrate değiştirilirken bir hata oluştu:', error);
activePeer.turboBitrate = -1;
});
}
}
}, 5000);
*/
let relative;
async function getStats()
@ -477,7 +477,7 @@ async function getStats()
Crypting D-TLS Cipher: ${stats.dtlsCipher}<br>
${stats.localcert ? `EndToEnd Crypto Local Cert. Algoritm: ${stats.localcert.fingerprintAlgorithm}<br>
EndToEnd Crypto Remote Cert. Algoritm: ${stats.remotecert.fingerprintAlgorithm}<hr>` : ''}
Bitrate Booster: ${activePeer.turboBitrate==0?"Disabled"/*"Waiting conditions"*/:activePeer.turboBitrate==1?"Boosting":"Fail"}<br>
Bitrate Booster: ${activePeer.turboBitrate==0?"Waiting conditions":activePeer.turboBitrate==1?"Boosting":"Fail"}<br>
Codec Handcooling : Failed<br>
Hardware Accelerated : Failed<hr>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2140
yarn.lock Normal file

File diff suppressed because it is too large Load Diff