Bläddra i källkod

front-end sockets gg

woat 6 år sedan
förälder
incheckning
5e41f987bc
5 ändrade filer med 146 tillägg och 52 borttagningar
  1. 84
    46
      package-lock.json
  2. 3
    1
      package.json
  3. 29
    1
      src/app/app.module.ts
  4. 3
    1
      src/app/post.service.ts
  5. 27
    3
      src/app/timeline/timeline.component.ts

+ 84
- 46
package-lock.json Visa fil

@@ -411,6 +411,22 @@
411 411
         "semver-intersect": "^1.1.2"
412 412
       }
413 413
     },
414
+    "@stomp/ng2-stompjs": {
415
+      "version": "4.0.1",
416
+      "resolved": "https://registry.npmjs.org/@stomp/ng2-stompjs/-/ng2-stompjs-4.0.1.tgz",
417
+      "integrity": "sha512-LiP/VoCLGhwVR56T0WCLN3pV1Cx8ifgteNIKzAtKngJJjtkwk9cHAoiPz/u3ZPmuCxcd+JpGrIM/j0utg2CfUg==",
418
+      "requires": {
419
+        "@stomp/stompjs": "^4.0.0 >=4.0.7"
420
+      }
421
+    },
422
+    "@stomp/stompjs": {
423
+      "version": "4.0.7",
424
+      "resolved": "https://registry.npmjs.org/@stomp/stompjs/-/stompjs-4.0.7.tgz",
425
+      "integrity": "sha512-2fI/P978d7Kux3KqOfF5GLkiCbwgrPjOZwkgr0qZvVh9b+kHVueqhkxDGIGVyyrUO4Iwdmy5s6sXPc5RxhFlQA==",
426
+      "requires": {
427
+        "websocket": "^1.0.24"
428
+      }
429
+    },
414 430
     "@types/jasmine": {
415 431
       "version": "2.8.8",
416 432
       "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.8.8.tgz",
@@ -2369,7 +2385,6 @@
2369 2385
       "version": "2.6.9",
2370 2386
       "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
2371 2387
       "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
2372
-      "dev": true,
2373 2388
       "requires": {
2374 2389
         "ms": "2.0.0"
2375 2390
       }
@@ -3080,7 +3095,6 @@
3080 3095
       "version": "0.1.6",
3081 3096
       "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-0.1.6.tgz",
3082 3097
       "integrity": "sha1-Cs7ehJ7X3RzMMsgRuxG5RNTykjI=",
3083
-      "dev": true,
3084 3098
       "requires": {
3085 3099
         "original": ">=0.0.5"
3086 3100
       }
@@ -3705,14 +3719,12 @@
3705 3719
         "balanced-match": {
3706 3720
           "version": "1.0.0",
3707 3721
           "bundled": true,
3708
-          "dev": true,
3709
-          "optional": true
3722
+          "dev": true
3710 3723
         },
3711 3724
         "brace-expansion": {
3712 3725
           "version": "1.1.11",
3713 3726
           "bundled": true,
3714 3727
           "dev": true,
3715
-          "optional": true,
3716 3728
           "requires": {
3717 3729
             "balanced-match": "^1.0.0",
3718 3730
             "concat-map": "0.0.1"
@@ -3727,20 +3739,17 @@
3727 3739
         "code-point-at": {
3728 3740
           "version": "1.1.0",
3729 3741
           "bundled": true,
3730
-          "dev": true,
3731
-          "optional": true
3742
+          "dev": true
3732 3743
         },
3733 3744
         "concat-map": {
3734 3745
           "version": "0.0.1",
3735 3746
           "bundled": true,
3736
-          "dev": true,
3737
-          "optional": true
3747
+          "dev": true
3738 3748
         },
3739 3749
         "console-control-strings": {
3740 3750
           "version": "1.1.0",
3741 3751
           "bundled": true,
3742
-          "dev": true,
3743
-          "optional": true
3752
+          "dev": true
3744 3753
         },
3745 3754
         "core-util-is": {
3746 3755
           "version": "1.0.2",
@@ -3857,8 +3866,7 @@
3857 3866
         "inherits": {
3858 3867
           "version": "2.0.3",
3859 3868
           "bundled": true,
3860
-          "dev": true,
3861
-          "optional": true
3869
+          "dev": true
3862 3870
         },
3863 3871
         "ini": {
3864 3872
           "version": "1.3.5",
@@ -3870,7 +3878,6 @@
3870 3878
           "version": "1.0.0",
3871 3879
           "bundled": true,
3872 3880
           "dev": true,
3873
-          "optional": true,
3874 3881
           "requires": {
3875 3882
             "number-is-nan": "^1.0.0"
3876 3883
           }
@@ -3885,7 +3892,6 @@
3885 3892
           "version": "3.0.4",
3886 3893
           "bundled": true,
3887 3894
           "dev": true,
3888
-          "optional": true,
3889 3895
           "requires": {
3890 3896
             "brace-expansion": "^1.1.7"
3891 3897
           }
@@ -3893,14 +3899,12 @@
3893 3899
         "minimist": {
3894 3900
           "version": "0.0.8",
3895 3901
           "bundled": true,
3896
-          "dev": true,
3897
-          "optional": true
3902
+          "dev": true
3898 3903
         },
3899 3904
         "minipass": {
3900 3905
           "version": "2.2.4",
3901 3906
           "bundled": true,
3902 3907
           "dev": true,
3903
-          "optional": true,
3904 3908
           "requires": {
3905 3909
             "safe-buffer": "^5.1.1",
3906 3910
             "yallist": "^3.0.0"
@@ -3919,7 +3923,6 @@
3919 3923
           "version": "0.5.1",
3920 3924
           "bundled": true,
3921 3925
           "dev": true,
3922
-          "optional": true,
3923 3926
           "requires": {
3924 3927
             "minimist": "0.0.8"
3925 3928
           }
@@ -4000,8 +4003,7 @@
4000 4003
         "number-is-nan": {
4001 4004
           "version": "1.0.1",
4002 4005
           "bundled": true,
4003
-          "dev": true,
4004
-          "optional": true
4006
+          "dev": true
4005 4007
         },
4006 4008
         "object-assign": {
4007 4009
           "version": "4.1.1",
@@ -4013,7 +4015,6 @@
4013 4015
           "version": "1.4.0",
4014 4016
           "bundled": true,
4015 4017
           "dev": true,
4016
-          "optional": true,
4017 4018
           "requires": {
4018 4019
             "wrappy": "1"
4019 4020
           }
@@ -4135,7 +4136,6 @@
4135 4136
           "version": "1.0.2",
4136 4137
           "bundled": true,
4137 4138
           "dev": true,
4138
-          "optional": true,
4139 4139
           "requires": {
4140 4140
             "code-point-at": "^1.0.0",
4141 4141
             "is-fullwidth-code-point": "^1.0.0",
@@ -4756,8 +4756,7 @@
4756 4756
     "http-parser-js": {
4757 4757
       "version": "0.4.13",
4758 4758
       "resolved": "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.4.13.tgz",
4759
-      "integrity": "sha1-O9bW/ebjFyyTNMOzO2wZPYD+ETc=",
4760
-      "dev": true
4759
+      "integrity": "sha1-O9bW/ebjFyyTNMOzO2wZPYD+ETc="
4761 4760
     },
4762 4761
     "http-proxy": {
4763 4762
       "version": "1.17.0",
@@ -4926,8 +4925,7 @@
4926 4925
     "inherits": {
4927 4926
       "version": "2.0.3",
4928 4927
       "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
4929
-      "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
4930
-      "dev": true
4928
+      "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
4931 4929
     },
4932 4930
     "ini": {
4933 4931
       "version": "1.3.5",
@@ -5221,8 +5219,7 @@
5221 5219
     "is-typedarray": {
5222 5220
       "version": "1.0.0",
5223 5221
       "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
5224
-      "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=",
5225
-      "dev": true
5222
+      "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
5226 5223
     },
5227 5224
     "is-utf8": {
5228 5225
       "version": "0.2.1",
@@ -5609,8 +5606,7 @@
5609 5606
     "json3": {
5610 5607
       "version": "3.3.2",
5611 5608
       "resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz",
5612
-      "integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=",
5613
-      "dev": true
5609
+      "integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE="
5614 5610
     },
5615 5611
     "json5": {
5616 5612
       "version": "0.5.1",
@@ -6494,8 +6490,7 @@
6494 6490
     "ms": {
6495 6491
       "version": "2.0.0",
6496 6492
       "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
6497
-      "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
6498
-      "dev": true
6493
+      "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
6499 6494
     },
6500 6495
     "multicast-dns": {
6501 6496
       "version": "6.2.3",
@@ -6517,7 +6512,6 @@
6517 6512
       "version": "2.10.0",
6518 6513
       "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz",
6519 6514
       "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==",
6520
-      "dev": true,
6521 6515
       "optional": true
6522 6516
     },
6523 6517
     "nanomatch": {
@@ -7124,7 +7118,6 @@
7124 7118
       "version": "1.0.1",
7125 7119
       "resolved": "https://registry.npmjs.org/original/-/original-1.0.1.tgz",
7126 7120
       "integrity": "sha512-IEvtB5vM5ULvwnqMxWBLxkS13JIEXbakizMSo3yoPNPCIWzg8TG3Usn/UhXoZFM/m+FuEA20KdzPSFq/0rS+UA==",
7127
-      "dev": true,
7128 7121
       "requires": {
7129 7122
         "url-parse": "~1.4.0"
7130 7123
       }
@@ -7807,8 +7800,7 @@
7807 7800
     "querystringify": {
7808 7801
       "version": "2.0.0",
7809 7802
       "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.0.0.tgz",
7810
-      "integrity": "sha512-eTPo5t/4bgaMNZxyjWx6N2a6AuE0mq51KWvpc7nU/MAqixcI6v6KrGUKES0HaomdnolQBBXU/++X6/QQ9KL4tw==",
7811
-      "dev": true
7803
+      "integrity": "sha512-eTPo5t/4bgaMNZxyjWx6N2a6AuE0mq51KWvpc7nU/MAqixcI6v6KrGUKES0HaomdnolQBBXU/++X6/QQ9KL4tw=="
7812 7804
     },
7813 7805
     "randomatic": {
7814 7806
       "version": "3.0.0",
@@ -8187,8 +8179,7 @@
8187 8179
     "requires-port": {
8188 8180
       "version": "1.0.0",
8189 8181
       "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
8190
-      "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=",
8191
-      "dev": true
8182
+      "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
8192 8183
     },
8193 8184
     "resolve": {
8194 8185
       "version": "1.8.1",
@@ -8271,9 +8262,9 @@
8271 8262
       }
8272 8263
     },
8273 8264
     "rxjs": {
8274
-      "version": "6.2.1",
8275
-      "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.1.tgz",
8276
-      "integrity": "sha512-OwMxHxmnmHTUpgO+V7dZChf3Tixf4ih95cmXjzzadULziVl/FKhHScGLj4goEw9weePVOH2Q0+GcCBUhKCZc/g==",
8265
+      "version": "6.2.2",
8266
+      "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.2.tgz",
8267
+      "integrity": "sha512-0MI8+mkKAXZUF9vMrEoPnaoHkfzBPP4IGwUYRJhIRJF6/w3uByO1e91bEHn8zd43RdkTMKiooYKmwz7RH6zfOQ==",
8277 8268
       "requires": {
8278 8269
         "tslib": "^1.9.0"
8279 8270
       }
@@ -8959,6 +8950,29 @@
8959 8950
         }
8960 8951
       }
8961 8952
     },
8953
+    "sockjs-client-web": {
8954
+      "version": "1.1.1-alpha.2",
8955
+      "resolved": "https://registry.npmjs.org/sockjs-client-web/-/sockjs-client-web-1.1.1-alpha.2.tgz",
8956
+      "integrity": "sha512-5z0kLtfyhWym0d04VQrAxB+5+85OY6T82gFYhChF4JcsWWJInVLt2frK95bnD2igl3jtgGaf/V5yA9xrTNoy7A==",
8957
+      "requires": {
8958
+        "debug": "^2.2.0",
8959
+        "eventsource": "~0.1.6",
8960
+        "faye-websocket": "~0.11.0",
8961
+        "inherits": "^2.0.1",
8962
+        "json3": "^3.3.2",
8963
+        "url-parse": "^1.1.1"
8964
+      },
8965
+      "dependencies": {
8966
+        "faye-websocket": {
8967
+          "version": "0.11.1",
8968
+          "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.11.1.tgz",
8969
+          "integrity": "sha1-8O/hjE9W5PQK/H4Gxxn9XuYYjzg=",
8970
+          "requires": {
8971
+            "websocket-driver": ">=0.5.1"
8972
+          }
8973
+        }
8974
+      }
8975
+    },
8962 8976
     "source-list-map": {
8963 8977
       "version": "2.0.0",
8964 8978
       "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.0.tgz",
@@ -9676,6 +9690,15 @@
9676 9690
       "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
9677 9691
       "dev": true
9678 9692
     },
9693
+    "typedarray-to-buffer": {
9694
+      "version": "3.1.5",
9695
+      "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
9696
+      "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
9697
+      "optional": true,
9698
+      "requires": {
9699
+        "is-typedarray": "^1.0.0"
9700
+      }
9701
+    },
9679 9702
     "typescript": {
9680 9703
       "version": "2.7.2",
9681 9704
       "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.7.2.tgz",
@@ -9926,7 +9949,6 @@
9926 9949
       "version": "1.4.1",
9927 9950
       "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.1.tgz",
9928 9951
       "integrity": "sha512-x95Td74QcvICAA0+qERaVkRpTGKyBHHYdwL2LXZm5t/gBtCB9KQSO/0zQgSTYEV1p0WcvSg79TLNPSvd5IDJMQ==",
9929
-      "dev": true,
9930 9952
       "requires": {
9931 9953
         "querystringify": "^2.0.0",
9932 9954
         "requires-port": "^1.0.0"
@@ -10413,11 +10435,22 @@
10413 10435
         "webpack-core": "^0.6.8"
10414 10436
       }
10415 10437
     },
10438
+    "websocket": {
10439
+      "version": "1.0.26",
10440
+      "resolved": "https://registry.npmjs.org/websocket/-/websocket-1.0.26.tgz",
10441
+      "integrity": "sha512-fjcrYDPIQxpTnqFQ9JjxUQcdvR89MFAOjPBlF+vjOt49w/XW4fJknUoMz/mDIn2eK1AdslVojcaOxOqyZZV8rw==",
10442
+      "optional": true,
10443
+      "requires": {
10444
+        "debug": "^2.2.0",
10445
+        "nan": "^2.3.3",
10446
+        "typedarray-to-buffer": "^3.1.2",
10447
+        "yaeti": "^0.0.6"
10448
+      }
10449
+    },
10416 10450
     "websocket-driver": {
10417 10451
       "version": "0.7.0",
10418 10452
       "resolved": "https://registry.npmjs.org/websocket-driver/-/websocket-driver-0.7.0.tgz",
10419 10453
       "integrity": "sha1-DK+dLXVdk67gSdS90NP+LMoqJOs=",
10420
-      "dev": true,
10421 10454
       "requires": {
10422 10455
         "http-parser-js": ">=0.4.0",
10423 10456
         "websocket-extensions": ">=0.1.1"
@@ -10426,8 +10459,7 @@
10426 10459
     "websocket-extensions": {
10427 10460
       "version": "0.1.3",
10428 10461
       "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz",
10429
-      "integrity": "sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==",
10430
-      "dev": true
10462
+      "integrity": "sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg=="
10431 10463
     },
10432 10464
     "when": {
10433 10465
       "version": "3.6.4",
@@ -10565,6 +10597,12 @@
10565 10597
       "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==",
10566 10598
       "dev": true
10567 10599
     },
10600
+    "yaeti": {
10601
+      "version": "0.0.6",
10602
+      "resolved": "https://registry.npmjs.org/yaeti/-/yaeti-0.0.6.tgz",
10603
+      "integrity": "sha1-8m9ITXJoTPQr7ft2lwqhYI+/lXc=",
10604
+      "optional": true
10605
+    },
10568 10606
     "yallist": {
10569 10607
       "version": "2.1.2",
10570 10608
       "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",

+ 3
- 1
package.json Visa fil

@@ -20,9 +20,11 @@
20 20
     "@angular/platform-browser": "^6.0.3",
21 21
     "@angular/platform-browser-dynamic": "^6.0.3",
22 22
     "@angular/router": "^6.0.3",
23
+    "@stomp/ng2-stompjs": "^4.0.1",
23 24
     "angular-in-memory-web-api": "^0.6.0",
24 25
     "core-js": "^2.5.4",
25
-    "rxjs": "^6.0.0",
26
+    "rxjs": "^6.2.2",
27
+    "sockjs-client-web": "^1.1.1-alpha.2",
26 28
     "zone.js": "^0.8.26"
27 29
   },
28 30
   "devDependencies": {

+ 29
- 1
src/app/app.module.ts Visa fil

@@ -2,6 +2,8 @@ import { BrowserModule } from '@angular/platform-browser';
2 2
 import { NgModule } from '@angular/core';
3 3
 import { FormsModule } from '@angular/forms';
4 4
 import { HttpClientModule } from '@angular/common/http';
5
+import { StompConfig, StompService } from '@stomp/ng2-stompjs';
6
+import * as SockJS from 'sockjs-client';
5 7
 
6 8
 import { AppComponent } from './app.component';
7 9
 import { StatusComponent } from './timeline/status/status.component';
@@ -16,6 +18,26 @@ import { MessageComponent } from './inbox/message/message.component';
16 18
 import { RouterModule, Routes } from '@angular/router';
17 19
 import { ChatroomComponent } from './chatroom/chatroom.component';
18 20
 
21
+export function socketProvider() {
22
+	return new SockJS('http://localhost:8080/stomp');
23
+}
24
+
25
+const stompConfig: StompConfig = {
26
+	url: socketProvider,
27
+
28
+	headers: {
29
+		login: 'guest',
30
+		passcode: 'guest'
31
+	},
32
+
33
+	heartbeat_in: 0,
34
+	heartbeat_out: 5000,
35
+
36
+	reconnect_delay: 5000,
37
+	debug: true
38
+
39
+};
40
+
19 41
 const appRoutes: Routes = [
20 42
 	{ path: '', component: TimelineComponent },
21 43
 	{ path: 'chatroom', component: ChatroomComponent }
@@ -44,7 +66,13 @@ const appRoutes: Routes = [
44 66
 			{ enableTracing: false }
45 67
 		),
46 68
 	],
47
-	providers: [],
69
+	providers: [
70
+		StompService,
71
+		{
72
+			provide: StompConfig,
73
+			useValue: stompConfig
74
+		}
75
+	],
48 76
 	bootstrap: [AppComponent]
49 77
 })
50 78
 export class AppModule { }

+ 3
- 1
src/app/post.service.ts Visa fil

@@ -7,7 +7,9 @@ import { HttpClient, HttpParams } from '@angular/common/http';
7 7
 
8 8
 export class PostService {
9 9
 
10
-	constructor( private http: HttpClient ) {}
10
+	constructor(private http: HttpClient) {
11
+
12
+	}
11 13
 
12 14
 	getAllPosts() {
13 15
 		return this.http.get('/api/post/all').toPromise();

+ 27
- 3
src/app/timeline/timeline.component.ts Visa fil

@@ -1,4 +1,7 @@
1
-import { Component, OnInit } from '@angular/core';
1
+import { Component, OnInit, OnDestroy } from '@angular/core';
2
+import { Observable } from 'rxjs';
3
+import { Subscription  } from 'rxjs';
4
+import { StompService } from '@stomp/ng2-stompjs';
2 5
 import { PostService } from '../post.service';
3 6
 
4 7
 @Component({
@@ -6,13 +9,34 @@ import { PostService } from '../post.service';
6 9
 	templateUrl: './timeline.component.html',
7 10
 	styleUrls: ['./timeline.component.css']
8 11
 })
12
+
9 13
 export class TimelineComponent implements OnInit {
14
+	private subscription: Subscription;
15
+	public messages: Observable<any>;
16
+
17
+	public subscribed: boolean;
18
+	public mq: Array<string> = [];
19
+	public count = 0;
20
+	private _counter = 1;
21
+
10 22
 	posts: any;
11 23
 
12
-	constructor( private postService: PostService ) { }
24
+	constructor(
25
+		private postService: PostService,
26
+		private _stompService: StompService) { }
13 27
 
14 28
 	ngOnInit() {
15
-		this.getAllPostsFromService();
29
+		this.subscribed = false;
30
+		this.subscribe();
31
+		// this.getAllPostsFromService();
32
+	}
33
+
34
+	public subscribe() {
35
+		if (this.subscribed) {
36
+			return;
37
+		}
38
+
39
+		this.messages = this._stompService.subscribe('')
16 40
 	}
17 41
 
18 42
 	async getAllPostsFromService() {