Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: v0.0.1 #1

Merged
merged 21 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: peer server
  • Loading branch information
KairuiLiu committed Apr 20, 2024
commit 64cc70a49a3679ec76e87f1ee1d78df01ff4cf72
11 changes: 5 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
SERVER_PORT=9876
PEERJS_PORT=9877

COTURN_PATH=/coturn
# Site Configuration
COTURN_PREFIX=coturn
COTURN_USERNAME=conflux
COTURN_PASSWORD=conflux
PEER_SERVER_PATH=/peer_signal

# Server Configuration
SERVER_PORT=9876
PEERJS_PORT=9877
JWT_SECRET=ConFlux-BeginYourIdeaConfluxAdventure

MONGO_URI=mongodb://127.0.0.1:27017
MONGO_DBNAME=conflux
MONGO_USER=conflux
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import wsController from './routes/ws';
const dev = process.env.MODE === 'DEV';

// PeerJS server
appPeer.use('/peer_signal', serverPeer);
appPeer.use(process.env.PEER_SERVER_PATH || '/peer_signal', serverPeer);

// WS Server
io.on('connection', (socket) => {
Expand Down
2 changes: 2 additions & 0 deletions src/model/meeting_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const MeetingInfoSchema = new Schema({
camera: { type: Boolean, required: true },
},
},
expandCamera: { type: Boolean, required: true },
mirrorCamera: { type: Boolean, required: true },
avatar: String
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/routes/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ router.get('/', (req, res) => {
res.json(
genSuccessResponse({
token: token,
COTURN_PATH: process.env.COTURN_PATH,
COTURN_PREFIX: process.env.COTURN_PREFIX,
PEER_SERVER_PATH: process.env.PEER_SERVER_PATH,
COTURN_USERNAME: process.env.COTURN_USERNAME,
COTURN_PASSWORD: process.env.COTURN_PASSWORD,
Expand Down
15 changes: 13 additions & 2 deletions src/routes/ws_meeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const meetControllers: Controllers<ClientMeetingKeys, SocketType, ServerType> =
dulplicatName = true;
else targetUser.name = participant_diff.name;
}
if (participant_diff.expandCamera !== undefined) {
targetUser.expandCamera = participant_diff.expandCamera;
}
if (participant_diff.mirrorCamera !== undefined) {
targetUser.mirrorCamera = participant_diff.mirrorCamera;
}
if (participant_diff.role !== undefined && isHostRequest)
targetUser.role = participant_diff.role;
if (participant_diff.state !== undefined) {
Expand All @@ -62,13 +68,18 @@ const meetControllers: Controllers<ClientMeetingKeys, SocketType, ServerType> =
participant_diff.role !== undefined
)
emitRoom(room_id, io, {
type: 'USER_UPDATE',
type: 'USER_UPDATE', // change multiple user state
data: meetInfo,
});
else
emitRoom(room_id, io, {
type: 'USER_STATE_UPDATE',
data: { muid, state: participant_diff.state },
data: {
muid,
state: participant_diff.state,
expandCamera: participant_diff.expandCamera,
mirrorCamera: participant_diff.mirrorCamera,
},
});

if (dulplicatName)
Expand Down
13 changes: 12 additions & 1 deletion src/routes/ws_room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import emitRoom from '@/utils/emit_room';

const roomControllers: Controllers<ClientRoomKeys, SocketType, ServerType> = {
JOIN_MEETING: async (data, sc, io) => {
const { room_id, user_name, muid, token, state, avatar } = data;
const {
room_id,
user_name,
muid,
token,
state,
avatar,
expandCamera,
mirrorCamera,
} = data;

const { success, err } = await wsBaseHandler(
token,
Expand Down Expand Up @@ -40,6 +49,8 @@ const roomControllers: Controllers<ClientRoomKeys, SocketType, ServerType> = {
role: isOrganizer ? 'HOST' : 'PARTICIPANT',
state,
avatar,
expandCamera,
mirrorCamera,
});

await meetInfo.save();
Expand Down
2 changes: 2 additions & 0 deletions src/types/participant.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ declare interface Participant {
role: 'HOST' | 'PARTICIPANT';
state: ParticipantState;
avatar?: string;
expandCamera: boolean;
mirrorCamera: boolean;
}
3 changes: 1 addition & 2 deletions src/www/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const appPeer = express();
const portPeer = normalizePort(process.env.PEERJS_PORT || '9877');
const httpServerPeer = createServer(appPeer);
httpServerPeer.listen(portPeer);
export const serverPeer = ExpressPeerServer(httpServerPeer, { path: '/' });
export const serverPeer = ExpressPeerServer(httpServerPeer, { path: '' });

// db
mongoose.connect(process.env.MONGO_URI!, {
Expand All @@ -70,4 +70,3 @@ mongoose.connect(process.env.MONGO_URI!, {
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', console.log.bind(console, 'Connected successfully to MongoDB'));

Loading