a4-socket-io
v9.0.0
Published
Angular 7 socket.io client
Downloads
1
Readme
a4-socket-io
Angular 7 socket.io client
How-To
Install
npm install a4-socket-io
SocketController decorator
@SocketController(url: string)
url
specifies where should the client connect to the socket.io server.
socket.component.ts
...
import { SocketController, OnConnect, OnDisconnect, OnSocketEvent } from '@angular/core';
...
@SocketController('localhost:3000')
@Component({
selector: 'app-socket',
templateUrl: './socket.component.html',
styleUrls: ['./socket.component.scss']
})
export class SocketComponent {
...
...
...
}
OnSocketEvent
@OnSocketEvent(eventName?: string)
message(data: string) {
...
...
...
}
If eventName
is specified, the socket service will use the specified event name otherwise, it will use the method name (ie. message
) as the event name.
OnConnect
@OnConnect()
connect() {
...
...
...
}
OnDisconnect
@OnDisconnect()
disconnect() {
...
...
...
}
Inject Socket Service
constructor(private socket: SocketService) {
...
}
Emit data to the socket.io server
...
this.socket.emit('eventName', data);
...