Sunday 23 December 2018

FCM push notification example

FCM push notification example

Question: What is FCM Messages?
Full form of FCM is Firebase Cloud Messaging.
FCM is a cross-platform messaging solution that lets you reliably deliver messages to android and IOS devices at no cost.
You can notify a client app that new message has been arrived.



Question: How does FCM works?
App server interacts with FCM (HTTP or XMPP protocol) and a client app. You can compose and send messages.
FCM built on Firebase Cloud Messaging.


Question: What is FCM Server?
FCM servers take messages from an app server and send to cient app.
FCM connection servers provided by Google.


Question: What is App Server?
App Server sends data to a client app (via the chosen FCM connection server) using XMPP or HTTP protocol.



Question: What are role of App Server?
  • Communicate with your client
  • Send properly formatted requests to the FCM connection server
  • Securely store the Server key and client registration tokens



Question:How to send notification to android/IOS device with FCM server?
$jsonData='{
  "to": "dhkC5_jTnck:APA91bF7L_KN7GFOPMiVsykjMGqydlftItfapC4Va63hRBuhFCrRKMdUonqhO1qjKT5_OYPMRAZFMA2UDVA1spAw9SpCsLE7B05vGtNttvuykIdxL7jKWWvJkA51T98O8ZZkubhXwQyRx",
  "notification": {
    "body": "New Gr sent you a message",
    "title": "domain.com ",
    "icon": "main_ve_logo",
    "click_action": "com.domain.fcm"
  },
  "data": {
    "type": "message",    
    "avatar": "http://img.domain.com/upload/default.jpg",
    "message_id": 1
  }
}';
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($fields),
    CURLOPT_HTTPHEADER => array(
      "authorization: key=FCM_SERVER_KEY",
      "cache-control: no-cache",
      "content-type: application/json"
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);




Thursday 20 December 2018

Node JS tutorial for beginner

NodeJS Framework Understanding

Question: What is NodeJS
Node.js is a platform built for fast and scalable network applications. It uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices. It can be used in Websites application, Android applicationa and IOS application etc.


Question: What type of framework is Nodejs?
NodeJS is JavaScript-based framework/platform



Question: Is Nodejs Server OR Cient Side?
Both, Node work for both.



Question: What is REPL?
REPL stands for Read Eval Print Loop
Node.js comes with virtual environment called REPL (also Node shell).


Question: What are most common REPL Commands?
ctrl + c
Terminate the current command.
ctrl + c twice 
terminate the Node REPL.
Up/Down Keys
see command history.
tab Keys
list of current commands.
.help
list of all commands.
.break
exit from multiline expression.
.save filename 
save the current Node REPL session to a file.
.load filename
load file content in current Node REPL session.



Question: How to exist from REPL?
ctrl + c twice 



Question: How to install module in NodeJS?
npm install express
for install express.


Question: How to uninstall module in NodeJS?
npm uninstall express
for uninstall express.