Fix streaming access token

This commit is contained in:
Alex Gleason 2021-03-24 17:53:09 -05:00
parent 94da1f6722
commit 74f48229fc
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 8 additions and 2 deletions

View file

@ -40,6 +40,7 @@ import Icon from 'soapbox/components/icon';
import { isStaff } from 'soapbox/utils/accounts'; import { isStaff } from 'soapbox/utils/accounts';
import ChatPanes from 'soapbox/features/chats/components/chat_panes'; import ChatPanes from 'soapbox/features/chats/components/chat_panes';
import ProfileHoverCard from 'soapbox/components/profile_hover_card'; import ProfileHoverCard from 'soapbox/components/profile_hover_card';
import { getAccessToken } from 'soapbox/utils/auth';
import { import {
Status, Status,
@ -111,7 +112,7 @@ const mapStateToProps = state => {
hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0, hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0,
hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0, hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0,
dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null, dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null,
accessToken: state.getIn(['auth', 'user', 'access_token']), accessToken: getAccessToken(state),
streamingUrl: state.getIn(['instance', 'urls', 'streaming_api']), streamingUrl: state.getIn(['instance', 'urls', 'streaming_api']),
me, me,
account, account,

View file

@ -1,13 +1,14 @@
'use strict'; 'use strict';
import WebSocketClient from 'websocket.js'; import WebSocketClient from 'websocket.js';
import { getAccessToken } from 'soapbox/utils/auth';
const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max)); const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max));
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() {}, onDisconnect() {}, onReceive() {} })) { export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() {}, onDisconnect() {}, onReceive() {} })) {
return (dispatch, getState) => { return (dispatch, getState) => {
const streamingAPIBaseURL = getState().getIn(['instance', 'urls', 'streaming_api']); const streamingAPIBaseURL = getState().getIn(['instance', 'urls', 'streaming_api']);
const accessToken = getState().getIn(['auth', 'user', 'access_token']); const accessToken = getAccessToken(getState());
const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState); const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState);
let polling = null; let polling = null;

View file

@ -0,0 +1,4 @@
export const getAccessToken = state => {
const me = state.getIn(['auth', 'me']);
return state.getIn(['auth', 'users', me, 'access_token']);
};