2019-11-02 03:29:33 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
|
|
|
import VoiceUsers from '/imports/api/voice-users';
|
2020-11-17 03:18:33 +08:00
|
|
|
import Users from '/imports/api/users'
|
2019-11-02 03:29:33 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
2020-06-02 05:37:14 +08:00
|
|
|
import { debounce } from 'lodash';
|
2019-11-02 03:29:33 +08:00
|
|
|
import TalkingIndicator from './component';
|
2019-11-14 01:56:26 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
2019-11-20 23:08:36 +08:00
|
|
|
import Service from './service';
|
2019-11-02 03:29:33 +08:00
|
|
|
|
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
|
|
|
const { enableTalkingIndicator } = APP_CONFIG;
|
|
|
|
|
|
|
|
const TalkingIndicatorContainer = (props) => {
|
|
|
|
if (!enableTalkingIndicator) return null;
|
|
|
|
return (<TalkingIndicator {...props} />);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withTracker(() => {
|
|
|
|
const talkers = {};
|
|
|
|
const meetingId = Auth.meetingID;
|
2019-11-14 00:24:38 +08:00
|
|
|
const usersTalking = VoiceUsers.find({ meetingId, joined: true, spoke: true }, {
|
2019-11-02 03:29:33 +08:00
|
|
|
fields: {
|
|
|
|
callerName: 1,
|
|
|
|
talking: 1,
|
2019-11-06 01:10:59 +08:00
|
|
|
color: 1,
|
|
|
|
startTime: 1,
|
2019-11-14 01:56:26 +08:00
|
|
|
voiceUserId: 1,
|
|
|
|
muted: 1,
|
2019-11-27 00:44:58 +08:00
|
|
|
intId: 1,
|
2019-11-02 03:29:33 +08:00
|
|
|
},
|
2019-11-20 23:08:36 +08:00
|
|
|
}).fetch().sort(Service.sortVoiceUsers);
|
2019-11-02 03:29:33 +08:00
|
|
|
|
|
|
|
if (usersTalking) {
|
2019-11-06 04:19:50 +08:00
|
|
|
for (let i = 0; i < usersTalking.length; i += 1) {
|
2019-11-14 01:56:26 +08:00
|
|
|
const {
|
2019-11-27 00:44:58 +08:00
|
|
|
callerName, talking, color, voiceUserId, muted, intId,
|
2019-11-14 01:56:26 +08:00
|
|
|
} = usersTalking[i];
|
2019-11-15 02:47:27 +08:00
|
|
|
|
2020-11-18 21:40:15 +08:00
|
|
|
const user = Users.findOne({ userId: voiceUserId }, { fields: { name: 1 } });
|
2020-11-17 03:18:33 +08:00
|
|
|
|
|
|
|
const _name = user ? user.name : 'USER';
|
|
|
|
|
2019-11-27 00:44:58 +08:00
|
|
|
talkers[`${intId}`] = {
|
2019-11-06 01:10:59 +08:00
|
|
|
color,
|
|
|
|
talking,
|
2019-11-14 01:56:26 +08:00
|
|
|
voiceUserId,
|
|
|
|
muted,
|
2020-11-17 03:18:33 +08:00
|
|
|
callerName: _name,
|
2019-11-06 01:10:59 +08:00
|
|
|
};
|
2019-11-06 04:19:50 +08:00
|
|
|
}
|
2019-11-02 03:29:33 +08:00
|
|
|
}
|
|
|
|
|
2019-11-14 01:56:26 +08:00
|
|
|
const muteUser = (id) => {
|
|
|
|
const user = VoiceUsers.findOne({ meetingId, voiceUserId: id }, {
|
|
|
|
fields: {
|
|
|
|
muted: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (user.muted) return;
|
|
|
|
makeCall('toggleVoice', id);
|
|
|
|
};
|
|
|
|
|
2019-11-02 03:29:33 +08:00
|
|
|
return {
|
|
|
|
talkers,
|
2020-06-02 05:37:14 +08:00
|
|
|
muteUser: id => debounce(muteUser(id), 500, { leading: true, trailing: false }),
|
2019-11-26 03:24:12 +08:00
|
|
|
openPanel: Session.get('openPanel'),
|
2019-11-02 03:29:33 +08:00
|
|
|
};
|
|
|
|
})(TalkingIndicatorContainer);
|