Sound Manager - Satellite-im/Core-PWA GitHub Wiki

The SoundManager class is responsible for defining and managing the sounds that can be played throughout the app.

Once you have instantiated the class you can:

  • play a specific sound
  • stop a specific sound
  • check if a sound is playing

How to Add Sounds

To add a new sound you have to update the "sounds" config in config.ts file:

sounds: {
    newMessage: 'QmfGYjbTXg66V8ZHzqQRVutUFmkbd5L3fV6DA72jTHDWAH',
    call: 'QmRdxeQF53abUesaFC8qmoNJ5FLS8LBuSyCmcXT5VhuKSm',
    hangup: 'QmWrRi5tdKZy3iqcR8mum9hFBbZ8qgvekhEM3Y4PD1TK28',
    mute: 'QmVk362FGmwfsXBj5zMv4x1Hp7Mp9RbYDMxsDXRAx5vyUo',
    unmute: 'QmWxv18LqpcaMhXVd1BLm9z9k1MfWDNexJ22dC6vLkdyro',
    deafen: 'Qmf4QinBSDk9AgvqsiaaZ2ZmhCfTwcSRpAgSCTxLGyZkyg',
    undeafen: 'QmSHtz5kSvX8JNZKMfkm6PjqScxoC864bmGd2g3ycwRqK1',
    upload: 'QmSHtz5kSvX8JNZKMfkm6PjqScxoC864bmGd2g3ycwRqK1',
    connected: 'QmUJMTmCdnzjcUT5nT2eGzXVDYbwDq3CanjKabYQ3Vu3Dt',
    new_sound: "IPFS_HASH"
  },

Then, you also have to update the Sounds enum in the SoundManager class located in SoundManager.ts:

export enum Sounds {
  NEW_MESSAGE = 'newMessage',
  CALL = 'call',
  HANGUP = 'hangup',
  MUTE = 'mute',
  UNMUTE = 'unmute',
  DEAFEN = 'deafen',
  UNDEAFEN = 'undeafen',
  UPLOAD = 'upload',
  CONNECTED = 'connected',
  NEW_SOUND = 'new_sound',
}

How to Play Sounds

To play a sound simply access the instance property $Sounds and call the playSound function with the sound you want to play:

this.$Sounds.playSound(Sounds.MUTE)

How to Stop Sounds

To stop a sound simply access the instance property $Sounds and call the stopSound function with the sound you want to stop:

this.$Sounds.stopSound(Sounds.MUTE)

How to Check if a Sound is Playing

To check if a sound is playing simply access the instance property $Sounds and call the isPlaying function with the sound you want to check:

const isPlaying = this.$Sounds.isPlaying(Sounds.MUTE)

This will return a boolean indicating whether the sound is playing or not.