handlers.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dezukvm
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. func (d *DezukVM) HandleVideoStreams(w http.ResponseWriter, r *http.Request, instanceUuid string) {
  7. targetInstance, err := d.GetInstanceByUUID(instanceUuid)
  8. if err != nil {
  9. http.Error(w, "Instance with specified UUID not found", http.StatusNotFound)
  10. return
  11. }
  12. targetInstance.usbCaptureDevice.ServeVideoStream(w, r)
  13. }
  14. func (d *DezukVM) HandleAudioStreams(w http.ResponseWriter, r *http.Request, instanceUuid string) {
  15. targetInstance, err := d.GetInstanceByUUID(instanceUuid)
  16. if err != nil {
  17. http.Error(w, "Instance with specified UUID not found", http.StatusNotFound)
  18. return
  19. }
  20. targetInstance.usbCaptureDevice.AudioStreamingHandler(w, r)
  21. }
  22. func (d *DezukVM) HandleHIDEvents(w http.ResponseWriter, r *http.Request, instanceUuid string) {
  23. targetInstance, err := d.GetInstanceByUUID(instanceUuid)
  24. if err != nil {
  25. http.Error(w, "Instance with specified UUID not found", http.StatusNotFound)
  26. return
  27. }
  28. targetInstance.usbKVMController.HIDWebSocketHandler(w, r)
  29. }
  30. func (d *DezukVM) HandleListInstances(w http.ResponseWriter, r *http.Request) {
  31. instances := []map[string]interface{}{}
  32. for _, instance := range d.UsbKvmInstance {
  33. instances = append(instances, map[string]interface{}{
  34. "uuid": instance.UUID(),
  35. "video_capture_dev": instance.Config.VideoCaptureDevicePath,
  36. "audio_capture_dev": instance.Config.AudioCaptureDevicePath,
  37. "video_resolution_width": instance.Config.CaptureVideoResolutionWidth,
  38. "video_resolution_height": instance.Config.CaptureeVideoResolutionHeight,
  39. "video_framerate": instance.Config.CaptureeVideoFPS,
  40. "audio_sample_rate": instance.Config.CaptureAudioSampleRate,
  41. "audio_channels": instance.Config.CaptureAudioChannels,
  42. "stream_info": instance.usbCaptureDevice.GetStreamInfo(),
  43. "usb_kvm_device": instance.Config.USBKVMDevicePath,
  44. "aux_mcu_device": instance.Config.AuxMCUDevicePath,
  45. "usb_mass_storage_side": instance.auxMCUController.GetUSBMassStorageSide(),
  46. })
  47. }
  48. w.Header().Set("Content-Type", "application/json")
  49. json.NewEncoder(w).Encode(instances)
  50. }