Utility Methods API for Vue SDK
The methods on this page are utility methods that don't fit into other categories.
Close PubNub
End all open requests and close
the PubNub instance.
Basic Usage
import PubNubVue from 'pubnub-vue';
const pubnub = PubNubVue.getInstance();
pubnub.stop();
Decrypt
This function allows to decrypt
the data.
Method(s)
To decrypt
the data you can use the following method(s) in Vue SDK.
decrypt(data: string, customCipherKey: ?string)
Parameter | Description |
---|---|
data *Type: String | The data to decrypt . |
customCipherKey Type: String | If it's not provided, the cipher key from config will be used. |
Basic Usage
import PubNubVue from 'pubnub-vue';
const pubnub = PubNubVue.getInstance();
const decrypted = pubnub.decrypt(encrypted, 'myCipherKey'); // Pass the encrypted data as the first parameter in decrypt Method
Returns
It returns the decrypted data
as an object.
Encrypt
This function allows to encrypt
the data.
Method(s)
To encrypt
the data you can use the following method(s) in Vue SDK.
encrypt(data: string, customCipherKey: ?string)
Parameter | Description |
---|---|
data *Type: String | The data to encrypt . |
customCipherKey Type: String | If it's not provided, the cipher key from config will be used. |
Basic Usage
import PubNubVue from 'pubnub-vue';
const pubnub = PubNubVue.getInstance();
const sCypher = "testCypher";
const msgContent = "This is the data I wish to encrypt.";
console.log('msgContent: '+ msgContent);
// Encrypt with pubnub
const encryptedMessage = pubnub.encrypt(JSON.stringify(msgContent), sCypher);
console.log('encryptedMessage PN: '+ encryptedMessage);
Returns
It returns the encrypted data
as string.
Reconnect
Call the reconnect
method to force the SDK to try and reach out PubNub.
Method(s)
To reconnect
the data you can use the following method(s) in Vue SDK.
reconnect()
This method doesn't take any arguments.
Basic Usage
import PubNubVue from 'pubnub-vue';
const pubnub = PubNubVue.getInstance();
pubnub.reconnect();
Time
This function will return a 17 digit precision Unix epoch.
The timetoken is constructed using the following algorithm:
timetoken = (Unix epoch time in seconds) * 10000000
Example of creating a timetoken for a specific time and date
08/19/2013 @ 9:20pm in UTC = 1376961606
timetoken = 1376961606 * 10000000
timetoken = 13769616060000000
Method(s)
To fetch Time
you can use the following method(s) in Vue SDK:
time(Function callback)
Parameter | Description |
---|---|
callback *Type: Function | Callback is called after a successful return. |
Basic Usage
import PubNubVue from 'pubnub-vue';
const pubnub = PubNubVue.getInstance();
pubnub.time(function(status, response) {
if (status.error) {
// handle error if something went wrong based on the status object
} else {
console.log(response.timetoken);
}
});
Response
//Example of status
{
error: false,
operation: 'PNTimeOperation',
statusCode: 200
}
//Example of response
{
timetoken: 15031768233407550
}
Other Examples
Basic usage using Promises
import PubNubVue from 'pubnub-vue';
const pubnub = PubNubVue.getInstance();
pubnub.time().then((timetoken) => {
console.log(timetoken);
}).catch((error) => {
console.log(error);
});
Push Notification Configuration
APNS2Configuration
APNS2
configuration type.
Method(s)
type APNS2Configuration = { collapseId?: string, expirationDate?: Date, targets: Array<APNS2Target>}
Parameter | Description |
---|---|
collapseId Type: String | Notification group / collapse identifier. Value will be used in APNS POST request as apns-collapse-id header value. |
expirationDate Type: Date | Date till which APNS will try to deliver notification to target device. Value will be used in APNS POST request as apns-expiration header value. |
targets *Type: Array< APNS2Target > | List of topics which should receive this notification. |
APNSNotificationPayload
APNSNotificationPayload
instance provides access to options specific only to mobile push notifications sent with APNs.
Properties
Parameter | Description |
---|---|
configurations Type: Array< APNS2NotificationConfiguration *> * | List of HTTP/2-based APNs delivery configurations. |
notification Type: Hash | Hash with parameters which specify user-visible key-value pairs. |
payload Type: Hash | Platform specific notification payload. In addition to data required to make notification visual presentation it can be used to pass additional information which should be sent to remote device. |
silent Type: Boolean | Whether operation system should handle notification layout by default or not. alert , sound and badge will be removed from resulting payload if set to true . |
APNS2Target
APNS2
configuration target type.
Method(s)
type APNS2Target = { topic: string, environment?: 'development' | 'production', excludedDevices?: Array<string>}
Parameter | Description |
---|---|
topic |