-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathlistRegistrationsByChannel.js
More file actions
59 lines (50 loc) · 1.88 KB
/
listRegistrationsByChannel.js
File metadata and controls
59 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* This sample demonstrates how the listRegistrations() method can be used to find all registrations for
* the given Notification Hub with an optional set of query parameters such as OData $top and $filter.
*
* See https://learn.microsoft.com/azure/notification-hubs/notification-hubs-push-notification-registration-management
* to learn about registrations.
*
*
* @summary Demonstrates how to update an installation using Azure Notification Hubs
*/
require("dotenv/config");
const { createClientContext, listRegistrationsByChannel } = require("@azure/notification-hubs/api");
// Define connection string and hub name
const connectionString = process.env.NOTIFICATIONHUBS_CONNECTION_STRING || "<connection string>";
const hubName = process.env.NOTIFICATION_HUB_NAME || "<hub name>";
// Define message constants
const DUMMY_DEVICE = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
const deviceToken = process.env.APNS_DEVICE_TOKEN || DUMMY_DEVICE;
const TOP = 100;
async function main() {
const context = createClientContext(connectionString, hubName);
const device = {
deviceToken,
kind: "apple",
};
// Unlimited
let allRegistrations = listRegistrationsByChannel(context, device);
let page = 0;
for await (const pages of allRegistrations.byPage()) {
console.log(`Page number ${page++}`);
for (const item of pages) {
console.log(JSON.stringify(item, null, 2));
}
}
// Top
page = 0;
allRegistrations = listRegistrationsByChannel(context, device, { top: TOP });
for await (const pages of allRegistrations.byPage()) {
console.log(`Page number ${page++}`);
for (const item of pages) {
console.log(JSON.stringify(item, null, 2));
}
}
}
main().catch((err) => {
console.log("listRegistrations Sample: Error occurred: ", err);
process.exit(1);
});