32 lines
910 B
TypeScript
Raw Normal View History

2022-09-02 15:17:05 +10:00
import { Injectable } from "@angular/core";
import { BehaviorSubject, Subject } from "rxjs";
import { createPrivacyNode } from "@waku/create";
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
import type { WakuPrivacy } from "@waku/interfaces";
2022-06-17 10:48:15 +10:00
@Injectable({
2022-09-02 15:17:05 +10:00
providedIn: "root",
2022-06-17 10:48:15 +10:00
})
export class WakuService {
private wakuSubject = new Subject<WakuPrivacy>();
2022-06-17 10:48:15 +10:00
public waku = this.wakuSubject.asObservable();
2022-09-02 15:17:05 +10:00
private wakuStatusSubject = new BehaviorSubject("");
2022-06-17 10:48:15 +10:00
public wakuStatus = this.wakuStatusSubject.asObservable();
2022-09-02 15:17:05 +10:00
constructor() {}
2022-06-17 10:48:15 +10:00
init() {
createPrivacyNode({ defaultBootstrap: true }).then((waku) => {
2022-09-02 15:17:05 +10:00
waku.start().then(() => {
this.wakuSubject.next(waku);
this.wakuStatusSubject.next("Connecting...");
2022-06-17 10:48:15 +10:00
2022-09-02 15:17:05 +10:00
waitForRemotePeer(waku).then(() => {
this.wakuStatusSubject.next("Connected");
});
2022-06-17 10:48:15 +10:00
});
});
}
}