9.0.0 • Published 4 years ago

a4-socket-io v9.0.0

Weekly downloads
12
License
-
Repository
-
Last release
4 years ago

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);
  ...
9.0.0

4 years ago

8.0.0

5 years ago

7.0.0

6 years ago

6.0.0

6 years ago