--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+module.exports = function (app) {\r
+ if (typeof app.channel !== 'function') {\r
+ // If no real-time functionality has been configured just return\r
+ return;\r
+ }\r
+\r
+ app.on('connection', connection => {\r
+ // On a new real-time connection, add it to the anonymous channel\r
+ app.channel('anonymous').join(connection);\r
+ \r
+ });\r
+\r
+ app.on('login', (authResult, { connection }) => {\r
+ // connection can be undefined if there is no\r
+ // real-time connection, e.g. when logging in via REST\r
+ if (connection) {\r
+ // Obtain the logged in user from the connection\r
+ // const user = connection.user;\r
+\r
+ // The connection is no longer anonymous, remove it\r
+ app.channel('anonymous').leave(connection);\r
+\r
+ // Add it to the authenticated user channel\r
+ app.channel('authenticated').join(connection);\r
+\r
+ // Channels can be named anything and joined on any condition\r
+\r
+ // E.g. to send real-time events only to admins use\r
+ // if(user.isAdmin) { app.channel('admins').join(connection); }\r
+\r
+ // If the user has joined e.g. chat rooms\r
+ // if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(channel));\r
+\r
+ // Easily organize users by email and userid for things like messaging\r
+ // app.channel(`emails/${user.email}`).join(channel);\r
+ // app.channel(`userIds/$(user.id}`).join(channel);\r
+ }\r
+ });\r
+\r
+ //eslint-disable-next-line no-unused-vars\r
+ app.publish((data, hook) => {\r
+ // Here you can add event publishers to channels set up in `channels.js`\r
+ // To publish only for a specific event use `app.publish(eventname, () => {})`\r
+\r
+ console.log('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line\r
+\r
+ // e.g. to publish all service events to all authenticated users use\r
+ return app.channel('authenticated');\r
+ });\r
+\r
+ // Here you can also add service specific event publishers\r
+ // e.g. the publish the `users` service `created` event to the `admins` channel\r
+ // app.service('users').publish('created', () => app.channel('admins'));\r
+\r
+ // With the userid and email organization from above you can easily select involved users\r
+ // app.service('messages').publish(() => {\r
+ // return [\r
+ // app.channel(`userIds/${data.createdBy}`),\r
+ // app.channel(`emails/${data.recipientEmail}`)\r
+ // ];\r
+ // });\r
+};\r