UNPKG

ngx-socketio2-updated

Version:
126 lines (119 loc) 3.72 kB
import * as i0 from '@angular/core'; import { InjectionToken, Inject, Injectable, NgModule } from '@angular/core'; import { fromEvent, take } from 'rxjs'; import { io } from 'socket.io-client'; const SOCKETIO_CONFIG = new InjectionToken('SocketioConfig'); class Socket { /** * @see {@link Socket.id} */ get id() { return this.socket.id; } /** * @see {@link Socket.connected} */ get connected() { return this.socket.connected; } /** * @see {@link Socket.disconnected} */ get disconnected() { return this.socket.disconnected; } /** * @see {@link Socket.io} */ get io() { return this.socket.io; } /** * @see {@link Socket.auth} */ get auth() { return this.socket.auth; } /** * @see {@link Socket.auth} */ set auth(auth) { this.socket.auth = auth; } constructor( // eslint-disable-next-line @angular-eslint/prefer-inject { url, options }) { this.socket = io(url, options); } ngOnDestroy() { this.socket.offAny(); } /** * @see {@link Socket.connect} */ connect() { this.socket.connect(); return this; } /** * @see {@link Socket.disconnect} */ disconnect() { this.socket.disconnect(); return this; } /** * @see {@link Socket.send} */ send(...args) { this.socket.send(...args); return this; } /** * @see {@link Socket.emit} */ emit(eventName, ...args) { this.socket.emit(eventName, ...args); return this; } /** * @see {@link Socket.on} */ on(eventName) { return fromEvent(this.socket, eventName); } /** * @see {@link Socket.once} */ once(eventName) { return this.on(eventName).pipe(take(1)); } /** * @see {@link Socket.compress} */ compress(compress) { this.socket.compress(compress); return this; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: Socket, deps: [{ token: SOCKETIO_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: Socket }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: Socket, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: undefined, decorators: [{ type: Inject, args: [SOCKETIO_CONFIG] }] }] }); class SocketioModule { static forRoot(config = { url: '' }) { return { ngModule: SocketioModule, providers: [ { provide: SOCKETIO_CONFIG, useValue: config }, Socket, ], }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: SocketioModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.0", ngImport: i0, type: SocketioModule }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: SocketioModule }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: SocketioModule, decorators: [{ type: NgModule }] }); /* * Public API Surface of ngx-socketio2 */ /** * Generated bundle index. Do not edit. */ export { Socket, SocketioModule }; //# sourceMappingURL=ngx-socketio2-updated.mjs.map