From 528110d56f4e4f3be7ca1f3476d95a0c249a9a81 Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Thu, 11 Jul 2019 00:55:01 +0900
Subject: [PATCH] refs #956 Stop user streaming after remove account
association
---
src/main/account.ts | 6 +++---
src/main/index.ts | 18 ++++++++++++++++--
src/renderer/store/Preferences/Account.ts | 2 +-
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/main/account.ts b/src/main/account.ts
index 86ddfc1a..058665a8 100644
--- a/src/main/account.ts
+++ b/src/main/account.ts
@@ -175,16 +175,16 @@ export default class Account {
})
}
- removeAccount(id: string): Promise {
+ removeAccount(id: string): Promise {
return new Promise((resolve, reject) => {
this.db.remove(
{
_id: id
},
{ multi: true },
- (err, numRemoved) => {
+ (err, _numRemoved) => {
if (err) return reject(err)
- resolve(numRemoved)
+ resolve(id)
}
)
})
diff --git a/src/main/index.ts b/src/main/index.ts
index c3b3c90b..5bc5319c 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -363,8 +363,9 @@ ipcMain.on('update-account', (event: Event, acct: LocalAccount) => {
ipcMain.on('remove-account', (event: Event, id: string) => {
accountManager
.removeAccount(id)
- .then(() => {
- event.sender.send('response-remove-account')
+ .then((id) => {
+ stopUserStreaming(id)
+ event.sender.send('response-remove-account', id)
})
.catch(err => {
event.sender.send('error-remove-account', err)
@@ -493,6 +494,19 @@ ipcMain.on('stop-all-user-streamings', () => {
})
})
+/**
+ * Stop an user streaming in all user streamings.
+ * @param id specified user id in nedb.
+ */
+const stopUserStreaming = (id: string) => {
+ Object.keys(userStreamings).map((key: string) => {
+ if (key === id && userStreamings[id]) {
+ userStreamings[id]!.stop()
+ userStreamings[id] = null
+ }
+ })
+}
+
type StreamingSetting = {
account: LocalAccount
useWebsocket: boolean
diff --git a/src/renderer/store/Preferences/Account.ts b/src/renderer/store/Preferences/Account.ts
index 5b47ce75..4af4114e 100644
--- a/src/renderer/store/Preferences/Account.ts
+++ b/src/renderer/store/Preferences/Account.ts
@@ -49,7 +49,7 @@ const actions: ActionTree = {
ipcRenderer.removeAllListeners('response-remove-account')
reject(err)
})
- ipcRenderer.once('response-remove-account', () => {
+ ipcRenderer.once('response-remove-account', (_id: string) => {
ipcRenderer.removeAllListeners('error-remove-account')
resolve()
})