From 1a51ca2051b272fa015f80e8602d13f09cf40f52 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 27 Jan 2024 16:53:02 +0100 Subject: [PATCH] GH-85: Fix TS errors --- src/components/AddNewServer.tsx | 36 ++++++++++++++++++--------------- src/helper/ChatMessage.ts | 3 ++- src/helper/webrtc/WebRTC.ts | 3 ++- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/components/AddNewServer.tsx b/src/components/AddNewServer.tsx index 7070231..5f23348 100644 --- a/src/components/AddNewServer.tsx +++ b/src/components/AddNewServer.tsx @@ -54,12 +54,12 @@ function AddNewServer({ serverInfo, identityCerts, onSave, onConnect }: Readonly { + 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, @@ -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; @@ -100,7 +104,7 @@ function AddNewServer({ serverInfo, identityCerts, onSave, onConnect }: Readonly // Regular option return option.name; }} - renderOption={(props, option) =>
  • {option.name}
  • } + renderOption={(props, option) =>
  • {typeof option === 'string' ? option : option.name}
  • } freeSolo renderInput={(params) => ( diff --git a/src/helper/ChatMessage.ts b/src/helper/ChatMessage.ts index aa509bb..65bcea5 100644 --- a/src/helper/ChatMessage.ts +++ b/src/helper/ChatMessage.ts @@ -30,7 +30,8 @@ export class ChatMessageHandler { channel_id: [0], tree_id: [0], message: data, - timestamp: Date.now() + timestamp: Date.now(), + id: "" }) this.setChatMessage(""); } diff --git a/src/helper/webrtc/WebRTC.ts b/src/helper/webrtc/WebRTC.ts index 05f748f..fc744c9 100644 --- a/src/helper/webrtc/WebRTC.ts +++ b/src/helper/webrtc/WebRTC.ts @@ -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' }] }; @@ -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();