chrome.gcm
Description: |
Use chrome.gcm to enable apps and extensions to send and receive messages through the Google Cloud Messaging Service.
|
Availability: |
Since Chrome 35.
|
Permissions: |
"gcm"
|
Learn More: |
Implementing GCM Client on Chrome
|
Summary
Properties | |
---|---|
MAX_MESSAGE_SIZE | |
Methods | |
register −
chrome.gcm.register(array of string senderIds, function callback)
| |
unregister −
chrome.gcm.unregister(function callback)
| |
send −
chrome.gcm.send(object message, function callback)
| |
Events | |
onMessage | |
onMessagesDeleted | |
onSendError |
Properties
4,096 |
chrome.gcm.MAX_MESSAGE_SIZE |
The maximum size (in bytes) of all key/value pairs in a message. |
Methods
register
chrome.gcm.register(array of string senderIds, function callback)
Registers the application with GCM. The registration ID will be returned by the callback
. If register
is called again with the same list of senderIds
, the same registration ID will be returned.
Parameters | |||||
---|---|---|---|---|---|
array of string | senderIds |
A list of server IDs that are allowed to send messages to the application. It should contain at least one and no more than 100 sender IDs. |
|||
function | callback |
Function called when registration completes. It should check runtime.lastError for error when The callback parameter should be a function that looks like this: function(string registrationId) {...};
|
unregister
chrome.gcm.unregister(function callback)
Unregisters the application from GCM.
Parameters | ||
---|---|---|
function | callback |
A function called after the unregistration completes. Unregistration was successful if runtime.lastError is not set. The callback parameter should be a function that looks like this: function() {...};
|
send
chrome.gcm.send(object message, function callback)
Sends a message according to its contents.
Parameters | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | message |
A message to send to the other party via GCM.
|
||||||||||||
function | callback |
A function called after the message is successfully queued for sending. runtime.lastError should be checked, to ensure a message was sent without problems. The callback parameter should be a function that looks like this: function(string messageId) {...};
|
Events
onMessage
Fired when a message is received through GCM.
addListener
chrome.gcm.onMessage.addListener(function callback)
Parameters | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(object message) {...};
|
onMessagesDeleted
Fired when a GCM server had to delete messages sent by an app server to the application. See Messages deleted event section of Cloud Messaging documentation for details on handling this event.
addListener
chrome.gcm.onMessagesDeleted.addListener(function callback)
Parameters | ||
---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function() {...};
|
onSendError
Fired when it was not possible to send a message to the GCM server.
addListener
chrome.gcm.onSendError.addListener(function callback)
Parameters | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(object error) {...};
|