Skip to content

Commit 758be2c

Browse files
authored
Merge pull request #6 from Share-Code-Development/develop
Develop
2 parents e0bba8d + 7471219 commit 758be2c

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/app/pages/code/view-snippet/view-snippet.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ export class ViewSnippetComponent implements OnInit, OnDestroy {
3737
});
3838
this.sub.add(
3939
this.snippetService.onSnippetMessages(this.codeId).subscribe({
40-
next: (res) => {
40+
next: (res) => {
4141
this.processMessage(res);
42-
},
43-
error: (err) => {
44-
console.error(err);
45-
}
46-
}))
42+
},
43+
error: (err) => {
44+
console.error(err);
45+
}
46+
}))
4747
}
4848
}
4949

src/app/services/snippet.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as signalR from '@microsoft/signalr';
77
import { environment } from '@environment';
88
import { ELocalStorage } from 'src/app/models/common.enum';
99
import { ESnippetSignalREvents } from '@app/models/snippet.enum';
10+
import { UserService } from './user.service';
1011

1112
@Injectable({
1213
providedIn: 'root'
@@ -19,17 +20,21 @@ export class SnippetService {
1920

2021
constructor(
2122
private http: HttpService,
23+
private userService: UserService
2224
) {
2325
}
2426

2527

2628
private startConnection(snippetId: string) {
2729
return new Observable<void>(observer => {
30+
const signalROptions: signalR.IHttpConnectionOptions = {
31+
withCredentials: true
32+
}
33+
if (this.userService.isLoggedIn) {
34+
signalROptions.accessTokenFactory = () => `Bearer ${localStorage.getItem(ELocalStorage.token)}`;
35+
}
2836
this.connection = new signalR.HubConnectionBuilder()
29-
.withUrl(`${environment.apiLiveUrl}/snippet?snippetId=${snippetId}`, {
30-
withCredentials: true,
31-
accessTokenFactory: () => 'Bearer ' + localStorage.getItem(ELocalStorage.token) || '',
32-
})
37+
.withUrl(`${environment.apiLiveUrl}/snippet?snippetId=${snippetId}`, signalROptions)
3338
.build();
3439
this.connection.start().then(() => {
3540
observer.next();

src/app/services/user.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class UserService {
117117
if (options?.recentSnippets) {
118118
urlParams.recentSnippets = true;
119119
}
120-
return this.http.getAsync(`${this.userEndPoint}/${userId}/snippets`, params);
120+
return this.http.getAsync(`${this.userEndPoint}/${userId}/snippets`, urlParams);
121121
}
122122

123123
}

src/environments/environment.prod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const environment = {
22
production: true,
33
apiUrl: 'https://api-sc.alenalex.me/v1/api',
4+
apiLiveUrl: 'https://api-sc.alenalex.me/v1/live',
45
googleClientId: '939503022711-9m2d1ejrp8ufj52m52iab1klqeqdk37k.apps.googleusercontent.com'
56
};

0 commit comments

Comments
 (0)