remove this.participants, clone object instead

This commit is contained in:
or-else
2023-06-15 15:20:39 -07:00
parent 8f9f41efe5
commit 685a1cd2a4
5 changed files with 20 additions and 30 deletions
+9 -13
View File
@@ -64,8 +64,6 @@ class VCPanel extends React.PureComponent {
this.handleData = this.handleData.bind(this); this.handleData = this.handleData.bind(this);
this.handleDevicesChanged = this.handleDevicesChanged.bind(this); this.handleDevicesChanged = this.handleDevicesChanged.bind(this);
this.startRoom = this.startRoom.bind(this); this.startRoom = this.startRoom.bind(this);
this.participants = {};
} }
componentDidMount() { componentDidMount() {
@@ -124,23 +122,21 @@ class VCPanel extends React.PureComponent {
const me = this.props.tinode.getMeTopic(); const me = this.props.tinode.getMeTopic();
const c = me.getContact(participant.identity); const c = me.getContact(participant.identity);
const name = c && c.public && c.public.fn ? c.public.fn : participant.identity;
const photo = makeImageUrl(c && c.public ? c.public.photo : null); const participants = Object.assign({}, this.state.participants);
const p = { participants[participant.identity] = {
name: name, name: c && c.public && c.public.fn ? c.public.fn : participant.identity,
photo: photo, photo: makeImageUrl(c && c.public ? c.public.photo : null),
participant: participant participant: participant
}; };
this.participants[participant.identity] = p this.setState({participants: participants});
console.log('participant connected', this.participants);
this.setState({participants: this.participants}, _ => { this.forceUpdate(); });
} }
} }
handleParticipantDisconnected(participant) { handleParticipantDisconnected(participant) {
console.log('Deleting participant ', participant.identity); const participants = Object.assign({}, this.state.participants);
delete this.participants[participant.identity]; delete participants[participant.identity];
this.setState({participants: this.participants}); this.setState({participants: participants});
} }
handleData(msg, participant) { handleData(msg, participant) {
+8 -14
View File
@@ -16764,7 +16764,6 @@ class VCPanel extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComponen
this.handleData = this.handleData.bind(this); this.handleData = this.handleData.bind(this);
this.handleDevicesChanged = this.handleDevicesChanged.bind(this); this.handleDevicesChanged = this.handleDevicesChanged.bind(this);
this.startRoom = this.startRoom.bind(this); this.startRoom = this.startRoom.bind(this);
this.participants = {};
} }
componentDidMount() { componentDidMount() {
const topic = this.props.tinode.getTopic(this.props.topic); const topic = this.props.tinode.getTopic(this.props.topic);
@@ -16815,27 +16814,22 @@ class VCPanel extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComponen
}); });
const me = this.props.tinode.getMeTopic(); const me = this.props.tinode.getMeTopic();
const c = me.getContact(participant.identity); const c = me.getContact(participant.identity);
const name = c && c.public && c.public.fn ? c.public.fn : participant.identity; const participants = Object.assign({}, this.state.participants);
const photo = (0,_lib_blob_helpers_js__WEBPACK_IMPORTED_MODULE_5__.makeImageUrl)(c && c.public ? c.public.photo : null); participants[participant.identity] = {
const p = { name: c && c.public && c.public.fn ? c.public.fn : participant.identity,
name: name, photo: (0,_lib_blob_helpers_js__WEBPACK_IMPORTED_MODULE_5__.makeImageUrl)(c && c.public ? c.public.photo : null),
photo: photo,
participant: participant participant: participant
}; };
this.participants[participant.identity] = p;
console.log('participant connected', this.participants);
this.setState({ this.setState({
participants: this.participants participants: participants
}, _ => {
this.forceUpdate();
}); });
} }
} }
handleParticipantDisconnected(participant) { handleParticipantDisconnected(participant) {
console.log('Deleting participant ', participant.identity); const participants = Object.assign({}, this.state.participants);
delete this.participants[participant.identity]; delete participants[participant.identity];
this.setState({ this.setState({
participants: this.participants participants: participants
}); });
} }
handleData(msg, participant) { handleData(msg, participant) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long