Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
513 stars 197 forks source link

Are sounds implemented yet? #9

Closed adamgins closed 9 years ago

adamgins commented 9 years ago

HI,

anything I am missing to get sounds to work?

here's my init:

Push.init({

            bagde: true,
            sound: true,
            alert: true
        });

BTW, they seem to work fine on iOS if I am using one with push simulators.

raix commented 9 years ago

Not sure about push in simulator - it might have quirks - the sound issue not sure - havent used it my self

raix commented 9 years ago

should work in 2.3.0 but QA is needed, havent tested sound at all - but its implemented

pefi1011 commented 9 years ago

Hi @adamgins I get the sound on android when the notification arrives without writing sound:true at all

adamgins commented 9 years ago

@pefi1011 thanks. Yep, that's what I have. I remember reading somewhere that with Cordova on iOS I think you need to specify the sound file.

If I send the test payload (using one of those APN test apps) it works:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff"
    },
    "acme1" : "bar",
    "acme2" : 42
}

but not using this package.

raix commented 9 years ago

It should work now

adamgins commented 9 years ago

Hi, still having an issue with sounds... Do I need to put my own sound file somewhere in the project?

I see code refers to notification.sound not sure what this evaluates to or if I need to pass it as a param

raix commented 9 years ago

@adamgins try the 2.3.3 - I've updated the path to the sound file. It should be placed in the meteor public folder. Meteor puts the app in sub folder application so its updated now - but I'm not 100% sure it will work, meteor actually runs a small server on the device so we are running at http://meteor.local

If you cant get sound to work we might have to try and use the server prefix instead.

krishnaff commented 9 years ago

Hello @adamgins Did you get the sound to work? I tried quite a few combinations including "sound" : "somefile.aiff". I merely want the default native alert tone to play when the push is delivered to the device. Just "sound": true does not work.

adamgins commented 9 years ago

yep, I have same issue. It works fine on Android but cannot get sound to work on iOS. Been flatout on other stuff to come back and look at it. @raix wondering if it works for you?

raix commented 9 years ago

Havent tested this part fully yet

hellogerard commented 9 years ago

@insaneinc01, @adamgins, This may be a long shot, but does this work:

sound: 'default'

if in call, or:

"sound": "default"

if in config.

adamgins commented 9 years ago

It's been a while since I have looked at this issue. Anyone get sounds working on iOS yet?

krishnaff commented 9 years ago

@hellogerard @adamgins No luck yet. Tried sound: 'default' both in the call and config, does not work.

I'm trying only on iOS though.

maabed commented 9 years ago

@hellogerard @adamgins

Push.send({
         from: 'Test',
         title: 'Test',
         text:msgText,
         sound: '/audio/mySound.mp3',
         badge: 1,
         query: { }
      });

works fine for me after adding org.apache.cordova.media plugin

raix commented 9 years ago

@maabed sounds cool - If you guys can confirm that adding the cordova.media plugin solves this we should prop. consider making the media plugin a dependency?

krishnaff commented 9 years ago

@maabed tried your suggestion, but it still doesn't work :( I did add org.apache.cordova.media. I have placed the mySound.mp3 file in the Public folder. Sorry I might be missing something very obvious here.

krishnaff commented 9 years ago

ok! I finally got the sounds working. Just the default native iOS push sound, not customized sounds.

config.push.json never worked for me. It always gets stuck on the Meteor splash screen. So I used @spencercarli suggestion here: https://github.com/raix/push/issues/21#issuecomment-69647337

if (Meteor.isServer) {
  Meteor.startup(function () {
    Push.debug = true;

    Push.Configure({
      apn: {
        passphrase: 'test1011',
        certData: Assets.getText('PushChatCert.pem'),
        keyData: Assets.getText('PushChatKey.pem'),
        gateway: 'gateway.sandbox.push.apple.com'
      },
      production: false
    });
  });
} 
if (Meteor.isClient) {
  Meteor.startup(function() {
    Push.Configure({
      "sound": true
    });
    Push.debug = true;
  })
}

And in push.send call:

Push.send({from: 'push',title: 'Congratulations',text: 'You can now Push to this device!', sound: 'blahblah', query: {}})

Note the value - sound: 'someString'. Thanks @maabed

raix commented 9 years ago

regarding:

config.push.json never worked for me. It always gets stuck on the Meteor splash screen

Have you tried using $ meteor --production?

I've filed an issue on this but they want a replication - I'm not sure I can

krishnaff commented 9 years ago

