This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description fishjam-dev/ts-client-sdk#53
- Loading branch information
1 parent
02d89a8
commit a69cdc1
Showing
14 changed files
with
630 additions
and
439 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
import type { PeerStatus } from "@fishjam-dev/react-client"; | ||
|
||
type Props = { | ||
status: PeerStatus; | ||
}; | ||
|
||
const getBadgeColor = (status: PeerStatus) => { | ||
switch (status) { | ||
case "joined": | ||
return "badge-success"; | ||
case "error": | ||
return "badge-error"; | ||
case "authenticated": | ||
case "connected": | ||
return "badge-info"; | ||
case "connecting": | ||
return "badge-warning"; | ||
} | ||
name: string; | ||
status: string | null; | ||
className: string; | ||
}; | ||
|
||
export const Badge = ({ status }: Props) => ( | ||
export const Badge = ({ name, status, className }: Props) => ( | ||
<div className="flex items-center gap-1"> | ||
<span>Status:</span> | ||
<span className={`badge ${getBadgeColor(status)}`}>{status}</span> | ||
<span>{name}</span> | ||
<span className={`badge ${className}`}>{status}</span> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
examples/use-camera-and-microphone-example/src/utils/BadgeUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { PeerStatus } from "@fishjam-dev/react-client"; | ||
import type { ReconnectionStatus } from "@fishjam-dev/ts-client"; | ||
|
||
export const getPeerStatusBadgeColor = (status: PeerStatus): string => { | ||
switch (status) { | ||
case "joined": | ||
return "badge-success"; | ||
case "error": | ||
return "badge-error"; | ||
case "authenticated": | ||
case "connected": | ||
return "badge-info"; | ||
case "connecting": | ||
return "badge-warning"; | ||
} | ||
return ""; | ||
}; | ||
|
||
export const getReconnectionStatusBadgeColor = (status: ReconnectionStatus) => { | ||
switch (status) { | ||
case "idle": | ||
return "badge-info"; | ||
case "error": | ||
return "badge-error"; | ||
case "reconnecting": | ||
return "badge-warning"; | ||
} | ||
}; |
85 changes: 85 additions & 0 deletions
85
examples/use-camera-and-microphone-example/src/utils/useReconnectLogs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { ClientEvents } from "@fishjam-dev/react-client"; | ||
import type { PeerMetadata, TrackMetadata } from "../fishjamSetup"; | ||
import { useClient } from "../fishjamSetup"; | ||
import { useEffect } from "react"; | ||
|
||
/* eslint-disable no-console */ | ||
export const useReconnectLogs = () => { | ||
const client = useClient(); | ||
|
||
useEffect(() => { | ||
if (!client) return; | ||
|
||
const onReconnectionStarted: ClientEvents<PeerMetadata, TrackMetadata>["reconnectionStarted"] = () => { | ||
console.log("%c" + "reconnectionStarted", "color:green"); | ||
}; | ||
|
||
const onReconnected: ClientEvents<PeerMetadata, TrackMetadata>["reconnected"] = () => { | ||
console.log("%cReconnected", "color:green"); | ||
}; | ||
|
||
const onReconnectionRetriesLimitReached: ClientEvents< | ||
PeerMetadata, | ||
TrackMetadata | ||
>["reconnectionRetriesLimitReached"] = () => { | ||
console.log("%cReconnectionRetriesLimitReached", "color:red"); | ||
}; | ||
|
||
const onSocketError: ClientEvents<PeerMetadata, TrackMetadata>["socketError"] = (error: Event) => { | ||
console.warn(error); | ||
}; | ||
|
||
const onConnectionError: ClientEvents<PeerMetadata, TrackMetadata>["connectionError"] = (error, client) => { | ||
if (client.isReconnecting()) { | ||
console.log("%c" + "During reconnection: connectionError %o", "color:gray", { | ||
error, | ||
// @ts-expect-error | ||
iceConnectionState: error?.event?.target?.["iceConnectionState"], | ||
}); | ||
} else { | ||
// @ts-expect-error | ||
console.warn({ error, state: error?.event?.target?.["iceConnectionState"] }); | ||
} | ||
}; | ||
|
||
const onJoinError: ClientEvents<PeerMetadata, TrackMetadata>["joinError"] = (event) => { | ||
console.log(event); | ||
}; | ||
|
||
const onAuthError: ClientEvents<PeerMetadata, TrackMetadata>["authError"] = (reason) => { | ||
if (client.isReconnecting()) { | ||
console.log("%c" + "During reconnection: authError: " + reason, "color:gray"); | ||
} | ||
}; | ||
|
||
const onSocketClose: ClientEvents<PeerMetadata, TrackMetadata>["socketClose"] = (event) => { | ||
if (client.isReconnecting()) { | ||
console.log("%c" + "During reconnection: Signaling socket closed", "color:gray"); | ||
} else { | ||
console.warn(event); | ||
} | ||
}; | ||
|
||
client.on("reconnectionStarted", onReconnectionStarted); | ||
client.on("reconnected", onReconnected); | ||
client.on("reconnectionRetriesLimitReached", onReconnectionRetriesLimitReached); | ||
|
||
client.on("socketError", onSocketError); | ||
client.on("connectionError", onConnectionError); | ||
client.on("joinError", onJoinError); | ||
client.on("authError", onAuthError); | ||
client.on("socketClose", onSocketClose); | ||
|
||
return () => { | ||
client.off("reconnectionStarted", onReconnectionStarted); | ||
client.off("reconnected", onReconnected); | ||
client.off("reconnectionRetriesLimitReached", onReconnectionRetriesLimitReached); | ||
|
||
client.off("socketError", onSocketError); | ||
client.off("connectionError", onConnectionError); | ||
client.off("joinError", onJoinError); | ||
client.off("authError", onAuthError); | ||
client.off("socketClose", onSocketClose); | ||
}; | ||
}, [client]); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.