Skip to content

Commit

Permalink
fixes anon chat and host button
Browse files Browse the repository at this point in the history
  • Loading branch information
night committed Sep 1, 2018
1 parent 2b84093 commit 957539f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "BetterTTV",
"author": "Night",
"version": "7.2.38",
"version": "7.2.39",
"description": "BetterTTV enhances Twitch with new features, emotes, and more.",
"main": "betterttv.js",
"scripts": {
Expand Down
36 changes: 32 additions & 4 deletions src/utils/twitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CHAT_CONTAINER = 'section[data-test-selector="chat-room-component-layout"]
const VOD_CHAT_CONTAINER = '.qa-vod-chat';
const CHAT_LIST = '.chat-list';
const PLAYER = '.player';
const CLIPS_BROADCASTER_INFO = '.clips-broadcaster-info';

const TMIActionTypes = {
MESSAGE: 0,
Expand Down Expand Up @@ -75,6 +76,26 @@ function searchReactParents(node, predicate, maxDepth = 15, depth = 0) {
return null;
}

function searchReactChildren(node, predicate, maxDepth = 15, depth = 0) {
try {
if (predicate(node)) {
return node;
}
} catch (_) {}

if (!node || depth > maxDepth) {
return null;
}

const {child, sibling} = node;
if (child || sibling) {
return searchReactChildren(child, predicate, maxDepth, depth + 1) || searchReactChildren(sibling, predicate, maxDepth, depth + 1);
}

return null;
}

let chatClient;
let currentUser;
let currentChannel;

Expand Down Expand Up @@ -174,7 +195,7 @@ module.exports = {
let router;
try {
const node = searchReactParents(
getReactInstance($('.clips-broadcaster-info')[0]),
getReactInstance($(CLIPS_BROADCASTER_INFO)[0]),
n => n.stateNode && n.stateNode.props && n.stateNode.props.data && n.stateNode.props.data.clip
);
router = node.stateNode.props.data.clip.broadcaster;
Expand Down Expand Up @@ -224,11 +245,18 @@ module.exports = {
},

getChatServiceClient() {
let client;
if (chatClient) return chatClient;

try {
client = this.getChatController().chatService.client;
const node = searchReactChildren(
getReactInstance($(REACT_ROOT)[0]),
n => n.stateNode && n.stateNode.join && n.stateNode.part && n.stateNode.client,
1000
);
chatClient = node.stateNode.client;
} catch (_) {}
return client;

return chatClient;
},

getChatServiceSocket() {
Expand Down
3 changes: 0 additions & 3 deletions src/watchers/chat-message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const PATCHED_SYMBOL = Symbol();
let twitchHandleMessage;

function bttvHandleMessage(message) {
console.log(message);
if (message && typeof message.type === 'number') {
let isPrevented = false;
watcher.emit('chat.message.handler', {
Expand All @@ -25,8 +24,6 @@ function patchChatController() {
const chatController = twitch.getChatController();
if (!chatController) return;

console.log(chatController);

const messageHandlerAPI = chatController.props.messageHandlerAPI;
if (!messageHandlerAPI) return;

Expand Down

0 comments on commit 957539f

Please sign in to comment.