Hi @raix , --production works! Thanks for that!

Btw, since my requirement is only to trigger the default Push sound on iOS, the org.apache.cordova.media plugin is really not needed.

raix commented 9 years ago

@insaneinc01 super :)

I actually thought the sound was HTML5 why the media plugin is a bit of a surprise.

adamgins commented 9 years ago

Hi folks, great stuff... just catching up here. So, am I reading correctly: 1) we don't actually need the plugin? 2) We just need to add the:

 Push.Configure({
      "sound": true
    });

to the client? 3) sorry a bit confused what's in the sound:<string>? is it just 'default'?

thanks

adamgins commented 9 years ago

Ah by the way, if I add the Push.Configure above, I get: Uncaught Error: Push.Configure should not be called more than once!

I am only calling it once in the client code. But I am using the config.push.json

raix commented 9 years ago

The config.push.json creates the specific Push.Configure in each environment - so you should only use one of the config methods - The sound should be set true in the config and in the push send you reference the sound file as string

adamgins commented 9 years ago

thanks… I was just trying that … but seemed to be getting an issue after installing Cordova media plugin.. do I actually need it?

On 9 Feb 2015, at 5:59 pm, Morten N.O. Nørgaard Henriksen notifications@github.com wrote:

The config.push.json creates the specific Push.Configure in each environment - so you should only use one of the config methods - The sound should be set true in the config and in the push send you reference the sound file as string

— Reply to this email directly or view it on GitHub.

raix commented 9 years ago

I dont think the media is required - but I'm not sure - playing sound on ios is triggy

krishnaff commented 9 years ago

@adamgins The Cordova media plugin is not needed if you only need to trigger the default native push sound on iOS. In the Push.Send call, the "sound": "default" or "sound": "yes" is needed. I guess any string value here will trigger the default push sound. Push.send({from: 'push',title: 'Congratulations', text: 'You can now Push to this device!', sound: 'blahblah', query: {}})

adamgins commented 9 years ago

Thanks @insaneinc01 ok sound playing now while app is open only. Is there something else I need to do so it plays if the app is closed?

adamgins commented 9 years ago

Hi, this started working for whilst the app was closed... not sure if it was an udpate...anyway, closing this. Thanks for all the help folks.

mvgalle commented 8 years ago

Followed all the ideas and examples shown here to do a custom sound. However, I am still not getting the custom sounds to play. I either get the default notification sound, or no sound at all. My config.push.json looks like this (and the actual push notifications do indeed appear):

{ "gcm": { "apiKey": "xxxxxxxx", "projectNumber": xxxxxxxxxx }, "production": false, "badge": true, "sound": true, "alert": true, "vibrate": true }

I have a server method to send the push notification:

'sendNotification': function(id,username){ Push.send({ from: 'push', title: 'My App', text: username + ' Pushed You!', sound: '/sounds/mySound.mp3', badge: 1, query: { userId: id } }); }

I have tried adding cordova.media.plugin but that did not help. All I need is to have a custom push sound. Any help or thoughts for how I could proceed would be great. Thanks everyone.

Streemo commented 8 years ago

I was only able to get vibrations and sound working in iOS after adding 'sound':'default' in the Push.send method. Unfortunately, I've had no success in using custom sounds.

I've tried all three of: 'sound':'www/application/{public,app,nothing}/sound.mp3' with no success.

I've even installed cordova-plugin-media, which I had to use the older commit for because of a cordova-android version > 5.0.0-dev requirement of the latest branch. Unfortunately, that package did nothing. I am going to try listing it as a dependency to this package.

At this point, I can get a default sound and vibrate on iOS, only a vibrate on Android. Still trying to figure out how to get sound working on android. I changed settings on my phone to allow sounds, but still no luck.

Will keep posted.

mvgalle commented 8 years ago

I have tried for weeks trying to get a custom sound to play on android using raix push with no success. I have used the methods you described as well as many others with no success. I'll post if I figure it out. Great package! If custom sounds would work it would be perfect. On Nov 16, 2015 12:16 AM, "Streemo" notifications@github.com wrote:

I was only able to get vibrations and sound working in iOS after adding 'sound':'default' in the Push.send method. Unfortunately, I've had no success in using custom sounds.

I've tried all three of: 'www/application/{public,app,nothing}/sound.mp3' with no success.

I've even installed cordova-plugin-media, which I had to use the older commit for because of a cordova-android version > 5.0.0-dev requirement of the latest branch. Unfortunately, this package did nothing. I am going to try listing it as a dependency to this package.

