-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Adds Flutter GCM package #913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright 2015 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package org.domokit.fitness; | ||
|
|
||
| import android.content.Context; | ||
|
|
||
| import org.chromium.mojo.system.Core; | ||
| import org.chromium.mojo.system.MessagePipeHandle; | ||
| import org.chromium.mojom.gcm.GcmService; | ||
| import org.domokit.gcm.RegistrationIntentService; | ||
| import org.domokit.sky.shell.ServiceFactory; | ||
| import org.domokit.sky.shell.ServiceRegistry; | ||
| import org.domokit.sky.shell.SkyApplication; | ||
|
|
||
| /** | ||
| * Sky implementation of {@link android.app.Application}, managing application-level global | ||
| * state and initializations. | ||
| */ | ||
| public class FitnessApplication extends SkyApplication { | ||
| /** | ||
| * Override this function to register more services. | ||
| */ | ||
| protected void onServiceRegistryAvailable(ServiceRegistry registry) { | ||
| super.onServiceRegistryAvailable(registry); | ||
|
|
||
| registry.register(GcmService.MANAGER.getName(), new ServiceFactory() { | ||
| @Override | ||
| public void connectToService(Context context, Core core, MessagePipeHandle pipe) { | ||
| GcmService.MANAGER.bind( | ||
| new RegistrationIntentService.MojoService(context), pipe); | ||
| } | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,3 +5,5 @@ dependencies: | |
| path: ../../packages/flutter | ||
| playfair: | ||
| path: ../../packages/playfair | ||
| gcm: | ||
| path: ../../packages/gcm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .DS_Store | ||
| .idea | ||
| .packages | ||
| .pub/ | ||
| build/ | ||
| packages | ||
| pubspec.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright 2015 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// Service exposed to Flutter apps that implements a subset of the GCM API. | ||
| /// | ||
| /// This library will probably be moved into a separate package eventually. | ||
| library gcm; | ||
|
|
||
| export 'src/gcm.dart'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright 2015, the Flutter authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
|
|
||
| import 'package:flutter/services.dart'; | ||
| import 'package:sky_services/gcm/gcm.mojom.dart'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like you didn't git add gcm.mojom.dart.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a generated file from gcm.mojom in https://github.com/flutter/engine/pull/2182/files
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right. Yeah we definitely don't want anything to end up in the engine repo for this eventually. But again, as you say, this is fine for initial discovery of the problem space. Might be worth putting comments around this saying this is all temporary and that eventually third-party services will have their own repo(s), just in case someone looks at the code in the meantime... |
||
|
|
||
| GcmServiceProxy _initGcmService() { | ||
| GcmServiceProxy gcmService = new GcmServiceProxy.unbound(); | ||
| shell.connectToService(null, gcmService); | ||
| return gcmService; | ||
| } | ||
|
|
||
| final GcmServiceProxy _gcmService = _initGcmService(); | ||
|
|
||
| typedef void GcmListenerCallback(String from, String message); | ||
| class _GcmListenerImpl implements GcmListener { | ||
| _GcmListenerImpl(this.callback); | ||
|
|
||
| GcmListenerCallback callback; | ||
|
|
||
| void onMessageReceived(String from, String message) { | ||
| callback(from, message); | ||
| } | ||
| } | ||
|
|
||
| Future<String> registerGcmService(String senderId, GcmListenerCallback listenerCallback) async { | ||
| GcmListenerStub listener = new GcmListenerStub.unbound() | ||
| ..impl = new _GcmListenerImpl(listenerCallback); | ||
| GcmServiceRegisterResponseParams result = | ||
| await _gcmService.ptr.register(senderId, listener); | ||
| return result.token; | ||
| } | ||
|
|
||
| void subscribeTopics(String token, List<String> topics) { | ||
| _gcmService.ptr.subscribeTopics(token, topics); | ||
| } | ||
|
|
||
| void unsubscribeTopics(String token, List<String> topics) { | ||
| _gcmService.ptr.unsubscribeTopics(token, topics); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: gcm | ||
| description: Bindings for Google Cloud Messaging API | ||
| version: 0.0.1 | ||
| author: Flutter Authors <[email protected]> | ||
| homepage: https://github.com/flutter/flutter/tree/master/packages/playfair | ||
|
|
||
| dependencies: | ||
| flutter: | ||
| path: ../flutter | ||
|
|
||
| dev_dependencies: | ||
| test: 0.12.6+1 | ||
|
|
||
| environment: | ||
| sdk: '>=1.12.0 <2.0.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably open a separate github repo for "third party services" and have this be one of them. @collinjackson has a similar issue with his work. cc @abarth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(it doesn't have to be now, but it should be really soon. Having Google-specific services in the Flutter repo gives a very mixed message about what Flutter is. We want to make sure other companies and developers understand that they are peers, not subordinate in any way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Our plan is to put them in the main repo first to see what is needed, then move them to a separate repo.