Skip to content

Commit

Permalink
don't disconnect signalr on create/join fail
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimalZed committed Apr 19, 2020
1 parent 4a99ee6 commit 2be43ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/app/modules/rtc/components/connection.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { selectHost } from "rtc/store/host/host.selectors";
export class ConnectionComponent {
public connected$ = merge(
this.rtc.open$.pipe(mapTo(true)),
this.rtc.createFailure$.pipe(mapTo(false)),
this.rtc.joinFailure$.pipe(mapTo(false)),
this.rtc.leave$.pipe(mapTo(false)),
this.rtc.close$.pipe(mapTo(false))
)
Expand Down
10 changes: 2 additions & 8 deletions src/app/modules/rtc/services/rtc-signaling.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,15 @@ export class RTCSignalingService implements OnDestroy {
return this.connection.invoke("create", name, password)
.catch((error) => {
console.error(error.message);
return this.connection.stop()
.then(() => {
throw error.message.split("HubException: ").pop();
});
throw error.message.split("HubException: ").pop();
});
}

public join(roomId: string, password: string): Promise<void> {
return this.connection.invoke("join", roomId, password)
.catch((error) => {
console.error(error.message);
return this.connection.stop()
.then(() => {
throw error.message.split("HubException: ").pop();
});
throw error.message.split("HubException: ").pop();
});
}

Expand Down
20 changes: 18 additions & 2 deletions src/app/modules/rtc/services/rtc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,26 @@ export class RTCService implements OnDestroy {
private create$ = this.createSubject
.pipe(
switchMap(({ name, password }) => this.connectSignaling().then(() => ({ name, password }))),
switchMap(({ name, password }) => this.signalingService.create(name, password)),
switchMap(({ name, password }) => this.signalingService.create(name, password).then(() => null).catch((error) => error)),
tap((errorMessage) => {
if (errorMessage) {
window.alert(`Could not create a room: ${errorMessage}`);
}
}),
shareReplay(1)
);

private createSuccess$ = this.create$
.pipe(
filter((errorMessage) => !errorMessage),
tap(() => this.store.dispatch(setHost()))
);

public createFailure$ = this.create$
.pipe(
filter((errorMessage) => errorMessage)
);

private joinSubject: Subject<{ roomId: string, password: string }> = new Subject();
private join$ = this.joinSubject
.pipe(
Expand Down Expand Up @@ -125,7 +141,7 @@ export class RTCService implements OnDestroy {
);

private subscription: Subscription = merge(
this.create$,
this.createSuccess$,
this.joinSuccess$,
this.open$,
this.processOffer$,
Expand Down

0 comments on commit 2be43ff

Please sign in to comment.