Chorme Web Push Notification with payload - php

self.addEventListener('push', function(event) {
var jsonObj = event.data.json();
}
I have written chrome web push notification, but event.data is always null.
Currently I am using GCMPushMessage library, I think I need php curl for sending notification. Can anybody help me to send web push notification with payload?

As of 2015 , this related SO post stated, this is an intended behavior.
A downside to the current implementation of the Push API in Chrome is that you can't send any data with a push message. Nope, nothing. The reason for this is that in a future implementation, payload data will have to be encrypted on your server before it's sent to a push messaging endpoint. This way the endpoint, whatever push provider it is, will not be able to easily view the content of the push message. This also protects against other vulnerabilities like poor validation of HTTPS certificates and man-in-the-middle attacks between your server and the push provider. However, this encryption isn't supported yet, so in the meantime you'll need to perform a fetch to get information needed to populate a notification.
As provided by the document you have to fetch the information then populate it in the notification.
An update was released March 2016 named : Web Push Payload Encryption
Prior to Chrome 50, push messages could not contain any payload data. When the 'push' event fired in your service worker, all you knew was that the server was trying to tell you something, but not what it might be. You then had to make a follow up request to the server and obtain the details of the notification to show, which might fail in poor network conditions.
Now in Chrome 50 (and in the current version of Firefox on desktop) you can send some arbitrary data along with the push so that the client can avoid making the extra request. However, with great power comes great responsibility, so all payload data must be encrypted.
Ensure you've followed the implementation needed for applying payload in web push for Chrome. Like some Client-side changes and Server-side changes.
Hope this helps.

Related

sending fcm notification messages to multiple android devices by registration_ids parameter

I want to send notifications to multiple android devices(where same app is installed) by fcm from php server side by calling this url -
https://fcm.googleapis.com/fcm/send
I checked sending messages to device groups but my requirement is such that there will not be definite devices to which i will send messages because i am going to do it in a hourly cron job, and each time a cron job runs it will send notification messages to different different devices according to requirements. or can it be done in another way?
But i am thinking to use "registration_ids" parameter instead of "to" parameter, details of these fields here in the Downstream HTTP messages section. In this registration_ids field i will put all required device registration tokens in array. Now my question is after receiving message in android device can the message be parsed in the android app sdk codes?. i am in a bit of doubt as in this documentation there are no mentions of registration_ids parameter when sending messages to multiple android devices. Please assure me. And furthermore, will the message be sent when android app is in background?!. Please don't write one line, provide some examples if possible.
In the documentation for building requests to send to multiple devices you will find an example of passing multiple FCM tokens in a single call to the FCM API in the tokens parameter (in Node.js) or by using a HTTP batch request with multiple subrequests (in the REST API).
If you're having a hard time making this work, posting a question that shows what you tried increases the chances that someone can help making it work.
Yes, the message is sent regardless of whether the app is in the foreground, or in background. Whether the notification is actually shown depends on many more factors, many of which are outside of your control (such as the Android version, device maker/OEM, and the user settings).

Poloniex push api

I am interested in writing some basic php to interface with the Poloniex push api.
Their website provides the following info:
https://poloniex.com/support/api/
A php wrapper can be found here:
http://pastebin.com/iuezwGRZ
From what i can determine there are three APIs being push, public and trading. The public and trading APIs provide functions that can be passed parameters etc. The push api stumps me totally as i cannot determine how it works.
The first link above states the API pushes live data and different feeds can be subscribed to.
My questions are:
A) How can php receive a live stream of data?
B) How do i subscribe to a feed?
I may have misunderstood the oush api and my apologies in advance if this is the case.
Edit1:
I believe i need a WAMP client to connect to a WAMP router such as Minion.
https://github.com/Vinelab/minion
Edit2:
Node.js example
http://pastebin.com/dMX7mZE0
The push API is based on Websocket protocol.
Initially you need first to make a connection to the websocket server,
after that you need to register to a data stream (price update stream for example), after that as soon as the server make an update to something (a price ), all connected clients who where previously registred to it will synchronously received the updated price
Finally you got the last price without the need of doublecheck at regular interval if the price has changed

Sending push messages to all open chrome browsers via GCM

I am trying to develop a web site which will send push notifications to all users currently watching it. I found some tutorials on how to send pushes to myself using GCM for Chrome and they are working fine,
(https://github.com/gauntface/simple-push-demo)
but I cannot understand how to send pushes to every user who is currently on my site and allowed to receive them. As far as I understand I need to collect their browser IDs when they subscribe
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
serviceWorkerRegistration.pushManager.subscribe({ userVisibleOnly: true })
.then(onPushSubscription)
but I cannot find how to get and store them (perhaps in MySQL DB with PHP code) and after that how to send a push to everyone (probably to iterate over all browsers IDs in my DB and send pushes to everyone separately with cURL requests). On my site I have code which uses ServiceWorkers and handles users subscription but everything is working for me only. Noone who is else on a site does not receive any notifications. Any help would be appreciated.

How to implement dynamic chat application in Ios using php, Something related to Skype like application

I am trying to implement a chat application in IOS. In general We use two php files one for posting a message(sender) another for retrieving the message(receiver).
I want to accomplish the following:
Consider A(sender) and B (Receiver).
A sent message to B. And A is waiting for B's reply. So i need to call post-api.php for sending a message and at the receivers side(B) i need to retrieve using getapi.php
when B reply to A it must automatically appear in my inbox(live chatbox) of A, without calling getapi.php. I know this scenario is not possible. But is there any solution or method so that my chat application works like skype or facebookchat.
There is multiple way to implement the chat functionality.
Polling: Send request to server and process the response from the server in timely fashion after a particular time interval using NSTimer(But remember is will cause the battery drain).
Using APNS: Using the official Apple push notification implementation, whenever there is new entry in chat table on server side send the notification to particular device using push notification and handle the notification using the delegate methods (Although not 100% reliable).Using Push Notification
Using Socket Programming: Using the socket programming you can have dedicated connection between client(device) and server. I have provided the link having the source at the end of the tutorial.Using Socket Programming
As you know that without getapi.php it is not possible to update chat list so you need to make management something like: you need to use NSTimer and with the help of timer you need to call your getapi.php service after certain time interval let say after 2min so that chat can be refresh and user get the reply this is the only possible way at my knowledge.

HTTP Commands via Jquery

I've been asked how we can send and receive HTTP requests to trigger a Mobile Text billing service. The billing service has no webservice to respond/trigger these message and will only take requests from a whitelisted IP. Therefore I assume we need a server side web service written that can handle a client request - trigger a billing message and return a reply to the client jquery/ajax.
This is coming from a fron-end developer with limited back end knowledge though! Therefore does anyone agree with my assumption - before I respond!?
Cheers
Paul
A webService is most prefferable. it gives more flexibility for future changes on the front end architechture (or type)

Categories