From 03985cede23dc0abb0f6756b5970fb38209919e5 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 9 May 2023 19:26:38 +0200 Subject: [PATCH 01/37] fix: dont start with audio muted --- frontend/src/components/jitsi/JitsiEntrypoint.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/jitsi/JitsiEntrypoint.tsx b/frontend/src/components/jitsi/JitsiEntrypoint.tsx index 9975e78..54a46e5 100644 --- a/frontend/src/components/jitsi/JitsiEntrypoint.tsx +++ b/frontend/src/components/jitsi/JitsiEntrypoint.tsx @@ -27,7 +27,7 @@ function JitsiEntrypoint({ roomName, userInfo, conferenceData, setConferenceData domain={JITSI_DOMAIN} roomName={roomName} configOverwrite={{ - startWithAudioMuted: true, + startWithAudioMuted: false, disableModeratorIndicator: true, startScreenSharing: true, enableEmailInStats: false, From 1e318817a4860f0e40914d26e58b1f315cb6ce54 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Mon, 19 Jun 2023 17:53:40 +0200 Subject: [PATCH 02/37] Switch to TVar --- backend/src/BroadcastUserData.hs | 4 ++-- backend/src/State/ConnectedClientsState.hs | 6 ++---- backend/src/Types/ConnectionState.hs | 4 ++-- backend/src/Types/RoomsState.hs | 8 ++++---- backend/src/WebServer.hs | 18 ++++++++++++++++++ backend/stack.yaml | 2 +- backend/stack.yaml.lock | 8 ++++---- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/backend/src/BroadcastUserData.hs b/backend/src/BroadcastUserData.hs index bc00f48..a53f81b 100644 --- a/backend/src/BroadcastUserData.hs +++ b/backend/src/BroadcastUserData.hs @@ -41,8 +41,8 @@ broadCastToClientsGeneric :: Text -> m () broadCastToClientsGeneric message = do - state <- getConnctedClients - liftIO $ broadcast message state + connectedClients <- getConnctedClients + liftIO (broadcast message connectedClients) broadcast :: Text -> ConnectedClients -> IO () broadcast message clients = do diff --git a/backend/src/State/ConnectedClientsState.hs b/backend/src/State/ConnectedClientsState.hs index e2ff726..550e953 100644 --- a/backend/src/State/ConnectedClientsState.hs +++ b/backend/src/State/ConnectedClientsState.hs @@ -72,9 +72,7 @@ modifyState :: m () modifyState modifyFunc = do state <- getConnectedClientState <$> ask - modifyMVar_ state $ \s -> - let s' = modifyFunc s - in return s' + atomically $ modifyTVar state modifyFunc class Monad m => MonadConnectedClientsRead m where getConnctedClients :: m ConnectedClients @@ -86,4 +84,4 @@ getConnctedClientsGeneric :: ) => m ConnectedClients getConnctedClientsGeneric = do - ask >>= readMVar . getConnectedClientState + ask >>= readTVarIO . getConnectedClientState diff --git a/backend/src/Types/ConnectionState.hs b/backend/src/Types/ConnectionState.hs index a787c9e..6f160a4 100644 --- a/backend/src/Types/ConnectionState.hs +++ b/backend/src/Types/ConnectionState.hs @@ -17,12 +17,12 @@ data Client = Client joinedRoom :: Bool } -type ConnectedClientsState = MVar ConnectedClients +type ConnectedClientsState = TVar ConnectedClients type ConnectedClients = [Client] initConnectionsState :: IO ConnectedClientsState -initConnectionsState = newMVar newConnectedClients +initConnectionsState = newTVarIO newConnectedClients newConnectedClients :: ConnectedClients newConnectedClients = [] diff --git a/backend/src/Types/RoomsState.hs b/backend/src/Types/RoomsState.hs index df5ae71..8448593 100644 --- a/backend/src/Types/RoomsState.hs +++ b/backend/src/Types/RoomsState.hs @@ -12,10 +12,10 @@ import ClassyPrelude import State.RoomDataState (MonadRoomDataStateRead (getRoomDataState)) import Types.RoomData (RoomsData) -type RoomsState = MVar RoomsData +type RoomsState = TVar RoomsData initRoomsState :: IO RoomsState -initRoomsState = newMVar [] +initRoomsState = newTVarIO [] class HasRoomsState a where getRoomsState :: a -> RoomsState @@ -29,7 +29,7 @@ updateRoomState :: m () updateRoomState newData = do state <- getRoomsState <$> ask - _ <- swapMVar state newData + _ <- atomically $ swapTVar state newData return () getRoomState :: @@ -40,7 +40,7 @@ getRoomState :: m RoomsData getRoomState = do state <- getRoomsState <$> ask - readMVar state + readTVarIO state roomStateDiffers :: ( MonadRoomDataStateRead m diff --git a/backend/src/WebServer.hs b/backend/src/WebServer.hs index c32a14d..1e256b9 100644 --- a/backend/src/WebServer.hs +++ b/backend/src/WebServer.hs @@ -121,6 +121,24 @@ notFound = do "404 - Not Found" throwError response +-- notFound :: +-- ( MonadIO m, +-- HasWebEnv env, +-- MonadReader env m, +-- MonadError ResponseReceived m +-- ) => +-- m ResponseReceived +-- notFound = do +-- respond' <- getRespond <$> ask +-- response <- +-- liftIO $ +-- respond' $ +-- responseLBS +-- status200 +-- [("Content-Type", "text/plain")] +-- "200 - Success" +-- response + runWebApp :: ( MonadIO m, MonadReader Env m diff --git a/backend/stack.yaml b/backend/stack.yaml index 99c2ab2..1c01a4b 100644 --- a/backend/stack.yaml +++ b/backend/stack.yaml @@ -16,7 +16,7 @@ # this way we can use prebuild binaries for hls #resolver: nightly-2022-11-12 #resolver: ghc-9.2.4 -resolver: lts-20.16 +resolver: lts-20.26 # # The location of a snapshot can be provided as a file or url. Stack assumes # a snapshot provided as a file might change, whereas a url resource does not. diff --git a/backend/stack.yaml.lock b/backend/stack.yaml.lock index 08fa9b8..ea5a850 100644 --- a/backend/stack.yaml.lock +++ b/backend/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - sha256: dad15e2ec0c09280a5c2e07190fb18710fc54472f029f34f861f686540824d81 - size: 649592 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/16.yaml - original: lts-20.16 + sha256: 5a59b2a405b3aba3c00188453be172b85893cab8ebc352b1ef58b0eae5d248a2 + size: 650475 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/26.yaml + original: lts-20.26 From 69aa82837c743de22ea188044a6b9f36892dd4be Mon Sep 17 00:00:00 2001 From: qvalentin Date: Mon, 19 Jun 2023 19:04:53 +0200 Subject: [PATCH 03/37] Add some logging --- backend/jitsi-rooms.cabal | 4 +++- backend/package.yaml | 1 + backend/src/RoomDataHandler.hs | 2 +- backend/src/WebServer.hs | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/jitsi-rooms.cabal b/backend/jitsi-rooms.cabal index 51a353c..416656e 100644 --- a/backend/jitsi-rooms.cabal +++ b/backend/jitsi-rooms.cabal @@ -1,6 +1,6 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.0. +-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack @@ -65,6 +65,7 @@ library , time , uuid , wai + , wai-extra , warp , websockets default-language: Haskell2010 @@ -91,6 +92,7 @@ executable jitsi-rooms-exe , time , uuid , wai + , wai-extra , warp , websockets default-language: Haskell2010 diff --git a/backend/package.yaml b/backend/package.yaml index 2e64954..dc41a92 100644 --- a/backend/package.yaml +++ b/backend/package.yaml @@ -33,6 +33,7 @@ dependencies: - lifted-base - mtl - time + - wai-extra ghc-options: - -Wall diff --git a/backend/src/RoomDataHandler.hs b/backend/src/RoomDataHandler.hs index e78fb1c..273846d 100644 --- a/backend/src/RoomDataHandler.hs +++ b/backend/src/RoomDataHandler.hs @@ -44,7 +44,7 @@ roomDataHandler :: m ResponseReceived roomDataHandler = do newRoomData <- parseBodyOrBadRequest - liftIO $ putStrLn "Got triggered form prosody" + liftIO $ putStrLn "Got triggered from prosody" whenM (roomStateDiffers newRoomData) $ do setRoomDataState newRoomData broadcastUserData diff --git a/backend/src/WebServer.hs b/backend/src/WebServer.hs index 1e256b9..8b572f9 100644 --- a/backend/src/WebServer.hs +++ b/backend/src/WebServer.hs @@ -15,6 +15,7 @@ import Control.Monad.Except import Network.HTTP.Types import Network.Wai import Network.Wai.Handler.Warp (run) +import Network.Wai.Middleware.RequestLogger (logStdoutDev) import RoomDataHandler (roomDataHandler) import State.ConnectedClientsState ( MonadConnectedClientsRead (..), @@ -165,5 +166,5 @@ runWebServer :: m () runWebServer = do putStrLn "http://localhost:8081/" - runWebApp >>= liftIO . run 8081 + runWebApp >>= liftIO . (run 8081 . logStdoutDev) return () From 2ea2aa4abb2d578e17184caef258e4600261f811 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Mon, 19 Jun 2023 19:09:20 +0200 Subject: [PATCH 04/37] Add some logging --- backend/converted.nix | 1 + backend/default.nix | 9 +++++++++ backend/src/Types/RoomsState.hs | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/converted.nix b/backend/converted.nix index 584d831..e7014db 100644 --- a/backend/converted.nix +++ b/backend/converted.nix @@ -10,6 +10,7 @@ , text , uuid , wai +, wai-extra , warp , websockets }: diff --git a/backend/default.nix b/backend/default.nix index 7a10366..d65d501 100644 --- a/backend/default.nix +++ b/backend/default.nix @@ -30,5 +30,14 @@ pkgs.dockerTools.buildImage { "9160/tcp" = { }; "8081/tcp" = { }; }; + Healthcheck = { + "Test" = [ + "CMD-SHELL" + "${pkgs.curl} -f http://0.0.0.0:8081" + ]; + "Interval" = 30000000000; + "Timeout" = 10000000000; + "Retries" = 3; + }; }; } diff --git a/backend/src/Types/RoomsState.hs b/backend/src/Types/RoomsState.hs index 8448593..145bbab 100644 --- a/backend/src/Types/RoomsState.hs +++ b/backend/src/Types/RoomsState.hs @@ -29,8 +29,9 @@ updateRoomState :: m () updateRoomState newData = do state <- getRoomsState <$> ask - _ <- atomically $ swapTVar state newData - return () + liftIO $ putStrLn "Upating room state" + atomically $ writeTVar state newData + liftIO $ putStrLn "Done Upating room state" getRoomState :: ( HasRoomsState env, From 6e43e10d1fe867be0d3694275c803cac7a6f148d Mon Sep 17 00:00:00 2001 From: qvalentin Date: Mon, 19 Jun 2023 19:45:49 +0200 Subject: [PATCH 05/37] Fix deps in converted.nix --- backend/converted.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/converted.nix b/backend/converted.nix index e7014db..f8b3710 100644 --- a/backend/converted.nix +++ b/backend/converted.nix @@ -31,6 +31,7 @@ mkDerivation { text uuid wai + wai-extra warp websockets ]; @@ -45,6 +46,7 @@ mkDerivation { text uuid wai + wai-extra warp websockets ]; From eedc21fb8ec5c53ba53582d3d06173451d515b5b Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 20 Jun 2023 17:54:50 +0200 Subject: [PATCH 06/37] Fix utf-8 --- .drone.yml | 1 + backend/app/Main.hs | 6 +- backend/default.nix | 12 +- backend/nix/sources.json | 14 +++ backend/nix/sources.nix | 194 ++++++++++++++++++++++++++++++ backend/nix/stack-integration.nix | 16 +++ 6 files changed, 233 insertions(+), 10 deletions(-) create mode 100644 backend/nix/sources.json create mode 100644 backend/nix/sources.nix create mode 100644 backend/nix/stack-integration.nix diff --git a/.drone.yml b/.drone.yml index f1b7944..172457a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -18,6 +18,7 @@ trigger: event: include: - tag + - push volumes: - name: drone-shared diff --git a/backend/app/Main.hs b/backend/app/Main.hs index 7dce4e5..146e9bd 100644 --- a/backend/app/Main.hs +++ b/backend/app/Main.hs @@ -1,7 +1,11 @@ module Main (main) where import ClassyPrelude +import GHC.IO.Encoding (setLocaleEncoding) +import GHC.IO.Encoding.UTF8 (utf8) import Lib (runBothServers) main :: IO () -main = runBothServers +main = do + setLocaleEncoding utf8 + runBothServers diff --git a/backend/default.nix b/backend/default.nix index d65d501..4a8ecbc 100644 --- a/backend/default.nix +++ b/backend/default.nix @@ -30,14 +30,8 @@ pkgs.dockerTools.buildImage { "9160/tcp" = { }; "8081/tcp" = { }; }; - Healthcheck = { - "Test" = [ - "CMD-SHELL" - "${pkgs.curl} -f http://0.0.0.0:8081" - ]; - "Interval" = 30000000000; - "Timeout" = 10000000000; - "Retries" = 3; - }; + Env = [ + "LANG=en_US.UTF-8" + ]; }; } diff --git a/backend/nix/sources.json b/backend/nix/sources.json new file mode 100644 index 0000000..6ce8996 --- /dev/null +++ b/backend/nix/sources.json @@ -0,0 +1,14 @@ +{ + "nixpkgs": { + "branch": "nixpkgs-unstable", + "description": "Nix Packages collection", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "abfd31179174133ab8131139d650297bf4da63b7", + "sha256": "1jmkz6l7sj876wzyn5niyfaxshbmw9fp3g8r41k1wbjvmm5xrnsn", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/abfd31179174133ab8131139d650297bf4da63b7.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/backend/nix/sources.nix b/backend/nix/sources.nix new file mode 100644 index 0000000..9a01c8a --- /dev/null +++ b/backend/nix/sources.nix @@ -0,0 +1,194 @@ +# This file has been generated by Niv. + +let + + # + # The fetchers. fetch_ fetches specs of type . + # + + fetch_file = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + + fetch_tarball = pkgs: name: spec: + let + name' = sanitizeName name + "-src"; + in + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + + fetch_git = name: spec: + let + ref = + if spec ? ref then spec.ref else + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + submodules = if spec ? submodules then spec.submodules else false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules == true + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + {} + else {}; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; + in + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); + + fetch_local = spec: spec.path; + + fetch_builtin-tarball = name: throw + ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=tarball -a builtin=true''; + + fetch_builtin-url = name: throw + ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. + $ niv modify ${name} -a type=file -a builtin=true''; + + # + # Various helpers + # + + # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 + sanitizeName = name: + ( + concatMapStrings (s: if builtins.isList s then "-" else s) + ( + builtins.split "[^[:alnum:]+._?=-]+" + ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) + ) + ); + + # The set of packages used when specs are fetched using non-builtins. + mkPkgs = sources: system: + let + sourcesNixpkgs = + import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; + hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; + hasThisAsNixpkgsPath = == ./.; + in + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import {} + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # The actual fetching function. + fetch = pkgs: name: spec: + + if ! builtins.hasAttr "type" spec then + abort "ERROR: niv spec ${name} does not have a 'type' attribute" + else if spec.type == "file" then fetch_file pkgs name spec + else if spec.type == "tarball" then fetch_tarball pkgs name spec + else if spec.type == "git" then fetch_git name spec + else if spec.type == "local" then fetch_local spec + else if spec.type == "builtin-tarball" then fetch_builtin-tarball name + else if spec.type == "builtin-url" then fetch_builtin-url name + else + abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; + + # If the environment variable NIV_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + replace = name: drv: + let + saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; + in + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + + # Ports of functions for older nix versions + + # a Nix version of mapAttrs if the built-in doesn't exist + mapAttrs = builtins.mapAttrs or ( + f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) + ); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatMapStrings = f: list: concatStrings (map f list); + concatStrings = builtins.concatStringsSep ""; + + # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 + optionalAttrs = cond: as: if cond then as else {}; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = { url, name ? null, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchurl attrs; + + # Create the final "sources" from the config + mkSources = config: + mapAttrs ( + name: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) config.sources; + + # The "config" used by the fetchers + mkConfig = + { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null + , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , system ? builtins.currentSystem + , pkgs ? mkPkgs sources system + }: rec { + # The sources, i.e. the attribute set of spec name to spec + inherit sources; + + # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers + inherit pkgs; + }; + +in +mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/backend/nix/stack-integration.nix b/backend/nix/stack-integration.nix new file mode 100644 index 0000000..68376c6 --- /dev/null +++ b/backend/nix/stack-integration.nix @@ -0,0 +1,16 @@ +let + sources = import ./sources.nix; + pkgs = import sources.nixpkgs { }; +in + +# See https://docs.haskellstack.org/en/stable/nix_integration/#using-a-custom-shellnix-file +{ ghc }: + +pkgs.haskell.lib.buildStackProject { + inherit ghc; + name = "haskell-stack-nix"; + # System dependencies needed at compilation time + buildInputs = [ + pkgs.zlib + ]; +} From f3e6699ca51dfe652d01d1b4a5c7f6997fef2318 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 4 Jul 2023 20:05:58 +0200 Subject: [PATCH 07/37] resizeable sidebar and meeting names on startpage --- frontend/src/App.tsx | 1 + frontend/src/components/meeting/Meeting.css | 4 +++ frontend/src/components/meeting/Meeting.tsx | 36 +++++++++++++++++++-- frontend/src/components/sidebar/Sidebar.css | 1 + 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/meeting/Meeting.css diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8fde18d..7206931 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -20,6 +20,7 @@ function App() { conferenceData={conferenceData} setConferenceData={setConferenceData} userInfo={userInfo} + usersData={roomData} /> ) diff --git a/frontend/src/components/meeting/Meeting.css b/frontend/src/components/meeting/Meeting.css new file mode 100644 index 0000000..9cbe859 --- /dev/null +++ b/frontend/src/components/meeting/Meeting.css @@ -0,0 +1,4 @@ +.meeting-quickjoin { + text-align: center + +} diff --git a/frontend/src/components/meeting/Meeting.tsx b/frontend/src/components/meeting/Meeting.tsx index ccc2b1f..dfd4b73 100644 --- a/frontend/src/components/meeting/Meeting.tsx +++ b/frontend/src/components/meeting/Meeting.tsx @@ -1,19 +1,26 @@ import { ConferenceData } from '../../background/jitsi/eventListeners' +import { UsersData } from '../../background/types/roomData' import useMeetingStarted from '../../hooks/useMeetingStarted' import { useRoomName } from '../../hooks/useRoomName' import JitsiEntrypoint from '../jitsi/JitsiEntrypoint' import { UserInfo } from '../jitsi/types' import MeetingNameInput from './MeetingNameInput' +import './Meeting.css' interface Props { conferenceData: ConferenceData | undefined setConferenceData: (newData: ConferenceData) => void userInfo: UserInfo + usersData: UsersData } -function Meeting({ conferenceData, setConferenceData, userInfo }: Props) { +function Meeting(props: Props) { + const { conferenceData, setConferenceData, userInfo, usersData } = props + console.log("[Rooms] meeting usersData", props) const [meetingStarted] = useMeetingStarted() const { roomName } = useRoomName() + const [_, setMeetingStarted] = useMeetingStarted() + const { updateAndSubmitRoomName: updateAndSubmitRoomName } = useRoomName() if (meetingStarted) { return ( @@ -26,7 +33,32 @@ function Meeting({ conferenceData, setConferenceData, userInfo }: Props) { ) } - return + return ( +
+ +
+ {usersData?.roomsData.map((roomData) => { + return ( + <> +

+ { + updateAndSubmitRoomName(roomData.roomName) + setMeetingStarted(true) + }} + > + {roomData.roomName} + +

+ {roomData.participants.map((participant) => ( +
{participant.displayName}
+ ))} + + ) + })} +
+
) } export default Meeting diff --git a/frontend/src/components/sidebar/Sidebar.css b/frontend/src/components/sidebar/Sidebar.css index 40a20cb..d74aba8 100644 --- a/frontend/src/components/sidebar/Sidebar.css +++ b/frontend/src/components/sidebar/Sidebar.css @@ -1,4 +1,5 @@ .sidebar { + resize: horizontal; display: flex; flex-direction: column; white-space: nowrap; From cc1808c9ec7c2331c189a19a828d77f953b4d1c2 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Wed, 5 Jul 2023 18:06:10 +0200 Subject: [PATCH 08/37] Use jotai for websocket --- frontend/src/hooks/useRoomName.ts | 2 +- frontend/src/hooks/useWebSocketConnection.ts | 23 +++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/frontend/src/hooks/useRoomName.ts b/frontend/src/hooks/useRoomName.ts index 459b201..6bbdfb0 100644 --- a/frontend/src/hooks/useRoomName.ts +++ b/frontend/src/hooks/useRoomName.ts @@ -1,5 +1,5 @@ import { atom, useAtom } from 'jotai' -import { useCallback, useState } from 'react' +import { useCallback } from 'react' const roomNameAtom = atom(getRoomNameFromUrl()) diff --git a/frontend/src/hooks/useWebSocketConnection.ts b/frontend/src/hooks/useWebSocketConnection.ts index 77aa0b1..5450cd6 100644 --- a/frontend/src/hooks/useWebSocketConnection.ts +++ b/frontend/src/hooks/useWebSocketConnection.ts @@ -1,19 +1,19 @@ -import { useCallback, useState } from 'react' +import { atom, useAtom } from 'jotai' +import { useCallback, useEffect } from 'react' import { WEBSOCKET_URL } from '../background/constants' import { UserInfo } from '../components/jitsi/types' -const createWebSocketConnection = (userInfo: UserInfo) => { - const webSocket = new WebSocket(WEBSOCKET_URL) - console.log('[Rooms] createWebSocketConnection') - webSocket.addEventListener('open', (_: Event) => webSocket.send(JSON.stringify(userInfo))) - return webSocket -} +const webSocket = new WebSocket(WEBSOCKET_URL) +const webSocketConnectionAtom = atom(webSocket) function useWebSocketConnection(userInfo: UserInfo) { console.log('[Rooms] useWebSocketConnection') - const [webSocketConnection] = useState(() => createWebSocketConnection(userInfo)) + const [webSocketConnection] = useAtom(webSocketConnectionAtom) + useEffect(() => { + sendMessageNowOrLater(webSocketConnection, JSON.stringify(userInfo)) + }, [webSocketConnection, userInfo]); const sendMessage = useCallback( (message: string) => { @@ -41,4 +41,11 @@ function useWebSocketConnection(userInfo: UserInfo) { return { onMessage, sendMessage, disconnect } } +const sendMessageNowOrLater = (webSocket: WebSocket, message: string) => { + if (webSocket.readyState !== WebSocket.OPEN) { + return webSocket.addEventListener('open', (_: Event) => webSocket.send(message)) + } + webSocket.send(message) +} + export default useWebSocketConnection From a5d769e9b59fe1fe77f15ba80886e6f040016ba0 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Thu, 6 Jul 2023 18:58:55 +0200 Subject: [PATCH 09/37] Fix url encoding for room names --- frontend/src/components/meeting/Meeting.tsx | 2 +- frontend/src/components/meeting/MeetingNameInput.tsx | 4 ++-- frontend/src/components/sidebar/Sidebar.tsx | 2 +- frontend/src/hooks/useRoomData.ts | 10 +++++++++- frontend/src/hooks/useRoomName.ts | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/meeting/Meeting.tsx b/frontend/src/components/meeting/Meeting.tsx index dfd4b73..d489575 100644 --- a/frontend/src/components/meeting/Meeting.tsx +++ b/frontend/src/components/meeting/Meeting.tsx @@ -48,7 +48,7 @@ function Meeting(props: Props) { setMeetingStarted(true) }} > - {roomData.roomName} + {decodeURI(roomData.roomName)} {roomData.participants.map((participant) => ( diff --git a/frontend/src/components/meeting/MeetingNameInput.tsx b/frontend/src/components/meeting/MeetingNameInput.tsx index 0da3d15..3c498be 100644 --- a/frontend/src/components/meeting/MeetingNameInput.tsx +++ b/frontend/src/components/meeting/MeetingNameInput.tsx @@ -8,7 +8,7 @@ function MeetingNameInput(props: { roomName: string; currentUser: string }) { const [_, setMeetingStarted] = useMeetingStarted() const onInput: React.ChangeEventHandler = (event) => { - updateRoomName(event.target.value) + updateRoomName(encodeURI(event.target.value)) event.preventDefault() } @@ -23,7 +23,7 @@ function MeetingNameInput(props: { roomName: string; currentUser: string }) {

Greetings {props.currentUser}

- +
diff --git a/frontend/src/components/sidebar/Sidebar.tsx b/frontend/src/components/sidebar/Sidebar.tsx index e67f381..3e69178 100644 --- a/frontend/src/components/sidebar/Sidebar.tsx +++ b/frontend/src/components/sidebar/Sidebar.tsx @@ -31,7 +31,7 @@ function Sidebar(props: Props) { setMeetingStarted(true) }} > - {roomData.roomName} + {decodeURI(roomData.roomName)} {roomData.participants.map((participant) => ( diff --git a/frontend/src/hooks/useRoomData.ts b/frontend/src/hooks/useRoomData.ts index f8a66f4..ccef5b3 100644 --- a/frontend/src/hooks/useRoomData.ts +++ b/frontend/src/hooks/useRoomData.ts @@ -2,7 +2,15 @@ import { useState } from 'react' import { UsersData } from '../background/types/roomData' function useRoomData() { - const [roomData, setRoomData] = useState() + const [roomData, setRoomDataInternal] = useState() + + const setRoomData = (usersData: UsersData) => { + usersData.roomsData = usersData.roomsData.map((roomData) => { + roomData.roomName = decodeURI(roomData.roomName) + return roomData + }) + setRoomDataInternal(usersData) + } return { roomData, setRoomData } } diff --git a/frontend/src/hooks/useRoomName.ts b/frontend/src/hooks/useRoomName.ts index 6bbdfb0..14e3c1f 100644 --- a/frontend/src/hooks/useRoomName.ts +++ b/frontend/src/hooks/useRoomName.ts @@ -46,7 +46,7 @@ function setRoomNameInUrl(roomName: string) { function setRoomNameInTitle(roomName: string) { if (!!roomName) { - document.title = roomName + document.title = decodeURI(roomName) } } From 77a00e68e9ad62d41a90c9e19818c72c7cb469fc Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 8 Jul 2023 12:32:42 +0200 Subject: [PATCH 10/37] fix url encoding in prosody module --- prodsody/Readme.md | 2 +- prodsody/docker-compose.yml | 2 +- prodsody/mod_jitsi_rooms.lua | 16 +++++++--------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/prodsody/Readme.md b/prodsody/Readme.md index 65ebf87..959a162 100644 --- a/prodsody/Readme.md +++ b/prodsody/Readme.md @@ -10,7 +10,7 @@ ### Get started - run `./run_dev.sh` -- open [https://localhost:8443/](https://localhost:8443/) +- open [https://localhost:8443/](https://localhost:8443/) (accept the risk about self-signed certs) - make changes to mod_jitsi_rooms.lua and save the file - prosody will be restarted - join a room in jitsi diff --git a/prodsody/docker-compose.yml b/prodsody/docker-compose.yml index 08feefc..0c4a04b 100644 --- a/prodsody/docker-compose.yml +++ b/prodsody/docker-compose.yml @@ -347,7 +347,7 @@ services: meet.jitsi: jitsi-rooms: - image: jitsi-rooms:67y5d9y2zbi7wkqm2jpcjj1k2614qwx2 + image: jitsi-rooms restart: ${RESTART_POLICY:-unless-stopped} ports: - '9160:9160' diff --git a/prodsody/mod_jitsi_rooms.lua b/prodsody/mod_jitsi_rooms.lua index dde9499..cfe138b 100644 --- a/prodsody/mod_jitsi_rooms.lua +++ b/prodsody/mod_jitsi_rooms.lua @@ -4,6 +4,7 @@ local json = require "util.json"; local array = require "util.array"; local iterators = require "util.iterators"; local jid = require "util.jid"; +local http = require "util.http"; local async_handler_wrapper = module:require "util".async_handler_wrapper; local get_room_from_jid = module:require "util".get_room_from_jid; @@ -12,9 +13,9 @@ local domain_name = "meet.jitsi" function get_participants_for_room(room_name) - local room_address = jid.join(room_name, muc_domain_prefix .. "." .. domain_name); - local room = get_room_from_jid(room_address); + local decoded_room_address = http.urldecode(room_address); + local room = get_room_from_jid(decoded_room_address); local occupants_json = array(); if room then local occupants = room._occupants; @@ -47,7 +48,6 @@ function get_participants_for_room(room_name) end function get_all_rooms_with_participants() - local sessions = prosody.full_sessions; local someTable = (it.join(it.keys(sessions))); @@ -74,7 +74,7 @@ end -- @return GET response, containing a json with participants details function handle_get_sessions(event) handle_room_event() - return { status_code = 200; body = get_all_rooms_with_participants() }; + return { status_code = 200, body = get_all_rooms_with_participants() }; end function module.load() @@ -86,9 +86,9 @@ function module.load() module:log("info", "Hello! You can reach me at: %s", module:http_url()); module:provides("http", { route = { - ["GET"] = function(event) return async_handler_wrapper(event, handle_get_sessions) end; + ["GET"] = function(event) return async_handler_wrapper(event, handle_get_sessions) end, - }; + }, }); end @@ -125,7 +125,6 @@ end --- Checks if event is triggered by healthchecks or focus user. function is_system_event(event) - if event == nil or event.room == nil or event.room.jid == nil then return true; end @@ -147,12 +146,11 @@ function handle_room_event(event) return; end - async_http_request("http://192.168.2.116:8081/roomdata", + async_http_request("http://jitsi-rooms:8081/roomdata", { method = "POST", body = get_all_rooms_with_participants() }) - end --Helper function to wait till a component is loaded before running the given callback From e21ca799d66481d40a4f3d4c11eed793c95a86c3 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sat, 8 Jul 2023 13:37:32 +0200 Subject: [PATCH 11/37] fix url encoding in prosody module --- prodsody/fix-permissions.sh | 0 .../prosody-plugins-custom/mod_jitsi_rooms.lua | 16 +++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) mode change 100644 => 100755 prodsody/fix-permissions.sh diff --git a/prodsody/fix-permissions.sh b/prodsody/fix-permissions.sh old mode 100644 new mode 100755 diff --git a/prodsody/jitsi-meet-cfg/prosody/prosody-plugins-custom/mod_jitsi_rooms.lua b/prodsody/jitsi-meet-cfg/prosody/prosody-plugins-custom/mod_jitsi_rooms.lua index dde9499..cfe138b 100644 --- a/prodsody/jitsi-meet-cfg/prosody/prosody-plugins-custom/mod_jitsi_rooms.lua +++ b/prodsody/jitsi-meet-cfg/prosody/prosody-plugins-custom/mod_jitsi_rooms.lua @@ -4,6 +4,7 @@ local json = require "util.json"; local array = require "util.array"; local iterators = require "util.iterators"; local jid = require "util.jid"; +local http = require "util.http"; local async_handler_wrapper = module:require "util".async_handler_wrapper; local get_room_from_jid = module:require "util".get_room_from_jid; @@ -12,9 +13,9 @@ local domain_name = "meet.jitsi" function get_participants_for_room(room_name) - local room_address = jid.join(room_name, muc_domain_prefix .. "." .. domain_name); - local room = get_room_from_jid(room_address); + local decoded_room_address = http.urldecode(room_address); + local room = get_room_from_jid(decoded_room_address); local occupants_json = array(); if room then local occupants = room._occupants; @@ -47,7 +48,6 @@ function get_participants_for_room(room_name) end function get_all_rooms_with_participants() - local sessions = prosody.full_sessions; local someTable = (it.join(it.keys(sessions))); @@ -74,7 +74,7 @@ end -- @return GET response, containing a json with participants details function handle_get_sessions(event) handle_room_event() - return { status_code = 200; body = get_all_rooms_with_participants() }; + return { status_code = 200, body = get_all_rooms_with_participants() }; end function module.load() @@ -86,9 +86,9 @@ function module.load() module:log("info", "Hello! You can reach me at: %s", module:http_url()); module:provides("http", { route = { - ["GET"] = function(event) return async_handler_wrapper(event, handle_get_sessions) end; + ["GET"] = function(event) return async_handler_wrapper(event, handle_get_sessions) end, - }; + }, }); end @@ -125,7 +125,6 @@ end --- Checks if event is triggered by healthchecks or focus user. function is_system_event(event) - if event == nil or event.room == nil or event.room.jid == nil then return true; end @@ -147,12 +146,11 @@ function handle_room_event(event) return; end - async_http_request("http://192.168.2.116:8081/roomdata", + async_http_request("http://jitsi-rooms:8081/roomdata", { method = "POST", body = get_all_rooms_with_participants() }) - end --Helper function to wait till a component is loaded before running the given callback From 5d70be142d63f7c5298556006f051c9b57d0af11 Mon Sep 17 00:00:00 2001 From: nf3lix Date: Wed, 12 Jul 2023 22:13:04 +0200 Subject: [PATCH 12/37] Enhance sidebar toggle button --- frontend/src/components/sidebar/useSidebarVisibility.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/sidebar/useSidebarVisibility.ts b/frontend/src/components/sidebar/useSidebarVisibility.ts index 2cbdbff..8a1589f 100644 --- a/frontend/src/components/sidebar/useSidebarVisibility.ts +++ b/frontend/src/components/sidebar/useSidebarVisibility.ts @@ -20,7 +20,7 @@ function useSidebarVisibility() { return { sidebarVisibility, toggleSidebarVisibility, sidebarToggleText } } const getSidebarToggleText = (sidebarVisibility: sidebarVisibilityOptions) => { - if (sidebarVisibility === 'full') return '<-' + if (sidebarVisibility === 'full') return '<--' if (sidebarVisibility === 'small') return '<-' if (sidebarVisibility === 'hidden') return '->' } From 66d70cbfe49d746da1b5d2a34b10408e8a6edf9e Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 25 Jul 2023 13:28:50 +0200 Subject: [PATCH 13/37] Revert "Use jotai for websocket" This reverts commit cc1808c9ec7c2331c189a19a828d77f953b4d1c2. --- frontend/src/hooks/useRoomName.ts | 2 +- frontend/src/hooks/useWebSocketConnection.ts | 23 +++++++------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/frontend/src/hooks/useRoomName.ts b/frontend/src/hooks/useRoomName.ts index 14e3c1f..1cf2422 100644 --- a/frontend/src/hooks/useRoomName.ts +++ b/frontend/src/hooks/useRoomName.ts @@ -1,5 +1,5 @@ import { atom, useAtom } from 'jotai' -import { useCallback } from 'react' +import { useCallback, useState } from 'react' const roomNameAtom = atom(getRoomNameFromUrl()) diff --git a/frontend/src/hooks/useWebSocketConnection.ts b/frontend/src/hooks/useWebSocketConnection.ts index 5450cd6..77aa0b1 100644 --- a/frontend/src/hooks/useWebSocketConnection.ts +++ b/frontend/src/hooks/useWebSocketConnection.ts @@ -1,19 +1,19 @@ -import { atom, useAtom } from 'jotai' -import { useCallback, useEffect } from 'react' +import { useCallback, useState } from 'react' import { WEBSOCKET_URL } from '../background/constants' import { UserInfo } from '../components/jitsi/types' +const createWebSocketConnection = (userInfo: UserInfo) => { + const webSocket = new WebSocket(WEBSOCKET_URL) + console.log('[Rooms] createWebSocketConnection') + webSocket.addEventListener('open', (_: Event) => webSocket.send(JSON.stringify(userInfo))) -const webSocket = new WebSocket(WEBSOCKET_URL) -const webSocketConnectionAtom = atom(webSocket) + return webSocket +} function useWebSocketConnection(userInfo: UserInfo) { console.log('[Rooms] useWebSocketConnection') - const [webSocketConnection] = useAtom(webSocketConnectionAtom) - useEffect(() => { - sendMessageNowOrLater(webSocketConnection, JSON.stringify(userInfo)) - }, [webSocketConnection, userInfo]); + const [webSocketConnection] = useState(() => createWebSocketConnection(userInfo)) const sendMessage = useCallback( (message: string) => { @@ -41,11 +41,4 @@ function useWebSocketConnection(userInfo: UserInfo) { return { onMessage, sendMessage, disconnect } } -const sendMessageNowOrLater = (webSocket: WebSocket, message: string) => { - if (webSocket.readyState !== WebSocket.OPEN) { - return webSocket.addEventListener('open', (_: Event) => webSocket.send(message)) - } - webSocket.send(message) -} - export default useWebSocketConnection From 1f5e5c944ce81b6a5273151601880c802694d756 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 1 Aug 2023 09:20:25 +0200 Subject: [PATCH 14/37] 'Fix' double chat messages --- frontend/src/hooks/useBackendData.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/hooks/useBackendData.ts b/frontend/src/hooks/useBackendData.ts index 43be19c..d347f93 100644 --- a/frontend/src/hooks/useBackendData.ts +++ b/frontend/src/hooks/useBackendData.ts @@ -12,6 +12,7 @@ function useBackendData(userInfo: UserInfo) { const { addChatMessage } = useAllChat() useEffect(() => { + console.log('[Rooms] add onMessage Listener') onMessage((messageString) => { console.log('[Rooms] message from ws', messageString) const messageObject = JSON.parse(messageString) @@ -20,7 +21,7 @@ function useBackendData(userInfo: UserInfo) { !!messageObject.content && addChatMessage(messageObject) return disconnect }) - }, [onMessage, setRoomData, disconnect]) + }, []) return { roomData, sendMessage } } From c77e006ce441744470a022251d789b9ffa521209 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 1 Aug 2023 09:38:44 +0200 Subject: [PATCH 15/37] Fix react keys --- frontend/src/components/meeting/Meeting.css | 5 ++++- frontend/src/components/meeting/Meeting.tsx | 7 ++++--- frontend/src/components/sidebar/Sidebar.tsx | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/meeting/Meeting.css b/frontend/src/components/meeting/Meeting.css index 9cbe859..a63af6c 100644 --- a/frontend/src/components/meeting/Meeting.css +++ b/frontend/src/components/meeting/Meeting.css @@ -1,4 +1,7 @@ .meeting-quickjoin { text-align: center - +} + +.meeting { + flex-grow: 3; } diff --git a/frontend/src/components/meeting/Meeting.tsx b/frontend/src/components/meeting/Meeting.tsx index d489575..eb0e3b3 100644 --- a/frontend/src/components/meeting/Meeting.tsx +++ b/frontend/src/components/meeting/Meeting.tsx @@ -6,6 +6,7 @@ import JitsiEntrypoint from '../jitsi/JitsiEntrypoint' import { UserInfo } from '../jitsi/types' import MeetingNameInput from './MeetingNameInput' import './Meeting.css' +import React from 'react' interface Props { conferenceData: ConferenceData | undefined @@ -34,12 +35,12 @@ function Meeting(props: Props) { } return ( -
+
{usersData?.roomsData.map((roomData) => { return ( - <> +

(
{participant.displayName}
))} - + ) })}

diff --git a/frontend/src/components/sidebar/Sidebar.tsx b/frontend/src/components/sidebar/Sidebar.tsx index 3e69178..b5440b5 100644 --- a/frontend/src/components/sidebar/Sidebar.tsx +++ b/frontend/src/components/sidebar/Sidebar.tsx @@ -5,6 +5,7 @@ import { UsersData } from '../../background/types/roomData' import useMeetingStarted from '../../hooks/useMeetingStarted' import { useRoomName } from '../../hooks/useRoomName' import Chat from '../chat/Chat' +import React from 'react' interface Props { usersData: UsersData @@ -22,7 +23,7 @@ function Sidebar(props: Props) {
-

No room

+

No room

{props.usersData.usersWithOutRoom.map((user) => (
{user.name}
))} From b8c7b4b9545a207d5a71958e0fe7ce3e7c903613 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 1 Aug 2023 10:21:12 +0200 Subject: [PATCH 16/37] Clean up backend code --- backend/src/RoomDataHandler.hs | 6 +----- backend/src/WebServer.hs | 28 ++++------------------------ backend/src/WebSocket/WSApp.hs | 4 +++- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/backend/src/RoomDataHandler.hs b/backend/src/RoomDataHandler.hs index 273846d..898bc55 100644 --- a/backend/src/RoomDataHandler.hs +++ b/backend/src/RoomDataHandler.hs @@ -16,16 +16,12 @@ import Network.Wai consumeRequestBodyStrict, responseLBS, ) -import State.ConnectedClientsState (MonadConnectedClientsRead) import State.RoomDataState ( MonadRoomDataStateModify (setRoomDataState), MonadRoomDataStateRead, ) -import Types.AppTypes (HasConnectedClientState) import Types.RoomsState - ( HasRoomsState, - roomStateDiffers, - updateRoomState, + ( roomStateDiffers, ) import Types.WebEnv ( HasWebEnv (getRequest), diff --git a/backend/src/WebServer.hs b/backend/src/WebServer.hs index 8b572f9..484cb37 100644 --- a/backend/src/WebServer.hs +++ b/backend/src/WebServer.hs @@ -15,7 +15,7 @@ import Control.Monad.Except import Network.HTTP.Types import Network.Wai import Network.Wai.Handler.Warp (run) -import Network.Wai.Middleware.RequestLogger (logStdoutDev) +import Network.Wai.Middleware.RequestLogger (logStdout) import RoomDataHandler (roomDataHandler) import State.ConnectedClientsState ( MonadConnectedClientsRead (..), @@ -27,9 +27,7 @@ import State.RoomDataState ) import Types.AppTypes (Env (..)) import Types.RoomsState - ( HasRoomsState (getRoomsState), - getRoomState, - roomStateDiffers, + ( getRoomState, updateRoomState, ) import Types.WebEnv @@ -122,24 +120,6 @@ notFound = do "404 - Not Found" throwError response --- notFound :: --- ( MonadIO m, --- HasWebEnv env, --- MonadReader env m, --- MonadError ResponseReceived m --- ) => --- m ResponseReceived --- notFound = do --- respond' <- getRespond <$> ask --- response <- --- liftIO $ --- respond' $ --- responseLBS --- status200 --- [("Content-Type", "text/plain")] --- "200 - Success" --- response - runWebApp :: ( MonadIO m, MonadReader Env m @@ -165,6 +145,6 @@ runWebServer :: ) => m () runWebServer = do - putStrLn "http://localhost:8081/" - runWebApp >>= liftIO . (run 8081 . logStdoutDev) + putStrLn "Webserver up and running at http://localhost:8081/" + runWebApp >>= liftIO . (run 8081 . logStdout) return () diff --git a/backend/src/WebSocket/WSApp.hs b/backend/src/WebSocket/WSApp.hs index 6d613ad..85a0786 100644 --- a/backend/src/WebSocket/WSApp.hs +++ b/backend/src/WebSocket/WSApp.hs @@ -33,11 +33,11 @@ wsApp = do broadcastUserData withCleanUp $ forever $ do handleWSAction - broadcastUserData handleWSAction :: ( MonadWebSocketSession m, MonadConnectedClientsModify m, + MonadRoomDataStateRead m, MonadBroadcast m, MonadAllChat m ) => @@ -47,8 +47,10 @@ handleWSAction = do case msg of JoinRoomMessage _ -> do joinRoom + broadcastUserData ClientInfoMessage clientInfo -> do updateClientName clientInfo + broadcastUserData AllChatMessageIncomingMessage incomingMessage -> do broadCastAllChatMessage incomingMessage From bc88f79feff326b6a146d26a4009dab175e68037 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sun, 6 Aug 2023 13:03:39 +0200 Subject: [PATCH 17/37] Fix double chat messages with useEffect cleanup --- frontend/src/hooks/useBackendData.ts | 8 +++++--- frontend/src/hooks/useWebSocketConnection.ts | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useBackendData.ts b/frontend/src/hooks/useBackendData.ts index d347f93..a69ac5e 100644 --- a/frontend/src/hooks/useBackendData.ts +++ b/frontend/src/hooks/useBackendData.ts @@ -7,20 +7,22 @@ import useWebSocketConnection from './useWebSocketConnection' function useBackendData(userInfo: UserInfo) { console.log('[Rooms] useBackendData') - const { onMessage, sendMessage, disconnect } = useWebSocketConnection(userInfo) + const { onMessage, cleanUpOnMessage, sendMessage, disconnect } = useWebSocketConnection(userInfo) const { roomData, setRoomData } = useRoomData() const { addChatMessage } = useAllChat() useEffect(() => { console.log('[Rooms] add onMessage Listener') - onMessage((messageString) => { + const messageCallback = (messageString: string) => { console.log('[Rooms] message from ws', messageString) const messageObject = JSON.parse(messageString) !!messageObject.roomsData && setRoomData(messageObject) !!messageObject.content && addChatMessage(messageObject) return disconnect - }) + } + onMessage(messageCallback) + return () => cleanUpOnMessage(messageCallback) }, []) return { roomData, sendMessage } diff --git a/frontend/src/hooks/useWebSocketConnection.ts b/frontend/src/hooks/useWebSocketConnection.ts index 77aa0b1..3fbb7bb 100644 --- a/frontend/src/hooks/useWebSocketConnection.ts +++ b/frontend/src/hooks/useWebSocketConnection.ts @@ -37,8 +37,12 @@ function useWebSocketConnection(userInfo: UserInfo) { ) const disconnect = useCallback(webSocketConnection.close, [webSocketConnection]) + const cleanUpOnMessage = useCallback((callbackToRemove: any) => { + console.log('[Rooms] cleanUpOnMessage') + webSocketConnection.removeEventListener('message', callbackToRemove) + }, [webSocketConnection]) - return { onMessage, sendMessage, disconnect } + return { onMessage, cleanUpOnMessage, sendMessage, disconnect } } export default useWebSocketConnection From 07b883636d7c81060ce807185cb8c90946212ff1 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Sun, 6 Aug 2023 13:09:45 +0200 Subject: [PATCH 18/37] Add filefighter favicon --- frontend/index.html | 2 +- frontend/public/favicon.ico | Bin 0 -> 548 bytes frontend/public/vite.svg | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) create mode 100755 frontend/public/favicon.ico delete mode 100644 frontend/public/vite.svg diff --git a/frontend/index.html b/frontend/index.html index db6a78f..d6b1c17 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -2,7 +2,7 @@ - + FF Jitsi Rooms diff --git a/frontend/public/favicon.ico b/frontend/public/favicon.ico new file mode 100755 index 0000000000000000000000000000000000000000..425b15acfd224b71a8498dd9c95c6ef55350f20c GIT binary patch literal 548 zcmeAS@N?(olHy`uVBq!ia0y~yV31{CV36ZrW?*1=e)H*M1_lPk;vjb?hIQv;UNSH+ zu%tWsIx;Y9?C1WI$jZRLkQU$*;<|L*D+UIJLnl78PMH7tSmfrJMyGH8IXShyX43!c z%!1i#w->mXtS*b2ml7Bm7UUee+Q_rNrLO(j>;GmQGjA?P3vapk?(nRdG_TIWfY6Xg zT?O>_ z%)r2R7=#&*=dVa%U|^K=ba4!^@UK1JSk$Z_z!GqLiCPnvNtD1=-v9q6-?SFk>U+14 z>CI=4Ad!bEu9eT0xX$FO51NuL^VPo1t?spJN7c@l^($|+PO+#737xvDVE5hkdrnGa zDTYn+y}W7hxjU-UbPF%9;aVo8Gv$)*r3Z;;4?oytcI?EqsV4GMXNK*%J0t4!v(Fdp zQ?9Q)RbMVK<=BpCpST4*J5O%8bgRtNu6>`m+Fc(RgZ8NC*D`Boy;`zR=0mcmR(5NF z*U_@83wz#MclS6QDGL=n5V0_Ci{7-zhktyP+qqMMxnjLNkKcc_cfQ5Pnkx_f+MNHx zB;Vf^c+RBKPJW8svRPqz-?FBsCbk?)3-