@@ -18,6 +18,7 @@ import { CreateGameReducer } from '../core/reducer';
1818import { InitializeGame } from '../core/initialize' ;
1919import { PlayerView } from '../plugins/main' ;
2020import type { Transport , TransportOpts } from './transport/transport' ;
21+ import { DummyTransport } from './transport/dummy' ;
2122import { ClientManager } from './manager' ;
2223import type {
2324 ActivePlayersArg ,
@@ -308,31 +309,17 @@ export class _ClientImpl<G extends any = any> {
308309
309310 this . store = createStore ( this . reducer , this . initialState , enhancer ) ;
310311
311- this . transport = ( {
312- isConnected : true ,
313- onAction : ( ) => { } ,
314- subscribe : ( ) => { } ,
315- subscribeMatchData : ( ) => { } ,
316- subscribeChatMessage : ( ) => { } ,
317- connect : ( ) => { } ,
318- disconnect : ( ) => { } ,
319- updateMatchID : ( ) => { } ,
320- updatePlayerID : ( ) => { } ,
321- } as unknown ) as Transport ;
322-
323- if ( multiplayer ) {
324- // typeof multiplayer is 'function'
325- this . transport = multiplayer ( {
326- gameKey : game ,
327- game : this . game ,
328- store : this . store ,
329- matchID,
330- playerID,
331- credentials,
332- gameName : this . game . name ,
333- numPlayers,
334- } ) ;
335- }
312+ if ( ! multiplayer ) multiplayer = DummyTransport ;
313+ this . transport = multiplayer ( {
314+ gameKey : game ,
315+ game : this . game ,
316+ store : this . store ,
317+ matchID,
318+ playerID,
319+ credentials,
320+ gameName : this . game . name ,
321+ numPlayers,
322+ } ) ;
336323
337324 this . createDispatchers ( ) ;
338325
@@ -341,20 +328,18 @@ export class _ClientImpl<G extends any = any> {
341328 this . notifySubscribers ( ) ;
342329 } ) ;
343330
344- if ( this . transport . onChatMessage ) {
345- this . chatMessages = [ ] ;
346- this . sendChatMessage = ( payload ) => {
347- this . transport . onChatMessage ( this . matchID , {
348- id : nanoid ( 7 ) ,
349- sender : this . playerID ,
350- payload : payload ,
351- } ) ;
352- } ;
353- this . transport . subscribeChatMessage ( ( message ) => {
354- this . chatMessages = [ ...this . chatMessages , message ] ;
355- this . notifySubscribers ( ) ;
331+ this . chatMessages = [ ] ;
332+ this . sendChatMessage = ( payload ) => {
333+ this . transport . onChatMessage ( this . matchID , {
334+ id : nanoid ( 7 ) ,
335+ sender : this . playerID ,
336+ payload : payload ,
356337 } ) ;
357- }
338+ } ;
339+ this . transport . subscribeChatMessage ( ( message ) => {
340+ this . chatMessages = [ ...this . chatMessages , message ] ;
341+ this . notifySubscribers ( ) ;
342+ } ) ;
358343 }
359344
360345 private notifySubscribers ( ) {
0 commit comments