Dart Documentationchrome.pushMessagingChromePushMessaging

ChromePushMessaging class

class ChromePushMessaging extends ChromeApi {
 static final JsObject _pushMessaging = chrome['pushMessaging'];

 ChromePushMessaging._();

 bool get available => _pushMessaging != null;

 /**
  * Retrieves the channel ID associated with this app or extension. Typically
  * an app or extension will want to send this value to its application server
  * so the server can use it to trigger push messages back to the app or
  * extension. If the interactive flag is set, we will ask the user to log in
  * when they are not already logged in.
  */
 Future<ChannelIdResult> getChannelId([bool interactive]) {
   if (_pushMessaging == null) _throwNotAvailable();

   var completer = new ChromeCompleter<ChannelIdResult>.oneArg(_createChannelIdResult);
   _pushMessaging.callMethod('getChannelId', [interactive, completer.callback]);
   return completer.future;
 }

 Stream<Message> get onMessage => _onMessage.stream;

 final ChromeStreamController<Message> _onMessage =
     new ChromeStreamController<Message>.oneArg(_pushMessaging, 'onMessage', _createMessage);

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.pushMessaging' is not available");
 }
}

Extends

ChromeApi > ChromePushMessaging

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _pushMessaging != null;

final Stream<Message> onMessage #

Stream<Message> get onMessage => _onMessage.stream;

Methods

Future<ChannelIdResult> getChannelId([bool interactive]) #

Retrieves the channel ID associated with this app or extension. Typically an app or extension will want to send this value to its application server so the server can use it to trigger push messages back to the app or extension. If the interactive flag is set, we will ask the user to log in when they are not already logged in.

Future<ChannelIdResult> getChannelId([bool interactive]) {
 if (_pushMessaging == null) _throwNotAvailable();

 var completer = new ChromeCompleter<ChannelIdResult>.oneArg(_createChannelIdResult);
 _pushMessaging.callMethod('getChannelId', [interactive, completer.callback]);
 return completer.future;
}