Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 13 example for Relay #515

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
de2b687
initial commit of basic angular app
jemboh Feb 7, 2022
60725d8
adding angular cache folder to gitignore
jemboh Feb 7, 2022
57ccd2d
added messages component to display messages
jemboh Feb 7, 2022
37abcc8
Added libraries needed to run js-waku and js-waku itself
jemboh Feb 8, 2022
15ae29b
Configured CommonJS dependencies to stop warnings
jemboh Feb 8, 2022
4100785
Added paths to crypto and stream libraries so TS can find them
jemboh Feb 8, 2022
a277388
[wip] Adding types for 'time-cache' library
jemboh Feb 8, 2022
2c946f9
Adding polyfills for 'process' and 'global'
jemboh Feb 8, 2022
288a27e
pointing to local build on js-waku rather than packaged
jemboh Feb 10, 2022
fccae93
buffer polyfills
jemboh Feb 10, 2022
e54220c
added protons type module
jemboh Feb 10, 2022
a860ff3
[wip] removed message service for now
jemboh Feb 10, 2022
6de338c
Angular (12) example of send/receive with waku relay
jemboh Feb 10, 2022
86b1bf2
adding protons and removing npm
jemboh Feb 15, 2022
f1def36
message html formatting
jemboh Feb 15, 2022
7e0f29f
implemented message interface
jemboh Feb 15, 2022
9b62c9e
prepended waku namespace for npmjs
jemboh Feb 15, 2022
95804ff
updated ts target due to BigInt usage
jemboh Feb 15, 2022
8d79ad0
Told typescript that waku object really is a type of Waku!
jemboh Feb 15, 2022
4ed9724
updated readme
jemboh Feb 15, 2022
9d5e572
updated wakuconnect url
jemboh Feb 15, 2022
35306e8
delete relay observer on component destruction
jemboh Feb 15, 2022
ecadaeb
Add relay-angular-chat to example CI
D4nte Feb 16, 2022
842308b
added bl types to the root for angular example
jemboh Feb 16, 2022
fa93ffb
removed gitignore entry for yarn lock files
jemboh Feb 16, 2022
9a4549f
adding yarn lockfile
jemboh Feb 16, 2022
684fdd3
shortened yarn command
jemboh Feb 16, 2022
024fa1a
destroy component on page reload
jemboh Feb 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/*
.nyc_output
.angular
build
node_modules
src/**.js
Expand Down
26 changes: 26 additions & 0 deletions examples/relay-angular-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Minimal Angular (v13) Waku Relay App

**Demonstrates**:

- Group messaging
- Angular/JavaScript
- Waku Relay
- Protobuf using `protons`
- No async/await syntax

A barebones messaging app to illustrate the [Angular Relay guide](https://docs.wakuconnect.dev/docs/guides/10_angular_relay/).

To run a development version locally, do:

```shell
git clone https://github.com/status-im/js-waku/ ; cd js-waku
npm install # Install dependencies for js-waku
npm run build # Build js-waku
cd examples/relay-reactjs-chat
yarn # Install dependencies for the web app
yarn run start # Start development server to serve the web app on http://localhost:4200/
jemboh marked this conversation as resolved.
Show resolved Hide resolved
```

### Known issues

There is a problem when using `npm` to install/run the Angular app.
jemboh marked this conversation as resolved.
Show resolved Hide resolved
130 changes: 130 additions & 0 deletions examples/relay-angular-chat/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"relay-angular-chat": {
"projectType": "application",
"schematics": {
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/relay-angular-chat",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": [],
"allowedCommonJsDependencies": [
"libp2p-gossipsub/src/utils",
"rlp",
"multiaddr/src/convert",
"varint",
"multihashes",
"@chainsafe/libp2p-noise/dist/src/noise",
"debug",
"libp2p",
"libp2p-bootstrap",
"libp2p-crypto",
"libp2p-websockets",
"libp2p-websockets/src/filters",
"libp2p/src/ping",
"multiaddr",
"peer-id",
"buffer",
"crypto",
"ecies-geth",
"secp256k1",
"libp2p-gossipsub",
"it-concat",
"protons"
]
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "relay-angular-chat:build:production"
},
"development": {
"browserTarget": "relay-angular-chat:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "relay-angular-chat:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
}
}
}
},
"defaultProject": "relay-angular-chat"
}
44 changes: 44 additions & 0 deletions examples/relay-angular-chat/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/relay-angular-chat'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};
44 changes: 44 additions & 0 deletions examples/relay-angular-chat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@waku/relay-angular-chat",
"version": "0.1.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "~13.2.0",
"@angular/common": "~13.2.0",
"@angular/compiler": "~13.2.0",
"@angular/core": "~13.2.0",
"@angular/forms": "~13.2.0",
"@angular/platform-browser": "~13.2.0",
"@angular/platform-browser-dynamic": "~13.2.0",
"@angular/router": "~13.2.0",
"crypto-browserify": "^3.12.0",
"js-waku": "file:../../build/esm",
"protons": "^2.0.3",
jemboh marked this conversation as resolved.
Show resolved Hide resolved
"rxjs": "~7.5.0",
"stream-browserify": "^3.0.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~13.2.2",
"@angular/cli": "~13.2.2",
"@angular/compiler-cli": "~13.2.0",
"@types/bl": "^5.0.2",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
"jasmine-core": "~4.0.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.1.0",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.5.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'protons';
15 changes: 15 additions & 0 deletions examples/relay-angular-chat/src/@types/time-cache/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare module "time-cache" {

interface ITimeCache {
put(key: string, value: any, validity: number): void;
get(key: string): any;
has(key: string): boolean;
}

type TimeCache = ITimeCache;

function TimeCache(options: object): TimeCache;

export = TimeCache;

}
25 changes: 25 additions & 0 deletions examples/relay-angular-chat/src/app/app.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Application-wide Styles */
h1 {
color: #369;
font-family: Arial, Helvetica, sans-serif;
font-size: 250%;
}
h2,
h3 {
color: #444;
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
}
body {
margin: 2em;
}
body,
input[type="text"],
button {
color: #333;
font-family: Cambria, Georgia, serif;
}
/* everywhere else */
* {
font-family: Arial, Helvetica, sans-serif;
}
9 changes: 9 additions & 0 deletions examples/relay-angular-chat/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>{{title}}</h1>
<p>Waku node's status: {{ wakuStatus }}</p>
<button (click)="sendMessageOnClick()" [disabled]="wakuStatus !== 'Connected'">Send Message</button>
<h2>Messages</h2>
<ul class="messages">
<li *ngFor="let message of messages">
<span>{{ message.timestamp }} {{ message.text }}</span>
</li>
</ul>
31 changes: 31 additions & 0 deletions examples/relay-angular-chat/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
});

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it(`should have as title 'relay-angular-chat'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('relay-angular-chat');
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('.content span')?.textContent).toContain('relay-angular-chat app is running!');
});
});
Loading