Skip to content

Commit 4c0c3a0

Browse files
committed
feat: subscribe to game service stream
1 parent 8645747 commit 4c0c3a0

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

electron/main/ipc/ipc.controller.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,36 @@ export class IpcController {
173173

174174
const credentials = await sgeService.loginCharacter(characterName);
175175

176-
const gameInstance = Game.newInstance({
176+
const gameInstance = await Game.newInstance({
177177
credentials,
178-
dispatch: this.dispatch,
179178
});
180179

181-
await gameInstance.connect();
180+
const gameStream = await gameInstance.connect();
181+
182+
this.dispatch('game:connect', {
183+
accountName,
184+
characterName,
185+
gameCode,
186+
});
187+
188+
gameStream.subscribe({
189+
next: (gameEvent) => {
190+
const channel = `game:event:${gameEvent.eventType}`.toLowerCase();
191+
this.dispatch(channel, gameEvent);
192+
},
193+
error: (error) => {
194+
logger.error('game service stream error', { error });
195+
this.dispatch('game:error', error);
196+
},
197+
complete: () => {
198+
logger.info('game service stream completed');
199+
this.dispatch('game:disconnect', {
200+
accountName,
201+
characterName,
202+
gameCode,
203+
});
204+
},
205+
});
182206
};
183207

184208
private sendCommandHandler: IpcInvokeHandler<'sendCommand'> = async (

0 commit comments

Comments
 (0)