Add oauth token to websocket connection

This commit is contained in:
2023-10-15 19:39:36 +02:00
parent d3b599738e
commit aab4433a55
3 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import {
HASHTAG_FILTER,
MASTODON_ACCESS_TOKEN,
MASTODON_INSTANCE,
ODESLI_API_KEY,
YOUTUBE_API_KEY
@ -352,10 +353,11 @@ export class TimelineReader {
}
private startWebsocket() {
const socket = new WebSocket(`wss://${MASTODON_INSTANCE}/api/v1/streaming`);
const socket = new WebSocket(
`wss://${MASTODON_INSTANCE}/api/v1/streaming?type=subscribe&stream=public:local&access_token=${MASTODON_ACCESS_TOKEN}`
);
socket.onopen = () => {
log.log('Connected to WS');
socket.send('{ "type": "subscribe", "stream": "public:local"}');
};
socket.onmessage = async (event) => {
try {
@ -392,7 +394,8 @@ export class TimelineReader {
};
socket.onclose = (event) => {
log.warn(
`Websocket connection to ${MASTODON_INSTANCE} closed. Code: ${event.code}, reason: '${event.reason}'`
`Websocket connection to ${MASTODON_INSTANCE} closed. Code: ${event.code}, reason: '${event.reason}'`,
event
);
setTimeout(() => {
log.info(`Attempting to reconenct to WS`);