Skip to content
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

Integrating FCM or PubSub Push #51

Open
Skquark opened this issue Apr 9, 2019 · 6 comments
Open

Integrating FCM or PubSub Push #51

Skquark opened this issue Apr 9, 2019 · 6 comments

Comments

@Skquark
Copy link

Skquark commented Apr 9, 2019

I'm facing problems using the Dart fcm_push or the pubsub push in gcloud. I installed the gcloud, googleapis and googleapis_auth dependencies, and set up the ServiceAccountCredentials to get the AuthClient, and everything seems to be done right, however I get this uncaught exception in the log:
ReferenceError: XMLHttpRequest is not defined
at /user_code/build/node/main.dart.js:9351:7

I just can't get past that, no matter what I tried. Is there a trick I'm missing, or a better way to push notifications to subscribers or user token ids using this interop? Here is my pubsub.yaml:

dependencies:
  firebase_functions_interop: ^1.0.0
  fcm_push: ^1.3.1
  gcloud: ^0.6.0+4
  googleapis: ^0.53.0
  cron: ^0.2.2

dev_dependencies:
  build_runner: ^1.0.0
  build_node_compilers: ^0.2.0
  googleapis_auth: '>=0.2.3 <0.3.0'

and my relevant imports:

import 'package:fcm_push/fcm_push.dart' as fcm;
import 'package:googleapis_auth/auth_io.dart' as auth;
import 'package:http/http.dart' as http;
import 'package:gcloud/pubsub.dart' as pubsub; 

and my code to init the client:

auth.AuthClient client;
pubsub.PubSub pubSub;
fcm.FCM cloudMessaging;

  var credentials = auth.ServiceAccountCredentials.fromJson(r'''
{
  "type": "service_account",
  "project_id": "....",
  "private_key_id": "....",
//Taken from key credentials json download
}
''');
  var scopes = pubsub.PubSub.SCOPES;
  print("Init 1 - auth client Metadata");
  client = await auth.clientViaServiceAccount(credentials, scopes);
  //client = await auth.clientViaMetadataServer();
  print("Init 2 - Getting pubSub");
  pubSub = new pubsub.PubSub(client, "functions");

Everything builds/deploys correctly, except in the log with the client auth, or try to do a cloudMessaging.send() I get that pesky XMLHttpRequest is not defined error that I can't find anything about fixing. Has anyone else been able to send push notifications from their Firebase Functions trigger? Seems like it would be a common use case, any help would be appreciated, thanks..

@Skquark Skquark changed the title FCM or PubSub Push Support Integrating FCM or PubSub Push Apr 13, 2019
@Skquark
Copy link
Author

Skquark commented Jun 1, 2019

I'm still trying to figure this out, I really don't want to redo all my code in the JavaScript. There's gotta be a way to send Firebase Cloud Messaging from here, that's my whole purpose of needing to run a Firebase Functions server to send notifications. Any ideas?

@ThinkDigitalSoftware
Copy link

It does seem like messaging is missing from the admin class here

@pulyaevskiy
Copy link
Owner

I'm not sure I understand the problem here. Do you have a cloud function which should send a PubSub message?

If you're using googleapis packages I'll likely need to implement Node.js specific googleapis_auth client, because it looks like only supports dart:io and web browser HTTP clients.

Of course, it would be nice to add FCM support to firebase_admin_interop so that we can use Firebase SDKs directly.

@ThinkDigitalSoftware
Copy link

Yeah, that's what I'm waiting for myself

@Skquark
Copy link
Author

Skquark commented Jun 3, 2019

I had hoped the native dart plugins would have been compatible, but I'm realizing the interop trick having to translate to node.js calls.. It would be nice if it was a builtin function for sure. I don't know if pubsub is easier to impliment or Cloud Messaging, I could go with either for pushing notification to a channel group or individual Firebase UIDs. Whatever's easier to hack together, it's that missing piece to get my app functional. If I can help, lemme know, but this part of code gets daunting... Thanks.

@kaciula
Copy link

kaciula commented Jul 15, 2021

Did anyone here manage to send a push message from dart in a Firebase function? I really hope I do not have to redo all my code using Javascript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants