init
Initialize and configure the push client.
Signature:
_tikPush('init', config);
Config:
- config.applicationServerKey
- config.authToken
- config.debug
- config.path
Example:
_tikPush('init', {
applicationServerKey: "your_application_server_public_key",
authToken: "your_auth_token_subscription",
debug: true,
path: "/"
});
pushAvailable
Checks for Browser Support and push availability.
Signature:
_tikPush('pushAvailable', callback);
The callback will be called with one parameter. This parameter is true if the browser is supported and the user has not denied notifications, otherwise its false. Example:
_tikPush('pushAvailable', function(isAvailable, reason){
if(isAvailable){
// push is available
} else {
if(reason === 'browserNotSupported'){
// current browser is not supported
} else if(reason === 'denied'){
// user denied notifications
} else if(reason === 'notSecure'){
// site is not running with https or is localhost|127.0.0.1
}
}
});
ready
Ensures the pushclient is initialized and the browser is supported. This is the default call to interact with the pushclient.
Signature:
_tikPush('ready', successCallback, failureCallback);
The ready call accepts two callbacks. The first one will only be called if the browser is supported and second one if the browser is not supported. The failureCallback is optional and is called with one parameter (reason). Reason can be denied or browserNotSupported. Example:
_tikPush('ready', function(pushclient){
// browser supported case
}, function(reason){
if(reason === "denied"){
// user denied push
} else if(reason === "browserNotSupported"){
// browser not supported
}
});
The successCallback will be called with the pushclient Object as parameter.
The pushclient Object
NOTE: All calls for the pushclient obbject are asynchron and return a promise.
subscribe
Subscribe to a channel.
Signature:
pushclient.subscribe(channelName, expiresAt)
Example:
pushclient.subscribe("news.top").then(function(){
// Do something after subscribe call
})
.catch(function(e){
// Handle error case
})
- channelName - Name of the channel to subscribe
- expiresAt - Optional: Expiration date of the subscription (Javascript Date)
unsubscribe
Subscribe to a channel.
Signature:
pushclient.unsubscribe(channelName)
Example:
pushclient.unsubscribe("news.top").then(function(){
// Do something after unsubscribe call
})
.catch(function(e){
// Handle error case
})
- channelName - Name of the channel to unsubscribe
isSubscribed
Check if a user is subscribed to a specific channel. Returns true or false.
Signature:
pushclient.isSubscribed(channelName)
Example:
pushclient.isSubscribed("news.top").then(function(isSubscribed){
if(isSubscribed){
// User is subscribed to channel
} else {
// User is not subscribed to channel
}
})
.catch(function(e){
// Handle error case
})
- channelName - Name of the channel
enablePush
This registers the service worker and requests a subscription from the browser and send this information to the Tickaroo Live Push Service. The first time the user will be asked for permission. This method will be called automatically the first time a users subscribes to a channel.
Signature:
pushclient.enablePush()
Example:
pushclient.enablePush().then(function(){
// Do something after subscribed to push
})
disablePush
This resets all subscriptions on the Tickaroo Push Service and unsubscribe the service worker.
Signature:
pushclient.disablePush()
Example:
pushclient.disablePush().then(function(){
// Do something after unsubscribed from push
})
pushEnabled
Check if a user has a active subscription.
Signature:
pushclient.pushEnabled()
Example:
pushclient.pushEnabled().then(function(pushEnabled){
if(pushEnabled){
// User is subscribed to push
} else {
// User is not subscribed to push
}
})