Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer streaming URL from instance information #2164

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions example/typescript/src/firefish/web_socket.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import generator, { Entity, WebSocketInterface } from 'megalodon'
import generator, { Entity } from 'megalodon'
import log4js from 'log4js'

const BASE_URL: string = process.env.FIREFISH_STREAMING_URL!
const BASE_URL: string = process.env.FIREFISH_URL!
const access_token: string = process.env.FIREFISH_ACCESS_TOKEN!

const client = generator('firefish', BASE_URL, access_token)

const stream: WebSocketInterface = client.userSocket()
client.localStreaming().then(stream => {
const logger = log4js.getLogger()
logger.level = 'debug'
stream.on('connect', () => {
logger.debug('connect')
})

const logger = log4js.getLogger()
logger.level = 'debug'
stream.on('connect', () => {
logger.debug('connect')
})
stream.on('pong', () => {
logger.debug('pong')
})

stream.on('pong', () => {
logger.debug('pong')
})
stream.on('update', (status: Entity.Status) => {
logger.debug(status)
})

stream.on('update', (status: Entity.Status) => {
logger.debug(status)
})
stream.on('notification', (notification: Entity.Notification) => {
logger.debug(notification)
})

stream.on('notification', (notification: Entity.Notification) => {
logger.debug(notification)
})
stream.on('error', (err: Error) => {
console.error(err)
})

stream.on('error', (err: Error) => {
console.error(err)
})

stream.on('close', () => {
logger.debug('close')
})
stream.on('close', () => {
logger.debug('close')
})

stream.on('parser-error', (err: Error) => {
console.error(err)
stream.on('parser-error', (err: Error) => {
console.error(err)
})
})
65 changes: 33 additions & 32 deletions example/typescript/src/mastodon/streaming.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
import generator, { Entity, WebSocketInterface } from 'megalodon'
import generator, { Entity } from 'megalodon'

const BASE_URL: string = process.env.MASTODON_STREAMING_URL!
const BASE_URL: string = process.env.MASTODON_URL!

const access_token: string = process.env.MASTODON_ACCESS_TOKEN!

const client = generator('mastodon', BASE_URL, access_token)

const stream: WebSocketInterface = client.localSocket()
stream.on('connect', () => {
console.log('connect')
})
client.localStreaming().then(stream => {
stream.on('connect', () => {
console.log('connect')
})

stream.on('pong', () => {
console.log('pong')
})
stream.on('pong', () => {
console.log('pong')
})

stream.on('update', (status: Entity.Status) => {
console.log(status)
})
stream.on('update', (status: Entity.Status) => {
console.log(status)
})

stream.on('notification', (notification: Entity.Notification) => {
console.log(notification)
})
stream.on('notification', (notification: Entity.Notification) => {
console.log(notification)
})

stream.on('delete', (id: number) => {
console.log(id)
})
stream.on('delete', (id: number) => {
console.log(id)
})

stream.on('error', (err: Error) => {
console.error(err)
})
stream.on('error', (err: Error) => {
console.error(err)
})

stream.on('status_update', (status: Entity.Status) => {
console.log('updated: ', status.url)
})
stream.on('status_update', (status: Entity.Status) => {
console.log('updated: ', status.url)
})

stream.on('heartbeat', () => {
console.log('thump.')
})
stream.on('heartbeat', () => {
console.log('thump.')
})

stream.on('close', () => {
console.log('close')
})
stream.on('close', () => {
console.log('close')
})

stream.on('parser-error', (err: Error) => {
console.error(err)
stream.on('parser-error', (err: Error) => {
console.error(err)
})
})
67 changes: 34 additions & 33 deletions example/typescript/src/mastodon/unauthorized_streaming.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
import generator, { Entity, WebSocketInterface } from 'megalodon'
import generator, { Entity } from 'megalodon'

declare var process: {
env: {
MASTODON_STREAMING_URL: string
MASTODON_URL: string
}
}

const url: string = process.env.MASTODON_STREAMING_URL
const url: string = process.env.MASTODON_URL

const client = generator('mastodon', url)

const stream: WebSocketInterface = client.localSocket()
stream.on('connect', () => {
console.log('connect')
})
client.localStreaming().then(stream => {
stream.on('connect', () => {
console.log('connect')
})

stream.on('pong', () => {
console.log('pong')
})
stream.on('pong', () => {
console.log('pong')
})

stream.on('update', (status: Entity.Status) => {
console.log(status)
})
stream.on('update', (status: Entity.Status) => {
console.log(status)
})

stream.on('notification', (notification: Entity.Notification) => {
console.log(notification)
})
stream.on('notification', (notification: Entity.Notification) => {
console.log(notification)
})

stream.on('delete', (id: number) => {
console.log(id)
})
stream.on('delete', (id: number) => {
console.log(id)
})

stream.on('error', (err: Error) => {
console.error(err)
})
stream.on('error', (err: Error) => {
console.error(err)
})

stream.on('status_update', (status: Entity.Status) => {
console.log('updated: ', status.url)
})
stream.on('status_update', (status: Entity.Status) => {
console.log('updated: ', status.url)
})

stream.on('heartbeat', () => {
console.log('thump.')
})
stream.on('heartbeat', () => {
console.log('thump.')
})

stream.on('close', () => {
console.log('close')
})
stream.on('close', () => {
console.log('close')
})

stream.on('parser-error', (err: Error) => {
console.error(err)
stream.on('parser-error', (err: Error) => {
console.error(err)
})
})
70 changes: 35 additions & 35 deletions example/typescript/src/pleroma/web_socket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import generator, { Entity, WebSocketInterface } from 'megalodon'
import generator, { Entity } from 'megalodon'
import log4js from 'log4js'

declare var process: {
Expand All @@ -7,52 +7,52 @@ declare var process: {
}
}

const BASE_URL: string = 'wss://pleroma.io'
const BASE_URL: string = 'https://pleroma.io'

const access_token: string = process.env.PLEROMA_ACCESS_TOKEN

const client = generator('pleroma', BASE_URL, access_token)

const stream: WebSocketInterface = client.userSocket()
client.userStreaming().then(stream => {
const logger = log4js.getLogger()
logger.level = 'debug'
stream.on('connect', () => {
logger.debug('connect')
})

const logger = log4js.getLogger()
logger.level = 'debug'
stream.on('connect', () => {
logger.debug('connect')
})
stream.on('pong', () => {
logger.debug('pong')
})

stream.on('pong', () => {
logger.debug('pong')
})
stream.on('update', (status: Entity.Status) => {
logger.debug(status.url)
})

stream.on('update', (status: Entity.Status) => {
logger.debug(status.url)
})

stream.on('notification', (notification: Entity.Notification) => {
logger.debug(notification)
})
stream.on('notification', (notification: Entity.Notification) => {
logger.debug(notification)
})

stream.on('delete', (id: number) => {
logger.debug(id)
})
stream.on('delete', (id: number) => {
logger.debug(id)
})

stream.on('error', (err: Error) => {
console.error(err)
})
stream.on('error', (err: Error) => {
console.error(err)
})

stream.on('heartbeat', () => {
logger.debug('thump.')
})
stream.on('heartbeat', () => {
logger.debug('thump.')
})

stream.on('status_update', (status: Entity.Status) => {
logger.debug('updated: ', status.url)
})
stream.on('status_update', (status: Entity.Status) => {
logger.debug('updated: ', status.url)
})

stream.on('close', () => {
logger.debug('close')
})
stream.on('close', () => {
logger.debug('close')
})

stream.on('parser-error', (err: Error) => {
logger.error(err)
stream.on('parser-error', (err: Error) => {
logger.error(err)
})
})
Loading