@@ -5,80 +5,80 @@ import Vue from "vue";
5
5
import { Component } from "vue-property-decorator" ;
6
6
7
7
import { map , filter , switchMap } from 'rxjs/operators' ;
8
- import { adapt } from '../stream-adapter' ;
8
+ import { adapt } from '../stream-adapter' ;
9
9
10
10
@Component ( { } )
11
11
export default class MainComponent extends Vue {
12
- connection : HubConnection = null ;
13
-
14
- get messages ( ) : string [ ] {
15
- return this . $store . state . messages ;
16
- }
17
-
18
- get newMessage ( ) :string {
19
- return this . $store . state . newMessage ;
20
- }
21
-
22
- set newMessage ( value : string ) {
23
- this . $store . commit ( 'updateNewMessage' , value ) ;
24
- }
25
-
26
- get newRestMessage ( ) :string {
27
- return this . $store . state . newRestMessage ;
28
- }
29
-
30
- set newRestMessage ( value : string ) {
31
- this . $store . commit ( 'updateNewRestMessage' , value ) ;
32
- }
33
-
34
- get number ( ) :string {
35
- return this . $store . state . number ;
36
- }
37
-
38
- set number ( value : string ) {
39
- this . $store . commit ( 'updateNumber' , value ) ;
40
- }
41
-
42
- created ( ) {
43
- this . connection = new HubConnectionBuilder ( )
44
- . configureLogging ( LogLevel . Information )
45
- . withUrl ( "/app" )
46
- . withHubProtocol ( new MessagePackHubProtocol ( ) )
47
- . build ( ) ;
48
-
49
- console . log ( this . connection ) ;
50
-
51
- this . connection . on ( "Send" , message => {
52
- this . $store . commit ( "addNewMessage" , message ) ;
53
- } ) ;
54
-
55
- this . connection . start ( ) . catch ( error => console . error ( error ) ) ;
56
- }
57
-
58
- async addMessage ( ) {
59
- await this . connection . invoke ( "Send" , { Message : this . newMessage } ) ;
60
- this . $store . commit ( "updateNewMessage" , null ) ;
61
- }
62
-
63
- async addRestMessage ( ) {
64
- await fetch ( "/message" , {
65
- method : "post" ,
66
- body : JSON . stringify ( { Message : this . newRestMessage } ) ,
67
- headers : {
68
- "content-type" : "application/json"
69
- }
70
- } ) ;
71
- this . $store . commit ( "updateNewMessage" , null ) ;
72
- }
73
-
74
- async countDown ( ) {
75
- var stream = this . connection . stream < string > ( "CountDown" , parseInt ( this . number ) ) ;
76
- var store = this . $store ;
77
-
78
- adapt ( stream ) . pipe (
79
- filter ( x => parseInt ( x ) % 2 === 0 )
80
- ) . subscribe ( x => store . commit ( "addNewMessage" , x ) ) ;
81
-
82
- this . number = null ;
83
- }
12
+ connection : HubConnection = null ;
13
+
14
+ get messages ( ) : string [ ] {
15
+ return this . $store . state . messages ;
16
+ }
17
+
18
+ get newMessage ( ) : string {
19
+ return this . $store . state . newMessage ;
20
+ }
21
+
22
+ set newMessage ( value : string ) {
23
+ this . $store . commit ( 'updateNewMessage' , value ) ;
24
+ }
25
+
26
+ get newRestMessage ( ) : string {
27
+ return this . $store . state . newRestMessage ;
28
+ }
29
+
30
+ set newRestMessage ( value : string ) {
31
+ this . $store . commit ( 'updateNewRestMessage' , value ) ;
32
+ }
33
+
34
+ get number ( ) : string {
35
+ return this . $store . state . number ;
36
+ }
37
+
38
+ set number ( value : string ) {
39
+ this . $store . commit ( 'updateNumber' , value ) ;
40
+ }
41
+
42
+ created ( ) {
43
+ this . connection = new HubConnectionBuilder ( )
44
+ . configureLogging ( LogLevel . Information )
45
+ . withUrl ( "/app" )
46
+ . withHubProtocol ( new MessagePackHubProtocol ( ) )
47
+ . build ( ) ;
48
+
49
+ console . log ( this . connection ) ;
50
+
51
+ this . connection . on ( "Send" , message => {
52
+ this . $store . commit ( "addNewMessage" , message ) ;
53
+ } ) ;
54
+
55
+ this . connection . start ( ) . catch ( error => console . error ( error ) ) ;
56
+ }
57
+
58
+ async addMessage ( ) {
59
+ await this . connection . invoke ( "Send" , { Message : this . newMessage } ) ;
60
+ this . $store . commit ( "updateNewMessage" , null ) ;
61
+ }
62
+
63
+ async addRestMessage ( ) {
64
+ await fetch ( "/message" , {
65
+ method : "post" ,
66
+ body : JSON . stringify ( { Message : this . newRestMessage } ) ,
67
+ headers : {
68
+ "content-type" : "application/json"
69
+ }
70
+ } ) ;
71
+ this . $store . commit ( "updateNewMessage" , null ) ;
72
+ }
73
+
74
+ async countDown ( ) {
75
+ var stream = this . connection . stream < string > ( "CountDown" , parseInt ( this . number ) ) ;
76
+ var store = this . $store ;
77
+
78
+ adapt ( stream ) . pipe (
79
+ filter ( x => parseInt ( x ) % 2 === 0 )
80
+ ) . subscribe ( x => store . commit ( "addNewMessage" , x ) ) ;
81
+
82
+ this . number = null ;
83
+ }
84
84
}
0 commit comments