At this point, I can get a default sound and vibrate on iOS, only a vibrate on Android. Still trying to figure out how to get sound working on android. I changed settings on my phone to allow sounds, but still no luck.

Will keep posted.

— Reply to this email directly or view it on GitHub https://github.com/raix/push/issues/9#issuecomment-156944113.

raix commented 8 years ago

I haven't tested sound yet since shifted to the new cordova plugin - please let me know if you find a bug (I do take pr's :) )

mvgalle commented 8 years ago

Solved! This may be a work around, but it does work and it works consistently. None of the above methods worked for me, however the following does work.

You will want to add a new folder under the following path in your project > .meteor/local/cordova-build/platforms/android/res/ , add a folder called raw . In the raw folder add your sounds.

The resulting folder is the exact location that the sounds are being referenced from in android. To see for yourself, you can run your app on a device and log the errors. Do the following:

  1. Build your application to your phone
  2. in the terminal type: adb logcat >> emulator.log
  3. Send yourself a push notification
  4. Check the log. Notice the following error in the log: Failed to open file 'android.resource://com.yourappname/res/raw/filename

--- Indeed the app is trying to reference a file that does not exist. Thats why creating a new directory called raw and placing the file inside it does the job.

* PLEASE NOTE! IN THE PUSH NOTIFICATION - I ALSO REMOVED THE FILE EXTENSION *.mp3

Push.send({ from: 'push', title: title, text: usernameFrom + ' ' + message, badge: badge, query: { userId: userIdTo }, sound: 'soundNameWithoutExtension' });

I hope this helps.

Matt

Streemo commented 8 years ago

I'll try this out and let you know if I can replicate the success. It's a bummer that this kind of stuff is not normalized. On Nov 24, 2015 2:11 PM, "mvgalle" notifications@github.com wrote:

Solved! This may be a work around, but it does work and it works consistently. None of the above methods worked for me, however the following does work.

You will want to add a new folder under the following path in your project

.meteor/local/cordova-build/platforms/android/res/ , add a folder called raw . In the raw folder add your sounds.

The resulting folder is the exact location that the sounds are being referenced from in android. To see for yourself, you can run your app on a device and log the errors. Do the following:

  1. Build your application to your phone
  2. in the terminal type: adb logcat >> emulator.log
  3. Send yourself a push notification
  4. Check the log. Notice the following error in the log: Failed to open file 'android.resource://com.yourappname/res/raw/filename

--- Indeed the app is trying to reference a file that does not exist. Thats why creating a new directory called raw and placing the file inside it does the job.

* PLEASE NOTE! IN THE PUSH NOTIFICATION - I ALSO REMOVED THE FILE EXTENSION *.mp3

Push.send({ from: 'push', title: title, text: usernameFrom + ' ' + message, badge: badge, query: { userId: userIdTo }, sound: 'soundNameWithoutExtension' });

I hope this helps.

Matt

— Reply to this email directly or view it on GitHub https://github.com/raix/push/issues/9#issuecomment-159422348.

MichaelJCole commented 8 years ago

@mvgalle brilliant solution!

Here's where it's documented in the cordova plugin

I added this to my build before the meteor command. It may require the app to have already been built once.

mkdir -p .meteor/local/cordova-build/platforms/android/res/raw
cp public/alert.mp3 .meteor/local/cordova-build/platforms/android/res/raw/alert.mp3

I tried naming the file res/raw/alert.mp3.mp3 hoping to call it alert.mp3 in the notification, but that did not work :-/ A unified API would likely either need to add the .mp3 for Android or for iOS.

1ns1d3r commented 8 years ago

@mvgalle it's works! thanks

willemserik commented 8 years ago

i can't get it working to play the default sound on IOS. in client/main.js i have: if (Meteor.isClient) { Meteor.startup(function() { Push.Configure({ "sound": true }); Push.debug = true; }) }

in config.push.json i have: { "apn-dev": { "passphrase": "xxxxxxxxxx", "key": "key.pem", "cert": "cert.pem", "gateway": "gateway.sandbox.push.apple.com" },
"production": false, "badge": true, "sound": true, "alert": true, "vibrate": true }

the alert is working and badge too but the sound is not working

Streemo commented 8 years ago

@mvgalle Great! Thanks for sharing, this works. If anyone is still having issues with this problem, here's a summary of what worked for me, from start to finish, using a custom modification of raix:push [1]:

Create myalert.mp3 and myalert.wav. Load myalert.wav into this package via package.js:

