2022-09-02 15:17:05 +10:00
|
|
|
import { Injectable } from "@angular/core";
|
|
|
|
|
import { BehaviorSubject, Subject } from "rxjs";
|
2022-11-18 13:53:36 +11:00
|
|
|
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 {
|
2022-09-14 22:36:00 +10:00
|
|
|
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() {
|
2022-09-14 22:36:00 +10:00
|
|
|
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
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|