{"id":16923211,"url":"https://github.com/hyperlife1119/ngx-socketio2","last_synced_at":"2025-03-17T07:31:40.232Z","repository":{"id":37043738,"uuid":"438674373","full_name":"HyperLife1119/ngx-socketio2","owner":"HyperLife1119","description":"A better Socket.IO module for Angular.","archived":false,"fork":false,"pushed_at":"2024-05-22T19:29:55.000Z","size":2007,"stargazers_count":11,"open_issues_count":15,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-05-22T20:38:16.867Z","etag":null,"topics":["angular","angular10","angular11","angular12","angular13","angular14","angular15","ngx-socket-io","ngx-socketio","observable","reactive","rxjs","socket-io","socket-io-client","socketio","socketio-client"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ngx-socketio2","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HyperLife1119.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-15T15:13:47.000Z","updated_at":"2024-05-29T19:21:19.238Z","dependencies_parsed_at":"2023-12-22T01:05:17.704Z","dependency_job_id":"4dc2323c-8533-48b8-be12-cd08593eb427","html_url":"https://github.com/HyperLife1119/ngx-socketio2","commit_stats":{"total_commits":55,"total_committers":5,"mean_commits":11.0,"dds":0.2727272727272727,"last_synced_commit":"842d021c4bd082074abf255e197fa9be5d4b513b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperLife1119%2Fngx-socketio2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperLife1119%2Fngx-socketio2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperLife1119%2Fngx-socketio2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HyperLife1119%2Fngx-socketio2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HyperLife1119","download_url":"https://codeload.github.com/HyperLife1119/ngx-socketio2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221674000,"owners_count":16861755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular10","angular11","angular12","angular13","angular14","angular15","ngx-socket-io","ngx-socketio","observable","reactive","rxjs","socket-io","socket-io-client","socketio","socketio-client"],"created_at":"2024-10-13T19:58:14.858Z","updated_at":"2024-10-27T12:14:37.364Z","avatar_url":"https://github.com/HyperLife1119.png","language":"TypeScript","readme":"# ngx-socketio2\n\nA better [Socket.IO](https://socket.io) module for [Angular](https://angular.io).\n\n[![npm version](https://img.shields.io/npm/v/ngx-socketio2/latest.svg)](https://npmjs.com/package/ngx-socketio2)\n![Node.js CI](https://github.com/HyperLife1119/ngx-socketio2/workflows/Node.js%20CI/badge.svg)\n![License](https://img.shields.io/badge/License-MIT-blue.svg)\n[![Angular](https://img.shields.io/badge/Build%20with-Angular%20CLI-red?logo=angular)](https://www.github.com/angular/angular)\n[![CodeFactor](https://www.codefactor.io/repository/github/hyperlife1119/ngx-socketio2/badge)](https://www.codefactor.io/repository/github/hyperlife1119/ngx-socketio2)\n\n## Features\n\n- The ability to type event objects.\n- More complete API.\n- Support chain call.\n- Responsive event listener.\n\n## Prerequisites\n\n- [Angular](https://angular.io) \u003e= 11.0.0\n- [Socket.IO](https://socket.io) \u003e= 4.0.0\n\n\n## Install\n\n```shell\nnpm i ngx-socketio2\n```\n\n## Usage\n\nImport and configure the `SocketioModule`:\n\n```ts\nimport { SocketioModule } from 'ngx-socketio2';\n\n@NgModule({\n  // ...\n  imports: [\n    // ...\n    SocketioModule.forRoot({\n      url: 'http://localhost:4200',\n      options: {\n        // Socket.IO client options\n      }\n    })\n  ]\n})\nexport class YourModule { }\n```\n\nGetting Socketio Service via DI:\n\n```ts\nimport { Injectable } from '@angular/core';\nimport { Socket } from 'ngx-socketio2';\nimport { tap } from 'rxjs/operators';\n\n@Injectable()\nexport class YourService {\n  constructor(private socket: Socket) {}\n\n  send(msg: string) {\n    this.socket.emit('message', msg);\n  }\n\n  sendMultiple(msg1: string, msg2: string) {\n    // Chain call.\n    this.socket.emit('message', msg1).emit('message', msg2);\n  }\n\n  receive() {\n    return this.socket.on\u003cstring\u003e('message').pipe(\n      tap((args: string) =\u003e {\n        // Do something...\n      })\n    );\n  }\n}\n```\n\n### Using multiple sockets with different endpoints\n\nIn this case, we no longer need the `SocketioModule`. Instead, use a new service that extends from the `Socketio` service and passes the configuration by calling `super(config)`.\n\n```ts\nimport { Injectable } from '@angular/core';\nimport { Socket } from 'ngx-socketio2';\n\n@Injectable()\nexport class Socket1Service extends Socket {\n  constructor() {\n    super({ url: 'http://localhost:4200' })\n  }\n}\n\n@Injectable()\nexport class Socket2Service extends Socket {\n  constructor() {\n    super({ url: 'http://localhost:6200' })\n  }\n}\n```\n\n```ts\n@NgModule({\n  // ...\n  providers: [\n    // ...\n    Socket1Service,\n    Socket2Service\n  ]\n})\nexport class YourModule { }\n```\n\n## API\n\n| Class          | API                                | Description                                                                                                                          |\n| -------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |\n| SocketioModule | .forRoot({ url[, options] })       | [https://socket.io/docs/v4/client-api/#iourl](https://socket.io/docs/v4/client-api/#iourl)                                           |\n| Socket         | .id                                | [https://socket.io/docs/v4/client-api/#socketid](https://socket.io/docs/v4/client-api/#socketid)                                     |\n|                | .connected                         | [https://socket.io/docs/v4/client-api/#socketconnected](https://socket.io/docs/v4/client-api/#socketconnected)                       |\n|                | .disconnected                      | [https://socket.io/docs/v4/client-api/#socketdisconnected](https://socket.io/docs/v4/client-api/#socketdisconnected)                 |\n|                | .io                                | [https://socket.io/docs/v4/client-api/#socketio](https://socket.io/docs/v4/client-api/#socketio)                                     |\n|                | .auth                              | [https://socket.io/docs/v4/client-options/#auth](https://socket.io/docs/v4/client-options/#auth)                                     |\n|                | .connect()                         | [https://socket.io/docs/v4/client-api/#socketconnect](https://socket.io/docs/v4/client-api/#socketconnect)                           |\n|                | .disconnect()                      | [https://socket.io/docs/v4/client-api/#socketdisconnect](https://socket.io/docs/v4/client-api/#socketdisconnect)                     |\n|                | .send([...args][, ack])            | [https://socket.io/docs/v4/client-api/#socketsendargs](https://socket.io/docs/v4/client-api/#socketsendargs)                         |\n|                | .emit(eventName[, ...args][, ack]) | [https://socket.io/docs/v4/client-api/#socketemiteventname-args](https://socket.io/docs/v4/client-api/#socketemiteventname-args)     |\n|                | .on(eventName)                     | [https://socket.io/docs/v4/client-api/#socketoneventname-callback](https://socket.io/docs/v4/client-api/#socketoneventname-callback) |\n|                | .once(eventName)                   | Similar to `.on(eventName)`, but only responds once.                                                                                 |\n|                | .compress(compress)                | [https://socket.io/docs/v4/client-api/#socketcompressvalue](https://socket.io/docs/v4/client-api/#socketcompressvalue)               |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperlife1119%2Fngx-socketio2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperlife1119%2Fngx-socketio2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperlife1119%2Fngx-socketio2/lists"}