fix(angular): use new js-waku api

This commit is contained in:
fryorcraken.eth 2022-09-02 15:17:05 +10:00
parent ef955e7133
commit b80e8fcda7
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 24 additions and 18 deletions

View File

@ -1,27 +1,30 @@
import { Injectable } from '@angular/core';
import { Waku } from 'js-waku';
import { BehaviorSubject, Subject } from 'rxjs';
import { Injectable } from "@angular/core";
import { Waku } from "js-waku";
import { BehaviorSubject, Subject } from "rxjs";
import { createWaku } from "js-waku/lib/create_waku";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer";
@Injectable({
providedIn: 'root'
providedIn: "root",
})
export class WakuService {
private wakuSubject = new Subject<Waku>();
public waku = this.wakuSubject.asObservable();
private wakuStatusSubject = new BehaviorSubject('');
private wakuStatusSubject = new BehaviorSubject("");
public wakuStatus = this.wakuStatusSubject.asObservable();
constructor() { }
constructor() {}
init() {
Waku.create({ bootstrap: { default: true } }).then(waku => {
this.wakuSubject.next(waku);
this.wakuStatusSubject.next('Connecting...');
createWaku({ defaultBootstrap: true }).then((waku) => {
waku.start().then(() => {
this.wakuSubject.next(waku);
this.wakuStatusSubject.next("Connecting...");
waku.waitForRemotePeer().then(() => {
this.wakuStatusSubject.next('Connected');
waitForRemotePeer(waku).then(() => {
this.wakuStatusSubject.next("Connected");
});
});
});
}

View File

@ -1,12 +1,15 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from "@angular/core";
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import { AppModule } from "./app/app.module";
import { environment } from "./environments/environment";
import "zone.js";
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));