refs #630 Handle delete event of streamings
This commit is contained in:
parent
6247e5ad7c
commit
8731f5f24b
|
@ -457,6 +457,9 @@ ipcMain.on('start-user-streaming', (event: Event, obj: StreamingSetting) => {
|
||||||
app.dock.setBadge('•')
|
app.dock.setBadge('•')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
(id: string) => {
|
||||||
|
event.sender.send('delete-start-user-streaming', id)
|
||||||
|
},
|
||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
// In macOS, sometimes window is closed (not quit).
|
// In macOS, sometimes window is closed (not quit).
|
||||||
|
@ -501,6 +504,9 @@ ipcMain.on('start-directmessages-streaming', (event: Event, obj: StreamingSettin
|
||||||
(update: Status) => {
|
(update: Status) => {
|
||||||
event.sender.send('update-start-directmessages-streaming', update)
|
event.sender.send('update-start-directmessages-streaming', update)
|
||||||
},
|
},
|
||||||
|
(id: string) => {
|
||||||
|
event.sender.send('delete-start-directmessages-streaming', id)
|
||||||
|
},
|
||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
if (!event.sender.isDestroyed()) {
|
if (!event.sender.isDestroyed()) {
|
||||||
|
@ -542,6 +548,9 @@ ipcMain.on('start-local-streaming', (event: Event, obj: StreamingSetting) => {
|
||||||
(update: Status) => {
|
(update: Status) => {
|
||||||
event.sender.send('update-start-local-streaming', update)
|
event.sender.send('update-start-local-streaming', update)
|
||||||
},
|
},
|
||||||
|
(id: string) => {
|
||||||
|
event.sender.send('delete-start-local-streaming', id)
|
||||||
|
},
|
||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
if (!event.sender.isDestroyed()) {
|
if (!event.sender.isDestroyed()) {
|
||||||
|
@ -583,6 +592,9 @@ ipcMain.on('start-public-streaming', (event: Event, obj: StreamingSetting) => {
|
||||||
(update: Status) => {
|
(update: Status) => {
|
||||||
event.sender.send('update-start-public-streaming', update)
|
event.sender.send('update-start-public-streaming', update)
|
||||||
},
|
},
|
||||||
|
(id: string) => {
|
||||||
|
event.sender.send('delete-start-public-streaming', id)
|
||||||
|
},
|
||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
if (!event.sender.isDestroyed()) {
|
if (!event.sender.isDestroyed()) {
|
||||||
|
@ -628,6 +640,9 @@ ipcMain.on('start-list-streaming', (event: Event, obj: ListID & StreamingSetting
|
||||||
(update: Status) => {
|
(update: Status) => {
|
||||||
event.sender.send('update-start-list-streaming', update)
|
event.sender.send('update-start-list-streaming', update)
|
||||||
},
|
},
|
||||||
|
(id: string) => {
|
||||||
|
event.sender.send('delete-start-list-streaming', id)
|
||||||
|
},
|
||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
if (!event.sender.isDestroyed()) {
|
if (!event.sender.isDestroyed()) {
|
||||||
|
@ -673,6 +688,9 @@ ipcMain.on('start-tag-streaming', (event: Event, obj: Tag & StreamingSetting) =>
|
||||||
(update: Status) => {
|
(update: Status) => {
|
||||||
event.sender.send('update-start-tag-streaming', update)
|
event.sender.send('update-start-tag-streaming', update)
|
||||||
},
|
},
|
||||||
|
(id: string) => {
|
||||||
|
event.sender.send('delete-start-tag-streaming', id)
|
||||||
|
},
|
||||||
(err: Error) => {
|
(err: Error) => {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
if (!event.sender.isDestroyed()) {
|
if (!event.sender.isDestroyed()) {
|
||||||
|
|
|
@ -6,15 +6,12 @@ export default class Streaming {
|
||||||
private client: Mastodon
|
private client: Mastodon
|
||||||
private listener: StreamListener | null
|
private listener: StreamListener | null
|
||||||
|
|
||||||
constructor (account: LocalAccount) {
|
constructor(account: LocalAccount) {
|
||||||
this.client = new Mastodon(
|
this.client = new Mastodon(account.accessToken!, account.baseURL + '/api/v1')
|
||||||
account.accessToken!,
|
|
||||||
account.baseURL + '/api/v1'
|
|
||||||
)
|
|
||||||
this.listener = null
|
this.listener = null
|
||||||
}
|
}
|
||||||
|
|
||||||
startUserStreaming (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
|
startUserStreaming(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
this.listener = this.client.stream('/streaming/user')
|
this.listener = this.client.stream('/streaming/user')
|
||||||
|
|
||||||
this.listener.on('connect', _ => {
|
this.listener.on('connect', _ => {
|
||||||
|
@ -29,6 +26,10 @@ export default class Streaming {
|
||||||
notificationCallback(notification)
|
notificationCallback(notification)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.listener.on('delete', (id: string) => {
|
||||||
|
deleteCallback(id)
|
||||||
|
})
|
||||||
|
|
||||||
this.listener.on('error', (err: Error) => {
|
this.listener.on('error', (err: Error) => {
|
||||||
errCallback(err)
|
errCallback(err)
|
||||||
})
|
})
|
||||||
|
@ -38,7 +39,7 @@ export default class Streaming {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
start (path: string, updateCallback: Function, errCallback: Function) {
|
start(path: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
this.listener = this.client.stream(path)
|
this.listener = this.client.stream(path)
|
||||||
this.listener.on('connect', _ => {
|
this.listener.on('connect', _ => {
|
||||||
log.info(`${path} started`)
|
log.info(`${path} started`)
|
||||||
|
@ -48,6 +49,10 @@ export default class Streaming {
|
||||||
updateCallback(status)
|
updateCallback(status)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.listener.on('delete', (id: string) => {
|
||||||
|
deleteCallback(id)
|
||||||
|
})
|
||||||
|
|
||||||
this.listener.on('error', (err: Error) => {
|
this.listener.on('error', (err: Error) => {
|
||||||
errCallback(err)
|
errCallback(err)
|
||||||
})
|
})
|
||||||
|
@ -57,7 +62,7 @@ export default class Streaming {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stop () {
|
stop() {
|
||||||
if (this.listener) {
|
if (this.listener) {
|
||||||
this.listener.removeAllListeners('connect')
|
this.listener.removeAllListeners('connect')
|
||||||
this.listener.removeAllListeners('update')
|
this.listener.removeAllListeners('update')
|
||||||
|
|
|
@ -7,29 +7,29 @@ export default class StreamingManager {
|
||||||
private websocket: WebSocket
|
private websocket: WebSocket
|
||||||
private useWebsocket: boolean
|
private useWebsocket: boolean
|
||||||
|
|
||||||
constructor (account: LocalAccount, useWebsocket = false) {
|
constructor(account: LocalAccount, useWebsocket = false) {
|
||||||
this.streaming = new Streaming(account)
|
this.streaming = new Streaming(account)
|
||||||
this.websocket = new WebSocket(account)
|
this.websocket = new WebSocket(account)
|
||||||
this.useWebsocket = useWebsocket
|
this.useWebsocket = useWebsocket
|
||||||
}
|
}
|
||||||
|
|
||||||
startUser (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
|
startUser(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
if (this.useWebsocket) {
|
if (this.useWebsocket) {
|
||||||
this._startUserSocket(updateCallback, notificationCallback, errCallback)
|
this._startUserSocket(updateCallback, notificationCallback, deleteCallback, errCallback)
|
||||||
} else {
|
} else {
|
||||||
this._startUserStreaming(updateCallback, notificationCallback, errCallback)
|
this._startUserStreaming(updateCallback, notificationCallback, deleteCallback, errCallback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start (path: string, params: string, updateCallback: Function, errCallback: Function) {
|
start(path: string, params: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
if (this.useWebsocket) {
|
if (this.useWebsocket) {
|
||||||
this._startSocket(path, params, updateCallback, errCallback)
|
this._startSocket(path, params, updateCallback, deleteCallback, errCallback)
|
||||||
} else {
|
} else {
|
||||||
this._startStreaming(path, params, updateCallback, errCallback)
|
this._startStreaming(path, params, updateCallback, deleteCallback, errCallback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stop () {
|
stop() {
|
||||||
this._stopStreaming()
|
this._stopStreaming()
|
||||||
this._stopSocket()
|
this._stopSocket()
|
||||||
}
|
}
|
||||||
|
@ -37,43 +37,35 @@ export default class StreamingManager {
|
||||||
/**
|
/**
|
||||||
* Using streaming for Mastodon
|
* Using streaming for Mastodon
|
||||||
*/
|
*/
|
||||||
_startUserStreaming (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
|
_startUserStreaming(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
this.streaming.startUserStreaming(updateCallback, notificationCallback, errCallback)
|
this.streaming.startUserStreaming(updateCallback, notificationCallback, deleteCallback, errCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
_startStreaming (path: string, params: string, updateCallback: Function, errCallback: Function) {
|
_startStreaming(path: string, params: string, updateCallback: Function, deleteCallback, errCallback: Function) {
|
||||||
const target = `/streaming/${path}?${params}`
|
const target = `/streaming/${path}?${params}`
|
||||||
this.streaming.start(
|
this.streaming.start(target, updateCallback, deleteCallback, errCallback)
|
||||||
target,
|
|
||||||
updateCallback,
|
|
||||||
errCallback
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_stopStreaming () {
|
_stopStreaming() {
|
||||||
this.streaming.stop()
|
this.streaming.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Using websocket for Pleroma
|
* Using websocket for Pleroma
|
||||||
*/
|
*/
|
||||||
_startUserSocket (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
|
_startUserSocket(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
this.websocket.startUserStreaming(updateCallback, notificationCallback, errCallback)
|
this.websocket.startUserStreaming(updateCallback, notificationCallback, deleteCallback, errCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
_startSocket (path: string, params: string, updateCallback: Function, errCallback: Function) {
|
_startSocket(path: string, params: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
let stream = path
|
let stream = path
|
||||||
if (stream === 'public/local') {
|
if (stream === 'public/local') {
|
||||||
stream = 'public:local'
|
stream = 'public:local'
|
||||||
}
|
}
|
||||||
this.websocket.start(
|
this.websocket.start(`${stream}&${params}`, updateCallback, deleteCallback, errCallback)
|
||||||
`${stream}&${params}`,
|
|
||||||
updateCallback,
|
|
||||||
errCallback
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_stopSocket () {
|
_stopSocket() {
|
||||||
this.websocket.stop()
|
this.websocket.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,13 @@ export default class WebSocket {
|
||||||
private client: Mastodon
|
private client: Mastodon
|
||||||
private listener: SocketListener | null
|
private listener: SocketListener | null
|
||||||
|
|
||||||
constructor (account: LocalAccount) {
|
constructor(account: LocalAccount) {
|
||||||
const url = account.baseURL.replace(/^https:\/\//, 'wss://')
|
const url = account.baseURL.replace(/^https:\/\//, 'wss://')
|
||||||
this.client = new Mastodon(
|
this.client = new Mastodon(account.accessToken!, url + '/api/v1')
|
||||||
account.accessToken!,
|
|
||||||
url + '/api/v1'
|
|
||||||
)
|
|
||||||
this.listener = null
|
this.listener = null
|
||||||
}
|
}
|
||||||
|
|
||||||
startUserStreaming (updateCallback: Function, notificationCallback: Function, errCallback: Function) {
|
startUserStreaming(updateCallback: Function, notificationCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
this.listener = this.client.socket('/streaming', 'user')
|
this.listener = this.client.socket('/streaming', 'user')
|
||||||
|
|
||||||
this.listener.on('connect', _ => {
|
this.listener.on('connect', _ => {
|
||||||
|
@ -30,6 +27,10 @@ export default class WebSocket {
|
||||||
notificationCallback(notification)
|
notificationCallback(notification)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.listener.on('delete', (id: string) => {
|
||||||
|
deleteCallback(id)
|
||||||
|
})
|
||||||
|
|
||||||
this.listener.on('error', (err: Error) => {
|
this.listener.on('error', (err: Error) => {
|
||||||
errCallback(err)
|
errCallback(err)
|
||||||
})
|
})
|
||||||
|
@ -49,7 +50,7 @@ export default class WebSocket {
|
||||||
* When hashtag timeline, the path is `hashtag&tag=tag_name`.
|
* When hashtag timeline, the path is `hashtag&tag=tag_name`.
|
||||||
* When list timeline, the path is `list&list=list_id`.
|
* When list timeline, the path is `list&list=list_id`.
|
||||||
*/
|
*/
|
||||||
start (stream: string, updateCallback: Function, errCallback: Function) {
|
start(stream: string, updateCallback: Function, deleteCallback: Function, errCallback: Function) {
|
||||||
this.listener = this.client.socket('/streaming', stream)
|
this.listener = this.client.socket('/streaming', stream)
|
||||||
this.listener.on('connect', _ => {
|
this.listener.on('connect', _ => {
|
||||||
log.info(`/streaming/?stream=${stream} started`)
|
log.info(`/streaming/?stream=${stream} started`)
|
||||||
|
@ -59,6 +60,10 @@ export default class WebSocket {
|
||||||
updateCallback(status)
|
updateCallback(status)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.listener.on('delete', (id: string) => {
|
||||||
|
deleteCallback(id)
|
||||||
|
})
|
||||||
|
|
||||||
this.listener.on('error', (err: Error) => {
|
this.listener.on('error', (err: Error) => {
|
||||||
errCallback(err)
|
errCallback(err)
|
||||||
})
|
})
|
||||||
|
@ -68,7 +73,7 @@ export default class WebSocket {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stop () {
|
stop() {
|
||||||
if (this.listener) {
|
if (this.listener) {
|
||||||
this.listener.removeAllListeners('connect')
|
this.listener.removeAllListeners('connect')
|
||||||
this.listener.removeAllListeners('update')
|
this.listener.removeAllListeners('update')
|
||||||
|
|
Loading…
Reference in New Issue