From 034aac99d9d89aaf5694898bad1cf3d14dda0412 Mon Sep 17 00:00:00 2001 From: empathicqubit Date: Sun, 27 May 2018 17:53:01 -0400 Subject: [PATCH] Better client unmounting in simulator. --- frontend/src/controller/simulator.js | 7 ++++--- frontend/src/view/simulator.js | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/controller/simulator.js b/frontend/src/controller/simulator.js index 34cd9d1..8e28e1f 100644 --- a/frontend/src/controller/simulator.js +++ b/frontend/src/controller/simulator.js @@ -61,6 +61,7 @@ function getProps (render) { } let client = { + _backend: backend, sources: [], realPosition: 0, clientId: 0, @@ -76,9 +77,6 @@ function getProps (render) { client.name = name; render(); }, - onComponentUnmount: () => { - backend.close(); - } }; StartAudioContext(backend._context, '.playit') @@ -123,6 +121,9 @@ function getProps (render) { render(); }, onSubmitPassword: (password) => doHello(password), + onComponentUnmount: () => { + clients.forEach(x => x._backend.close()); + }, onChangePassword: (password) => { simulator.password = password; render(); diff --git a/frontend/src/view/simulator.js b/frontend/src/view/simulator.js index 83532b4..29132d9 100644 --- a/frontend/src/view/simulator.js +++ b/frontend/src/view/simulator.js @@ -9,6 +9,9 @@ class Simulator extends React.Component { constructor(props) { super(props); } + componentWillUnmount() { + this.props.onComponentUnmount && this.props.onComponentUnmount(); + } render() { return (