Skip to content

Commit

Permalink
feat: auto remove room if no peer
Browse files Browse the repository at this point in the history
  • Loading branch information
woody146 committed Jun 21, 2023
1 parent 14801c1 commit a07e34b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MediaPeer } from '../entities/media.peer.js';
import { MediaWorker } from '../entities/media.worker.js';
import { fetchApi } from '../utils/api.js';
import { BaseService } from './base.js';
import { RoomService } from './room.js';

export class UserService extends BaseService {
/**
Expand Down Expand Up @@ -32,8 +33,21 @@ export class UserService extends BaseService {
await this.dataSource
.getRepository(MediaWorker)
.decrement({ id: peer.workerId }, 'peerCount', 1);

this.removeEmptyRoom(peer);
})
);
return {};
}

async removeEmptyRoom(data: { roomId: string }) {
const exist = await this.dataSource.getRepository(MediaPeer).findOne({
select: { id: true },
where: { roomId: data.roomId },
});
// if no one in room
if (!exist) {
this.createService(RoomService).close(data);
}
}
}

0 comments on commit a07e34b

Please sign in to comment.