@wix/realtime 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/docs-ts-model.json +62 -41
- package/package.json +2 -2
package/docs/docs-ts-model.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"fileName": "src/site/index.ts",
|
|
27
27
|
"line": 6,
|
|
28
28
|
"character": 6,
|
|
29
|
-
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/
|
|
29
|
+
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/b2ed98e/packages/realtime/src/site/index.ts#L6"
|
|
30
30
|
}
|
|
31
31
|
],
|
|
32
32
|
"type": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"fileName": "src/site/index.ts",
|
|
52
52
|
"line": 7,
|
|
53
53
|
"character": 6,
|
|
54
|
-
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/
|
|
54
|
+
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/b2ed98e/packages/realtime/src/site/index.ts#L7"
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
57
|
"signatures": [
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"fileName": "src/site/types.ts",
|
|
67
67
|
"line": 27,
|
|
68
68
|
"character": 24,
|
|
69
|
-
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/
|
|
69
|
+
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/b2ed98e/packages/realtime/src/site/types.ts#L27"
|
|
70
70
|
}
|
|
71
71
|
],
|
|
72
72
|
"parameters": [
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
"fileName": "src/site/index.ts",
|
|
155
155
|
"line": 1,
|
|
156
156
|
"character": 0,
|
|
157
|
-
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/
|
|
157
|
+
"url": "https://github.com/wix-private/wix-sdk-realtime/blob/b2ed98e/packages/realtime/src/site/index.ts#L1"
|
|
158
158
|
}
|
|
159
159
|
]
|
|
160
160
|
}
|
|
@@ -176,105 +176,126 @@
|
|
|
176
176
|
"type": "GUIDE",
|
|
177
177
|
"title": "Introduction",
|
|
178
178
|
"src": "# Introduction\nUsing the Realtime API you can create channels and channel resources where messages\n can be published. Site visitors who subscribe to a channel receive the published\n messages published to that channel. When a message is received you can handle the message any\n way you choose, such as displaying the contents of the message or changing the state\n of page elements depending on the contents of the message. You can also manage the\n permissions of who can read from specific channels.\n\n The `wix-realtime-backend` module is used in conjunction with the \n [`wix-realtime-frontend`](wix-realtime-frontend.html) module.\n\n Get hands-on experience with the Realtime API on our [Hello Realtime](https://www.wix.com/velo/example/hello-realtime) example page. \n\n Typical uses of the Realtime API include implementing a messaging system or\n as an alternative to using a polling mechanism.\n\n The Realtime API uses the following terminology:\n\n + **Channel**: A specific channel on which messages are published. Each channel\n has a unique name. Site visitors can subscribe to a channel to receive the \n messages that are published on it. When site visitors subscribe to a channel, they do not \n receive messages published to a resource on that same channel.\n + **Channel resource**: A subchannel on which messages are published. Subchannels\n can share a name with a channel and other subchannels, but they have a unique\n resource ID. When site visitors subscribe to a channel resource, they do not \n receive messages published to that same channel without a specified resource.\n Channel resources inherit their parent channel's permissions, unless specified\n otherwise.\n + **Message**: A message published on a channel or channel resource. A message can\n be of any type, such as a string, number, or object. Channel subscribers receive\n the messages published on the channel.\n + **Publish**: Sending a message over a channel or channel resource.\n + **Subscribe**: A site visitor subscribes to receive the messages published on a \n channel or channel resource.\n + **Permissions router**: The permissions router is used to define the permissions\n you want to grant to subscribers on channels and channel resources.\n + **Permissions handler**: Handles a permissions check for a specific user on a \n specific channel or channel resource.\n \n For a tutorial on using the Realtime API, see \n [Sending Messages with the Realtime API](https://support.wix.com/en/article/velo-tutorial-sending-messages-with-the-realtime-api).\n\n To use the Realtime API in the backend, import `wixRealtimeBackend` from the `wix-realtime-backend` module:\n\n ```javascript\n import wixRealtimeBackend from 'wix-realtime-backend';\n ```"
|
|
179
|
-
}
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
"/publish": [
|
|
180
182
|
{
|
|
181
183
|
"type": "EXAMPLE",
|
|
182
|
-
"title": "
|
|
183
|
-
"src": "
|
|
184
|
+
"title": "Publish to a channel",
|
|
185
|
+
"src": "import wixRealtimeBackend from 'wix-realtime-backend';\n\n// ...\n\nconst channel = {\"name\": \"someChannel\"};\n\nwixRealtimeBackend.publish(channel, \"My message\")\n .then(() => {\n // published\n });"
|
|
184
186
|
},
|
|
185
187
|
{
|
|
186
188
|
"type": "EXAMPLE",
|
|
187
|
-
"title": "
|
|
188
|
-
"src": "
|
|
189
|
+
"title": "Publish to a resource on a channel",
|
|
190
|
+
"src": "import wixRealtimeBackend from 'wix-realtime-backend';\n\n// ...\n\nconst channel = {\n \"name\": \"someChannel\",\n \"resourceId\": \"someId\"\n};\n\nwixRealtimeBackend.publish(channel, \"My message\")\n .then(() => {\n // published\n });"
|
|
189
191
|
},
|
|
190
192
|
{
|
|
191
193
|
"type": "EXAMPLE",
|
|
192
|
-
"title": "
|
|
193
|
-
"src": "
|
|
194
|
+
"title": "Publish to specific users on a channel and include publisher information",
|
|
195
|
+
"src": "import wixRealtimeBackend from 'wix-realtime-backend';\n\n// ...\n\nconst channel = {\"name\": \"someChannel\"};\n\nconst message = {\n \"firstKey\": \"firstValue\",\n \"secondKey\": \"secondValue\"\n};\n\nconst user1 = // get ID of first user to publish to\nconst user2 = // get ID of second user to publish to\n\nconst options = {\n \"users\" : [user1, user2],\n \"includePublisher\": true\n};\n\nwixRealtimeBackend.publish(channel, message, options)\n .then( () => {\n // published\n } );"
|
|
194
196
|
},
|
|
195
197
|
{
|
|
196
198
|
"type": "EXAMPLE",
|
|
197
|
-
"title": "
|
|
198
|
-
"src": "
|
|
199
|
-
|
|
199
|
+
"title": "Send and receive messages across multiple channels and channel resources",
|
|
200
|
+
"src": "import { subscribe } from 'wix-realtime-frontend';\nimport { publishMessage } from 'backend/realtime';\n\nconst channelA = { name: 'a' };\nconst channelB = { name: 'b' };\nconst channelB1 = { name: 'b', resourceId: '1' };\nconst channelB2 = { name: 'b', resourceId: '2' };\n\n$w.onReady(function () {\n subscribeToChannels();\n setupPublishButtons();\n});\n\nfunction subscribeToChannels() {\n subscribe(channelA, messageHandler);\n subscribe(channelB, messageHandler);\n subscribe(channelB1, messageHandler);\n subscribe(channelB2, messageHandler);\n}\n\nfunction setupPublishButtons() {\n $w('#publishButtonA').onClick(event => {\n publish(event.target, channelA);\n });\n\n $w('#publishButtonB').onClick(event => {\n publish(event.target, channelB);\n });\n\n $w('#publishButtonB1').onClick(event => {\n publish(event.target, channelB1);\n });\n\n $w('#publishButtonB2').onClick(event => {\n publish(event.target, channelB2);\n });\n}\n\nasync function publish(button, channel) {\n if ($w('#message').value) {\n button.disable();\n $w('#message').disable();\n\n await publishMessage(channel, $w('#message').value);\n\n $w('#message').value = undefined;\n $w('#message').enable();\n button.enable();\n }\n}\n\nfunction messageHandler(message, channel) {\n let textBoxId;\n\n if (channel.name === 'a') {\n textBoxId = '#receivedMessagesA';\n } else { // Channel B - check resource ID\n if (channel.resourceId === '1') {\n textBoxId = '#receivedMessagesB1';\n } else if (channel.resourceId === '2') {\n textBoxId = '#receivedMessagesB2';\n } else {\n textBoxId = '#receivedMessagesB';\n }\n }\n\n $w(textBoxId).value += (message.payload + '\\n');\n}",
|
|
201
|
+
"description": "You can test out the code in our [example template](https://manage.wix.com/edit-template/from?originTemplateId=a527f79a-9a33-46f9-a246-2d6c8dc37e5e&templateId=3a469df1-5a74-47ae-bb5e-5e21d6a4d5ef&autoDevMode=true)."
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
"/realtime_check_permission": [
|
|
200
205
|
{
|
|
201
206
|
"type": "EXAMPLE",
|
|
202
|
-
"title": "
|
|
203
|
-
"src": "
|
|
207
|
+
"title": "Grant permissions for a channel based on subscriber type",
|
|
208
|
+
"src": "// In realtime-permissions.js\n\nexport function realtime_check_permission(channel, subscriber) {\n // set default permissions\n let permissions = {\"read\": true};\n \n if(channel.name === \"MembersOnly\") {\n if(subscriber.type === \"Member\"){\n permissions.read = true; \n }\n else {\n permissions.read = false;\n }\n }\n \n return permissions;\n}"
|
|
204
209
|
},
|
|
205
210
|
{
|
|
206
211
|
"type": "EXAMPLE",
|
|
207
|
-
"title": "
|
|
208
|
-
"src": "
|
|
212
|
+
"title": "Grant permissions for a channel based on subscriber type using the permissions router",
|
|
213
|
+
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\npermissionsRouter.default( (channel, subscriber) => {\n return {\"read\": true};\n} );\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add(membersOnlyChannel, (channel, subscriber) => {\n if(subscriber.type === \"Member\") {\n return {\"read\": true};\n }\n else {\n return {\"read\": false};\n }\n});\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel,subscriber);\n}"
|
|
209
214
|
},
|
|
210
215
|
{
|
|
211
216
|
"type": "EXAMPLE",
|
|
212
|
-
"title": "
|
|
213
|
-
"src": "
|
|
217
|
+
"title": "Grant permissions based on user data",
|
|
218
|
+
"src": "// In realtime-permissions.js\n\nimport { members } from `wix-members-backend`;\n\nexport async function realtime_check_permission(channel, subscriber) {\n // set default permissions\n let permissions = { \"read\": true };\n\n if(channel.name === \"BobsOnly\") {\n let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });\n if(member.contactDetails.firstName === \"Bob\") {\n permissions.read = true;\n }\n else {\n permissions.read = false;\n }\n }\n \n return permissions;\n}"
|
|
214
219
|
},
|
|
215
220
|
{
|
|
216
221
|
"type": "EXAMPLE",
|
|
217
|
-
"title": "
|
|
218
|
-
"src": "
|
|
222
|
+
"title": "Grant permissions based on user data using the permissions router",
|
|
223
|
+
"src": "// In realtime-permissions.js\n\nimport { members } from `wix-members-backend`;\nimport { permissionsRouter } from 'wix-realtime-backend';\n\npermissionsRouter.default((channel, subscriber) => {\n return {\"read\": true};\n});\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => {\n let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });\n \n if(channel.resourceId === \"BobsOnly\") {\n if(member.contactDetails.firstName === \"Bob\") {\n return { \"read\": true };\n }\n else {\n return { \"read\": false };\n }\n }\n else {\n return { \"read\": true };\n }\n} );\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel, subscriber);\n}"
|
|
219
224
|
},
|
|
220
225
|
{
|
|
221
226
|
"type": "EXAMPLE",
|
|
222
|
-
"title": "
|
|
223
|
-
"src": "import { subscribe } from 'wix-realtime-frontend';\nimport { publishMessage } from 'backend/realtime';\n\nconst
|
|
224
|
-
|
|
227
|
+
"title": "Check permissions across multiple channels and channel resources",
|
|
228
|
+
"src": "import { subscribe } from 'wix-realtime-frontend';\nimport { publishMessage } from 'backend/realtime';\n\nconst updatesChannel = {name: 'updates'};\nconst updatesMembersChannel = {name: 'updates', resourceId: 'members'};\nconst updatesAdminsChannel = {name: 'updates', resourceId: 'admins'};\nconst updatesGuestsChannel = {name: 'updates', resourceId: 'guests'};\n\n$w.onReady(function () {\n subscribeToChannels();\n setupPublishButtons();\n});\n\nfunction subscribeToChannels() {\n subscribe(updatesChannel, messageHandler)\n .catch(() => console.log('Not subscribed to updates channel'));\n subscribe(updatesMembersChannel, messageHandler)\n .catch(() => console.log('Not subscribed to members channel'));\n subscribe(updatesAdminsChannel, messageHandler)\n .catch(() => console.log('Not subscribed to admins channel'));\n subscribe(updatesGuestsChannel, messageHandler)\n .catch(() => console.log('Not subscribed to guest channel'));\n}\n\nfunction messageHandler(message, channel) {\n const channelName = channel.name;\n const channelResource = channel.resourceId ? `-${channel.resourceId}` : '';\n let newMessageLine = `${channelName}${channelResource}: ${message.payload}\\n`;\n $w('#receivedMessages').value += newMessageLine;\n}\n\nfunction setupPublishButtons() {\n $w('#updateButton').onClick(event => {\n publish(event.target, updatesChannel);\n });\n\n $w('#memberUpdateButton').onClick(event => {\n publish(event.target, updatesMembersChannel);\n });\n\n $w('#adminUpdateButton').onClick(event => {\n publish(event.target, updatesAdminsChannel);\n });\n\n $w('#guestUpdateButton').onClick(event => {\n publish(event.target, updatesGuestsChannel);\n });\n}\n\nasync function publish(button, channel) {\n if ($w('#message').value) {\n button.disable();\n $w('#message').disable();\n\n await publishMessage(channel, $w('#message').value);\n\n $w('#message').value = undefined;\n $w('#message').enable();\n button.enable();\n }\n}",
|
|
229
|
+
"description": "You can test out the code in our [example template](https://manage.wix.com/edit-template/from?originTemplateId=a527f79a-9a33-46f9-a246-2d6c8dc37e5e&templateId=3a469df1-5a74-47ae-bb5e-5e21d6a4d5ef&autoDevMode=true)."
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
"/permissionsRouter": [
|
|
225
233
|
{
|
|
226
234
|
"type": "EXAMPLE",
|
|
227
|
-
"title": "
|
|
235
|
+
"title": "Grant permissions for a channel based on subscriber type using the permissions router",
|
|
228
236
|
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\npermissionsRouter.default( (channel, subscriber) => {\n return {\"read\": true};\n} );\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add(membersOnlyChannel, (channel, subscriber) => {\n if(subscriber.type === \"Member\") {\n return {\"read\": true};\n }\n else {\n return {\"read\": false};\n }\n});\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel,subscriber);\n}"
|
|
229
237
|
},
|
|
230
238
|
{
|
|
231
239
|
"type": "EXAMPLE",
|
|
232
|
-
"title": "
|
|
240
|
+
"title": "Grant permissions based on user data using the permissions router",
|
|
233
241
|
"src": "// In realtime-permissions.js\n\nimport { members } from `wix-members-backend`;\nimport { permissionsRouter } from 'wix-realtime-backend';\n\npermissionsRouter.default((channel, subscriber) => {\n return {\"read\": true};\n});\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => {\n let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });\n \n if(channel.resourceId === \"BobsOnly\") {\n if(member.contactDetails.firstName === \"Bob\") {\n return { \"read\": true };\n }\n else {\n return { \"read\": false };\n }\n }\n else {\n return { \"read\": true };\n }\n} );\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel, subscriber);\n}"
|
|
234
|
-
}
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
"/PermissionsRouter": [
|
|
245
|
+
{
|
|
246
|
+
"type": "GUIDE",
|
|
247
|
+
"title": "Introduction",
|
|
248
|
+
"src": "# Introduction\nUse the permissions router to define the permissions you want to grant to subscribers\n on channels or channel resources. You can set permissions on the channel and channel\n resource level. If you do not define permissions for a particular channel resource,\n that resource inherits the permissions of its parent channel.\n\n Typically you use the permissions router in the **realtime-permissions.js** file in\n your site's backend to:\n\n + Set default permissions for all channels and channel resources where no explicit\n permissions are defined.\n + Add permissions logic for specific channels or channel resources.\n + Check the permissions for a specific subscriber on a specific channel.\n\n > **Note:** Although it is recommended, you do not need to use the permissions router to set permissions. You can also define all your permissions logic in the [`realtime_check_permission()`](#realtime_check_permission) function."
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
"/PermissionsRouter/add": [
|
|
235
252
|
{
|
|
236
253
|
"type": "EXAMPLE",
|
|
237
|
-
"title": "
|
|
238
|
-
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\n// ...\n\npermissionsRouter.
|
|
254
|
+
"title": "Set a permissions handler for a specific channel",
|
|
255
|
+
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\n// ...\n\nconst adminAnnouncements = {\"name\": \"announcements\"}\n\npermissionsRouter.add( adminAnnouncements, (channel, subscriber) => {\n // add permissions check logic and return\n // permissions for announcements channel\n if(subscriber.type === \"Admin\") {\n return {\"read\": true};\n }\n else {\n return {\"read\": true};\n }\n} );"
|
|
239
256
|
},
|
|
240
257
|
{
|
|
241
258
|
"type": "EXAMPLE",
|
|
242
|
-
"title": "
|
|
259
|
+
"title": "Grant permissions for a channel based on subscriber type using the permissions router",
|
|
243
260
|
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\npermissionsRouter.default( (channel, subscriber) => {\n return {\"read\": true};\n} );\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add(membersOnlyChannel, (channel, subscriber) => {\n if(subscriber.type === \"Member\") {\n return {\"read\": true};\n }\n else {\n return {\"read\": false};\n }\n});\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel,subscriber);\n}"
|
|
244
261
|
},
|
|
245
262
|
{
|
|
246
263
|
"type": "EXAMPLE",
|
|
247
|
-
"title": "
|
|
264
|
+
"title": "Grant permissions based on user data using the permissions router",
|
|
248
265
|
"src": "// In realtime-permissions.js\n\nimport { members } from `wix-members-backend`;\nimport { permissionsRouter } from 'wix-realtime-backend';\n\npermissionsRouter.default((channel, subscriber) => {\n return {\"read\": true};\n});\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => {\n let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });\n \n if(channel.resourceId === \"BobsOnly\") {\n if(member.contactDetails.firstName === \"Bob\") {\n return { \"read\": true };\n }\n else {\n return { \"read\": false };\n }\n }\n else {\n return { \"read\": true };\n }\n} );\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel, subscriber);\n}"
|
|
249
|
-
}
|
|
266
|
+
}
|
|
267
|
+
],
|
|
268
|
+
"/PermissionsRouter/check": [
|
|
250
269
|
{
|
|
251
270
|
"type": "EXAMPLE",
|
|
252
|
-
"title": "
|
|
271
|
+
"title": "Check permission for a subscriber to a channel",
|
|
253
272
|
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\n// ...\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel,subscriber);\n}"
|
|
254
273
|
},
|
|
255
274
|
{
|
|
256
275
|
"type": "EXAMPLE",
|
|
257
|
-
"title": "
|
|
276
|
+
"title": "Grant permissions for a channel based on subscriber type using the permissions router",
|
|
258
277
|
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\npermissionsRouter.default( (channel, subscriber) => {\n return {\"read\": true};\n} );\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add(membersOnlyChannel, (channel, subscriber) => {\n if(subscriber.type === \"Member\") {\n return {\"read\": true};\n }\n else {\n return {\"read\": false};\n }\n});\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel,subscriber);\n}"
|
|
259
278
|
},
|
|
260
279
|
{
|
|
261
280
|
"type": "EXAMPLE",
|
|
262
|
-
"title": "
|
|
281
|
+
"title": "Grant permissions based on user data using the permissions router",
|
|
263
282
|
"src": "// In realtime-permissions.js\n\nimport { members } from `wix-members-backend`;\nimport { permissionsRouter } from 'wix-realtime-backend';\n\npermissionsRouter.default((channel, subscriber) => {\n return {\"read\": true};\n});\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => {\n let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });\n \n if(channel.resourceId === \"BobsOnly\") {\n if(member.contactDetails.firstName === \"Bob\") {\n return { \"read\": true };\n }\n else {\n return { \"read\": false };\n }\n }\n else {\n return { \"read\": true };\n }\n} );\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel, subscriber);\n}"
|
|
264
|
-
}
|
|
283
|
+
}
|
|
284
|
+
],
|
|
285
|
+
"/PermissionsRouter/default": [
|
|
265
286
|
{
|
|
266
287
|
"type": "EXAMPLE",
|
|
267
|
-
"title": "
|
|
268
|
-
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\n// ...\n\
|
|
288
|
+
"title": "Set a default permissions handler",
|
|
289
|
+
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\n// ...\n\npermissionsRouter.default( (channel, subscriber) => {\n // return default permissions\n return {\"read\": true};\n} );"
|
|
269
290
|
},
|
|
270
291
|
{
|
|
271
292
|
"type": "EXAMPLE",
|
|
272
|
-
"title": "
|
|
293
|
+
"title": "Grant permissions for a channel based on subscriber type using the permissions router",
|
|
273
294
|
"src": "// In realtime-permissions.js\n\nimport {permissionsRouter} from 'wix-realtime-backend';\n\npermissionsRouter.default( (channel, subscriber) => {\n return {\"read\": true};\n} );\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add(membersOnlyChannel, (channel, subscriber) => {\n if(subscriber.type === \"Member\") {\n return {\"read\": true};\n }\n else {\n return {\"read\": false};\n }\n});\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel,subscriber);\n}"
|
|
274
295
|
},
|
|
275
296
|
{
|
|
276
297
|
"type": "EXAMPLE",
|
|
277
|
-
"title": "
|
|
298
|
+
"title": "Grant permissions based on user data using the permissions router",
|
|
278
299
|
"src": "// In realtime-permissions.js\n\nimport { members } from `wix-members-backend`;\nimport { permissionsRouter } from 'wix-realtime-backend';\n\npermissionsRouter.default((channel, subscriber) => {\n return {\"read\": true};\n});\n\nconst membersOnlyChannel = {\"name\": \"MembersOnly\"};\n\npermissionsRouter.add( membersOnlyChannel, async (channel, subscriber) => {\n let member = await members.getMember(subscriber.id, { fieldsets: ['FULL'] });\n \n if(channel.resourceId === \"BobsOnly\") {\n if(member.contactDetails.firstName === \"Bob\") {\n return { \"read\": true };\n }\n else {\n return { \"read\": false };\n }\n }\n else {\n return { \"read\": true };\n }\n} );\n\nexport function realtime_check_permission(channel, subscriber) {\n return permissionsRouter.check(channel, subscriber);\n}"
|
|
279
300
|
}
|
|
280
301
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/realtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "cjs/build/index.js",
|
|
6
6
|
"module": "build/index.mjs",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
]
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
|
-
"falconPackageHash": "
|
|
61
|
+
"falconPackageHash": "9434a8301a399f826a233d24adf0546a7e1312088dbd9870ce952ca3"
|
|
62
62
|
}
|