sam-coder-cli 1.0.31 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/multiplayer-client.js +36 -2
- package/package.json +1 -1
|
@@ -775,7 +775,7 @@ class MultiplayerClient extends EventEmitter {
|
|
|
775
775
|
});
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
-
async joinSession(sessionId) {
|
|
778
|
+
async joinSession(sessionId, createIfNotExists = true) {
|
|
779
779
|
if (!sessionId) {
|
|
780
780
|
throw new Error('Session ID is required');
|
|
781
781
|
}
|
|
@@ -791,9 +791,10 @@ class MultiplayerClient extends EventEmitter {
|
|
|
791
791
|
|
|
792
792
|
const timeout = setTimeout(() => {
|
|
793
793
|
this.off('session_joined', onSessionJoined);
|
|
794
|
+
this.off('session_created', onSessionCreated);
|
|
794
795
|
this.off('error', onError);
|
|
795
796
|
reject(new Error('Session join timed out'));
|
|
796
|
-
},
|
|
797
|
+
}, 15000); // Increased timeout to 15 seconds
|
|
797
798
|
|
|
798
799
|
const onSessionJoined = (data) => {
|
|
799
800
|
if (data.sessionId === sessionId) {
|
|
@@ -802,21 +803,54 @@ class MultiplayerClient extends EventEmitter {
|
|
|
802
803
|
this.isHost = data.isHost || false;
|
|
803
804
|
this.emit('session_joined', data);
|
|
804
805
|
this.off('session_joined', onSessionJoined);
|
|
806
|
+
this.off('session_created', onSessionCreated);
|
|
805
807
|
this.off('error', onError);
|
|
808
|
+
console.log(`✅ Successfully joined session ${sessionId}`);
|
|
806
809
|
resolve(data);
|
|
807
810
|
}
|
|
808
811
|
};
|
|
809
812
|
|
|
813
|
+
const onSessionCreated = (data) => {
|
|
814
|
+
if (data.sessionId === sessionId) {
|
|
815
|
+
clearTimeout(timeout);
|
|
816
|
+
this.sessionId = sessionId;
|
|
817
|
+
this.isHost = true;
|
|
818
|
+
this.emit('session_joined', { ...data, isHost: true });
|
|
819
|
+
this.off('session_joined', onSessionJoined);
|
|
820
|
+
this.off('session_created', onSessionCreated);
|
|
821
|
+
this.off('error', onError);
|
|
822
|
+
console.log(`✅ Created and joined new session ${sessionId}`);
|
|
823
|
+
resolve({ ...data, isHost: true });
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
|
|
810
827
|
const onError = (error) => {
|
|
828
|
+
if (error.message === 'Session not found' && createIfNotExists) {
|
|
829
|
+
// If session doesn't exist and we're allowed to create it
|
|
830
|
+
this.off('session_joined', onSessionJoined);
|
|
831
|
+
this.off('error', onError);
|
|
832
|
+
console.log(`Session ${sessionId} not found, creating new session...`);
|
|
833
|
+
this.createSession(sessionId)
|
|
834
|
+
.then(() => {
|
|
835
|
+
this.once('session_created', onSessionCreated);
|
|
836
|
+
this.once('error', onError);
|
|
837
|
+
})
|
|
838
|
+
.catch(reject);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
|
|
811
842
|
clearTimeout(timeout);
|
|
812
843
|
this.off('session_joined', onSessionJoined);
|
|
844
|
+
this.off('session_created', onSessionCreated);
|
|
813
845
|
this.off('error', onError);
|
|
846
|
+
console.error('Error joining session:', error.message);
|
|
814
847
|
reject(error);
|
|
815
848
|
};
|
|
816
849
|
|
|
817
850
|
this.on('session_joined', onSessionJoined);
|
|
818
851
|
this.on('error', onError);
|
|
819
852
|
|
|
853
|
+
console.log(`Attempting to join session ${sessionId}...`);
|
|
820
854
|
this.send({
|
|
821
855
|
type: 'join_session',
|
|
822
856
|
sessionId: sessionId,
|