Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 0c77ed7

Browse files
Fix auto added protocol (#73)
1 parent 013efdb commit 0c77ed7

File tree

6 files changed

+28
-24
lines changed

6 files changed

+28
-24
lines changed

src/components/CreateRoom.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const roomCounterAtom = atomWithStorage<number>("last-room-id", 0);
3030
const isRoomEnforceEncoding = (value: string): value is EnforceEncoding => value === "h264" || value === "vp8";
3131

3232
export const CreateRoom: FC<Props> = ({ refetchIfNeeded, host }) => {
33-
const { roomApi } = useServerSdk();
33+
const { roomApi, currentURISchema } = useServerSdk();
3434
const [videoCodec, setEnforceEncodingInput] = useAtom(videoCodecAtomFamily(host));
3535
const [maxPeers, setMaxPeers] = useAtom(maxPeersAtom(host));
3636

@@ -51,9 +51,10 @@ export const CreateRoom: FC<Props> = ({ refetchIfNeeded, host }) => {
5151
const path = useAtomValue(pathAtom);
5252
const serverToken = useAtomValue(serverTokenAtom);
5353

54-
const addServer = (host: string) => {
54+
const addServer = (httpProtocol: string, host: string) => {
5555
setJellyfishServers((current) => {
56-
const id = `${current.isHttps ? "https" : "http"}://${host}${path}`;
56+
const id = `${httpProtocol}://${host}${path}`;
57+
5758
return {
5859
...current,
5960
[id]: {
@@ -183,8 +184,11 @@ export const CreateRoom: FC<Props> = ({ refetchIfNeeded, host }) => {
183184
})
184185
.then((response) => {
185186
if (host !== response.data.data.jellyfish_address) {
186-
showToastInfo(`Room created on ${response.data.data.jellyfish_address}`);
187-
addServer(response.data.data.jellyfish_address);
187+
const protocol = currentURISchema ?? "http";
188+
189+
showToastInfo(`Room created on ${protocol}://${response.data.data.jellyfish_address}`);
190+
191+
addServer(protocol, response.data.data.jellyfish_address);
188192
}
189193
refetchIfNeeded();
190194
setRoomOrder((prev) => {

src/components/HLSPlayback.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const autoPlayHlsAtom = atomWithStorage("hls-auto-play", true);
99
const showHlsPreviewAtom = atomWithStorage("show-hls-preveiew", true);
1010

1111
export default function HlsPlayback({ roomId, isPlayable }: { roomId: string; isPlayable: boolean }) {
12-
const { signalingHost, currentHttpProtocol } = useServerSdk();
12+
const { signalingHost, currentURISchema } = useServerSdk();
1313
const [autoPlay, setAutoPlay] = useAtom(autoPlayHlsAtom);
1414
const [showHlsPreview, setShowHlsPreview] = useAtom(showHlsPreviewAtom);
1515
const hls = useRef<Hls | null>(null);
1616

17-
const hlsLink = `${currentHttpProtocol}://${signalingHost}/hls/${roomId}/index.m3u8`;
17+
const hlsLink = `${currentURISchema}://${signalingHost}/hls/${roomId}/index.m3u8`;
1818

1919
const loadUrl = useCallback(
2020
(media: HTMLVideoElement | null) => {

src/components/ServerSdkContext.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { showToastError } from "./Toasts";
66

77
export type ServerSdkType = {
88
signalingHost: string | null;
9-
signalingProtocol: string | null;
9+
signalingURISchema: string | null;
1010
signalingPath: string | null;
11-
currentHttpProtocol: string | null;
11+
currentURISchema: string | null;
1212
roomApi: RoomApi | null;
1313
hlsApi: HlsApi | null;
1414
httpApiUrl: string | null;
@@ -21,8 +21,8 @@ const ServerSdkContext = React.createContext<ServerSdkType | undefined>(undefine
2121
type Props = {
2222
children: React.ReactNode;
2323
signalingHost: string;
24-
signalingProtocol: "wss" | "ws";
25-
currentHttpProtocol: "https" | "http";
24+
signalingURISchema: "wss" | "ws";
25+
currentURISchema: "https" | "http";
2626
signalingPath: string;
2727
serverToken: string;
2828
};
@@ -41,11 +41,11 @@ export const ServerSDKProvider = ({
4141
children,
4242
signalingHost,
4343
signalingPath,
44-
signalingProtocol,
44+
signalingURISchema,
4545
serverToken,
46-
currentHttpProtocol,
46+
currentURISchema,
4747
}: Props) => {
48-
const httpApiUrl = `${currentHttpProtocol}://${signalingHost}`;
48+
const httpApiUrl = `${currentURISchema}://${signalingHost}`;
4949

5050
const client = useMemo(
5151
() =>
@@ -56,7 +56,7 @@ export const ServerSDKProvider = ({
5656
}),
5757
[serverToken],
5858
);
59-
const httpServerUrl = signalingProtocol + "://" + signalingHost + signalingPath.replace("peer", "server");
59+
const httpServerUrl = signalingURISchema + "://" + signalingHost + signalingPath.replace("peer", "server");
6060

6161
const [serverWebsocket, setServerWebsocket] = useState<WebSocket | null>(null);
6262

@@ -94,10 +94,10 @@ export const ServerSDKProvider = ({
9494
hlsApi,
9595
serverWebsocket,
9696
serverToken,
97-
signalingProtocol,
97+
signalingURISchema,
9898
signalingHost,
9999
signalingPath,
100-
currentHttpProtocol,
100+
currentURISchema,
101101
}}
102102
>
103103
{children}

src/containers/Client.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const Client = ({
9999

100100
const api = client.useSelector((snapshot) => snapshot.connectivity.api);
101101
const jellyfishClient = client.useSelector((snapshot) => snapshot.connectivity.client);
102-
const { signalingHost, signalingPath, signalingProtocol, hlsApi } = useServerSdk();
102+
const { signalingHost, signalingPath, signalingURISchema, hlsApi } = useServerSdk();
103103
const [showClientState, setShowClientState] = useLocalStorageState(`show-client-state-json-${peerId}`);
104104
const [attachClientMetadata, setAttachClientMetadata] = useLocalStorageState(`attach-client-metadata-${peerId}`);
105105
const [showMetadataEditor, setShowMetadataEditor] = useLocalStorageState(`show-metadata-editor-${peerId}`);
@@ -329,10 +329,10 @@ export const Client = ({
329329
return;
330330
}
331331
const singling: SignalingUrl | undefined =
332-
signalingHost && signalingProtocol && signalingPath
332+
signalingHost && signalingURISchema && signalingPath
333333
? {
334334
host: signalingHost,
335-
protocol: signalingProtocol,
335+
protocol: signalingURISchema,
336336
path: signalingPath,
337337
}
338338
: undefined;

src/containers/JellyfishInstance.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const JellyfishInstance = ({
4040
const { state, dispatch } = useStore();
4141
const [refetchRequested] = useAtom(refetchAtom);
4242

43-
const { roomApi, signalingPath, signalingProtocol, serverToken } = useServerSdk();
43+
const { roomApi, signalingPath, signalingURISchema, serverToken } = useServerSdk();
4444

4545
const { refetchRoomsIfNeeded, refetchRooms, allRooms } = useApi();
4646

@@ -111,7 +111,7 @@ export const JellyfishInstance = ({
111111
{showEvents ? "Hide" : "Show"} server events
112112
</button>
113113
<Link
114-
to={`./servers/${host}/internals?${urlParams(signalingProtocol, signalingPath, serverToken)}`}
114+
to={`./servers/${host}/internals?${urlParams(signalingURISchema, signalingPath, serverToken)}`}
115115
className="btn btn-sm mx-1 my-0"
116116
target="_blank"
117117
>

src/containers/JellyfishServer.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const JellyfishServer = ({ host, isWss, path, serverToken, refetchDemand,
1919
<ServerSDKProvider
2020
signalingHost={host}
2121
signalingPath={path}
22-
signalingProtocol={isWss ? "wss" : "ws"}
23-
currentHttpProtocol={isHttps ? "https" : "http"}
22+
signalingURISchema={isWss ? "wss" : "ws"}
23+
currentURISchema={isHttps ? "https" : "http"}
2424
serverToken={serverToken}
2525
>
2626
<RoomsContextProvider>

0 commit comments

Comments
 (0)