'Uncaught TypeError: illegal call' when trying to support browser cross-prefixes in clojurescript

getUserMedia

has a number of prefixes that are still needed in many browsers. I am trying to hide the use of these prefixes by putting all the prefixes in getUserMedia

.

(def getUserMedia
  (or js/navigator.getUserMedia
      js/navigator.webkitGetUserMedia
      js/navigator.mozGetUserMedia
      js/navigator.msGetUserMedia))

(defn start-fx [app]
  (if getUserMedia
    (getUserMedia 
     ;; WORKS IF I REPLACE THE ABOVE getUserMedia WITH
     ;; js/navigator.webkitGetUserMedia USING CHROME BROWSER
     #js {:video true :audio true}
     #(om/update! app :record-src (.createObjectURL js/window.URL %))
     #(throw %))
    (js/alert "This browser does not support video recording!")))

      

When I try to call this from start-fx

, I get a Uncaught TypeError: Illegal invocation

when called getUserMedia

. What should I do to allow my code to be browser compatible?

+3


source to share


2 answers


getUserMedia

must be attached to an object navigator

. The JavaScript equivalent would be:



var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia ||
                   navigator.mozGetUserMedia || msGetUserMedia;
if (getUserMedia) {
  getUserMedia = getUserMedia.bind(navigator);
}

      

+5


source


To get an answer, I am posting a fix for the problem. Perhaps there should be a better solution?



(def getUserMedia
  (or js/navigator.getUserMedia
      js/navigator.webkitGetUserMedia
      js/navigator.mozGetUserMedia
      js/navigator.msGetUserMedia))

(defn start-fx [app]
  (if getUserMedia
    (let [[c s f] [#js {:video true :audio true}
                   #(om/update! app 
                               :record-src 
                               (.createObjectURL js/window.URL %))
                   #(throw %)]]
      (getUserMedia c s f))
    (js/alert "This browser does not support video recording!")))

      

0


source







All Articles