Skip to content

Commit 0a23cc5

Browse files
committed
Fix pixelfed websocket
1 parent 30949a9 commit 0a23cc5

File tree

4 files changed

+64
-346
lines changed

4 files changed

+64
-346
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import generator, { Entity } from 'megalodon'
2+
3+
const BASE_URL: string = process.env.PIXELFED_URL!
4+
5+
const access_token: string = process.env.PIXELFED_ACCESS_TOKEN!
6+
7+
const client = generator('pixelfed', BASE_URL, access_token)
8+
9+
client.localStreaming().then(stream => {
10+
stream.on('connect', () => {
11+
console.log('connect')
12+
})
13+
14+
stream.on('pong', () => {
15+
console.log('pong')
16+
})
17+
18+
stream.on('update', (status: Entity.Status) => {
19+
console.log(status)
20+
})
21+
22+
stream.on('notification', (notification: Entity.Notification) => {
23+
console.log(notification)
24+
})
25+
26+
stream.on('delete', (id: number) => {
27+
console.log(id)
28+
})
29+
30+
stream.on('error', (err: Error) => {
31+
console.error(err)
32+
})
33+
34+
stream.on('status_update', (status: Entity.Status) => {
35+
console.log('updated: ', status.url)
36+
})
37+
38+
stream.on('heartbeat', () => {
39+
console.log('thump.')
40+
})
41+
42+
stream.on('close', () => {
43+
console.log('close')
44+
})
45+
46+
stream.on('parser-error', (err: Error) => {
47+
console.error(err)
48+
})
49+
})

megalodon/src/pixelfed.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,44 +3069,26 @@ export default class Pixelfed implements MegalodonInterface {
30693069
}
30703070

30713071
public async userStreaming(): Promise<WebSocketInterface> {
3072-
return new Promise((_, reject) => {
3073-
const err = new NotImplementedError('Pixelfed does not support this method')
3074-
reject(err)
3075-
})
3072+
return this.client.socket()
30763073
}
30773074

30783075
public async publicStreaming(): Promise<WebSocketInterface> {
3079-
return new Promise((_, reject) => {
3080-
const err = new NotImplementedError('Pixelfed does not support this method')
3081-
reject(err)
3082-
})
3076+
return this.client.socket()
30833077
}
30843078

30853079
public async localStreaming(): Promise<WebSocketInterface> {
3086-
return new Promise((_, reject) => {
3087-
const err = new NotImplementedError('Pixelfed does not support this method')
3088-
reject(err)
3089-
})
3080+
return this.client.socket()
30903081
}
30913082

30923083
public async tagStreaming(_tag: string): Promise<WebSocketInterface> {
3093-
return new Promise((_, reject) => {
3094-
const err = new NotImplementedError('Pixelfed does not support this method')
3095-
reject(err)
3096-
})
3084+
return this.client.socket()
30973085
}
30983086

30993087
public async listStreaming(_list_id: string): Promise<WebSocketInterface> {
3100-
return new Promise((_, reject) => {
3101-
const err = new NotImplementedError('Pixelfed does not support this method')
3102-
reject(err)
3103-
})
3088+
return this.client.socket()
31043089
}
31053090

31063091
public async directStreaming(): Promise<WebSocketInterface> {
3107-
return new Promise((_, reject) => {
3108-
const err = new NotImplementedError('Pixelfed does not support this method')
3109-
reject(err)
3110-
})
3092+
return this.client.socket()
31113093
}
31123094
}

megalodon/src/pixelfed/api_client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PixelfedEntity from './entity'
88
import MegalodonEntity from '../entity'
99
import NotificationType, { UnknownNotificationTypeError } from '../notification'
1010
import PixelfedNotificationType from './notification'
11+
import Streaming from './web_socket'
1112

1213
namespace PixelfedAPI {
1314
/**
@@ -23,6 +24,7 @@ namespace PixelfedAPI {
2324
postForm<T = any>(path: string, params?: any, headers?: { [key: string]: string }): Promise<Response<T>>
2425
del<T = any>(path: string, params?: any, headers?: { [key: string]: string }): Promise<Response<T>>
2526
cancel(): void
27+
socket(): Streaming
2628
}
2729

2830
/**
@@ -359,6 +361,10 @@ namespace PixelfedAPI {
359361
public cancel(): void {
360362
return this.abortController.abort()
361363
}
364+
365+
public socket(): Streaming {
366+
return new Streaming()
367+
}
362368
}
363369

364370
export namespace Entity {

0 commit comments

Comments
 (0)