feat(jazz): add password support for room joining

This commit is contained in:
zarazaex69
2026-04-14 01:16:59 +03:00
parent ff09ee2bfd
commit 902f6bc610
2 changed files with 14 additions and 5 deletions

View File

@@ -131,7 +131,7 @@ func createRoom(ctx context.Context) (*RoomInfo, error) {
}, nil
}
func joinRoom(ctx context.Context, roomID string) (*RoomInfo, error) {
func joinRoom(ctx context.Context, roomID, password string) (*RoomInfo, error) {
clientID := uuid.New().String()
headers := map[string]string{
"X-Jazz-ClientId": clientID,
@@ -141,7 +141,7 @@ func joinRoom(ctx context.Context, roomID string) (*RoomInfo, error) {
}
preconnectPayload := map[string]any{
"password": "",
"password": password,
"jazzNextMigration": map[string]any{
"b2bBaseRoomSupport": true,
"demoRoomBaseSupport": true,
@@ -193,7 +193,7 @@ func joinRoom(ctx context.Context, roomID string) (*RoomInfo, error) {
return &RoomInfo{
RoomID: roomID,
Password: "",
Password: password,
ConnectorURL: preconnectResp.ConnectorURL,
}, nil
}

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"strings"
"sync"
"sync/atomic"
"time"
@@ -49,9 +50,17 @@ func NewPeer(ctx context.Context, roomID, name string, onData func([]byte)) (*Pe
if err != nil {
return nil, fmt.Errorf("create room: %w", err)
}
log.Printf("Jazz room created: %s (password: %s)", roomInfo.RoomID, roomInfo.Password)
log.Printf("Jazz room created: %s:%s", roomInfo.RoomID, roomInfo.Password)
log.Printf("To connect client use: -id \"%s:%s\"", roomInfo.RoomID, roomInfo.Password)
} else {
roomInfo, err = joinRoom(ctx, roomID)
var password string
parts := strings.Split(roomID, ":")
if len(parts) == 2 {
roomID = parts[0]
password = parts[1]
}
roomInfo, err = joinRoom(ctx, roomID, password)
if err != nil {
return nil, fmt.Errorf("join room: %w", err)
}