Commit 3a5e08e4 authored by Dennis Willers's avatar Dennis Willers :basketball:

Add Socket.io and test it on error page

parent 5477ea1c
This diff is collapsed.
......@@ -24,8 +24,10 @@
"@angular/platform-browser-dynamic": "~11.0.5",
"@angular/router": "~11.0.5",
"rxjs": "~6.6.0",
"socket.io": "^3.0.4",
"tslib": "^2.0.0",
"zone.js": "~0.10.2"
"zone.js": "~0.10.2",
"socket.io-client": "latest"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1100.5",
......
......@@ -7,6 +7,7 @@
<br>
<mat-progress-spinner color="primary" mode="determinate" value="value">
</mat-progress-spinner>
<button (click)="move('left')">Test me</button>
</div>
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
import {io} from 'socket.io-client';
@Component({
selector: 'app-error',
......@@ -8,12 +9,26 @@ import {Router} from '@angular/router';
})
export class ErrorComponent implements OnInit {
private socket: any;
constructor(private router: Router) {}
ngOnInit(): void {
this.socket = io('http://localhost:3000');
this.listen();
}
listen(): any {
this.socket.on('position', (data: any) => {
console.log('Listener:' , data);
});
}
toStartpage(): void {
this.router.navigate(['']);
}
move(direction: string): any {
console.log('left: ', direction);
this.socket.emit('move', direction);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment