       delete streams[id]
       bus.delete('tawk/stream/' + id)
 
-  microphone = await AgoraRTC.createMicrophoneAudioTrack()
-  video = await AgoraRTC.createCameraVideoTrack()
-  my_stream = new MediaStream([video.getMediaStreamTrack(), microphone.getMediaStreamTrack()])
-  window.received_track(my_id, video.getMediaStreamTrack(), "video")
-  window.received_track(my_id, microphone.getMediaStreamTrack(), "audio")
-
-  await client.publish([video, microphone])
+  window.received_track(my_id, window.camera.getMediaStreamTrack(), "video")
+  window.received_track(my_id, window.microphone.getMediaStreamTrack(), "audio")
+
+  await client.publish([window.camera, window.microphone])
+
+window.initialize_av = ->
+  try
+    # Save as global variables so we can enable/disable as necessary
+    [window.microphone, window.camera] = await AgoraRTC.createMicrophoneAndCameraTracks()
+    sb['tawk/av_check'] =
+      camera: true
+      microphone: true
+  catch e
+    console.error(e)
+    sb['tawk/av_check'] =
+      camera: false
+      microphone: false

streams = {}
agora_initialized = false

###############################################################################
# Client Bus (all state prefixed with tawk/)

    AV_BUTTON
      danger: !me.video
      onClick: (e) ->
        if window.camera == undefined
          # TODO: warn the user when they don't have an accessible camera but
          # try to turn on video. This silently keeps it off.
          me.video = false
        else
          # TODO: call window.camera.close() to turn off camera entirely. Right
          # now when you turn off video, your camera light is on, even though we
          # aren't using that camera feed.
          me.video = !!!me.video
          window.camera.setEnabled(me.video)
      VIDEO_ICON
        on: !!me.video
        width: 16
