mirror of
https://github.com/logos-messaging/examples.waku.org.git
synced 2026-01-05 22:33:08 +00:00
use latest waku
This commit is contained in:
parent
9190da0e0d
commit
95aba1b173
8293
examples/relay-angular-chat/package-lock.json
generated
8293
examples/relay-angular-chat/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -21,9 +21,8 @@
|
|||||||
"@angular/platform-browser": "~14.2.11",
|
"@angular/platform-browser": "~14.2.11",
|
||||||
"@angular/platform-browser-dynamic": "~14.2.11",
|
"@angular/platform-browser-dynamic": "~14.2.11",
|
||||||
"@angular/router": "~14.2.11",
|
"@angular/router": "~14.2.11",
|
||||||
"@waku/core": "^0.0.6",
|
"@waku/sdk": "^0.0.16",
|
||||||
"@waku/create": "^0.0.4",
|
"@waku/interfaces": "^0.0.15",
|
||||||
"@waku/interfaces": "^0.0.5",
|
|
||||||
"protobufjs": "^7.1.2",
|
"protobufjs": "^7.1.2",
|
||||||
"rxjs": "~7.5.7",
|
"rxjs": "~7.5.7",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
import { Component, OnInit } from "@angular/core";
|
import { Component, OnInit } from "@angular/core";
|
||||||
import { WakuService } from "../waku.service";
|
import { WakuService } from "../waku.service";
|
||||||
import type { WakuPrivacy } from "@waku/interfaces";
|
import type { RelayNode, Unsubscribe } from "@waku/interfaces";
|
||||||
import protobuf from "protobufjs";
|
import protobuf from "protobufjs";
|
||||||
import { DecoderV0, EncoderV0 } from "@waku/core/lib/waku_message/version_0";
|
import { waku, createDecoder, createEncoder } from "@waku/sdk";
|
||||||
import type { MessageV0 } from "@waku/core/lib/waku_message/version_0";
|
|
||||||
|
|
||||||
const ProtoChatMessage = new protobuf.Type("ChatMessage")
|
const ProtoChatMessage = new protobuf.Type("ChatMessage")
|
||||||
.add(new protobuf.Field("timestamp", 1, "uint32"))
|
.add(new protobuf.Field("timestamp", 1, "uint32"))
|
||||||
@ -21,17 +20,17 @@ interface MessageInterface {
|
|||||||
})
|
})
|
||||||
export class MessagesComponent implements OnInit {
|
export class MessagesComponent implements OnInit {
|
||||||
contentTopic: string = `/js-waku-examples/1/chat/proto`;
|
contentTopic: string = `/js-waku-examples/1/chat/proto`;
|
||||||
decoder: DecoderV0;
|
decoder: waku.Decoder;
|
||||||
encoder: EncoderV0;
|
encoder: waku.Encoder;
|
||||||
messages: MessageInterface[] = [];
|
messages: MessageInterface[] = [];
|
||||||
messageCount: number = 0;
|
messageCount: number = 0;
|
||||||
waku!: WakuPrivacy;
|
waku!: RelayNode;
|
||||||
wakuStatus!: string;
|
wakuStatus!: string;
|
||||||
deleteObserver?: () => void;
|
deleteObserver?: Unsubscribe;
|
||||||
|
|
||||||
constructor(private wakuService: WakuService) {
|
constructor(private wakuService: WakuService) {
|
||||||
this.decoder = new DecoderV0(this.contentTopic);
|
this.decoder = createDecoder(this.contentTopic);
|
||||||
this.encoder = new EncoderV0(this.contentTopic);
|
this.encoder = createEncoder({ contentTopic: this.contentTopic });
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -41,10 +40,10 @@ export class MessagesComponent implements OnInit {
|
|||||||
|
|
||||||
this.wakuService.waku.subscribe((waku) => {
|
this.wakuService.waku.subscribe((waku) => {
|
||||||
this.waku = waku;
|
this.waku = waku;
|
||||||
this.deleteObserver = this.waku.relay.addObserver(
|
this.deleteObserver = this.waku.relay.subscribe(
|
||||||
this.decoder,
|
this.decoder,
|
||||||
this.processIncomingMessages
|
this.processIncomingMessages
|
||||||
);
|
) as Unsubscribe;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.onbeforeunload = () => this.ngOnDestroy();
|
window.onbeforeunload = () => this.ngOnDestroy();
|
||||||
@ -69,7 +68,7 @@ export class MessagesComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
processIncomingMessages = (wakuMessage: MessageV0) => {
|
processIncomingMessages = (wakuMessage: waku.DecodedMessage) => {
|
||||||
if (!wakuMessage.payload) return;
|
if (!wakuMessage.payload) return;
|
||||||
|
|
||||||
const { text, timestamp } = ProtoChatMessage.decode(
|
const { text, timestamp } = ProtoChatMessage.decode(
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
import { BehaviorSubject, Subject } from "rxjs";
|
import { BehaviorSubject, Subject } from "rxjs";
|
||||||
import { createPrivacyNode } from "@waku/create";
|
import { createRelayNode, waitForRemotePeer } from "@waku/sdk";
|
||||||
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
|
import type { RelayNode } from "@waku/interfaces";
|
||||||
import type { WakuPrivacy } from "@waku/interfaces";
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: "root",
|
providedIn: "root",
|
||||||
})
|
})
|
||||||
export class WakuService {
|
export class WakuService {
|
||||||
private wakuSubject = new Subject<WakuPrivacy>();
|
private wakuSubject = new Subject<RelayNode>();
|
||||||
public waku = this.wakuSubject.asObservable();
|
public waku = this.wakuSubject.asObservable();
|
||||||
|
|
||||||
private wakuStatusSubject = new BehaviorSubject("");
|
private wakuStatusSubject = new BehaviorSubject("");
|
||||||
@ -17,7 +16,7 @@ export class WakuService {
|
|||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
createPrivacyNode({ defaultBootstrap: true }).then((waku) => {
|
createRelayNode({ defaultBootstrap: true }).then((waku) => {
|
||||||
waku.start().then(() => {
|
waku.start().then(() => {
|
||||||
this.wakuSubject.next(waku);
|
this.wakuSubject.next(waku);
|
||||||
this.wakuStatusSubject.next("Connecting...");
|
this.wakuStatusSubject.next("Connecting...");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user