Skip to content

Commit

Permalink
Merge pull request #110 from lugy-bupt/master
Browse files Browse the repository at this point in the history
Remove peer from state when receiving leave msg
  • Loading branch information
adwpc authored Nov 1, 2021
2 parents dc0817d + 77ca539 commit dc7e9f9
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,39 @@ function App(props) {
};

connector.onpeerevent = (ev) => {
console.log("onpeerevent: state = ", ev.state, ", peer = ", ev.peer.uid, ", name = ", ev.peer.info.name);

if (ev.state == PeerState.JOIN) {
notificationTip("Peer Join", "peer => " + ev.peer.info.name + ", join!");
onSystemMessage(ev.peer.info.name + ", join!");
} else if (ev.state == PeerState.LEAVE) {
notificationTip("Peer Leave", "peer => " + ev.peer.info.name + ", leave!");
onSystemMessage(ev.peer.info.name + ", leave!");
}


let peerInfo = {
'uid': ev.peer.uid,
'name': ev.peer.info.name,
'state': ev.state,
};
let _peers = peers;
let find = false;
_peers.forEach((item) => {
if (item.uid == ev.peer.uid) {
item = peerInfo;
find = true;
}
});
if (!find) {
_peers.push(peerInfo);
}
setPeers([..._peers])
console.log("onpeerevent: state = ", ev.state, ", peer = ", ev.peer.uid, ", name = ", ev.peer.info.name);

let peers = this.state.peers || [];
if(ev.state == PeerState.JOIN){
this._notification("Peer Join", "peer => " + ev.peer.info.name + ", join!");
this._onSystemMessage(ev.peer.info.name + ", join!");

let peerInfo = {
'uid':ev.peer.uid,
'name':ev.peer.info.name,
'state':ev.state,
};
let find = false;
peers.forEach((item) => {
if(item.uid == ev.peer.uid){
item = peerInfo;
find = true;
}
});
if(!find){
peers.push(peerInfo);
}

}else if(ev.state == PeerState.LEAVE){
this._notification("Peer Leave", "peer => " + ev.peer.info.name + ", leave!");
this._onSystemMessage(ev.peer.info.name + ", leave!");

peers.filter(item => item.uid != ev.peer.uid);
}

this.setState({
peers:peers,
});
};

connector.onstreamevent = (ev) => {
Expand Down

0 comments on commit dc7e9f9

Please sign in to comment.