refs #125 Apply list streaming in websocket for misskey
This commit is contained in:
parent
58a14f4b56
commit
6e258fdd73
|
@ -1875,8 +1875,8 @@ export default class Misskey implements MegalodonInterface {
|
|||
throw new NoImplementedError('TODO: implement')
|
||||
}
|
||||
|
||||
public listSocket(_list_id: string): WebSocketInterface {
|
||||
throw new NoImplementedError('TODO: implement')
|
||||
public listSocket(list_id: string): WebSocketInterface {
|
||||
return this.client.socket('list', list_id)
|
||||
}
|
||||
|
||||
public directSocket(): WebSocketInterface {
|
||||
|
|
|
@ -460,12 +460,15 @@ namespace MisskeyAPI {
|
|||
return this.cancelTokenSource.cancel('Request is canceled by user')
|
||||
}
|
||||
|
||||
public socket(channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation'): WebSocket {
|
||||
public socket(
|
||||
channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list',
|
||||
listId?: string | null
|
||||
): WebSocket {
|
||||
if (!this.accessToken) {
|
||||
throw new Error('accessToken is required')
|
||||
}
|
||||
const url = this.baseUrl + '/streaming'
|
||||
const streaming = new WebSocket(url, channel, this.accessToken)
|
||||
const streaming = new WebSocket(url, channel, this.accessToken, listId)
|
||||
process.nextTick(() => {
|
||||
streaming.start()
|
||||
})
|
||||
|
|
|
@ -6,8 +6,9 @@ import MisskeyAPI from './api_client'
|
|||
|
||||
export default class WebSocket extends EventEmitter implements WebSocketInterface {
|
||||
public url: string
|
||||
public channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation'
|
||||
public channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list'
|
||||
public parser: Parser
|
||||
public listId: string | null = null
|
||||
private _accessToken: string
|
||||
private _reconnectInterval: number
|
||||
private _reconnectMaxAttempts: number
|
||||
|
@ -16,11 +17,19 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
private _client: WS | null = null
|
||||
private _channelID: string
|
||||
|
||||
constructor(url: string, channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation', accessToken: string) {
|
||||
constructor(
|
||||
url: string,
|
||||
channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list',
|
||||
accessToken: string,
|
||||
listId?: string | null
|
||||
) {
|
||||
super()
|
||||
this.url = url
|
||||
this.parser = new Parser()
|
||||
this.channel = channel
|
||||
if (listId) {
|
||||
this.listId = listId
|
||||
}
|
||||
this._accessToken = accessToken
|
||||
this._reconnectInterval = 10000
|
||||
this._reconnectMaxAttempts = Infinity
|
||||
|
@ -105,6 +114,20 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
})
|
||||
)
|
||||
break
|
||||
case 'list':
|
||||
this._client.send(
|
||||
JSON.stringify({
|
||||
type: 'connect',
|
||||
body: {
|
||||
channel: 'userList',
|
||||
id: this._channelID,
|
||||
params: {
|
||||
listId: this.listId
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
break
|
||||
default:
|
||||
this._client.send(
|
||||
JSON.stringify({
|
||||
|
|
Loading…
Reference in a new issue