Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit86dec70

Browse files
expose joinUser method from chat controller comp
1 parent0d5a7ab commit86dec70

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

‎client/packages/lowcoder/src/comps/comps/chatBoxComponent/chatControllerComp.tsx‎

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ const handleStopTyping = (
142142
}
143143
};
144144

145+
consthandleJoinUser=async(
146+
comp:ConstructorToComp<typeofChatControllerComp>,
147+
userId:string,
148+
userName:string,
149+
)=>{
150+
try{
151+
// Update the component's internal state with public user credentials
152+
comp.children.userId.getView().onChange(userId);
153+
comp.children.userName.getView().onChange(userName);
154+
155+
console.log('[ChatController] 👤 Public user joined as:',{ userId, userName});
156+
157+
// The chat manager will automatically reconnect with new credentials
158+
// due to the useEffect that watches for userId/userName changes
159+
returntrue;
160+
}catch(error){
161+
console.error('[ChatBox] 💥 Error joining as public user:',error);
162+
returnfalse;
163+
}
164+
};
165+
145166
constchildrenMap={
146167
...chatCompChildrenMap,
147168
visible:withDefault(BooleanStateControl,"false"),
@@ -176,13 +197,16 @@ const ChatBoxView = React.memo((
176197
// Initialize chat manager
177198
constmodeValue=props.modeas'local'|'collaborative'|'hybrid';
178199

200+
// Only initialize chat manager if userId and userName are provided
201+
constshouldInitialize=!!(props.userId.value&&props.userName.value);
202+
179203
constchatManager=useChatManager({
180204
userId:props.userId.value,
181205
userName:props.userName.value,
182206
applicationId:props.applicationId.value,
183207
roomId:props.roomId.value,
184208
mode:modeValue,// Use mode from props
185-
autoConnect:true,
209+
autoConnect:shouldInitialize,// Only auto-connect if credentials are provided
186210
});
187211

188212
useEffect(()=>{
@@ -220,6 +244,21 @@ const ChatBoxView = React.memo((
220244
}
221245
},[chatManager.isConnected,props.userId.value,loadRooms]);
222246

247+
// Handle reconnection when userId or userName changes
248+
useEffect(()=>{
249+
if(props.userId.value&&props.userName.value){
250+
if(chatManager.isConnected){
251+
// Disconnect and let the chat manager reconnect with new credentials
252+
chatManager.disconnect().then(()=>{
253+
console.log('[ChatController] 🔄 Reconnecting with new user credentials');
254+
});
255+
}else{
256+
// If not connected and we have credentials, trigger connection
257+
console.log('[ChatController] 🔌 Connecting with user credentials');
258+
}
259+
}
260+
},[props.userId.value,props.userName.value]);
261+
223262
// Refresh joined rooms periodically
224263
useEffect(()=>{
225264
if(!chatManager.isConnected)return;
@@ -471,6 +510,25 @@ ChatControllerComp = withMethodExposing(ChatControllerComp, [
471510
handleSendMessage(comp,values?.[0]);
472511
},
473512
},
513+
{
514+
method:{
515+
name:"joinUser",
516+
description:"Allow users to join the chat server with their own credentials",
517+
params:[
518+
{
519+
name:"userId",
520+
type:"string",
521+
},
522+
{
523+
name:"userName",
524+
type:"string",
525+
},
526+
],
527+
},
528+
execute:async(comp:ConstructorToComp<typeofChatControllerComp>,values:any)=>{
529+
returnawaithandleJoinUser(comp,values?.[0],values?.[1]);
530+
},
531+
},
474532
]);
475533

476534
ChatControllerComp=withExposingConfigs(ChatControllerComp,[
@@ -480,6 +538,9 @@ ChatControllerComp = withExposingConfigs(ChatControllerComp, [
480538
newNameConfig("participants",trans("chatBox.participants")),
481539
newNameConfig("currentRoom",trans("chatBox.currentRoom")),
482540
newNameConfig("typingUsers",trans("chatBox.typingUsers")),
541+
newNameConfig("allowRoomCreation",trans("chatBox.allowRoomCreation")),
542+
newNameConfig("allowRoomJoining",trans("chatBox.allowRoomJoining")),
543+
newNameConfig("roomPermissionMode",trans("chatBox.roomPermissionMode")),
483544
newNameConfig("userId",trans("chatBox.userId")),
484545
newNameConfig("userName",trans("chatBox.userName")),
485546
]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp