Guest User

Untitled

a guest
Jun 6th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. VIDEO_STREAM = null
  2. angular.module('selfieApp').directive 'camera', ['$compile', ($compile) ->
  3.   restrict: 'A'
  4.   link: (scope, element, attrs) ->
  5.     element.on 'click', ->
  6.       [ew,eh] = [element[0].width, element[0].height]
  7.       navigator.getUserMedia mediaOpts(ew,eh)
  8.       , (stream) ->
  9.         VIDEO_STREAM = stream
  10.         html = "<video width='#{ew}' height='#{eh}' src='#{window.URL.createObjectURL stream}' usermedia></video>"
  11.         e = $compile(html)(scope)
  12.         element.replaceWith e
  13.         e[0].play()
  14.       , (err) -> console.log "err", err
  15.   ]
  16. angular.module('selfieApp').directive 'usermedia', ['$compile', ($compile) ->
  17.   restrict: 'A'
  18.   link: (scope, element, attrs) ->
  19.     canvas = document.createElement('canvas')
  20.     context = canvas.getContext('2d')
  21.     element.on 'click', ->
  22.       [ew,eh] = [element[0].width, element[0].height]
  23.       canvas.width = ew
  24.       canvas.height = eh
  25.       context.drawImage(element[0], 0, 0, ew, eh)
  26.       html = "<img src='#{canvas.toDataURL('image/png')}' camera class='selfie_img' width='#{ew}' height='#{eh}'>"
  27.       e = $compile(html)(scope)
  28.       element[0].pause()
  29.       VIDEO_STREAM.stop() if VIDEO_STREAM
  30.       element.replaceWith e
  31.   ]
Advertisement
Add Comment
Please, Sign In to add comment