Skip to content

Commit aab00bd

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
* address Codacy quality checks suggestions.
* Indentation as per other code base
1 parent 27519f1 commit aab00bd

18 files changed

+283
-234
lines changed

docs-snippets/access-manager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ try {
4747
});
4848
} catch (error) {
4949
console.error(
50-
`Grant token error: ${error}.${(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''}`,
50+
`Grant token error: ${error}.${
51+
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
52+
}`,
5153
);
5254
}
5355
// snippet.end
@@ -122,7 +124,9 @@ try {
122124
});
123125
} catch (error) {
124126
console.error(
125-
`Grant token error: ${error}.${(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''}`,
127+
`Grant token error: ${error}.${
128+
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
129+
}`,
126130
);
127131
}
128132
// snippet.end

docs-snippets/app-context.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const customField = { visible: 'team' };
1414

1515
// Function to set and then update channel metadata
1616
try {
17-
let response = await pubnub.objects.setChannelMetadata({
17+
const response = await pubnub.objects.setChannelMetadata({
1818
channel: channel,
1919
data: {
2020
name: name,
@@ -25,22 +25,22 @@ try {
2525
console.log('The channel has been created with name and description.\n');
2626

2727
// Fetch current object with custom fields
28-
let currentObjectResponse = await pubnub.objects.getChannelMetadata({
28+
const currentObjectResponse = await pubnub.objects.getChannelMetadata({
2929
channel: channel,
3030
include: {
3131
customFields: true,
3232
},
3333
});
34-
let currentObject = currentObjectResponse.data;
34+
const currentObject = currentObjectResponse.data;
3535

3636
// Initialize the custom field object
37-
let custom = currentObject.custom || {};
37+
const custom = currentObject.custom || {};
3838

3939
// Add or update the field
4040
custom['edit'] = 'admin';
4141

4242
// Writing the updated object back to the server
43-
let setResponse = await pubnub.objects.setChannelMetadata({
43+
const setResponse = await pubnub.objects.setChannelMetadata({
4444
channel: channel,
4545
data: {
4646
name: currentObject.name || '',

docs-snippets/basic-usage/access-manager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ try {
4545

4646
// snippet.parseTokenBasicUsage
4747
pubnub.parseToken(
48-
'p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI',
48+
'p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnc' +
49+
'tokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI',
4950
);
5051
// snippet.end
5152

5253
// snippet.setTokenBasicUsage
5354
pubnub.setToken(
54-
'p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnctokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI',
55+
'p0thisAkFl043rhDdHRsCkNyZXisRGNoYW6hanNlY3JldAFDZ3Jwsample3KgQ3NwY6BDcGF0pERjaGFuoENnc' +
56+
'tokenVzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI',
5557
);
5658
// snippet.end

docs-snippets/basic-usage/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PubNub from '../../src/web/index';
22

33
// snippet.configurationBasicUsageSubscriptionWorkerUrl
4-
var pubnub = new PubNub({
4+
const pubnub = new PubNub({
55
subscribeKey: 'demo',
66
publishKey: 'demo',
77
userId: 'unique-user-id',
@@ -29,7 +29,7 @@ PubNub.generateUUID();
2929

3030
// snippet.configurationBasicUsage
3131
// Initialize PubNub with your keys
32-
var pubnub = new PubNub({
32+
const pubnubConfig = new PubNub({
3333
subscribeKey: 'YOUR_SUBSCRIBE_KEY',
3434
publishKey: 'YOUR_PUBLISH_KEY',
3535
userId: 'YOUR_USER_ID',

docs-snippets/basic-usage/download-file-web.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@ const pubnub = new PubNub({
1010
// snippet.downloadFileWebBasicUsage
1111
// In browser
1212
// download the intended file
13-
let file;
14-
try {
15-
file = await pubnub.downloadFile({
16-
channel: 'my_channel',
17-
id: '...',
18-
name: 'cat_picture.jpg',
19-
});
20-
} catch (error) {
21-
console.error(
22-
`Download file error: ${error}.${
23-
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
24-
}`,
25-
);
26-
}
13+
const downloadFile = async () => {
14+
try {
15+
const file = await pubnub.downloadFile({
16+
channel: 'my_channel',
17+
id: '...',
18+
name: 'cat_picture.jpg',
19+
});
2720

28-
// have proper html element to display the file
29-
const myImageTag = document.createElement('img');
30-
myImageTag.src = URL.createObjectURL(await file!.toFile());
21+
// have proper html element to display the file
22+
const myImageTag = document.createElement('img');
23+
myImageTag.src = URL.createObjectURL(await file!.toFile());
3124

32-
// attach the file content to the html element
33-
document.body.appendChild(myImageTag);
25+
// attach the file content to the html element
26+
document.body.appendChild(myImageTag);
27+
} catch (error) {
28+
console.error(
29+
`Download file error: ${error}.${
30+
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
31+
}`,
32+
);
33+
}
34+
};
3435
// snippet.end

docs-snippets/basic-usage/event-listener.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ const pubnub = new PubNub({
88

99
// snippet.eventListenerBasicUsage
1010
// create a subscription from a channel entity
11-
const channel = pubnub.channel('channel_1')
11+
const channel = pubnub.channel('channel_1');
1212
const subscription1 = channel.subscription({ receivePresenceEvents: true });
1313

1414
// create a subscription set with multiple channels
1515
const subscriptionSet1 = pubnub.subscriptionSet({ channels: ['ch1', 'ch2'] });
1616

1717
// add a status listener
1818
pubnub.addListener({
19-
status: (s) => {console.log('Status', s.category) }
19+
status: (s) => {
20+
console.log('Status', s.category);
21+
},
2022
});
2123

2224
// add message and presence listeners
2325
subscription1.addListener({
24-
// Messages
25-
message: (m) => { console.log('Received message', m) },
26-
// Presence
27-
presence: (p) => { console.log('Presence event', p) },
26+
// Messages
27+
message: (m) => {
28+
console.log('Received message', m);
29+
},
30+
// Presence
31+
presence: (p) => {
32+
console.log('Presence event', p);
33+
},
2834
});
2935

30-
// add event-specific message actions listener
36+
// add event-specific message actions listener
3137
subscriptionSet1.onMessageAction = (p) => {
32-
console.log('Message action event:', p);
38+
console.log('Message action event:', p);
3339
};
3440

3541
subscription1.subscribe();
@@ -39,7 +45,9 @@ subscriptionSet1.subscribe();
3945
// snippet.eventListenerAddConnectionStatusListenersBasicUsage
4046
// add a status listener
4147
pubnub.addListener({
42-
status: (s) => {console.log('Status', s.category) }
48+
status: (s) => {
49+
console.log('Status', s.category);
50+
},
4351
});
4452
// snippet.end
4553

docs-snippets/basic-usage/message-actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ try {
4646
// snippet.end
4747

4848
// snippet.getMessageActionsBasicUsage
49-
// to get some data in response, first publish a message and then add a message action using addMessageAction() method.
49+
// to get some data in response, first publish a message and then add a message action
50+
// using addMessageAction() method.
5051
try {
5152
const response = await pubnub.getMessageActions({
5253
channel: 'channel_name',

docs-snippets/basic-usage/miscellaneous.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ const file = pubnub.File.create({ data: fileBuffer, name: 'cat_picture.jpg', mim
3232
const encryptedFile = await pubnub.encryptFile(file);
3333
// snippet.end
3434

35-
let encrypted = '..';
35+
const encrypted = '..';
3636
// snippet.decryptBasicUsage
37-
var decrypted = pubnub.decrypt(encrypted); // Pass the encrypted data as the first parameter in decrypt Method
37+
const decrypted = pubnub.decrypt(encrypted); // Pass the encrypted data as the first parameter in decrypt Method
3838
// snippet.end
3939

4040
// snippet.decryptFileBasicUsage

docs-snippets/basic-usage/mobile-push.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ try {
142142

143143
// snippet.buildNotificationPayloadBasicUsage
144144

145-
let builder = PubNub.notificationPayload('Chat invitation', "You have been invited to 'quiz' chat");
146-
let messagePayload = builder.buildPayload(['apns2', 'fcm']);
145+
const builder = PubNub.notificationPayload('Chat invitation', "You have been invited to 'quiz' chat");
146+
const messagePayload = builder.buildPayload(['apns2', 'fcm']);
147147
// add required fields to the payload
148148

149149
const response = await pubnub.publish({

docs-snippets/basic-usage/publish-subscribe.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ const pubnub = new PubNub({
77
});
88

99
// snippet.publishBasicUsage
10-
try {
11-
const response = await pubnub.publish({
12-
message: { text: 'Hello World' },
13-
channel: 'my_channel',
14-
sendByPost: false,
15-
storeInHistory: true,
16-
meta: { sender: 'user123' },
17-
customMessageType: 'text-message',
18-
});
19-
console.log('Publish Success:', response);
20-
} catch (error) {
21-
console.error(
22-
`Publish Failed: ${error}.${
23-
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
24-
}`,
25-
);
26-
}
10+
try {
11+
const response = await pubnub.publish({
12+
message: { text: 'Hello World' },
13+
channel: 'my_channel',
14+
sendByPost: false,
15+
storeInHistory: true,
16+
meta: { sender: 'user123' },
17+
customMessageType: 'text-message',
18+
});
19+
console.log('Publish Success:', response);
20+
} catch (error) {
21+
console.error(
22+
`Publish Failed: ${error}.${
23+
(error as PubNubError).status ? ` Additional information: ${(error as PubNubError).status}` : ''
24+
}`,
25+
);
26+
}
2727
// snippet.end
2828

2929
// snippet.signalBasicUsage
@@ -124,17 +124,16 @@ groupSubscription1.subscribe();
124124
pubnub.unsubscribeAll();
125125
// snippet.end
126126

127-
128127
// *********** OLD SYNTAX ***********
129128
// snippet.OLDsubscribeBasicUsage
130129
pubnub.subscribe({
131-
channels: ["my_channel"],
130+
channels: ['my_channel'],
132131
});
133132
// snippet.end
134133

135134
// snippet.OLDUnsubscribeBasicUsage
136135
pubnub.unsubscribe({
137-
channels: ["my_channel"],
136+
channels: ['my_channel'],
138137
});
139138
// snippet.end
140139

0 commit comments

Comments
 (0)