{"_id":"@atton16/ngx-socket-io","_rev":"1-2436da50ec77dcaf4d8516627c8141d5","name":"@atton16/ngx-socket-io","dist-tags":{"latest":"3.2.1"},"versions":{"3.2.1":{"name":"@atton16/ngx-socket-io","version":"3.2.1","description":"Socket.IO module for Angular","main":"index.ts","scripts":{"build":"ng-packagr"},"repository":{"type":"git","url":"git+ssh://git@github.com/atton16/ngx-socket-io.git"},"keywords":["Angular","Socket-io","TypeScript"],"author":{"name":"rodgc"},"contributors":[{"name":"Attawit Kittikrairit","email":"atton16@gmail.com","url":"https://attawit.me"}],"license":"MIT","bugs":{"url":"https://github.com/atton16/ngx-socket-io/issues"},"homepage":"https://github.com/atton16/ngx-socket-io#readme","dependencies":{"core-js":"^3.0.0","reflect-metadata":"^0.1.10","socket.io":"^2.2.0","socket.io-client":"^2.2.0","zone.js":"^0.10.1"},"peerDependencies":{"@angular/common":"^11.0.0","@angular/core":"^11.0.0","rxjs":"^6.1.0"},"devDependencies":{"@angular/compiler":"^11.0.0","@angular/compiler-cli":"^11.0.0","@angular/core":"^11.0.0","@types/node":"^12.7.1","@types/socket.io":"^2.1.2","@types/socket.io-client":"^1.4.32","ng-packagr":"^11.0.0","rxjs":"^6.1.0","server-destroy":"^1.0.1","tslint":"^5.18.0","typescript":"4.0.5"},"gitHead":"424d63807747e8c7ada75313118381302c84a0a0","_id":"@atton16/ngx-socket-io@3.2.1","_nodeVersion":"14.15.4","_npmVersion":"7.5.4","dist":{"integrity":"sha512-yKnMPU1PUhptshThsA8T61aUJYb5hIz7egCA3Ui8BUcB6gEpjrYLPj8Gvasno37XsocukBG+3lrWqoLofi3Q3g==","shasum":"e34381d59b3de35e138c7c931c0fb6b08bc4890f","tarball":"https://registry.npmjs.org/@atton16/ngx-socket-io/-/ngx-socket-io-3.2.1.tgz","fileCount":32,"unpackedSize":71740,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgLLR4CRA9TVsSAnZWagAAO/oP/2ymx2WA9Oxx5FV0lP7g\ny6t/+5XDTB8O8cFVbMsMldlR2YVDb1BqZFTHkntj3fymL9D+vWHGcn3kUryU\nbVBdQr/+RM9K+JdmScMWsL9NYQW4ewazycWwqXV9UAjmJYBsBxPAKbg3MTHx\nGwNzgHaG3KWLoIe00gFyZkJVAvbRLbvS1JvkFprV0Uzznra/RWlV4LyXS+D5\nPDUcvbjOR/Roa5Ayj5N8oFSkbvWgXHQtKw9jRxk7zdsuW/vi8JAQ2wTfW+gL\ntgnTnePBGLM/N5aQmjn4JLW/4DA7KnWlpUurP25GSZstlbH+JOSkOKNfbLSm\nUH9B4JRO02PHLD76wM1SSq/wQgItQ9dkuNqxLGszbqLzfOP9H+sLnFdeDbV/\nHOtJjQo0beABnEW+YBAE1eavQTUiN+iKotmF3B2ityIG9aStosCeRWs58NSs\nh+rBFx1W1U3lE9dDzF5ASRhFL52kuAkMV0zbzosLTALg9TVBVCAFa7Payg6q\nWIUHNN7seiXuyQMYByH9Myl72KNTrtXWPsp/k8lBuy0BB4wP2nOyH6w19sUk\nctylHDkuTuBvM2k3WDJQGdwVuFWRMjSMQvs9Rxrtq5PEzrPH+juSCca9GiOQ\nnh87Qj9YFNT9WbKFG27sfOklCsDIz6yYf6nf9wE6U4NV1BvKS3X25h1VGWKy\nKVRG\r\n=9y8Q\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC+Y+CHbiIKXYBLZMsjM9l2YVfxZH/tV3G53nKBPD4KsAIgeDdiqX382SyolnalT+2evw8+X/h+w9Ged/wikPlmAtk="}]},"_npmUser":{"name":"atton16-org","email":"atton16@gmail.com"},"directories":{},"maintainers":[{"name":"atton16-org","email":"atton16@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ngx-socket-io_3.2.1_1613542520252_0.4862281299484028"},"_hasShrinkwrap":false}},"time":{"created":"2021-02-17T06:15:20.050Z","3.2.1":"2021-02-17T06:15:20.436Z","modified":"2022-04-04T16:20:46.537Z"},"maintainers":[{"name":"atton16-org","email":"atton16@gmail.com"}],"description":"Socket.IO module for Angular","homepage":"https://github.com/atton16/ngx-socket-io#readme","keywords":["Angular","Socket-io","TypeScript"],"repository":{"type":"git","url":"git+ssh://git@github.com/atton16/ngx-socket-io.git"},"contributors":[{"name":"Attawit Kittikrairit","email":"atton16@gmail.com","url":"https://attawit.me"}],"author":{"name":"rodgc"},"bugs":{"url":"https://github.com/atton16/ngx-socket-io/issues"},"license":"MIT","readme":"# ngx-socket-io\n[![Build Status](https://travis-ci.org/rodgc/ngx-socket-io.svg?branch=master)](https://travis-ci.org/rodgc/ngx-socket-io)\n[![npm version](https://badge.fury.io/js/ngx-socket-io.svg)](https://badge.fury.io/js/ngx-socket-io)\n[![npm downloads](https://img.shields.io/badge/Downloads-132%2Fmonth-brightgreen.svg)](https://github.com/rodgc/ngx-socket-io)\n\n[Socket.IO](http://socket.io/) module for Angular\n\n## Install\n``` npm install ngx-socket-io ```\n\n## How to use\n\n### Import and configure SocketIoModule\n\n```ts\nimport { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';\n\nconst config: SocketIoConfig = { url: 'http://localhost:8988', options: {} };\n\n@NgModule({\n  declarations: [\n    AppComponent\n  ],\n  imports: [\n    BrowserModule,\n    SocketIoModule.forRoot(config)\n  ],\n  providers: [],\n  bootstrap: [AppComponent]\n})\nexport class AppModule { }\n```\n\nWe need to configure ```SocketIoModule``` module using the object ```config``` of type ```SocketIoConfig```, this object accepts two optional properties they are the same used here [io(url[, options])](https://github.com/socketio/socket.io-client/blob/master/docs/API.md#iourl-options).\n\nNow we pass the configuration to the static method ```forRoot``` of ```SocketIoModule```\n\n\n### Using your socket Instance\n\nThe ```SocketIoModule``` provides now a configured ```Socket``` service that can be injected anywhere inside the ```AppModule```.\n\n```typescript\n\nimport { Injectable } from '@angular/core';\nimport { Socket } from 'ngx-socket-io';\nimport { map } from 'rxjs/operators';\n\n@Injectable()\nexport class ChatService {\n\n    constructor(private socket: Socket) { }\n\n    sendMessage(msg: string){\n        this.socket.emit(\"message\", msg);\n    }\n     getMessage() {\n         return this.socket\n             .fromEvent(\"message\")\n             .pipe(map((data) => data.msg));\n    }\n}\n\n```\n\n### Using multiple sockets with different end points\n\nIn this case we do not configure the ```SocketIoModule``` directly using ```forRoot```. What we have to do is: extend the ```Socket``` service, and call ```super()``` with the ```SocketIoConfig``` object type (passing ```url``` & ```options``` if any).\n\n```typescript\n\nimport { Injectable, NgModule } from '@angular/core';\nimport { Socket } from 'ngx-socket-io';\n\n@Injectable()\nexport class SocketOne extends Socket {\n\n    constructor() {\n        super({ url: 'http://url_one:portOne', options: {} });\n    }\n\n}\n\n@Injectable()\nexport class SocketTwo extends Socket {\n\n    constructor() {\n        super({ url: 'http://url_two:portTwo', options: {} });\n    }\n\n}\n\n@NgModule({\n  declarations: [\n    //components\n  ],\n  imports: [\n    SocketIoModule,\n    //...\n  ],\n  providers: [SocketOne, SocketTwo],\n  bootstrap: [/** AppComponent **/]\n})\nexport class AppModule { }\n\n```\n\nNow you can inject ```SocketOne```, ```SocketTwo``` in any other services and / or components.\n\n\n## API\n\nMost of the functionalities here you are already familiar with.\n\nThe only addition is the ```fromEvent``` method, which returns an ```Observable``` that you can subscribe to.\n\n### `socket.of(namespace: string)`\n\nTakes an namespace.\nWorks the same as in Socket.IO.\n\n### `socket.on(eventName: string, callback: Function)`\n\nTakes an event name and callback.\nWorks the same as in Socket.IO.\n\n### `socket.removeListener(eventName: string, callback?: Function)`\n\nTakes an event name and callback.\nWorks the same as in Socket.IO.\n\n### `socket.removeAllListeners(eventName?: string)`\n\nTakes an event name.\nWorks the same as in Socket.IO.\n\n### `socket.emit(eventName:string, ...args: any[])`\n\nSends a message to the server.\nWorks the same as in Socket.IO.\n\n### `socket.fromEvent<T>(eventName: string): Observable<T>`\n\nTakes an event name and returns an Observable that you can subscribe to.\n\n### `socket.fromEventOnce<T>(eventName: string): Promise<T>`\n\nCreates a Promise for a one-time event.\n\nYou should keep a reference to the Observable subscription and unsubscribe when you're done with it.\nThis prevents memory leaks as the event listener attached will be removed (using ```socket.removeListener```) ONLY and when/if you unsubscribe.\n\nIf you have multiple subscriptions to an Observable only the last unsubscription will remove the listener.\n\n## Know Issue\n\nFor `error TS2345` you need to add this to your `tsconfig.json`.\n\n```json\n{\n  ...\n  \"compilerOptions\": {\n    ...\n    \"paths\": {\n      \"rxjs\": [\"node_modules/rxjs\"]\n    }\n  },\n}\n```\n\n## Related projects\n\n- [bougarfaoui/ng-socket-io](https://github.com/bougarfaoui/ng-socket-io) - Socket.IO module for Angular\n\n## LICENSE\n\nMIT\n\n","readmeFilename":"README.md"}