1
- <template >
2
- </template >
1
+ <template ></template >
3
2
4
3
<script >
5
- import * as signalR from ' @aspnet/signalr' ;
6
- import { createNamespacedHelpers } from ' vuex' ;
7
- const { mapGetters: commonGetters } = createNamespacedHelpers (' common' );
4
+ import * as signalR from " @aspnet/signalr" ;
5
+ import { createNamespacedHelpers } from " vuex" ;
6
+ import { getPassenger } from " @/api/passengers" ;
7
+ const { mapGetters: commonGetters } = createNamespacedHelpers (" common" );
8
8
const {
9
9
mapGetters: tripGetters ,
10
10
mapActions: tripActions
11
- } = createNamespacedHelpers (' trips' );
11
+ } = createNamespacedHelpers (" trips" );
12
12
13
13
export default {
14
- name: ' SignalRTrips' ,
14
+ name: " SignalRTrips" ,
15
15
data () {
16
16
return {};
17
17
},
18
18
computed: {
19
- ... commonGetters ([' notificationSystem' , ' user' ]),
20
- ... tripGetters ([' trip' , ' currentStep' , ' contentLoading' ])
19
+ ... commonGetters ([" notificationSystem" , " user" ]),
20
+ ... tripGetters ([" trip" , " currentStep" , " contentLoading" ])
21
21
},
22
22
watch: {
23
23
user (val , old ) {
@@ -30,123 +30,133 @@ export default {
30
30
}
31
31
},
32
32
methods: {
33
- ... tripActions ([' setTrip' , ' setCurrentStep' , ' createTrip' , ' getSignalRInfo' ]),
33
+ ... tripActions ([
34
+ " setTrip" ,
35
+ " setCurrentStep" ,
36
+ " createTrip" ,
37
+ " getSignalRInfo"
38
+ ]),
34
39
async getSignalRInformation () {
35
- let rawResponse = await this .getSignalRInfo (); // {url: '', status: 201};//await this.getSignalRInfo();
36
- if (rawResponse .status === 200 ) {
37
- let signalRInfo = rawResponse .data ;
38
- console .log (` Connection Endpoint: ${ signalRInfo .url } ` );
39
- return signalRInfo;
40
- } else {
41
- console .log (` getSignalRInfo Response status: ${ rawResponse .status } ` );
42
- throw ` Could not obtain SignalR info. Response was ${
43
- rawResponse .status
44
- } ` ;
45
- return null ;
40
+ let passengerInfo = await getPassenger (this .user .idToken .oid );
41
+ if (passengerInfo && passengerInfo .data ) {
42
+ // Pass in the current user email so messages can be sent to just the user.
43
+ let rawResponse = await this .getSignalRInfo (passengerInfo .data .email ); // {url: '', status: 201};//await this.getSignalRInfo();
44
+ if (rawResponse .status === 200 ) {
45
+ let signalRInfo = rawResponse .data ;
46
+ console .log (` Connection Endpoint: ${ signalRInfo .url } ` );
47
+ return signalRInfo;
48
+ } else {
49
+ console .log (` getSignalRInfo Response status: ${ rawResponse .status } ` );
50
+ throw ` Could not obtain SignalR info. Response was ${
51
+ rawResponse .status
52
+ } ` ;
53
+ return null ;
54
+ }
46
55
}
47
56
},
48
57
connectToSignalR () {
49
58
if (this .user !== null ) {
50
- this .getSignalRInformation ()
51
- .then (signalrInfo => {
52
- if (signalrInfo !== null && signalrInfo !== undefined ) {
53
- let options = {
54
- accessTokenFactory : () => signalrInfo .accessToken
55
- };
56
-
57
- let hubConnection = new signalR.HubConnectionBuilder ()
58
- .withUrl (signalrInfo .url , options)
59
- .configureLogging (signalR .LogLevel .Information )
60
- .build ();
59
+ this .getSignalRInformation ()
60
+ .then (signalrInfo => {
61
+ if (signalrInfo !== null && signalrInfo !== undefined ) {
62
+ let options = {
63
+ accessTokenFactory : () => signalrInfo .accessToken
64
+ };
61
65
62
- console .log (' Connected to SignalR' );
66
+ let hubConnection = new signalR.HubConnectionBuilder ()
67
+ .withUrl (signalrInfo .url , options)
68
+ .configureLogging (signalR .LogLevel .Information )
69
+ .build ();
63
70
64
- hubConnection .on (' tripUpdated' , trip => {
65
- console .log (` tripUpdated Trip code: ${ trip .code } ` );
66
- this .$toast .success (
67
- ` Trip Code: ${ trip .code } . Message: tripUpdated.` ,
68
- ' Trip Updated' ,
69
- this .notificationSystem .options .success
70
- );
71
- });
71
+ console .log (" Connected to SignalR" );
72
72
73
- hubConnection .on (' tripDriversNotified ' , trip => {
74
- console .log (` tripDriversNotified Trip code: ${ trip .code } ` );
75
- this .$toast .info (
76
- ` Trip Code: ${ trip .code } . Message: tripDriversNotified .` ,
77
- ' Drivers Notified ' ,
78
- this .notificationSystem .options .info
79
- );
80
- });
73
+ hubConnection .on (" tripUpdated " , trip => {
74
+ console .log (` tripUpdated Trip code: ${ trip .code } ` );
75
+ this .$toast .success (
76
+ ` Trip Code: ${ trip .code } . Message: tripUpdated .` ,
77
+ " Trip Updated " ,
78
+ this .notificationSystem .options .success
79
+ );
80
+ });
81
81
82
- hubConnection .on (' tripDriverPicked' , trip => {
83
- console .log (` tripDriverPicked Trip code: ${ trip .code } ` );
84
- this .setCurrentStep (2 );
85
- this .setTrip (trip);
86
- this .$toast .info (
87
- ` Trip Code: ${ trip .code } . Message: tripDriverPicked.` ,
88
- ' Driver Picked' ,
89
- this .notificationSystem .options .info
90
- );
91
- });
82
+ hubConnection .on (" tripDriversNotified" , trip => {
83
+ console .log (` tripDriversNotified Trip code: ${ trip .code } ` );
84
+ this .$toast .info (
85
+ ` Trip Code: ${ trip .code } . Message: tripDriversNotified.` ,
86
+ " Drivers Notified" ,
87
+ this .notificationSystem .options .info
88
+ );
89
+ });
92
90
93
- hubConnection .on (' tripStarting' , trip => {
94
- console .log (` tripStarting Trip code: ${ trip .code } ` );
95
- this .setCurrentStep (3 );
96
- this .$toast .info (
97
- ` Trip Code: ${ trip .code } . Message: tripStarting.` ,
98
- ' Trip Starting' ,
99
- this .notificationSystem .options .info
100
- );
101
- });
91
+ hubConnection .on (" tripDriverPicked" , trip => {
92
+ console .log (` tripDriverPicked Trip code: ${ trip .code } ` );
93
+ this .setCurrentStep (2 );
94
+ this .setTrip (trip);
95
+ this .$toast .info (
96
+ ` Trip Code: ${ trip .code } . Message: tripDriverPicked.` ,
97
+ " Driver Picked" ,
98
+ this .notificationSystem .options .info
99
+ );
100
+ });
102
101
103
- hubConnection .on (' tripRunning' , trip => {
104
- console .log (` tripRunning Trip code: ${ trip .code } ` );
105
- if (this .currentStep < 3 ) {
102
+ hubConnection .on (" tripStarting" , trip => {
103
+ console .log (` tripStarting Trip code: ${ trip .code } ` );
106
104
this .setCurrentStep (3 );
107
- }
108
- this .$toast .info (
109
- ` Trip Code: ${ trip .code } . Message: tripRunning.` ,
110
- ' Trip Running' ,
111
- this .notificationSystem .options .info
112
- );
113
- });
105
+ this .$toast .info (
106
+ ` Trip Code: ${ trip .code } . Message: tripStarting.` ,
107
+ " Trip Starting" ,
108
+ this .notificationSystem .options .info
109
+ );
110
+ });
114
111
115
- hubConnection .on (' tripCompleted' , trip => {
116
- console .log (` tripCompleted Trip code: ${ trip .code } ` );
117
- this .setCurrentStep (4 );
118
- this .$toast .success (
119
- ` Trip Code: ${ trip .code } . Message: tripCompleted.` ,
120
- ' Trip Completed' ,
121
- this .notificationSystem .options .success
122
- );
123
- });
112
+ hubConnection .on (" tripRunning" , trip => {
113
+ console .log (` tripRunning Trip code: ${ trip .code } ` );
114
+ if (this .currentStep < 3 ) {
115
+ this .setCurrentStep (3 );
116
+ }
117
+ this .$toast .info (
118
+ ` Trip Code: ${ trip .code } . Message: tripRunning.` ,
119
+ " Trip Running" ,
120
+ this .notificationSystem .options .info
121
+ );
122
+ });
124
123
125
- hubConnection .on (' tripAborted ' , trip => {
126
- console .log (` tripAborted Trip code: ${ trip .code } ` );
127
- this .setCurrentStep (0 );
128
- this .$toast .warning (
129
- ` Trip Code: ${ trip .code } . Message: tripAborted .` ,
130
- ' Trip Aborted ' ,
131
- this .notificationSystem .options .warning
132
- );
133
- });
124
+ hubConnection .on (" tripCompleted " , trip => {
125
+ console .log (` tripCompleted Trip code: ${ trip .code } ` );
126
+ this .setCurrentStep (4 );
127
+ this .$toast .success (
128
+ ` Trip Code: ${ trip .code } . Message: tripCompleted .` ,
129
+ " Trip Completed " ,
130
+ this .notificationSystem .options .success
131
+ );
132
+ });
134
133
135
- hubConnection .start ().catch (err => console .log (err .toString ()));
136
- } else {
137
- console .log (' signalrInfo is null' );
138
- }
139
- })
140
- .catch (err => {
141
- this .$toast .error (
142
- err .response ? err .response : err .message ? err .message : err,
143
- ' Error' ,
144
- this .notificationSystem .options .error
145
- );
146
- });
147
- }
148
- else {
149
- console .log (' Not connecting to SignalR because the user is not authenticated.' )
134
+ hubConnection .on (" tripAborted" , trip => {
135
+ console .log (` tripAborted Trip code: ${ trip .code } ` );
136
+ this .setCurrentStep (0 );
137
+ this .$toast .warning (
138
+ ` Trip Code: ${ trip .code } . Message: tripAborted.` ,
139
+ " Trip Aborted" ,
140
+ this .notificationSystem .options .warning
141
+ );
142
+ });
143
+
144
+ hubConnection .start ().catch (err => console .log (err .toString ()));
145
+ } else {
146
+ console .log (" signalrInfo is null" );
147
+ }
148
+ })
149
+ .catch (err => {
150
+ this .$toast .error (
151
+ err .response ? err .response : err .message ? err .message : err,
152
+ " Error" ,
153
+ this .notificationSystem .options .error
154
+ );
155
+ });
156
+ } else {
157
+ console .log (
158
+ " Not connecting to SignalR because the user is not authenticated."
159
+ );
150
160
}
151
161
}
152
162
},
0 commit comments