diff --git a/src/ts/process/index.ts b/src/ts/process/index.ts index af1c5c0d..2879545f 100644 --- a/src/ts/process/index.ts +++ b/src/ts/process/index.ts @@ -21,6 +21,7 @@ import { additionalInformations } from "./embedding/addinfo"; import { cipherChat, decipherChat } from "./cipherChat"; import { getInlayImage, supportsInlayImage } from "../image"; import { getGenerationModelString } from "./models/modelString"; +import { sendPeerChar } from "../sync/multiuser"; export interface OpenAIChat{ role: 'system'|'user'|'assistant'|'function' @@ -976,6 +977,8 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n } } + sendPeerChar() + if(req.special){ if(req.special.emotion){ let charemotions = get(CharEmotion) diff --git a/src/ts/sync/multiuser.ts b/src/ts/sync/multiuser.ts index 4c502549..8634fc2f 100644 --- a/src/ts/sync/multiuser.ts +++ b/src/ts/sync/multiuser.ts @@ -14,6 +14,7 @@ async function importPeerJS(){ let conn:DataConnection let peer:Peer let connections:DataConnection[] = [] +let connectionOpen = false export async function createMultiuserRoom(){ //create a room with webrtc @@ -69,7 +70,7 @@ export async function createMultiuserRoom(){ await sleep(100) } - + connectionOpen = true alertNormal("Room ID: " + roomId) return } @@ -98,9 +99,10 @@ export async function joinMultiuserRoom(){ alertWait("Waiting for peerserver to connect...") let open = false + conn = peer.connect(roomId); + conn.on('open', function() { alertWait("Waiting for host to accept connection") - conn = peer.connect(roomId); open = true conn.send({ type: 'request-char' @@ -142,6 +144,7 @@ export async function joinMultiuserRoom(){ return } } + connectionOpen = true alertNormal("Connected") }); @@ -149,6 +152,9 @@ export async function joinMultiuserRoom(){ export function sendPeerChar(){ + if(!connectionOpen){ + return + } if(!conn){ // host user for(const connection of connections){