Skip to content

Commit 87440aa

Browse files
committed
feat(pubsub): emit game connect, disconnect, and error messages
1 parent 053f93d commit 87440aa

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

electron/renderer/context/game.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,17 @@ export const GameProvider: React.FC<GameProviderProps> = (
112112
characterName,
113113
gameCode,
114114
});
115+
pubsub.publish('game:connect', {
116+
accountName,
117+
characterName,
118+
gameCode,
119+
});
115120
}
116121
);
117122
return () => {
118123
unsubscribe();
119124
};
120-
}, [logger]);
125+
}, [logger, pubsub]);
121126

122127
useEffect(() => {
123128
const unsubscribe = window.api.onMessage(
@@ -129,6 +134,11 @@ export const GameProvider: React.FC<GameProviderProps> = (
129134
characterName,
130135
gameCode,
131136
});
137+
pubsub.publish('game:disconnect', {
138+
accountName,
139+
characterName,
140+
gameCode,
141+
});
132142
// In the event that the user quits the game via a command,
133143
// or the game client closes unexpectedly, we need to explicitly
134144
// run the quit character hook logic to update UI state.
@@ -140,14 +150,15 @@ export const GameProvider: React.FC<GameProviderProps> = (
140150
return () => {
141151
unsubscribe();
142152
};
143-
}, [logger, quitCharacter]);
153+
}, [logger, pubsub, quitCharacter]);
144154

145155
useEffect(() => {
146156
const unsubscribe = window.api.onMessage(
147157
'game:error',
148158
(_event: IpcRendererEvent, message: GameErrorMessage) => {
149159
const { error } = message;
150160
logger.error('game:error', { error });
161+
pubsub.publish('game:error', error);
151162
pubsub.publish('toast:add', {
152163
title: 'Game Error',
153164
type: 'danger',

0 commit comments

Comments
 (0)