Skip to content

Commit

Permalink
fix: Crash on safari
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSusa committed Jan 9, 2021
1 parent c55447f commit a7d915e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cliptor",
"author": "timmsusa@googlemail.com",
"description": "Cliptor was invented to have the same functionality available like ablton live matrix sequencer",
"version": "0.0.14",
"version": "0.0.15",
"main": "./src/app/electron.js",
"homepage": "./",
"private": false,
Expand Down Expand Up @@ -137,4 +137,4 @@
"last 1 safari version"
]
}
}
}
4 changes: 4 additions & 0 deletions src/clip/Clip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ButtonLoadAudioFile } from './ButtonLoadAudioFile'
import { actionsContent, actionsViewSettings } from '../global-state'
import { AudioDriverOutMenu } from './AudioDriverOutMenu'
import context from '../global-state/context'
import { isSafari } from '../utils/is-safari'

const useStyles = makeStyles(() => ({
root: {
Expand Down Expand Up @@ -269,6 +270,9 @@ export function Clip({ url, tracksId, clipId }) {
return {
container: ref,
audioContext,
audioScriptProcessor: isSafari()
? audioContext.createScriptProcessor(1024, 1, 1)
: null,
closeAudioContext: false,
barWidth: 2,
barRadius: 2,
Expand Down
3 changes: 2 additions & 1 deletion src/global-state/context.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext } from 'react'

let AudioContext = window.AudioContext || window.webkitAudioContext
const audioContext = new AudioContext()
// const audioContext = new (window.AudioContext || window.webkitAudioContext)()
const context = createContext({ audioContext })

export default context
34 changes: 10 additions & 24 deletions src/global-state/thunks/drivers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,17 @@ export function initDrivers() {

async function scanForAudioDrivers() {
let list = []
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
return new Promise((resolve, reject) => {
if (isSafari) {
navigator.webkitGetUserMedia(
{ audio: true, video: false },
async function () {
list = await refreshDeviceList(list)
resolve(list)
},
function (err) {
reject(err)
}
)
} else {
navigator.getUserMedia(
{ audio: true, video: false },
async function () {
list = await refreshDeviceList(list)
resolve(list)
},
function (err) {
reject(err)
}
)
}
navigator.mediaDevices.getUserMedia(
{ audio: true, video: false },
async function () {
list = await refreshDeviceList(list)
resolve(list)
},
function (err) {
reject(err)
}
)
})
}
async function refreshDeviceList(listl) {
Expand Down
2 changes: 1 addition & 1 deletion src/menu-app-bar/MenuAppBarCmp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function MenuAppBarCmp(props) {
className={classes.typoColorStyle}
href={'https://github.com/TimSusa/cliptor/releases'}
>
Download here!
Download Desktop App here!
</a>
</React.Fragment>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/is-safari.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function isSafari() {
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
}

1 comment on commit a7d915e

@vercel
Copy link

@vercel vercel bot commented on a7d915e Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.