{"id":19050901,"url":"https://github.com/tomasbasham/ember-cli-pubnub","last_synced_at":"2025-04-24T01:23:15.495Z","repository":{"id":51047600,"uuid":"48889129","full_name":"tomasbasham/ember-cli-pubnub","owner":"tomasbasham","description":"An ember-cli addon to to integrate the PubNub low-latency, realtime messaging platform","archived":false,"fork":false,"pushed_at":"2022-12-07T00:58:14.000Z","size":950,"stargazers_count":6,"open_issues_count":6,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T15:54:03.682Z","etag":null,"topics":["ember-addon","ember-cli","pubnub","real-time","websocket"],"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/tomasbasham.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-01T20:50:50.000Z","updated_at":"2023-05-17T20:19:22.000Z","dependencies_parsed_at":"2023-01-23T14:25:15.440Z","dependency_job_id":null,"html_url":"https://github.com/tomasbasham/ember-cli-pubnub","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-pubnub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-pubnub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-pubnub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomasbasham%2Fember-cli-pubnub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomasbasham","download_url":"https://codeload.github.com/tomasbasham/ember-cli-pubnub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250541844,"owners_count":21447589,"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":["ember-addon","ember-cli","pubnub","real-time","websocket"],"created_at":"2024-11-08T23:16:39.255Z","updated_at":"2025-04-24T01:23:15.471Z","avatar_url":"https://github.com/tomasbasham.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-cli-pubnub [![Build Status](https://travis-ci.com/tomasbasham/ember-cli-pubnub.svg?branch=master)](https://travis-ci.com/tomasbasham/ember-cli-pubnub) [![Maintainability](https://api.codeclimate.com/v1/badges/ab32267129e27c3b95d2/maintainability)](https://codeclimate.com/github/tomasbasham/ember-cli-pubnub/maintainability)\n\nAn [Ember CLI](https://ember-cli.com/) addon to integrate the PubNub\nlow-latency, realtime messaging platform.\n\nPubNub utilises a publish/subscribe model functioning within a quarter of a\nsecond to give the user a sense of immediate or current updates to application\ndata making it ideal for chat or any other application requiring transient\ndata.\n\nThis addon allows ember to establish and maintain persistent web socket\nconnections to the [PubNub](https://www.pubnub.com/) service and synchronises\nmessages being sent to and from remote peers.\n\n## Compatibility\n\n* Ember.js v2.18 or above\n* Ember CLI v2.13 or above\n\n## Installation\n\nFrom within your Ember CLI project directory run:\n```\nember install ember-cli-pubnub\n```\n\n## Usage\n\nThis addon implements a shim for the PubNub V4 JavaScript library that can be\nimported as an es6 module. The library is initialised with a `pubnub` service\nthat should be used to make requests to the PubNub backend.\n\n### Configuration\n\nBefore the `pubnub` service can be used it first must be configured through\n`config/environment`. Here you must supply both your PubNub subscribe and\npublish API keys.\n\n##### Configuration Example\n\n```JavaScript\n// config/environment.js\nmodule.exports = function(environment) {\n  var ENV = {\n    pubnub: {\n      subscribeKey: 'sub-c-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',\n      publishKey: 'pub-c-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',\n      ssl: true\n    }\n  };\n\n  return ENV;\n};\n```\n\nOptionally you may specify whether the PubNub JavaScript library is fetched\nover HTTPS using the `ssl` key. Although optional, it is recommended that you\nset this to `true` within a production environment.\n\n### Injection\n\nThis addon makes no assumptions about what ember objects you want to make the\n`pubnub` service available. Therefore in order to make the service available\nyou need to implement you own injections.\n\n##### Injection Initializer Example\n\n```JavaScript\n// app/initializers/pubnub.js\nexport function initialize(application) {\n  application.inject('controller', 'pubnub', 'service:pubnub');\n  application.inject('route', 'pubnub', 'service:pubnub');\n};\n\nexport default {\n  name: 'pubnub',\n  initialize: initialize\n};\n```\n\nThis will make the `pubnub` service available to all controllers and routes. It\nis however unlikely that you will require the service to be injected into every\ncontroller or route of your applications. Therefore it is recommended that you\ninclude the service on a per object basis.\n\n##### Injection Controller Example\n\n```JavaScript\n// app/controllers/application.js\nimport Controller from '@ember/controller';\nimport { inject } from '@ember/service';\n\nexport default Controller.extend({\n  pubnub: inject()\n});\n```\n\nThis will create a dependency on the application controller and inject the\n`pubnub` service into this controller only. This can be repeated across all\nobjects that need access to the service.\n\n### Subscribe\n\nIn order to receive messages published to a channel use the `subscribe`\nfunction passing the required unique channel name. Other optional parameters\ncan be passed into the subscribe function as key/value pairs and are defined\nwithin the API reference on the PubNub website.\n\n##### Subscribe Example\n\n```JavaScript\n// app/controllers/application.js\nimport Controller from '@ember/controller';\n\nimport { get } from '@ember/object';\nimport { on } from '@ember/object/evented';\nimport { inject } from '@ember/service';\n\nexport default Controller.extend({\n  pubnub: inject(),\n\n  joinChannel: on('init', function() {\n    const pubnub = get(this, 'pubnub');\n\n    pubnub.subscribe({\n      channels: ['lobby'],\n      withPresence: true\n    });\n  })\n});\n```\n\nThis will subscribe the client  to the `lobby` channel and additionally\nsubscribe to the presence channel instance conventionally named `lobby-pnpres`.\n\n### Publish\n\nIn order to publish messages to a channel that a client has previously\nsubscribed use the `publish` function passing both the required channel name\nand message. Other optional parameters can be passed into the `publish`\nfunction as key/value pairs and are defined within the API reference on the\nPubNub website.\n\n##### Publish Example\n\n```JavaScript\n// app/controllers/application.js\nimport Controller from '@ember/controller';\n\nimport { get } from '@ember/object';\nimport { inject } from '@ember/service';\n\nexport default Controller.extend({\n  pubnub: inject(),\n\n  actions: {\n    publish(message) {\n      const pubnub = get(this, 'pubnub');\n\n      pubnub.publish({\n        channel: 'lobby',\n        message: 'Hello, World'\n      });\n    }\n  }\n});\n```\n\nThis will publish the message `Hello, World` to the `lobby` channel. All client\nthat have subscribed to this channel will receive this message.\n\n### Advanced Setup\n\nPrevious examples demonstrate how to subscribe to a channel and subsequently\npublish a message to the same channel. However there is no guarantee that a\nclient will only publish messages after it has successfully subscribed to a\nchannel. Therefore a client may not receive all of it's own messages.\n\nTo ensure the client only publishes messages after it has subscribed to a\nchannel use the `addListener` function. This allows callbacks for channel\nstatus changes that receives events when a client has subscribed to a channel.\n\n##### Advanced Example\n\n```JavaScript\n// app/controllers/application.js\nimport Controller from '@ember/controller';\n\nimport { get } from '@ember/object';\nimport { on } from '@ember/object/evented';\nimport { inject } from '@ember/service';\n\nexport default Controller.extend({\n  pubnub: inject(),\n\n  joinChannel: on('init', function() {\n    const pubnub = get(this, 'pubnub');\n    const channel = 'lobby';\n\n    pubnub.addListener({\n      status: function(status) {\n        const message = 'Hello, World';\n\n        if (status.category === 'PNConnectedCategory') {\n          pubnub.publish({ channel, message }, function(status) {\n            // handle publish status.\n          });\n        }\n      }, message: function(message) {\n        // handle message.\n      }, presence: function(event) {\n        // handle presence.\n      }\n    });\n\n    pubnub.subscribe({\n      channels: [channel],\n      withPresence: true\n    });\n  })\n});\n```\n\nBy following this pattern on a client that both subscribes and publishes to a\nchannel a client will be able to receive it own published messages. It also\nsets up a callback to receive message from other clients on the channel and\npresence events.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasbasham%2Fember-cli-pubnub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomasbasham%2Fember-cli-pubnub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomasbasham%2Fember-cli-pubnub/lists"}