├── LICENSE.txt ├── README.md ├── websocket-project-backend ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── hselmi │ │ │ └── websocketproject │ │ │ ├── ChatController.java │ │ │ ├── ChatMessage.java │ │ │ ├── WebSocketConfig.java │ │ │ └── WebsocketProjectApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── hselmi │ └── websocketproject │ └── WebsocketProjectApplicationTests.java └── websocket-project-frontend ├── .editorconfig ├── .gitignore ├── angular.json ├── browserslist ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.spec.ts │ ├── app.component.ts │ ├── app.module.ts │ ├── chat │ │ ├── chat.component.html │ │ ├── chat.component.scss │ │ ├── chat.component.spec.ts │ │ └── chat.component.ts │ ├── models │ │ └── message.ts │ └── services │ │ ├── chat.service.spec.ts │ │ └── chat.service.ts ├── assets │ ├── .gitkeep │ ├── bootstrap │ │ └── bootstrap.min.css │ └── js │ │ ├── sockjs.min.js │ │ └── stomp.min.js ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.scss └── test.ts ├── tsconfig.app.json ├── tsconfig.json ├── tsconfig.spec.json └── tslint.json /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) [2019] [Houssem Selmi] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 |

5 | 6 | 7 | 8 | # Real-time Chat Application 💬 9 | 10 | 11 | 12 | ### Fully working chat application project built using Java EE Spring Boot WebSocket & Angular 9 13 | 14 | 15 | 16 | 17 | # Table of content 18 | 19 | 26 | 27 | 28 | 29 | # About the project 30 | Fully working real-time chat application to practice spring WebSocket and STOMP as a simple text-based messaging protocol to establish a persistent connection between a client and server to deliver and receive chat messages instantly without the use of long-polling. 31 | 32 | 33 | 34 | 35 | 36 | # Getting Started 37 | 38 | ## Prerequisites 39 | * #### Front-End ( Angular ) 40 | * A stable version of node installed on your machine 41 | * Npm 42 | * `npm install npm@latest -g` 43 | * Angular CLI 44 | * `npm install -g @angular/cli@9.1.13` 45 | 46 | 47 | * #### Back-End ( Spring Boot ) 48 | * Java SDK v1.8 or higher 49 | * Apache Maven 3.3 or above 50 | 51 | ## Installation 52 | 53 | **Clone the repo** :blush: 54 | 55 | 56 | git clone https://github.com/Houssem-Selmi/websocket-project.git 57 | 58 | 59 | 60 | 61 | ### Back-End ( Spring Boot ) 62 | 63 | 64 | * Open the folder 'websocket-project-backend' with your favorite Java IDE 65 | 66 | * Run the Spring Boot Java project 67 |
68 | 69 | 70 | ### Front-End ( Angular ) 71 | Access the Front-End folder 72 | 73 | cd websocket-project-frontend 74 | 75 | Install the dependencies 76 | 77 | npm install 78 | 79 | Start the angular project 80 | 81 | ng serve 82 | 83 | Now you should see the application running in your browser, type a username and start the chat. 84 | 85 | 86 | 87 | ### Congrats 👏 🎉 88 | **Now everything is set up correctly and you can start exploring the real-time chat application 💬** 89 | 90 | 91 | ## Author 92 | 93 | **Houssem Selmi** :pencil2: 94 | 95 | * [https://github.com/Houssem-Selmi](https://github.com/Houssem-Selmi) 96 | * [https://www.linkedin.com/in/hselmi/](https://www.linkedin.com/in/hselmi/) 97 | 98 | 99 | ## License 100 | 101 | Code released under the [ MIT License](https://github.com/Houssem-Selmi/booki/blob/master/LICENSE.txt). 102 | -------------------------------------------------------------------------------- /websocket-project-backend/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /websocket-project-backend/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.net.*; 18 | import java.io.*; 19 | import java.nio.channels.*; 20 | import java.util.Properties; 21 | 22 | public class MavenWrapperDownloader { 23 | 24 | private static final String WRAPPER_VERSION = "0.5.6"; 25 | /** 26 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 27 | */ 28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 30 | 31 | /** 32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 33 | * use instead of the default one. 34 | */ 35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 36 | ".mvn/wrapper/maven-wrapper.properties"; 37 | 38 | /** 39 | * Path where the maven-wrapper.jar will be saved to. 40 | */ 41 | private static final String MAVEN_WRAPPER_JAR_PATH = 42 | ".mvn/wrapper/maven-wrapper.jar"; 43 | 44 | /** 45 | * Name of the property which should be used to override the default download url for the wrapper. 46 | */ 47 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 48 | 49 | public static void main(String args[]) { 50 | System.out.println("- Downloader started"); 51 | File baseDirectory = new File(args[0]); 52 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 53 | 54 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 55 | // wrapperUrl parameter. 56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 57 | String url = DEFAULT_DOWNLOAD_URL; 58 | if (mavenWrapperPropertyFile.exists()) { 59 | FileInputStream mavenWrapperPropertyFileInputStream = null; 60 | try { 61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 62 | Properties mavenWrapperProperties = new Properties(); 63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 65 | } catch (IOException e) { 66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 67 | } finally { 68 | try { 69 | if (mavenWrapperPropertyFileInputStream != null) { 70 | mavenWrapperPropertyFileInputStream.close(); 71 | } 72 | } catch (IOException e) { 73 | // Ignore ... 74 | } 75 | } 76 | } 77 | System.out.println("- Downloading from: " + url); 78 | 79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 80 | if (!outputFile.getParentFile().exists()) { 81 | if (!outputFile.getParentFile().mkdirs()) { 82 | System.out.println( 83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 84 | } 85 | } 86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 87 | try { 88 | downloadFileFromURL(url, outputFile); 89 | System.out.println("Done"); 90 | System.exit(0); 91 | } catch (Throwable e) { 92 | System.out.println("- Error downloading"); 93 | e.printStackTrace(); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 100 | String username = System.getenv("MVNW_USERNAME"); 101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 102 | Authenticator.setDefault(new Authenticator() { 103 | @Override 104 | protected PasswordAuthentication getPasswordAuthentication() { 105 | return new PasswordAuthentication(username, password); 106 | } 107 | }); 108 | } 109 | URL website = new URL(urlString); 110 | ReadableByteChannel rbc; 111 | rbc = Channels.newChannel(website.openStream()); 112 | FileOutputStream fos = new FileOutputStream(destination); 113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 114 | fos.close(); 115 | rbc.close(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /websocket-project-backend/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Houssem-Selmi/websocket-project/11ab3d5f017ba02bc5b21289ca6ded310ef5972f/websocket-project-backend/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /websocket-project-backend/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /websocket-project-backend/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /websocket-project-backend/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /websocket-project-backend/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.2 9 | 10 | 11 | com.hselmi 12 | websocket-project 13 | 0.0.1-SNAPSHOT 14 | websocket-project 15 | websocket-project-backend 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-websocket 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /websocket-project-backend/src/main/java/com/hselmi/websocketproject/ChatController.java: -------------------------------------------------------------------------------- 1 | package com.hselmi.websocketproject; 2 | import org.springframework.messaging.handler.annotation.MessageMapping; 3 | import org.springframework.messaging.handler.annotation.SendTo; 4 | import org.springframework.stereotype.Controller; 5 | 6 | // The chat message-handling Controller 7 | @Controller 8 | public class ChatController { 9 | // mapped to handle chat messages to the /sendmsg destination 10 | @MessageMapping("/sendmsg") 11 | // the return value is broadcast to all subscribers of /chat/messages 12 | @SendTo("/chat/messages") 13 | public ChatMessage chat(ChatMessage message) throws Exception { 14 | Thread.sleep(1000); // simulated delay 15 | return new ChatMessage(message.getText(), message.getUsername(), message.getAvatar()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /websocket-project-backend/src/main/java/com/hselmi/websocketproject/ChatMessage.java: -------------------------------------------------------------------------------- 1 | package com.hselmi.websocketproject; 2 | 3 | /** 4 | * POJO representing the chat message 5 | */ 6 | public class ChatMessage { 7 | private String text; 8 | private String username; 9 | private String avatar; 10 | 11 | public ChatMessage(){ 12 | 13 | } 14 | 15 | public ChatMessage(String text ,String username, String avatar) { 16 | this.text = text; 17 | this.username = username; 18 | this.avatar = avatar; 19 | } 20 | 21 | 22 | public String getText() { 23 | return text; 24 | } 25 | 26 | public void setText(String text) { 27 | this.text = text; 28 | } 29 | 30 | 31 | public String getUsername() { 32 | return username; 33 | } 34 | 35 | public void setUsername(String username) { 36 | this.username = username; 37 | } 38 | 39 | public String getAvatar() { 40 | return avatar; 41 | } 42 | 43 | public void setAvatar(String avatar) { 44 | this.avatar = avatar; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /websocket-project-backend/src/main/java/com/hselmi/websocketproject/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.hselmi.websocketproject; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 6 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 7 | import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; 8 | 9 | 10 | @Configuration 11 | // Enables WebSocket message handling 12 | @EnableWebSocketMessageBroker 13 | public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { 14 | 15 | @Override 16 | public void configureMessageBroker(MessageBrokerRegistry config) { 17 | /* 18 | * enable a simple memory-based message broker to carry the chat messages 19 | * back to the client on destinations prefixed with /chat 20 | * */ 21 | config.enableSimpleBroker("/chat"); 22 | /* 23 | * designates the /app prefix for messages that are bound for 24 | * methods annotated with @MessageMapping 25 | * */ 26 | config.setApplicationDestinationPrefixes("/app"); 27 | } 28 | 29 | @Override 30 | public void registerStompEndpoints(StompEndpointRegistry registry) { 31 | /* 32 | * Register /chat-websocket endpoint, 33 | * setAllowedOriginPatterns is used to prevent CORS issue when using the 34 | * Angular application as a client 35 | * 36 | * */ 37 | registry.addEndpoint("/chat-websocket").setAllowedOriginPatterns("*") 38 | .withSockJS(); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /websocket-project-backend/src/main/java/com/hselmi/websocketproject/WebsocketProjectApplication.java: -------------------------------------------------------------------------------- 1 | package com.hselmi.websocketproject; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class WebsocketProjectApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(WebsocketProjectApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /websocket-project-backend/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /websocket-project-backend/src/test/java/com/hselmi/websocketproject/WebsocketProjectApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.hselmi.websocketproject; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class WebsocketProjectApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /websocket-project-frontend/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /websocket-project-frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /websocket-project-frontend/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "websocket-project-frontend": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | } 12 | }, 13 | "root": "", 14 | "sourceRoot": "src", 15 | "prefix": "app", 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/websocket-project-frontend", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "tsconfig.app.json", 25 | "aot": true, 26 | "assets": ["src/favicon.ico", "src/assets"], 27 | "styles": [ 28 | "node_modules/@nebular/theme/styles/prebuilt/default.css", 29 | "src/assets/bootstrap/bootstrap.min.css", 30 | "src/styles.scss" 31 | ], 32 | "scripts": [] 33 | }, 34 | "configurations": { 35 | "production": { 36 | "fileReplacements": [ 37 | { 38 | "replace": "src/environments/environment.ts", 39 | "with": "src/environments/environment.prod.ts" 40 | } 41 | ], 42 | "optimization": true, 43 | "outputHashing": "all", 44 | "sourceMap": false, 45 | "extractCss": true, 46 | "namedChunks": false, 47 | "extractLicenses": true, 48 | "vendorChunk": false, 49 | "buildOptimizer": true, 50 | "budgets": [ 51 | { 52 | "type": "initial", 53 | "maximumWarning": "2mb", 54 | "maximumError": "5mb" 55 | }, 56 | { 57 | "type": "anyComponentStyle", 58 | "maximumWarning": "6kb", 59 | "maximumError": "10kb" 60 | } 61 | ] 62 | } 63 | } 64 | }, 65 | "serve": { 66 | "builder": "@angular-devkit/build-angular:dev-server", 67 | "options": { 68 | "browserTarget": "websocket-project-frontend:build" 69 | }, 70 | "configurations": { 71 | "production": { 72 | "browserTarget": "websocket-project-frontend:build:production" 73 | } 74 | } 75 | }, 76 | "extract-i18n": { 77 | "builder": "@angular-devkit/build-angular:extract-i18n", 78 | "options": { 79 | "browserTarget": "websocket-project-frontend:build" 80 | } 81 | }, 82 | "test": { 83 | "builder": "@angular-devkit/build-angular:karma", 84 | "options": { 85 | "main": "src/test.ts", 86 | "polyfills": "src/polyfills.ts", 87 | "tsConfig": "tsconfig.spec.json", 88 | "karmaConfig": "karma.conf.js", 89 | "assets": ["src/favicon.ico", "src/assets"], 90 | "styles": ["src/styles.scss"], 91 | "scripts": [] 92 | } 93 | }, 94 | "lint": { 95 | "builder": "@angular-devkit/build-angular:tslint", 96 | "options": { 97 | "tsConfig": [ 98 | "tsconfig.app.json", 99 | "tsconfig.spec.json", 100 | "e2e/tsconfig.json" 101 | ], 102 | "exclude": ["**/node_modules/**"] 103 | } 104 | }, 105 | "e2e": { 106 | "builder": "@angular-devkit/build-angular:protractor", 107 | "options": { 108 | "protractorConfig": "e2e/protractor.conf.js", 109 | "devServerTarget": "websocket-project-frontend:serve" 110 | }, 111 | "configurations": { 112 | "production": { 113 | "devServerTarget": "websocket-project-frontend:serve:production" 114 | } 115 | } 116 | } 117 | } 118 | } 119 | }, 120 | "defaultProject": "websocket-project-frontend" 121 | } 122 | -------------------------------------------------------------------------------- /websocket-project-frontend/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /websocket-project-frontend/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /websocket-project-frontend/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('websocket-project-frontend app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /websocket-project-frontend/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /websocket-project-frontend/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /websocket-project-frontend/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/websocket-project-frontend'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /websocket-project-frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "websocket-project-frontend", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^9.1.13", 15 | "@angular/cdk": "^11.0.4", 16 | "@angular/common": "~9.1.13", 17 | "@angular/compiler": "~9.1.13", 18 | "@angular/core": "~9.1.13", 19 | "@angular/forms": "~9.1.13", 20 | "@angular/platform-browser": "~9.1.13", 21 | "@angular/platform-browser-dynamic": "~9.1.13", 22 | "@angular/router": "~9.1.13", 23 | "@nebular/eva-icons": "^6.2.1", 24 | "@nebular/theme": "^6.2.1", 25 | "eva-icons": "^1.1.3", 26 | "rxjs": "~6.5.4", 27 | "tslib": "^1.10.0", 28 | "zone.js": "~0.10.2" 29 | }, 30 | "devDependencies": { 31 | "@angular-devkit/build-angular": "~0.901.13", 32 | "@angular/cli": "~9.1.13", 33 | "@angular/compiler-cli": "~9.1.13", 34 | "@types/node": "^12.11.1", 35 | "@types/jasmine": "~3.5.0", 36 | "@types/jasminewd2": "~2.0.3", 37 | "codelyzer": "^5.1.2", 38 | "jasmine-core": "~3.5.0", 39 | "jasmine-spec-reporter": "~4.2.1", 40 | "karma": "~5.0.0", 41 | "karma-chrome-launcher": "~3.1.0", 42 | "karma-coverage-istanbul-reporter": "~2.1.0", 43 | "karma-jasmine": "~3.0.1", 44 | "karma-jasmine-html-reporter": "^1.4.2", 45 | "protractor": "~7.0.0", 46 | "ts-node": "~8.3.0", 47 | "tslint": "~6.1.0", 48 | "typescript": "~3.8.3" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { AppComponent } from './app.component'; 4 | import { ChatComponent } from './chat/chat.component'; 5 | 6 | const routes: Routes = []; 7 | 8 | @NgModule({ 9 | imports: [RouterModule.forRoot(routes)], 10 | exports: [RouterModule] 11 | }) 12 | export class AppRoutingModule {} 13 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Real-time chat application using 5 |  Spring web-socket and 6 | Angular. 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | Please enter your username : 16 | 23 | 32 |
33 |
34 |
35 |
36 |
37 | 38 | 44 |
45 | 46 | 47 | Made by   48 | 49 | Houssem Selmi  ✏️ 52 |
53 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | ::ng-deep nb-layout-column { 2 | width: 100%; 3 | } 4 | 5 | .bolder-text { 6 | font-weight: bold; 7 | } 8 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'websocket-project-frontend'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('websocket-project-frontend'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('websocket-project-frontend app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | templateUrl: './app.component.html', 7 | styleUrls: ['./app.component.scss'] 8 | }) 9 | export class AppComponent { 10 | // The entered username 11 | username = ''; 12 | // will hold a random theme for the chat component 13 | selectedTheme = ''; 14 | // will hold a random avatar for the chat component 15 | selectedAvatar = ''; 16 | // Detect when the user clicked on 'START' 17 | isReady = false; 18 | // List of themes and avatars to pass one randomly to the chat component 19 | themes = ['primary', 'warning', 'info', 'success']; 20 | avatars = [ 21 | 'https://mir-s3-cdn-cf.behance.net/user/115/24e8af100183223.59cbd13b396ba.png', 22 | 'https://github.com/Houssem-Selmi/booki/blob/master/Booki-Back-end/upload-dir/default.png?raw=true', 23 | 'https://github.com/Houssem-Selmi/booki/blob/master/Booki-Back-end/upload-dir/hs3.png?raw=true', 24 | 'https://github.com/Houssem-Selmi/booki/blob/master/Booki-Back-end/upload-dir/hs4.png?raw=true', 25 | 'https://github.com/Houssem-Selmi/booki/blob/master/Booki-Back-end/upload-dir/hs5.png?raw=true', 26 | 'https://github.com/Houssem-Selmi/booki/blob/master/Booki-Back-end/upload-dir/hs6.png?raw=true', 27 | 'https://github.com/Houssem-Selmi/booki/blob/master/Booki-Back-end/upload-dir/hs7.png?raw=true' 28 | ]; 29 | 30 | // Select one random avatar and theme for every chat component 31 | constructor(private _router: Router) { 32 | this.selectedTheme = this.getTheme(); 33 | this.selectedAvatar = this.getAvatar(); 34 | } 35 | 36 | // Get random theme 37 | getTheme() { 38 | return this.themes[Math.floor(Math.random() * this.themes.length)]; 39 | } 40 | 41 | // Get random avatar 42 | getAvatar() { 43 | return this.avatars[Math.floor(Math.random() * this.avatars.length)]; 44 | } 45 | 46 | // show the chat component 47 | chat() { 48 | this.isReady = true; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 3 | 4 | import { NgModule } from '@angular/core'; 5 | import { 6 | NbThemeModule, 7 | NbCardModule, 8 | NbLayoutModule, 9 | NbChatModule, 10 | NbInputModule, 11 | NbButtonModule, 12 | NbFormFieldModule 13 | } from '@nebular/theme'; 14 | 15 | import { AppRoutingModule } from './app-routing.module'; 16 | import { AppComponent } from './app.component'; 17 | import { ChatService } from './services/chat.service'; 18 | import { ChatComponent } from './chat/chat.component'; 19 | import { FormsModule } from '@angular/forms'; 20 | 21 | @NgModule({ 22 | declarations: [AppComponent, ChatComponent], 23 | imports: [ 24 | BrowserModule, 25 | AppRoutingModule, 26 | BrowserAnimationsModule, 27 | NbInputModule, 28 | NbButtonModule, 29 | NbCardModule, 30 | FormsModule, 31 | NbLayoutModule, 32 | NbChatModule, 33 | NbFormFieldModule, 34 | NbThemeModule.forRoot({ name: 'default' }) 35 | ], 36 | providers: [ChatService], 37 | bootstrap: [AppComponent] 38 | }) 39 | export class AppModule {} 40 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/chat/chat.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 12 | 13 | 14 | 15 |
16 |
17 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/chat/chat.component.scss: -------------------------------------------------------------------------------- 1 | nb-chat { 2 | margin: 1rem; 3 | } 4 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/chat/chat.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ChatComponent } from './chat.component'; 4 | 5 | describe('ChatComponent', () => { 6 | let component: ChatComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ChatComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ChatComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/chat/chat.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { ChatService } from '../services/chat.service'; 4 | import { Message } from '../models/message'; 5 | 6 | @Component({ 7 | selector: 'app-chat', 8 | templateUrl: './chat.component.html', 9 | styleUrls: ['./chat.component.scss'] 10 | }) 11 | export class ChatComponent implements OnInit { 12 | // Holding the chat messages 13 | messages: any[] = []; 14 | username: string = ''; 15 | theme: string = ''; 16 | avatar: string = ''; 17 | 18 | @Input('username') 19 | set setUsername(value: string) { 20 | this.username = value; 21 | } 22 | 23 | @Input('theme') 24 | set setTheme(value: string) { 25 | this.theme = value; 26 | } 27 | @Input('avatar') 28 | set setAvatar(value: string) { 29 | this.avatar = value; 30 | } 31 | 32 | constructor(public chatService: ChatService) {} 33 | ngOnInit(): void {} 34 | 35 | // Prepare the chat message then call the chatService method 'sendMessage' to actually send the message 36 | sendMessage(event: any, avatar: string) { 37 | let obj: Message = { 38 | text: event.message, 39 | avatar: avatar, 40 | username: this.username 41 | }; 42 | 43 | this.chatService.sendMessage(obj); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/models/message.ts: -------------------------------------------------------------------------------- 1 | // Chat message model 2 | export interface Message { 3 | text: string; 4 | username: string; 5 | avatar: string; 6 | } 7 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/services/chat.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { ChatService } from './chat.service'; 4 | 5 | describe('ChatService', () => { 6 | let service: ChatService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(ChatService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/app/services/chat.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Message } from '../models/message'; 3 | /** 4 | * Declaring SockJS and Stomp : check the assets/js folder and the index.html script section 5 | */ 6 | declare var SockJS; 7 | declare var Stomp; 8 | 9 | @Injectable({ 10 | providedIn: 'root' 11 | }) 12 | export class ChatService { 13 | // Store the chat messages 14 | public messages = []; 15 | 16 | public stompClient; 17 | 18 | constructor() { 19 | this.initializeWebSocketConnection(); 20 | } 21 | 22 | initializeWebSocketConnection() { 23 | /** 24 | * Create a SockJS server with created back-end endpoint called /chat-websocket and added it over Stomp. 25 | */ 26 | const serverUrl = 'http://localhost:8080/chat-websocket'; 27 | const ws = new SockJS(serverUrl); 28 | this.stompClient = Stomp.over(ws); 29 | const that = this; 30 | /** 31 | * Connect stomp client and subscribe asynchronously to the chat message-handling Controller endpoint and push any message body into the messages array 32 | */ 33 | this.stompClient.connect({}, function(frame) { 34 | that.stompClient.subscribe('/chat/messages', message => { 35 | if (message.body) { 36 | let obj = JSON.parse(message.body); 37 | that.addMessage(obj.text, obj.username, obj.avatar); 38 | } 39 | }); 40 | }); 41 | } 42 | 43 | // Prepare and push the chat messages into the messages array 44 | addMessage(message: any, username: string, avatar: string) { 45 | this.messages.push({ 46 | text: message, 47 | date: new Date(), 48 | user: { 49 | name: username, 50 | avatar: avatar 51 | } 52 | }); 53 | } 54 | 55 | // Send a chat message using stomp client 56 | sendMessage(msg: Message) { 57 | this.stompClient.send('/app/sendmsg', {}, JSON.stringify(msg)); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Houssem-Selmi/websocket-project/11ab3d5f017ba02bc5b21289ca6ded310ef5972f/websocket-project-frontend/src/assets/.gitkeep -------------------------------------------------------------------------------- /websocket-project-frontend/src/assets/js/stomp.min.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 1.7.1 2 | /* 3 | Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 4 | 5 | Copyright (C) 2010-2013 [Jeff Mesnil](http://jmesnil.net/) 6 | Copyright (C) 2012 [FuseSource, Inc.](http://fusesource.com) 7 | */ 8 | (function() { 9 | var t, 10 | e, 11 | n, 12 | i, 13 | r = {}.hasOwnProperty, 14 | o = [].slice; 15 | t = { LF: "\n", NULL: "\x00" }; 16 | n = (function() { 17 | var e; 18 | function n(t, e, n) { 19 | this.command = t; 20 | this.headers = e != null ? e : {}; 21 | this.body = n != null ? n : ""; 22 | } 23 | n.prototype.toString = function() { 24 | var e, i, o, s, u; 25 | e = [this.command]; 26 | o = this.headers["content-length"] === false ? true : false; 27 | if (o) { 28 | delete this.headers["content-length"]; 29 | } 30 | u = this.headers; 31 | for (i in u) { 32 | if (!r.call(u, i)) continue; 33 | s = u[i]; 34 | e.push("" + i + ":" + s); 35 | } 36 | if (this.body && !o) { 37 | e.push("content-length:" + n.sizeOfUTF8(this.body)); 38 | } 39 | e.push(t.LF + this.body); 40 | return e.join(t.LF); 41 | }; 42 | n.sizeOfUTF8 = function(t) { 43 | if (t) { 44 | return encodeURI(t).match(/%..|./g).length; 45 | } else { 46 | return 0; 47 | } 48 | }; 49 | e = function(e) { 50 | var i, r, o, s, u, a, c, f, h, l, p, d, g, b, m, v, y; 51 | s = e.search(RegExp("" + t.LF + t.LF)); 52 | u = e.substring(0, s).split(t.LF); 53 | o = u.shift(); 54 | a = {}; 55 | d = function(t) { 56 | return t.replace(/^\s+|\s+$/g, ""); 57 | }; 58 | v = u.reverse(); 59 | for (g = 0, m = v.length; g < m; g++) { 60 | l = v[g]; 61 | f = l.indexOf(":"); 62 | a[d(l.substring(0, f))] = d(l.substring(f + 1)); 63 | } 64 | i = ""; 65 | p = s + 2; 66 | if (a["content-length"]) { 67 | h = parseInt(a["content-length"]); 68 | i = ("" + e).substring(p, p + h); 69 | } else { 70 | r = null; 71 | for ( 72 | c = b = p, y = e.length; 73 | p <= y ? b < y : b > y; 74 | c = p <= y ? ++b : --b 75 | ) { 76 | r = e.charAt(c); 77 | if (r === t.NULL) { 78 | break; 79 | } 80 | i += r; 81 | } 82 | } 83 | return new n(o, a, i); 84 | }; 85 | n.unmarshall = function(n) { 86 | var i; 87 | return (function() { 88 | var r, o, s, u; 89 | s = n.split(RegExp("" + t.NULL + t.LF + "*")); 90 | u = []; 91 | for (r = 0, o = s.length; r < o; r++) { 92 | i = s[r]; 93 | if ((i != null ? i.length : void 0) > 0) { 94 | u.push(e(i)); 95 | } 96 | } 97 | return u; 98 | })(); 99 | }; 100 | n.marshall = function(e, i, r) { 101 | var o; 102 | o = new n(e, i, r); 103 | return o.toString() + t.NULL; 104 | }; 105 | return n; 106 | })(); 107 | e = (function() { 108 | var e; 109 | function r(t) { 110 | this.ws = t; 111 | this.ws.binaryType = "arraybuffer"; 112 | this.counter = 0; 113 | this.connected = false; 114 | this.heartbeat = { outgoing: 1e4, incoming: 1e4 }; 115 | this.maxWebSocketFrameSize = 16 * 1024; 116 | this.subscriptions = {}; 117 | } 118 | r.prototype.debug = function(t) { 119 | var e; 120 | return typeof window !== "undefined" && window !== null 121 | ? (e = window.console) != null 122 | ? e.log(t) 123 | : void 0 124 | : void 0; 125 | }; 126 | e = function() { 127 | if (Date.now) { 128 | return Date.now(); 129 | } else { 130 | return new Date().valueOf; 131 | } 132 | }; 133 | r.prototype._transmit = function(t, e, i) { 134 | var r; 135 | r = n.marshall(t, e, i); 136 | if (typeof this.debug === "function") { 137 | this.debug(">>> " + r); 138 | } 139 | while (true) { 140 | if (r.length > this.maxWebSocketFrameSize) { 141 | this.ws.send(r.substring(0, this.maxWebSocketFrameSize)); 142 | r = r.substring(this.maxWebSocketFrameSize); 143 | if (typeof this.debug === "function") { 144 | this.debug("remaining = " + r.length); 145 | } 146 | } else { 147 | return this.ws.send(r); 148 | } 149 | } 150 | }; 151 | r.prototype._setupHeartbeat = function(n) { 152 | var r, o, s, u, a, c; 153 | if ((a = n.version) !== i.VERSIONS.V1_1 && a !== i.VERSIONS.V1_2) { 154 | return; 155 | } 156 | (c = (function() { 157 | var t, e, i, r; 158 | i = n["heart-beat"].split(","); 159 | r = []; 160 | for (t = 0, e = i.length; t < e; t++) { 161 | u = i[t]; 162 | r.push(parseInt(u)); 163 | } 164 | return r; 165 | })()), 166 | (o = c[0]), 167 | (r = c[1]); 168 | if (!(this.heartbeat.outgoing === 0 || r === 0)) { 169 | s = Math.max(this.heartbeat.outgoing, r); 170 | if (typeof this.debug === "function") { 171 | this.debug("send PING every " + s + "ms"); 172 | } 173 | this.pinger = i.setInterval( 174 | s, 175 | (function(e) { 176 | return function() { 177 | e.ws.send(t.LF); 178 | return typeof e.debug === "function" 179 | ? e.debug(">>> PING") 180 | : void 0; 181 | }; 182 | })(this) 183 | ); 184 | } 185 | if (!(this.heartbeat.incoming === 0 || o === 0)) { 186 | s = Math.max(this.heartbeat.incoming, o); 187 | if (typeof this.debug === "function") { 188 | this.debug("check PONG every " + s + "ms"); 189 | } 190 | return (this.ponger = i.setInterval( 191 | s, 192 | (function(t) { 193 | return function() { 194 | var n; 195 | n = e() - t.serverActivity; 196 | if (n > s * 2) { 197 | if (typeof t.debug === "function") { 198 | t.debug( 199 | "did not receive server activity for the last " + n + "ms" 200 | ); 201 | } 202 | return t.ws.close(); 203 | } 204 | }; 205 | })(this) 206 | )); 207 | } 208 | }; 209 | r.prototype._parseConnect = function() { 210 | var t, e, n, i; 211 | t = 1 <= arguments.length ? o.call(arguments, 0) : []; 212 | i = {}; 213 | switch (t.length) { 214 | case 2: 215 | (i = t[0]), (e = t[1]); 216 | break; 217 | case 3: 218 | if (t[1] instanceof Function) { 219 | (i = t[0]), (e = t[1]), (n = t[2]); 220 | } else { 221 | (i.login = t[0]), (i.passcode = t[1]), (e = t[2]); 222 | } 223 | break; 224 | case 4: 225 | (i.login = t[0]), (i.passcode = t[1]), (e = t[2]), (n = t[3]); 226 | break; 227 | default: 228 | (i.login = t[0]), 229 | (i.passcode = t[1]), 230 | (e = t[2]), 231 | (n = t[3]), 232 | (i.host = t[4]); 233 | } 234 | return [i, e, n]; 235 | }; 236 | r.prototype.connect = function() { 237 | var r, s, u, a; 238 | r = 1 <= arguments.length ? o.call(arguments, 0) : []; 239 | a = this._parseConnect.apply(this, r); 240 | (u = a[0]), (this.connectCallback = a[1]), (s = a[2]); 241 | if (typeof this.debug === "function") { 242 | this.debug("Opening Web Socket..."); 243 | } 244 | this.ws.onmessage = (function(i) { 245 | return function(r) { 246 | var o, u, a, c, f, h, l, p, d, g, b, m; 247 | c = 248 | typeof ArrayBuffer !== "undefined" && r.data instanceof ArrayBuffer 249 | ? ((o = new Uint8Array(r.data)), 250 | typeof i.debug === "function" 251 | ? i.debug("--- got data length: " + o.length) 252 | : void 0, 253 | (function() { 254 | var t, e, n; 255 | n = []; 256 | for (t = 0, e = o.length; t < e; t++) { 257 | u = o[t]; 258 | n.push(String.fromCharCode(u)); 259 | } 260 | return n; 261 | })().join("")) 262 | : r.data; 263 | i.serverActivity = e(); 264 | if (c === t.LF) { 265 | if (typeof i.debug === "function") { 266 | i.debug("<<< PONG"); 267 | } 268 | return; 269 | } 270 | if (typeof i.debug === "function") { 271 | i.debug("<<< " + c); 272 | } 273 | b = n.unmarshall(c); 274 | m = []; 275 | for (d = 0, g = b.length; d < g; d++) { 276 | f = b[d]; 277 | switch (f.command) { 278 | case "CONNECTED": 279 | if (typeof i.debug === "function") { 280 | i.debug("connected to server " + f.headers.server); 281 | } 282 | i.connected = true; 283 | i._setupHeartbeat(f.headers); 284 | m.push( 285 | typeof i.connectCallback === "function" 286 | ? i.connectCallback(f) 287 | : void 0 288 | ); 289 | break; 290 | case "MESSAGE": 291 | p = f.headers.subscription; 292 | l = i.subscriptions[p] || i.onreceive; 293 | if (l) { 294 | a = i; 295 | h = f.headers["message-id"]; 296 | f.ack = function(t) { 297 | if (t == null) { 298 | t = {}; 299 | } 300 | return a.ack(h, p, t); 301 | }; 302 | f.nack = function(t) { 303 | if (t == null) { 304 | t = {}; 305 | } 306 | return a.nack(h, p, t); 307 | }; 308 | m.push(l(f)); 309 | } else { 310 | m.push( 311 | typeof i.debug === "function" 312 | ? i.debug("Unhandled received MESSAGE: " + f) 313 | : void 0 314 | ); 315 | } 316 | break; 317 | case "RECEIPT": 318 | m.push( 319 | typeof i.onreceipt === "function" ? i.onreceipt(f) : void 0 320 | ); 321 | break; 322 | case "ERROR": 323 | m.push(typeof s === "function" ? s(f) : void 0); 324 | break; 325 | default: 326 | m.push( 327 | typeof i.debug === "function" 328 | ? i.debug("Unhandled frame: " + f) 329 | : void 0 330 | ); 331 | } 332 | } 333 | return m; 334 | }; 335 | })(this); 336 | this.ws.onclose = (function(t) { 337 | return function() { 338 | var e; 339 | e = "Whoops! Lost connection to " + t.ws.url; 340 | if (typeof t.debug === "function") { 341 | t.debug(e); 342 | } 343 | t._cleanUp(); 344 | return typeof s === "function" ? s(e) : void 0; 345 | }; 346 | })(this); 347 | return (this.ws.onopen = (function(t) { 348 | return function() { 349 | if (typeof t.debug === "function") { 350 | t.debug("Web Socket Opened..."); 351 | } 352 | u["accept-version"] = i.VERSIONS.supportedVersions(); 353 | u["heart-beat"] = [t.heartbeat.outgoing, t.heartbeat.incoming].join( 354 | "," 355 | ); 356 | return t._transmit("CONNECT", u); 357 | }; 358 | })(this)); 359 | }; 360 | r.prototype.disconnect = function(t, e) { 361 | if (e == null) { 362 | e = {}; 363 | } 364 | this._transmit("DISCONNECT", e); 365 | this.ws.onclose = null; 366 | this.ws.close(); 367 | this._cleanUp(); 368 | return typeof t === "function" ? t() : void 0; 369 | }; 370 | r.prototype._cleanUp = function() { 371 | this.connected = false; 372 | if (this.pinger) { 373 | i.clearInterval(this.pinger); 374 | } 375 | if (this.ponger) { 376 | return i.clearInterval(this.ponger); 377 | } 378 | }; 379 | r.prototype.send = function(t, e, n) { 380 | if (e == null) { 381 | e = {}; 382 | } 383 | if (n == null) { 384 | n = ""; 385 | } 386 | e.destination = t; 387 | return this._transmit("SEND", e, n); 388 | }; 389 | r.prototype.subscribe = function(t, e, n) { 390 | var i; 391 | if (n == null) { 392 | n = {}; 393 | } 394 | if (!n.id) { 395 | n.id = "sub-" + this.counter++; 396 | } 397 | n.destination = t; 398 | this.subscriptions[n.id] = e; 399 | this._transmit("SUBSCRIBE", n); 400 | i = this; 401 | return { 402 | id: n.id, 403 | unsubscribe: function() { 404 | return i.unsubscribe(n.id); 405 | } 406 | }; 407 | }; 408 | r.prototype.unsubscribe = function(t) { 409 | delete this.subscriptions[t]; 410 | return this._transmit("UNSUBSCRIBE", { id: t }); 411 | }; 412 | r.prototype.begin = function(t) { 413 | var e, n; 414 | n = t || "tx-" + this.counter++; 415 | this._transmit("BEGIN", { transaction: n }); 416 | e = this; 417 | return { 418 | id: n, 419 | commit: function() { 420 | return e.commit(n); 421 | }, 422 | abort: function() { 423 | return e.abort(n); 424 | } 425 | }; 426 | }; 427 | r.prototype.commit = function(t) { 428 | return this._transmit("COMMIT", { transaction: t }); 429 | }; 430 | r.prototype.abort = function(t) { 431 | return this._transmit("ABORT", { transaction: t }); 432 | }; 433 | r.prototype.ack = function(t, e, n) { 434 | if (n == null) { 435 | n = {}; 436 | } 437 | n["message-id"] = t; 438 | n.subscription = e; 439 | return this._transmit("ACK", n); 440 | }; 441 | r.prototype.nack = function(t, e, n) { 442 | if (n == null) { 443 | n = {}; 444 | } 445 | n["message-id"] = t; 446 | n.subscription = e; 447 | return this._transmit("NACK", n); 448 | }; 449 | return r; 450 | })(); 451 | i = { 452 | VERSIONS: { 453 | V1_0: "1.0", 454 | V1_1: "1.1", 455 | V1_2: "1.2", 456 | supportedVersions: function() { 457 | return "1.1,1.0"; 458 | } 459 | }, 460 | client: function(t, n) { 461 | var r, o; 462 | if (n == null) { 463 | n = ["v10.stomp", "v11.stomp"]; 464 | } 465 | r = i.WebSocketClass || WebSocket; 466 | o = new r(t, n); 467 | return new e(o); 468 | }, 469 | over: function(t) { 470 | return new e(t); 471 | }, 472 | Frame: n 473 | }; 474 | if (typeof exports !== "undefined" && exports !== null) { 475 | exports.Stomp = i; 476 | } 477 | if (typeof window !== "undefined" && window !== null) { 478 | i.setInterval = function(t, e) { 479 | return window.setInterval(e, t); 480 | }; 481 | i.clearInterval = function(t) { 482 | return window.clearInterval(t); 483 | }; 484 | window.Stomp = i; 485 | } else if (!exports) { 486 | self.Stomp = i; 487 | } 488 | }.call(this)); 489 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Houssem-Selmi/websocket-project/11ab3d5f017ba02bc5b21289ca6ded310ef5972f/websocket-project-frontend/src/favicon.ico -------------------------------------------------------------------------------- /websocket-project-frontend/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | WebSocket Chat App 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /websocket-project-frontend/src/styles.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Houssem-Selmi/websocket-project/11ab3d5f017ba02bc5b21289ca6ded310ef5972f/websocket-project-frontend/src/styles.scss -------------------------------------------------------------------------------- /websocket-project-frontend/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /websocket-project-frontend/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": ["src/main.ts", "src/polyfills.ts"], 8 | "include": ["src/**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /websocket-project-frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": ["es2018", "dom"] 15 | }, 16 | "angularCompilerOptions": { 17 | "fullTemplateTypeCheck": true, 18 | "strictInjectionParameters": true 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /websocket-project-frontend/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /websocket-project-frontend/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-return-shorthand": true, 12 | "curly": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "directive-class-suffix": true, 19 | "directive-selector": [ 20 | true, 21 | "attribute", 22 | "app", 23 | "camelCase" 24 | ], 25 | "component-selector": [ 26 | true, 27 | "element", 28 | "app", 29 | "kebab-case" 30 | ], 31 | "eofline": true, 32 | "import-blacklist": [ 33 | true, 34 | "rxjs/Rx" 35 | ], 36 | "import-spacing": true, 37 | "indent": { 38 | "options": [ 39 | "spaces" 40 | ] 41 | }, 42 | "max-classes-per-file": false, 43 | "max-line-length": [ 44 | true, 45 | 140 46 | ], 47 | "member-ordering": [ 48 | true, 49 | { 50 | "order": [ 51 | "static-field", 52 | "instance-field", 53 | "static-method", 54 | "instance-method" 55 | ] 56 | } 57 | ], 58 | "no-console": [ 59 | true, 60 | "debug", 61 | "info", 62 | "time", 63 | "timeEnd", 64 | "trace" 65 | ], 66 | "no-empty": false, 67 | "no-inferrable-types": [ 68 | true, 69 | "ignore-params" 70 | ], 71 | "no-non-null-assertion": true, 72 | "no-redundant-jsdoc": true, 73 | "no-switch-case-fall-through": true, 74 | "no-var-requires": false, 75 | "object-literal-key-quotes": [ 76 | true, 77 | "as-needed" 78 | ], 79 | "quotemark": [ 80 | true, 81 | "single" 82 | ], 83 | "semicolon": { 84 | "options": [ 85 | "always" 86 | ] 87 | }, 88 | "space-before-function-paren": { 89 | "options": { 90 | "anonymous": "never", 91 | "asyncArrow": "always", 92 | "constructor": "never", 93 | "method": "never", 94 | "named": "never" 95 | } 96 | }, 97 | "typedef-whitespace": { 98 | "options": [ 99 | { 100 | "call-signature": "nospace", 101 | "index-signature": "nospace", 102 | "parameter": "nospace", 103 | "property-declaration": "nospace", 104 | "variable-declaration": "nospace" 105 | }, 106 | { 107 | "call-signature": "onespace", 108 | "index-signature": "onespace", 109 | "parameter": "onespace", 110 | "property-declaration": "onespace", 111 | "variable-declaration": "onespace" 112 | } 113 | ] 114 | }, 115 | "variable-name": { 116 | "options": [ 117 | "ban-keywords", 118 | "check-format", 119 | "allow-pascal-case" 120 | ] 121 | }, 122 | "whitespace": { 123 | "options": [ 124 | "check-branch", 125 | "check-decl", 126 | "check-operator", 127 | "check-separator", 128 | "check-type", 129 | "check-typecast" 130 | ] 131 | }, 132 | "no-conflicting-lifecycle": true, 133 | "no-host-metadata-property": true, 134 | "no-input-rename": true, 135 | "no-inputs-metadata-property": true, 136 | "no-output-native": true, 137 | "no-output-on-prefix": true, 138 | "no-output-rename": true, 139 | "no-outputs-metadata-property": true, 140 | "template-banana-in-box": true, 141 | "template-no-negated-async": true, 142 | "use-lifecycle-interface": true, 143 | "use-pipe-transform-interface": true 144 | }, 145 | "rulesDirectory": [ 146 | "codelyzer" 147 | ] 148 | } --------------------------------------------------------------------------------