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