Related Games: Valorant
Issue Description: When I try to add an event listener for overwolf.games.events.onInfoUpdates2
in an in-game window, the event isn’t firing when the info is updated. Other events like overwolf.games.onGameInfoUpdated
work in my in-game window. When I add a listener for overwolf.games.events.onInfoUpdates2
in my background window, it works fine.
Steps to reproduce:
My App is using React and TypeScript
Code
BackgroundWindow.tsx.tsx
import { useOverwolfEvent } from 'hooks';
const BackgroundWindow = () => {
useOverwolfEvent(overwolf.games.events.onInfoUpdates2, (event) => {
console.log(JSON.stringify(event, null, 2));
});
return <></>;
}
IngameWindow.tsx.tsx
import { useOverwolfEvent } from 'hooks';
const IngameWindow = () => {
useOverwolfEvent(overwolf.games.events.onInfoUpdates2, (event) => {
console.log(JSON.stringify(event, null, 2));
});
return <div>Ingame Stats Window</div>;
}
hooks/useOverwolfEvent.ts
export function useOverwolfEvent<T>(
event: overwolf.Event<T>,
callback?: (result: T) => void
): T | null {
const [data, setData] = useState<T | null>(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
callback = useCallback(callback || (() => {}), []);
useEffect(() => {
function overwolfEventHandler(event: T) {
console.log('event fired');
setData(event);
if (callback !== undefined) {
callback(event);
}
}
console.log("added listener")
event.addListener(overwolfEventHandler);
return () => {
event.removeListener(overwolfEventHandler);
};
}, [event, callback]);
return data;
}
Logs
background.html.log
2022-06-25 19:40:22,729 (INFO) ================== new session ==================
2022-06-25 19:40:22,730 (INFO) </Files/static/js/main.187faea5.js> (:2) - Current window: background
2022-06-25 19:40:22,732 (INFO) </Files/static/js/103.2d8fbf7f.chunk.js> (:1) - added listener
[...]
2022-06-25 19:40:50,015 (INFO) </Files/static/js/103.2d8fbf7f.chunk.js> (:1) - event fired
2022-06-25 19:40:50,015 (INFO) </Files/static/js/103.2d8fbf7f.chunk.js> (:1) - {
"info": {
"game_info": {
"scene": "Range"
}
},
"feature": "game_info"
}
[...]
ingame.html.log
2022-06-25 19:40:22,837 (INFO) ================== new session ==================
2022-06-25 19:40:22,837 (INFO) </Files/static/js/main.187faea5.js> (:2) - Current window: pregame-stats
2022-06-25 19:40:22,838 (INFO) </Files/static/js/728.6be8e360.chunk.js> (:1) - added listener
[End of Logs]
I think the error is in my useOverwolfEvent()
Hook, but I don’t know what it is. Is it essential, that the listener functions have different names? I am naming all listeners overwolfEventHanlder
.
I checked in the Overwolf Task Manager if both windows were open and if the correct code is running.
EDIT
If I remove the listener in the background window, the listener in the in-game window still doesn’t work.