This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.messageGrpcService.sendMessage({ message }).subscribe(...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public messages: Observable<Message.AsObject[]> = this.chatGrpcService.getChat() | |
.pipe(map(res => res.messagesList)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public onSubmit(): void { | |
if (this.form.valid) { | |
this.authGrpcService.auth(this.form.value) | |
.subscribe( | |
res => { | |
this.authService.loggedIn(res.token); | |
this.form.reset(); | |
this.router.navigateByUrl('/chat'); | |
}, | |
err => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function grpcJwtMetadata(token: string = null): Metadata { | |
return { | |
Authorization: token || localStorage.getItem(environment.token), | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class ChatGrpcService { | |
constructor(private client: ChatServicePromiseClient) { | |
} | |
public getChat(): Observable<ChatList.AsObject> { | |
const req = new Stub(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function grpcStream<T>(client: ClientReadableStream<T>): Observable<T> { | |
let stream: ClientReadableStream<T> = null; | |
let subscriptionCounter = 0; | |
const data: Observable<any> = new Observable((observer: Observer<T>) => { | |
if (subscriptionCounter === 0) { | |
stream = client; | |
} | |
subscriptionCounter++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class AuthGrpcService { | |
constructor(private client: AuthServicePromiseClient) { | |
} | |
public auth(data: AuthReq.AsObject): Observable<AuthRes.AsObject> { | |
const req = new AuthReq(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function grpcUnary<T>(promise): Observable<T> { | |
return from(promise).pipe( | |
map((response: jspb.Message) => response.toObject()), | |
catchError((error: Status) => { | |
if (error.code === StatusCode.UNAUTHENTICATED) { | |
jwtAuthError$.next(); | |
} | |
return throwError(error); | |
}), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class AuthGrpcService { | |
constructor(private client: AuthServicePromiseClient) { | |
} | |
public auth(data: AuthReq.AsObject): Observable<AuthRes.AsObject> { | |
const req = new AuthReq(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class AuthService { | |
private ngOnDestroy$ = new Subject<void>(); | |
private loggedInSubject$ = new ReplaySubject<boolean>(1); | |
constructor( | |
private router: Router, |