logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

ruffle_service.js (1284B)


  1. const createRuffleService = () => {
  2. let ruffleInstance = null
  3. const getRuffle = () => new Promise((resolve, reject) => {
  4. if (ruffleInstance) {
  5. resolve(ruffleInstance)
  6. return
  7. }
  8. // Ruffle needs these to be set before it's loaded
  9. // https://github.com/ruffle-rs/ruffle/issues/3952
  10. window.RufflePlayer = {}
  11. window.RufflePlayer.config = {
  12. polyfills: false,
  13. publicPath: '/static/ruffle'
  14. }
  15. // Currently it's seems like a better way of loading ruffle
  16. // because it needs the wasm publically accessible, but it needs path to it
  17. // and filename of wasm seems to be pseudo-randomly generated (is it a hash?)
  18. const script = document.createElement('script')
  19. // see webpack config, using CopyPlugin to copy it from node_modules
  20. // provided via ruffle-mirror
  21. script.src = '/static/ruffle/ruffle.js'
  22. script.type = 'text/javascript'
  23. script.onerror = (e) => { reject(e) }
  24. script.onabort = (e) => { reject(e) }
  25. script.oncancel = (e) => { reject(e) }
  26. script.onload = () => {
  27. ruffleInstance = window.RufflePlayer
  28. resolve(ruffleInstance)
  29. }
  30. document.body.appendChild(script)
  31. })
  32. return { getRuffle }
  33. }
  34. const RuffleService = createRuffleService()
  35. export default RuffleService