mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-30 17:09:43 +00:00
feat(jazz): add password support for room joining
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user