Skip to content

Commit

Permalink
GH-85: Fix TS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SetZero committed Feb 4, 2024
1 parent b63f73e commit 519cc39
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
36 changes: 20 additions & 16 deletions src/components/AddNewServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ function AddNewServer({ serverInfo, identityCerts, onSave, onConnect }: Readonly
<Box mt={2}>
<Autocomplete
value={identity}
onChange={(event, newValue: IdentitySelectionType) => {
onChange={(event, newValue: string | IdentitySelectionType | null) => {
if (typeof newValue === 'string') {
setIdentity({
name: newValue,
});
} else if (newValue && newValue.inputValue) {
} else if (newValue?.inputValue) {
// Create a new value from the user input
setIdentity({
name: newValue.inputValue,
Expand All @@ -69,26 +69,30 @@ function AddNewServer({ serverInfo, identityCerts, onSave, onConnect }: Readonly
}
}}
filterOptions={(options, params) => {
const filtered = filter(options, params);

const { inputValue } = params;
// Suggest the creation of a new value
const isExisting = options.some((option) => inputValue === option);
if (inputValue !== '' && !isExisting) {
filtered.push({
inputValue,
name: `Add "${inputValue}"`,
});
if (typeof options !== 'string') {
const filtered = filter(options as IdentitySelectionType[], params);

const { inputValue } = params;
// Suggest the creation of a new value
const isExisting = options.some((option) => typeof option !== 'string' && inputValue === option?.name);
if (inputValue !== '' && !isExisting) {
filtered.push({
inputValue,
name: `Add "${inputValue}"`,
});
}

return filtered;
} else {
return [];
}

return filtered;
}}
selectOnFocus
clearOnBlur
handleHomeEndKeys
id="free-solo-with-text-demo"
options={identityCertsObj}
getOptionLabel={(option: IdentitySelectionType) => {
getOptionLabel={(option: string | IdentitySelectionType) => {
// Value selected with enter, right from the input
if (typeof option === 'string') {
return option;
Expand All @@ -100,7 +104,7 @@ function AddNewServer({ serverInfo, identityCerts, onSave, onConnect }: Readonly
// Regular option
return option.name;
}}
renderOption={(props, option) => <li {...props}>{option.name}</li>}
renderOption={(props, option) => <li {...props}>{typeof option === 'string' ? option : option.name}</li>}
freeSolo
renderInput={(params) => (
<TextField {...params} label={t("Client Certitcate")} />
Expand Down
3 changes: 2 additions & 1 deletion src/helper/ChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class ChatMessageHandler {
channel_id: [0],
tree_id: [0],
message: data,
timestamp: Date.now()
timestamp: Date.now(),
id: ""
})
this.setChatMessage("");
}
Expand Down
3 changes: 2 additions & 1 deletion src/helper/webrtc/WebRTC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class WebRTCViewer {
private configuration: { iceServers: { urls: string; }[]; };
private stream: MediaStream | null = null;
private onStreamListeners: ((stream: MediaStream) => void)[] = [];
private peerConnection: RTCPeerConnection | null = null;

constructor(signalingServerUrl: string, userId: number, roomId: number) {
this.configuration = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' }] };
Expand Down Expand Up @@ -148,7 +149,7 @@ export class WebRTCViewer {

onStreamEnd(callback: () => void) {
if (this.peerConnection) {
this.peerConnection.onremovestream = callback;
this.peerConnection.ontrack = null;
this.peerConnection.oniceconnectionstatechange = () => {
if (this.peerConnection?.iceConnectionState === 'disconnected') {
callback();
Expand Down

0 comments on commit 519cc39

Please sign in to comment.