...
api.addAssets('lib/public/myalert.wav','client');
api.export('Push')
...

Next, we need to add myalert.mp3 into a special folder to work with android. see @mvgalle's post

#in your project's root
mkdir .meteor/local/cordova-build/platforms/android/res/raw
cp path/to/myalertmp3 .meteor/local/cordova-build/platforms/android/res/raw/myalert.mp3

Your config.push.json should look like this:

{
  ...
  "sound":true
}

Your calls to Push.send should look like this:

Push.send({
  ...
  apn:{
    //this works because we added 'myalert.wav' as an asset to the custom push package.
    sound: "www/application/packages/yourname_push/lib/public/myalert.wav",
    ...
  },
  gcm: {
    //this will refer to the file we placed in '.meteor/local/.../android/res/raw'
    sound: "myalert",
    ...
  }
})

[1] To create a custom modification of raix:push, use git clone to pipe the source code of raix:push into yourproject/packages/push. Then modify the name in package.js to yourname:push. I did this because I needed to modify some source code of raix:push. If you don't need to modify the source, then you can just put myalert.wav into yourproject/public, and meteor should load it into the www/application/... directory during the build.

MichaelJCole commented 8 years ago

Clever @Streemo ! Thanks for posting this!

raix commented 8 years ago

nice guys - should we add the solution to the docs or somehow improve the api?

maciejsaw commented 8 years ago

Is this eventually handled by this package? Perfect solution would be to keep the audio file somewhere and add a filepath to mobile.config so that it's automatically added into res/raw folder when building.

maciejsaw commented 8 years ago

The cordova-build-override folder might help http://guide.meteor.com/mobile.html#advanced-build

I can confirm that this solution worked for me on Android.

  1. In root of your project create path /cordova-build-override folder
  2. Place your audio file in a folder structure like this /cordova-build-override/platforms/android/res/raw/sound.mp3 Don't use special characters and hyphens in sound file name screen shot 2016-05-01 at 11 59 59 pm
  3. In config.push.json say "sound": true screen shot 2016-05-02 at 12 04 56 am
  4. When sending push say sound: "sound" (sound.mp3 referred WITHOUT extension) screen shot 2016-05-01 at 11 59 47 pm

@raix can you add this into the docs and update the example app?

Possible solution for iOS (NOT TESTED): I assume for iOS you can use similar workflow but place the sound file in public folder and refer the file with full path of cordova build:

Push.send({
  ...
  apn:{
    //this should work because we added audio files in the public folder
    //so this file will be copied to cordova build into the path below
    sound: "www/application/app/sound.wav",
    ...
  },
  gcm: {
    //this will refer to the audio file we placed in /cordova-build-override
    sound: "sound",
    ...
  }
})
ouya99 commented 8 years ago

anyone tested

Possible solution for iOS (NOT TESTED): I assume for iOS you can use similar workflow but place the sound file in public folder and refer the file with full path of cordova build:

for iOS?

philipthomasme commented 8 years ago

@java99 Exactly. For iOS simply place the file in the public folder and refer to it like so: sound: "www/application/app/sound.wav"

sahanDissanayake commented 8 years ago

@philipthomasme where do you write this piece of code ?

maciejsaw commented 8 years ago

@sahanDissanayake I think you specify it in Push.send configuration, see my post above.

sahanDissanayake commented 8 years ago

yep sweet :) working through it right now.

wasn't 100% sure because you had ... after the sound is defined.. But I will give this a shot

Also I'm thinking from your post that For Android it is mp3 and for IOS it is WAV format ?

Thanks

maciejsaw commented 8 years ago

I can only confirm that for Android it's MP3. For iOS I didn't implement it yet. But I've seen people using .wav for iOS in the posts above.

sahanDissanayake commented 8 years ago

@maabed Perfect solution on the top.. Everything is working So Android sound file is MP3 and IOS uses WAV

( I had the ipad on silent mode.. DUHH!!! ) Thanks

sahanDissanayake commented 8 years ago

hi @maciejsaw since you are one of the few poeple that got the plugin to work on Android maybe you might have an idea

There are no badge on the icon and also if you send multiple push notifications from the server then one notification on the phone is replaced by the next notification on ANDROID, Which means there is always one ONE notification on tray 😢

raix:push@3.0.0-rc.2

My cordova-plugins

de.appplant.cordova.plugin.local-notification@0.8.4
org.apache.cordova.dialogs@1.2.1
org.apache.cordova.vibration@2.1.1