Skip to content

Commit

Permalink
7TV Emotes 1.4.22
Browse files Browse the repository at this point in the history
* Fixed: Animated avatars should now properly replace their corresponding static counterparts (Thanks to SirStendec for an additional helper method in FFZ)
* Fixed: Connect to 7TV socket when not logged in to also get live emote updates, animated avatars and other cosmetics
  • Loading branch information
Lordmau5 committed Mar 29, 2024
1 parent 7047269 commit c228fac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/7tv-emotes/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main",
"clips"
],
"version": "1.4.21",
"version": "1.4.22",
"short_name": "7TV",
"name": "7TV Emotes",
"author": "Melonify",
Expand All @@ -14,5 +14,5 @@
"website": "https://7tv.app",
"settings": "add_ons.7tv_emotes",
"created": "2021-07-12T23:18:04.000Z",
"updated": "2024-01-24T20:01:03.706Z"
"updated": "2024-03-29T22:03:31.676Z"
}
26 changes: 2 additions & 24 deletions src/7tv-emotes/modules/avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,8 @@ export default class Avatars extends FrankerFaceZ.utilities.module.Module {
const avatarComponent = this.fine.getOwner(avatar);
if (!avatarComponent) return;

// Find the nearest parent that has information about the user login
const parent = this.fine.searchParent(avatarComponent, e => e.props?.user?.login
|| e.props?.targetLogin
|| e.props?.userLogin
|| e.props?.channelLogin
|| e.props?.video?.owner?.login
|| e.props?.content?.channelLogin,
50);

// props.user.login is for our own avatar in the top right
// props.targetLogin is for viewer cards
// props.userLogin appears to be for channels in the sidebar
// props.channelLogin is for the main channel you're watching
// props.content.channelLogin is for theatre / fullscreen mode
// The 'alt' attribute is a fallback
const pprops = parent?.props;

const login = pprops?.user?.login
|| pprops?.targetLogin
|| pprops?.userLogin
|| pprops?.channelLogin
|| pprops?.video?.owner?.login
|| pprops?.content?.channelLogin
|| avatar.getAttribute('alt');
const node = this.fine.searchParentNode(avatarComponent, e => e.memoizedProps?.userLogin);
const login = node?.memoizedProps?.userLogin;

// No login? No avatar.
if (!login) return;
Expand Down
39 changes: 21 additions & 18 deletions src/7tv-emotes/modules/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {

async get7TVUserData() {
const user = this.site.getUser();
if (!user) return;

const resp = await this.stv_api.user.fetchUserData(user.id);

this._user_id = resp?.user?.id || false;
if (user) {
const resp = await this.stv_api.user.fetchUserData(user.id);

this._user_id = resp?.user?.id || false;
}

this.connect();
}
Expand Down Expand Up @@ -338,22 +338,22 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
}
}

connect() {
if (!this.site.getUser()) {
return;
}

connect(is_planned_reconnect = false) {
if (this._connected || this._connecting) {
return;
}
this._connecting = true;

this.log.info('Socket: Connecting to socket server...');
if (!is_planned_reconnect) {
this.log.info('Socket: Connecting to socket server...');
}

this.socket = new WebSocket('wss://events.7tv.io/v3');

this.socket.onopen = () => {
this.log.info('Socket: Connected to socket server.');
if (!is_planned_reconnect) {
this.log.info('Socket: Connected to socket server.');
}

this._connected = true;
this._connecting = false;
Expand All @@ -371,16 +371,17 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
return;
}

this.log.info('Socket: Lost connection to socket server...', evt);
const is_planned_reconnect = evt.code === 4012;
if (!is_planned_reconnect) {
this.log.info('Socket: Lost connection to socket server...', evt);

if (evt.code !== 4012) {
this._connect_attempts++;
}

this._subscriptions = {};
this._rooms = {};

this.reconnect();
this.reconnect(is_planned_reconnect);
};

this.socket.onmessage = message => {
Expand All @@ -396,10 +397,12 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
};
}

reconnect() {
reconnect(is_planned_reconnect = false) {
this.disconnect();

this.log.info('Socket: Trying to reconnect to socket server...');
if (!is_planned_reconnect) {
this.log.info('Socket: Trying to reconnect to socket server...');
}

// Optimally this should always end up being 0 on a normal disconnect (End of Stream event)
// meaning we'll pretty much immediately reconnect
Expand All @@ -410,7 +413,7 @@ export default class Socket extends FrankerFaceZ.utilities.module.Module {
this._connect_attempts++;

setTimeout(() => {
this.connect();
this.connect(is_planned_reconnect);
}, delay);
}

Expand Down

0 comments on commit c228fac

Please sign in to comment.