{"id":17419776,"url":"https://github.com/bendrucker/angular-sockjs","last_synced_at":"2025-04-15T00:03:03.622Z","repository":{"id":13500261,"uuid":"16191009","full_name":"bendrucker/angular-sockjs","owner":"bendrucker","description":"SockJS component for AngularJS","archived":false,"fork":false,"pushed_at":"2021-01-26T04:22:38.000Z","size":35,"stargazers_count":46,"open_issues_count":1,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T08:13:56.240Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/bendrucker.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}},"created_at":"2014-01-24T00:57:15.000Z","updated_at":"2024-01-03T14:11:05.000Z","dependencies_parsed_at":"2022-09-10T20:00:14.672Z","dependency_job_id":null,"html_url":"https://github.com/bendrucker/angular-sockjs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fangular-sockjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fangular-sockjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fangular-sockjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fangular-sockjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bendrucker","download_url":"https://codeload.github.com/bendrucker/angular-sockjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968835,"owners_count":21191160,"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":[],"created_at":"2024-10-17T02:32:40.851Z","updated_at":"2025-04-15T00:03:03.589Z","avatar_url":"https://github.com/bendrucker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# angular-sockjs [![Build Status](https://travis-ci.org/bendrucker/angular-sockjs.png?branch=master)](https://travis-ci.org/bendrucker/angular-sockjs)\n[SockJS](https://github.com/sockjs/sockjs-client) provider for AngularJS.\n\nBased on [Brian Ford's angular-socket-io](https://github.com/btford/angular-socket-io). \n\n\n## Install\n\n1. `bower install angular-sockjs`\n2. Made sure the [SockJS client library](https://github.com/sockjs/sockjs-client) is loaded.\n3. Include the `socket.js` script provided by this component into your app.\n4. Add `bd.sockjs` as a module dependency to your app.\n\n\n## Usage\n\nThis module exposes a `socketFactory`, which is an API for instantiating\nsockets that are integrated with Angular's digest cycle.\n\n\n### Making a Socket Instance\n\n```javascript\n// in the top-level module of the app\nangular.module('myApp', [\n  'bd.sockjs',\n  'myApp.MyCtrl'\n])\n.factory('mySocket', function (socketFactory) {\n  return socketFactory();\n});\n```\n\nWith that, you can inject your `mySocket` service into controllers and\nother serivices within your application!\n\n### Using Your Socket Instance\n\nBuilding on the example above:\n\n```javascript\n// in the top-level module of the app\nangular.module('myApp', [\n  'bd.sockjs',\n  'myApp.MyCtrl'\n])\n.factory('mySocket', function (socketFactory) {\n  return socketFactory({\n    url: 'https://example.com'\n  });\n})\n.controller('MyController', function (mySocket) {\n  // ...\n});\n```\n\n\n## API\n\nSince the SockJS API uses single event handlers rather than Socket.io's event emitter style, this library provides a lightweight wrapper around the handlers.\n\n### `socket.setHandler(event, callback)`\nAccepts valid socket events: `open`, [`close`](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent), and [`message`](https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent). Returns socket wrapper so multiple calls can be chained.\n\n### `socket.removeHandler(event)`\nHandles the same events as `socket.setHandler`. Returns socket wrapper so multiple calls can be chained. \n\n### `socket.send(message)`\nSends a socket message.\n\n### `socket.close([code], [reason])`\nAttempts to close the socket.\n\n***\n\n## Options\n\n#### `socketFactory({socket: })`\n\nThis option allows you to provide the `socket` service with a `SockJS` instance to be used internally.\nThis is useful if you need to hold a reference to the `sockjs` object for use elsewhere.\n\n```javascript\nangular.module('myApp', [\n  'bd.sockjs'\n])\n.factory('mySocket', function (socketFactory) {\n  var sockjs = new SockJS('http://host');\n\n  mySocket = socketFactory({\n    socket: sockjs\n  });\n\n  return mySocket;\n});\n```\n\n#### `socketFactory({url: })`\n\nThis option allows you to provide a URL to pass through to the SockJS constructor.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fangular-sockjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbendrucker%2Fangular-sockjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fangular-sockjs/lists"}