Merge pull request #957 from h3poteto/iss-956
closes #956 Stop user streaming after remove account association
This commit is contained in:
commit
47a12a5a5e
|
@ -175,16 +175,16 @@ export default class Account {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAccount(id: string): Promise<number> {
|
removeAccount(id: string): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.db.remove(
|
this.db.remove(
|
||||||
{
|
{
|
||||||
_id: id
|
_id: id
|
||||||
},
|
},
|
||||||
{ multi: true },
|
{ multi: true },
|
||||||
(err, numRemoved) => {
|
(err, _numRemoved) => {
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
resolve(numRemoved)
|
resolve(id)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -363,8 +363,9 @@ ipcMain.on('update-account', (event: Event, acct: LocalAccount) => {
|
||||||
ipcMain.on('remove-account', (event: Event, id: string) => {
|
ipcMain.on('remove-account', (event: Event, id: string) => {
|
||||||
accountManager
|
accountManager
|
||||||
.removeAccount(id)
|
.removeAccount(id)
|
||||||
.then(() => {
|
.then((id) => {
|
||||||
event.sender.send('response-remove-account')
|
stopUserStreaming(id)
|
||||||
|
event.sender.send('response-remove-account', id)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
event.sender.send('error-remove-account', 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 = {
|
type StreamingSetting = {
|
||||||
account: LocalAccount
|
account: LocalAccount
|
||||||
useWebsocket: boolean
|
useWebsocket: boolean
|
||||||
|
|
|
@ -49,7 +49,7 @@ const actions: ActionTree<AccountState, RootState> = {
|
||||||
ipcRenderer.removeAllListeners('response-remove-account')
|
ipcRenderer.removeAllListeners('response-remove-account')
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('response-remove-account', () => {
|
ipcRenderer.once('response-remove-account', (_id: string) => {
|
||||||
ipcRenderer.removeAllListeners('error-remove-account')
|
ipcRenderer.removeAllListeners('error-remove-account')
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue