a4-socket-io
TypeScript icon, indicating that this package has built-in type declarations

9.0.0 • Public • Published

a4-socket-io

Angular 7 socket.io client

How-To

Install

npm install a4-socket-io

SocketController decorator

@SocketController(urlstring)

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(datastring) {
  ...
  ...
  ...
}

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 socketSocketService) {
  ...
}

Emit data to the socket.io server

  ...
  this.socket.emit('eventName', data);
  ...

Readme

Keywords

Package Sidebar

Install

npm i a4-socket-io

Weekly Downloads

1

Version

9.0.0

License

none

Unpacked Size

160 kB

Total Files

35

Last publish

Collaborators

  • cccheng