diff --git a/doc/用例描述(已作废).docx b/doc/用例描述(已作废).docx deleted file mode 100644 index 0195e60..0000000 --- a/doc/用例描述(已作废).docx +++ /dev/null @@ -1,46 +0,0 @@ -ͼ - - -Ƶȡ -ҵĿ꣺ȡƵϢ -ִߣϵͳ -ǰͷ - -1ͷ -2ȡͷϢ -3ػƶ -չ -1a: ѡǰúͷ - -ֻȡ -ҵĿ꣺ȡϢ -ִߣϵͳ -ǰƶ˻򱾵 - -1ȡϢ -2ֽзƬ -3ػƶ - - - -ҵĿ꣺Ϣз -ִߣϵͳ - -1Ϣ -2ݷӦ -3ݷ͵ƶ˻򱾵 -4Ϣû -չ -4aжƵתΪֻתΪ - - -ҵĿ꣺ؾ⼰web -ִߣ - -1ҳ -2ûз -3û֮ݹͨƵݵȣ -չ -4aû - - diff --git a/doc/第一次作业.md b/doc/第一次作业.md deleted file mode 100644 index c12bb65..0000000 --- a/doc/第一次作业.md +++ /dev/null @@ -1,159 +0,0 @@ -## 1、系统说明: - -##### 手语翻译项目旨在构建一个手语翻译系统,方便手语与自然语言的相互转换,这个系统的主要功能有: - -1. 实现手语视频录制,并转化为自然语言 -2. 完成自然语言转化为手语动画 -3. 实现设备间算力共享 - -##### 手语翻译系统只有一类用户:用户 - -功能1,2供用户使用 - -功能3根据用户意愿开启 - -##### 该系统必须满足以下限制: - -1. 能以较低的性能要求实现运算 -2. 仅在用户允许情况下使用算力共享 - -## 2、需求获取与分析 - -### 2.1系统初步用例图: - -![](/home/smj/Work/for_you/model/用例及分析类图/初步用例图.png) - -### 2.2用例描述与顺序图: - -**用例名**:输入自然语言 -**业务目标**:用户输入需要翻译的自然语言 -**执行者**:用户 -**前置条件**:app正常运行 -**基本事件流**: - -​ 1、用户打开手语翻译app -​ 2、app跳转到主页面 -​ 3、用户点击输入框 -​ 4、用户输入自然语言 -​ 5、用户提交自然语言 -​ 6、app接收自然语言 -**扩展交互动作**: - -​ 1a: 修改输入内容 - -​ 1a1:直接在输入框进行文本编辑 - -**后置条件**:输入数据无损失 - -**可靠性需求**:数据安全性无限接近100% - -![](/home/smj/Work/work2/输入自然语言.png) - -**用例名**:获取手语视频 -**业务目标**:用户上传视频到app -**执行者**:用户 -**前置条件**:app正常运行 -**基本事件流**: - -​ 1、用户打开手语翻译app -​ 2、app跳转到主页面 -​ 3、app提示是否打开摄像头 -​ 4、用户允许app开启摄像头 -​ 5、用户打开摄像头 -​ 6、app获取摄像头视频流 -**扩展交互动作**: - -​ 1a: 重新录制视频 - -​ 1a1:删除已录制视频并重新录制 - -**后置条件**:硬件正常时,能获取无损视频 - -**可靠性要求**:视频在传输过程中受损率无限接近0% - -![](/home/smj/Work/work2/获取手语视频.png) - -**用例名**:翻译自然语言为动画 -**业务目标**:将用户输入或云端获取的自然语言转换为3D动画 -**执行者**:用户 -**前置条件**: - -​ 1、网络正常连接或本地算力足够 - -​ 2、用户已输入自然语言 -**基本事件流**: -​ 1、用户点击“语言翻译”按钮 -​ 2、app对获取自然语言进行翻译 -​ 3、app提示翻译成功 -**扩展交互动作**: - -​ 1a: 选择本地运算或云端运算 - -​ 1a1:根据选择来确定运算设备 - -**后置条件**:在词库内有对应数据时,可生成完整动画 - -**性能要求**:响应事件小于200ms - -**可靠性要求**:保证词条对应数据100%正确 - -![](/home/smj/Work/work2/翻译自然语言为动画.png) - -**用例名**:翻译视频为自然语言 -**业务目标**:将用户输入或云端获取的视频转换为自然语言 -**执行者**:用户 -**前置条件**: - -​ 1、网络正常连接或本地算力足够 - -​ 2、用户已输入视频 -**基本事件流**: -​ 1、用户点击“视频翻译”按钮 -​ 2、app显示正在翻译 -​ 3、app对视频进行翻译 -​ 4、app显示翻译成功 -**扩展交互动作**: - -​ 1a: 选择本地运算或云端运算 - -​ 1a1:根据选择来确定运算设备 - -**后置条件**:当视频内容有效时,根据视频可生成对应自然语言 - -**性能要求**:每秒处理速度达到30fps - -**可靠性要求**:翻译直译准确率达到90%以上 - -![](/home/smj/Work/work2/翻译视频为自然语言.png) - -**用例名**:显示动画 -**业务目标**:在app显示数据转换后的3D动画 -**执行者**:用户 -**前置条件**:app已经获取3D动画数据 -**基本事件流**: - 1、用户点击“翻译自然语言”按钮 - 2、app显示生成3D动画 - -**后置条件**:当动画生成后,在屏幕指定位置展示动画 - -**可靠性要求**:动作混淆错位等错误发生率为0% - -![](/home/smj/Work/work2/显示动画.png) - -**用例名**:显示自然语言 -**业务目标**:在app显示数据转换后的自然语言 -**执行者**:用户 -**前置条件**:app已经获取处理后的自然语言 -**基本事件流**: - 1、用户点击“翻译手语动画”按钮 - 2、app显示翻译后的自然语言 - -**后置条件**:当收到自然语言时,在屏幕指定位置生成文字 - -**可靠性要求**::保证数据准确度为100% - -![](/home/smj/Work/work2/显示自然语言.png) - -### 2.3分析类图: - -![](/home/smj/Work/work2/分析类图.png) diff --git a/doc/第一次作业.pdf b/doc/第一次作业.pdf deleted file mode 100644 index d5cd245..0000000 Binary files a/doc/第一次作业.pdf and /dev/null differ diff --git a/doc/第二次作业.md b/doc/第二次作业.md deleted file mode 100644 index f2ee684..0000000 --- a/doc/第二次作业.md +++ /dev/null @@ -1,44 +0,0 @@ - - -## 3、体系结构设计: - -### 3.1体系结构的逻辑视图 - -![](/home/smj/Documents/软工/体系结构逻辑视图.drawio.png) - -### 3.2体系结构设计的开发视图 - -![](/home/smj/Documents/软工/体系结构开发视图.drawio.png) - - - -## 4、用户界面设计 - -### 4.1系统界面的外观设计及其类表示 - -#### 4.1.1视频翻译界面及其类表示: - -![](/home/smj/Work/for_you/model/app/im1.png) - -![](/home/smj/Work/work2/手语翻译.png) - -#### 4.1.2文字翻译界面及其类表示: - -![](/home/smj/Work/for_you/model/app/im2.png) - -![](/home/smj/Work/work2/自然语言翻译.png) - -#### 4.1.3设置界面及其类表示: - -![im3](/home/smj/Work/for_you/model/app/im3.png) - -![](/home/smj/Work/work2/设置.png) - -### 4.2界面流的类表示: - -![](/home/smj/Work/work2/界面流类表示.png) - -### 4.3界面流的顺序图: - -![](/home/smj/Work/work2/界面流顺序图.png) - diff --git a/doc/第二次作业.pdf b/doc/第二次作业.pdf deleted file mode 100644 index 6daba11..0000000 Binary files a/doc/第二次作业.pdf and /dev/null differ diff --git a/doc/软件需求构思.docx b/doc/软件需求构思.docx deleted file mode 100644 index e767ccb..0000000 Binary files a/doc/软件需求构思.docx and /dev/null differ diff --git a/model/体系结构/体系结构开发视图.drawio.png b/model/体系结构/体系结构开发视图.drawio.png deleted file mode 100644 index 19737c6..0000000 Binary files a/model/体系结构/体系结构开发视图.drawio.png and /dev/null differ diff --git a/model/体系结构/体系结构逻辑视图.drawio.png b/model/体系结构/体系结构逻辑视图.drawio.png deleted file mode 100644 index 27098e0..0000000 Binary files a/model/体系结构/体系结构逻辑视图.drawio.png and /dev/null differ diff --git a/src/webserver/go.mod b/src/webserver/go.mod new file mode 100644 index 0000000..d9c5f17 --- /dev/null +++ b/src/webserver/go.mod @@ -0,0 +1,29 @@ +module webserver + +go 1.19 + +require ( + github.com/gin-gonic/gin v1.8.1 + github.com/mattn/go-sqlite3 v1.14.16 +) + +require ( + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-playground/validator/v10 v10.10.0 // indirect + github.com/goccy/go-json v0.9.7 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/leodido/go-urn v1.2.1 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.0.1 // indirect + github.com/ugorji/go/codec v1.2.7 // indirect + golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect + golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect + golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 // indirect + golang.org/x/text v0.3.6 // indirect + google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/src/webserver/go.sum b/src/webserver/go.sum new file mode 100644 index 0000000..276077c --- /dev/null +++ b/src/webserver/go.sum @@ -0,0 +1,88 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= +github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= +github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= +github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= +github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= +github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= +github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= +github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= +github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 h1:siQdpVirKtzPhKl3lZWozZraCFObP8S1v6PRp0bLrtU= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/webserver/info.db b/src/webserver/info.db new file mode 100644 index 0000000..2e2a8ff Binary files /dev/null and b/src/webserver/info.db differ diff --git a/src/webserver/info1.db b/src/webserver/info1.db new file mode 100644 index 0000000..f8eddbb Binary files /dev/null and b/src/webserver/info1.db differ diff --git a/src/webserver/info2.db b/src/webserver/info2.db new file mode 100644 index 0000000..65142ad Binary files /dev/null and b/src/webserver/info2.db differ diff --git a/src/webserver/main.exe b/src/webserver/main.exe new file mode 100644 index 0000000..bfd7251 Binary files /dev/null and b/src/webserver/main.exe differ diff --git a/src/webserver/main.go b/src/webserver/main.go new file mode 100644 index 0000000..1c24429 --- /dev/null +++ b/src/webserver/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + "webserver/routers" +) + +func main() { + endPoint := fmt.Sprintf("0.0.0.0:%d", 8000) + server := &http.Server{ + Addr: endPoint, + Handler: routers.InitRouter(), + } + log.Printf("[info] start http server listening %s", endPoint) + if err := server.ListenAndServe(); err != nil { + log.Printf("start http server failed %s", err) + } +} diff --git a/src/webserver/pkg/api/address.go b/src/webserver/pkg/api/address.go new file mode 100644 index 0000000..8f1bbb7 --- /dev/null +++ b/src/webserver/pkg/api/address.go @@ -0,0 +1,86 @@ +package api + +import ( + "database/sql" + "errors" + "fmt" + "github.com/gin-gonic/gin" + "net" + "net/http" + "strconv" + "time" + app "webserver/pkg/app" +) + +// 获取本设备的mac地址 +func getMacAddress() (macAddress string) { + netInterfaces, err := net.Interfaces() + if err != nil { + fmt.Printf("fail to get net interfaces: %v", err) + return macAddress + } + + for _, netInterface := range netInterfaces { + if netInterface.Name == "WLAN" { + macAddress := netInterface.HardwareAddr + return macAddress.String() + } + } + return macAddress +} + +// 获取本设备的IP地址 +func getIpAddress() (addr string, err error) { + var ( + ief *net.Interface + addrs []net.Addr + ipv4Addr net.IP + ) + if ief, err = net.InterfaceByName("WLAN"); err != nil { + return + } + if addrs, err = ief.Addrs(); err != nil { + return + } + for _, addr := range addrs { + if ipv4Addr = addr.(*net.IPNet).IP.To4(); ipv4Addr != nil { + break + } + } + if ipv4Addr == nil { + return "", errors.New(fmt.Sprintf("interface WLAN don't have an ipv4 address\n")) + } + return ipv4Addr.String(), nil +} + +// 向服务器发送本设备的mac地址和IP地址 +func SendAddress(c *gin.Context) { + appG := app.Gin{C: c} + now := time.Now() + hour := now.Hour() + minute := now.Minute() + t := hour*100 + minute + macAddress := getMacAddress() + ipAddress, err := getIpAddress() + if err != nil { + fmt.Println(err) + } + db, err := sql.Open("sqlite3", "info2.db") + if err != nil { + fmt.Println(err) + } + defer db.Close() + rows, err := db.Query(`select macAddress from Endpoint where macAddress = ?;`, macAddress) + defer rows.Close() + var endpoint Endpoint + rows.Next() + rows.Scan(&endpoint.macAddress) + if endpoint.macAddress == "" { + db.Exec(`insert into Endpoint values (?,?,?,?);`, macAddress, ipAddress, 0, t) + } else { + db.Exec(`update Endpoint set ipAddress = ? where macAddress = ?;`, ipAddress, macAddress) + db.Exec(`update Endpoint set isOnLine = ? where macAddress = ?;`, t, macAddress) + } + str := "time:" + strconv.Itoa(t) + " mac:" + macAddress + " ip:" + ipAddress + appG.Response(http.StatusOK, "true", str) +} diff --git a/src/webserver/pkg/api/request.go b/src/webserver/pkg/api/request.go new file mode 100644 index 0000000..a398e96 --- /dev/null +++ b/src/webserver/pkg/api/request.go @@ -0,0 +1,71 @@ +package api + +import ( + "database/sql" + "fmt" + "github.com/gin-gonic/gin" + _ "github.com/mattn/go-sqlite3" + "math/rand" + "net/http" + "strings" + "time" + app "webserver/pkg/app" +) + +type Endpoint struct { + ipAddress string + macAddress string +} + +// 拉取在线的算力设备 +func ipAddress() []string { + now := time.Now() + hour := now.Hour() + minute := now.Minute() + t := hour*100 + minute - 100 + db, err := sql.Open("sqlite3", "info2.db") + if err != nil { + fmt.Println(err) + } + defer db.Close() + rows, _ := db.Query(`select average from Average;`) + defer rows.Close() + var average int + rows.Next() + rows.Scan(&average) + rows, _ = db.Query(`select ipAddress from Endpoint where times <= ? and isOnLine >= ?;`, average, t) + defer rows.Close() + var endpoint Endpoint + ipAddress := "" + for rows.Next() { + rows.Scan(&endpoint.ipAddress) + ipAddress += endpoint.ipAddress + "," + } + rows.Close() + sep := "," + IpAddress := strings.Split(ipAddress, sep) + return IpAddress +} + +func init() { + rand.Seed(time.Now().UnixNano()) +} + +// 洗牌算法 +func shuffle(n []string) { + for i := 0; i < len(n); i++ { + a := rand.Intn(len(n)) + b := rand.Intn(len(n)) + n[a], n[b] = n[b], n[a] + } +} + +// 返回可进行运算的设备地址 +func Request(c *gin.Context) { + appG := app.Gin{C: c} + var ipAddress = ipAddress() + for i := 0; i < 3; i++ { + shuffle(ipAddress) + } + appG.Response(http.StatusOK, "成功", ipAddress) +} diff --git a/src/webserver/pkg/api/sqlite.go b/src/webserver/pkg/api/sqlite.go new file mode 100644 index 0000000..e49ed61 --- /dev/null +++ b/src/webserver/pkg/api/sqlite.go @@ -0,0 +1,196 @@ +package api + +import ( + "database/sql" + "fmt" + "github.com/gin-gonic/gin" + _ "github.com/mattn/go-sqlite3" + "net/http" + app "webserver/pkg/app" +) + +type XYZ struct { + Word string `json:"word"` +} + +type TRANSLATION struct { + Word string `json:"word"` +} + +type XYZBody struct { + fig00 string + fig01 string + fig02 string + fig03 string + fig04 string + fig05 string + fig06 string + fig07 string + fig08 string + fig09 string + fig10 string + fig11 string + fig12 string + fig13 string + fig14 string + fig15 string + fig16 string + fig17 string + fig18 string + fig19 string + fig20 string + fig21 string + fig22 string + fig23 string + fig24 string + fig25 string + fig26 string + fig27 string + fig28 string + fig29 string + fig30 string + fig31 string + fig32 string + fig33 string + fig34 string + fig35 string + fig36 string + fig37 string + fig38 string + fig39 string + fig40 string + fig41 string + fig42 string + fig43 string + fig44 string + fig45 string + fig46 string + fig47 string + fig48 string + fig49 string + fig50 string + fig51 string + fig52 string + fig53 string + fig54 string + fig55 string + fig56 string + fig57 string + fig58 string + fig59 string + fig60 string + fig61 string + fig62 string + fig63 string + fig64 string + fig65 string + fig66 string + fig67 string + fig68 string + fig69 string + fig70 string + fig71 string + fig72 string + fig73 string + fig74 string + fig75 string + fig76 string + fig77 string + fig78 string + fig79 string + fig80 string + fig81 string + fig82 string + fig83 string + fig84 string + fig85 string + fig86 string + fig87 string + fig88 string + fig89 string + fig90 string + fig91 string + fig92 string + fig93 string + fig94 string + fig95 string + fig96 string + fig97 string + fig98 string + fig99 string + fig100 string + fig101 string + fig102 string + fig103 string + fig104 string + fig105 string + fig106 string + fig107 string + fig108 string + fig109 string + fig110 string + fig111 string + fig112 string + fig113 string + fig114 string + fig115 string + fig116 string + fig117 string + fig118 string + fig119 string + fig120 string + fig121 string + fig122 string + fig123 string + fig124 string + fig125 string +} + +func SqliteQueryXYZ(c *gin.Context) { + appG := app.Gin{C: c} + s := c.Query("str") + var str []string + runes := []rune(s) + for i := 0; i < len(runes); i++ { + str = append(str, string(runes[i])) + } + db, err := sql.Open("sqlite3", "info.db") + if err != nil { + fmt.Println(err) + } + defer db.Close() + strs := "" + for i := 0; i < len(str); i++ { + var rows, _ = db.Query(`select fig00, fig01, fig02, fig03, fig04, fig05, fig06, fig07, fig08, fig09, fig10, fig11, fig12, fig13, fig14, fig15, fig16, fig17, fig18, fig19, fig20, fig21, fig22, fig23, fig24, fig25, fig26, fig27, fig28, fig29, fig30, fig31, fig32, fig33, fig34, fig35, fig36, fig37, fig38, fig39, fig40, fig41, fig42, fig43, fig44, fig45, fig46, fig47, fig48, fig49, fig50, fig51, fig52, fig53, fig54, fig55, fig56, fig57, fig58, fig59, fig60, fig61, fig62, fig63, fig64, fig65, fig66, fig67, fig68, fig69,fig70, fig71, fig72, fig73, fig74, fig75, fig76, fig77, fig78, fig79, fig80, fig81, fig82, fig83, fig84, fig85, fig86, fig87, fig88, fig89, fig90, fig91, fig92, fig93, fig94, fig95, fig96, fig97, fig98, fig99, fig100, fig101, fig102, fig103, fig104, fig105, fig106, fig107, fig108, fig109, fig110, fig111, fig112, fig113, fig114, fig115, fig116, fig117, fig118, fig119, fig120, fig121, fig122, fig123, fig124, fig125 from XYZ where word = ?`, str[i]) + var body XYZBody + rows.Next() + rows.Scan(&body.fig00, &body.fig01, &body.fig02, &body.fig03, &body.fig04, &body.fig05, &body.fig06, &body.fig07, &body.fig08, &body.fig09, &body.fig10, &body.fig11, &body.fig12, &body.fig13, &body.fig14, &body.fig15, &body.fig16, &body.fig17, &body.fig18, &body.fig19, &body.fig20, &body.fig21, &body.fig22, &body.fig23, &body.fig24, &body.fig25, &body.fig26, &body.fig27, &body.fig28, &body.fig29, &body.fig30, &body.fig31, &body.fig32, &body.fig33, &body.fig34, &body.fig35, &body.fig36, &body.fig37, &body.fig38, &body.fig39, &body.fig40, &body.fig41, &body.fig42, &body.fig43, &body.fig44, &body.fig45, &body.fig46, &body.fig47, &body.fig48, &body.fig49, &body.fig50, &body.fig51, &body.fig52, &body.fig53, &body.fig54, &body.fig55, &body.fig56, &body.fig57, &body.fig58, &body.fig59, &body.fig60, &body.fig61, &body.fig62, &body.fig63, &body.fig64, &body.fig65, &body.fig66, &body.fig67, &body.fig68, &body.fig69, &body.fig70, &body.fig71, &body.fig72, &body.fig73, &body.fig74, &body.fig75, &body.fig76, &body.fig77, &body.fig78, &body.fig79, &body.fig80, &body.fig81, &body.fig82, &body.fig83, &body.fig84, &body.fig85, &body.fig86, &body.fig87, &body.fig88, &body.fig89, &body.fig90, &body.fig91, &body.fig92, &body.fig93, &body.fig94, &body.fig95, &body.fig96, &body.fig97, &body.fig98, &body.fig99, &body.fig100, &body.fig101, &body.fig102, &body.fig103, &body.fig104, &body.fig105, &body.fig106, &body.fig107, &body.fig108, &body.fig109, &body.fig110, &body.fig111, &body.fig112, &body.fig113, &body.fig114, &body.fig115, &body.fig116, &body.fig117, &body.fig118, &body.fig119, &body.fig120, &body.fig121, &body.fig122, &body.fig123, &body.fig124, &body.fig125) + if body.fig00 == "" { + strs += "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" + } else { + strs += body.fig00 + "," + body.fig01 + "," + body.fig02 + "," + body.fig03 + "," + body.fig04 + "," + body.fig05 + "," + body.fig06 + "," + body.fig07 + "," + body.fig08 + "," + body.fig09 + "," + body.fig10 + "," + body.fig11 + "," + body.fig12 + "," + body.fig13 + "," + body.fig14 + "," + body.fig15 + "," + body.fig16 + "," + body.fig17 + "," + body.fig18 + "," + body.fig19 + "," + body.fig20 + "," + body.fig21 + "," + body.fig22 + "," + body.fig23 + "," + body.fig24 + "," + body.fig25 + "," + body.fig26 + "," + body.fig27 + "," + body.fig28 + "," + body.fig29 + "," + body.fig30 + "," + body.fig31 + "," + body.fig32 + "," + body.fig33 + "," + body.fig34 + "," + body.fig35 + "," + body.fig36 + "," + body.fig37 + "," + body.fig38 + "," + body.fig39 + "," + body.fig40 + "," + body.fig41 + "," + body.fig42 + "," + body.fig43 + "," + body.fig44 + "," + body.fig45 + "," + body.fig46 + "," + body.fig47 + "," + body.fig48 + "," + body.fig49 + "," + body.fig50 + "," + body.fig51 + "," + body.fig52 + "," + body.fig53 + "," + body.fig54 + "," + body.fig55 + "," + body.fig56 + "," + body.fig57 + "," + body.fig58 + "," + body.fig59 + "," + body.fig60 + "," + body.fig61 + "," + body.fig62 + "," + body.fig63 + "," + body.fig64 + "," + body.fig65 + "," + body.fig66 + "," + body.fig67 + "," + body.fig68 + "," + body.fig69 + "," + body.fig70 + "," + body.fig71 + "," + body.fig72 + "," + body.fig73 + "," + body.fig74 + "," + body.fig75 + "," + body.fig76 + "," + body.fig77 + "," + body.fig78 + "," + body.fig79 + "," + body.fig80 + "," + body.fig81 + "," + body.fig82 + "," + body.fig83 + "," + body.fig84 + "," + body.fig85 + "," + body.fig86 + "," + body.fig87 + "," + body.fig88 + "," + body.fig89 + "," + body.fig90 + "," + body.fig91 + "," + body.fig92 + "," + body.fig93 + "," + body.fig94 + "," + body.fig95 + "," + body.fig96 + "," + body.fig97 + "," + body.fig98 + "," + body.fig99 + "," + body.fig100 + "," + body.fig101 + "," + body.fig102 + "," + body.fig103 + "," + body.fig104 + "," + body.fig105 + "," + body.fig106 + "," + body.fig107 + "," + body.fig108 + "," + body.fig109 + "," + body.fig110 + "," + body.fig111 + "," + body.fig112 + "," + body.fig113 + "," + body.fig114 + "," + body.fig115 + "," + body.fig116 + "," + body.fig117 + "," + body.fig118 + "," + body.fig119 + "," + body.fig120 + "," + body.fig121 + "," + body.fig122 + "," + body.fig123 + "," + body.fig124 + "," + body.fig125 + } + strs += "|" + rows.Close() + } + appG.Response(http.StatusOK, "true", strs) +} + +func SqliteQueryTRANSLATION(c *gin.Context) { + appG := app.Gin{C: c} + s := c.Query("str") + db, err := sql.Open("sqlite3", "info1.db") + if err != nil { + fmt.Println(err) + } + defer db.Close() + rows, _ := db.Query(`select word from TRANSLATION where num = ?;`, s) + var str string + rows.Next() + rows.Scan(&str) + rows.Close() + if str == "" { + str = "0" + } + appG.Response(http.StatusOK, "true", str) +} diff --git a/src/webserver/pkg/app/response.go b/src/webserver/pkg/app/response.go new file mode 100644 index 0000000..80b714d --- /dev/null +++ b/src/webserver/pkg/app/response.go @@ -0,0 +1,24 @@ +package pkg + +import ( + "github.com/gin-gonic/gin" +) + +type Gin struct { + C *gin.Context +} + +type Response struct { + Code int `json:"code"` + Msg string `json:"msg"` + Data interface{} `json:"data"` +} + +func (g *Gin) Response(httpCode int, errMsg string, data interface{}) { + g.C.JSON(httpCode, Response{ + Code: httpCode, + Msg: errMsg, + Data: data, + }) + return +} diff --git a/src/webserver/routers/router.go b/src/webserver/routers/router.go new file mode 100644 index 0000000..5ea6577 --- /dev/null +++ b/src/webserver/routers/router.go @@ -0,0 +1,21 @@ +package routers + +import ( + "github.com/gin-gonic/gin" + "net/http" + api "webserver/pkg/api" +) + +// InitRouter 初始化路由信息 +func InitRouter() *gin.Engine { + r := gin.Default() + // 静态文件路由 + r.LoadHTMLGlob("./template/*") + r.StaticFS("/template", http.Dir("template")) + r.StaticFS("/static", http.Dir("static")) + r.GET("/trans", api.SqliteQueryTRANSLATION) + r.GET("/xyz", api.SqliteQueryXYZ) + r.GET("/address", api.SendAddress) + r.GET("/request", api.Request) + return r +} diff --git a/src/webserver/static/hand/camera_utils.js b/src/webserver/static/hand/camera_utils.js new file mode 100644 index 0000000..2f55270 --- /dev/null +++ b/src/webserver/static/hand/camera_utils.js @@ -0,0 +1,539 @@ +(function() { + /* + + Copyright The Closure Library Authors. + SPDX-License-Identifier: Apache-2.0 + */ + 'use strict'; + + function n(a) { + var b = 0; + return function() { + return b < a.length ? { + done: !1, + value: a[b++] + } : { + done: !0 + } + } + } + var q = "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, e) { + if (a == Array.prototype || a == Object.prototype) return a; + a[b] = e.value; + return a + }; + + function t(a) { + a = ["object" == typeof globalThis && globalThis, a, "object" == typeof window && window, "object" == typeof self && self, "object" == typeof global && global]; + for (var b = 0; b < a.length; ++b) { + var e = a[b]; + if (e && e.Math == Math) return e + } + throw Error("Cannot find global object"); + } + var u = t(this); + + function v(a, b) { + if (b) a: { + var e = u;a = a.split("."); + for (var f = 0; f < a.length - 1; f++) { + var h = a[f]; + if (!(h in e)) break a; + e = e[h] + } + a = a[a.length - 1];f = e[a];b = b(f);b != f && null != b && q(e, a, { + configurable: !0, + writable: !0, + value: b + }) + } + } + v("Symbol", function(a) { + function b(l) { + if (this instanceof b) throw new TypeError("Symbol is not a constructor"); + return new e(f + (l || "") + "_" + h++, l) + } + + function e(l, c) { + this.g = l; + q(this, "description", { + configurable: !0, + writable: !0, + value: c + }) + } + if (a) return a; + e.prototype.toString = function() { + return this.g + }; + var f = "jscomp_symbol_" + (1E9 * Math.random() >>> 0) + "_", + h = 0; + return b + }); + v("Symbol.iterator", function(a) { + if (a) return a; + a = Symbol("Symbol.iterator"); + for (var b = "Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "), e = 0; e < b.length; e++) { + var f = u[b[e]]; + "function" === typeof f && "function" != typeof f.prototype[a] && q(f.prototype, a, { + configurable: !0, + writable: !0, + value: function() { + return w(n(this)) + } + }) + } + return a + }); + + function w(a) { + a = { + next: a + }; + a[Symbol.iterator] = function() { + return this + }; + return a + } + + function x(a) { + var b = "undefined" != typeof Symbol && Symbol.iterator && a[Symbol.iterator]; + return b ? b.call(a) : { + next: n(a) + } + } + + function y() { + this.i = !1; + this.g = null; + this.o = void 0; + this.j = 1; + this.m = 0; + this.h = null + } + + function z(a) { + if (a.i) throw new TypeError("Generator is already running"); + a.i = !0 + } + y.prototype.l = function(a) { + this.o = a + }; + + function A(a, b) { + a.h = { + F: b, + G: !0 + }; + a.j = a.m + } + y.prototype.return = function(a) { + this.h = { + return: a + }; + this.j = this.m + }; + + function B(a) { + this.g = new y; + this.h = a + } + + function C(a, b) { + z(a.g); + var e = a.g.g; + if (e) return D(a, "return" in e ? e["return"] : function(f) { + return { + value: f, + done: !0 + } + }, b, a.g.return); + a.g.return(b); + return H(a) + } + + function D(a, b, e, f) { + try { + var h = b.call(a.g.g, e); + if (!(h instanceof Object)) throw new TypeError("Iterator result " + h + " is not an object"); + if (!h.done) return a.g.i = !1, h; + var l = h.value + } catch (c) { + return a.g.g = null, A(a.g, c), H(a) + } + a.g.g = null; + f.call(a.g, l); + return H(a) + } + + function H(a) { + for (; a.g.j;) try { + var b = a.h(a.g); + if (b) return a.g.i = !1, { + value: b.value, + done: !1 + } + } catch (e) { + a.g.o = void 0, A(a.g, e) + } + a.g.i = !1; + if (a.g.h) { + b = a.g.h; + a.g.h = null; + if (b.G) throw b.F; + return { + value: b.return, + done: !0 + } + } + return { + value: void 0, + done: !0 + } + } + + function I(a) { + this.next = function(b) { + z(a.g); + a.g.g ? b = D(a, a.g.g.next, b, a.g.l) : (a.g.l(b), b = H(a)); + return b + }; + this.throw = function(b) { + z(a.g); + a.g.g ? b = D(a, a.g.g["throw"], b, a.g.l) : (A(a.g, b), b = H(a)); + return b + }; + this.return = function(b) { + return C(a, b) + }; + this[Symbol.iterator] = function() { + return this + } + } + + function J(a) { + function b(f) { + return a.next(f) + } + + function e(f) { + return a.throw(f) + } + return new Promise(function(f, h) { + function l(c) { + c.done ? f(c.value) : Promise.resolve(c.value).then(b, e).then(l, h) + } + l(a.next()) + }) + } + v("Promise", function(a) { + function b(c) { + this.h = 0; + this.i = void 0; + this.g = []; + this.o = !1; + var d = this.j(); + try { + c(d.resolve, d.reject) + } catch (g) { + d.reject(g) + } + } + + function e() { + this.g = null + } + + function f(c) { + return c instanceof b ? c : new b(function(d) { + d(c) + }) + } + if (a) return a; + e.prototype.h = function(c) { + if (null == this.g) { + this.g = []; + var d = this; + this.i(function() { + d.l() + }) + } + this.g.push(c) + }; + var h = u.setTimeout; + e.prototype.i = function(c) { + h(c, 0) + }; + e.prototype.l = function() { + for (; this.g && this.g.length;) { + var c = this.g; + this.g = []; + for (var d = 0; d < c.length; ++d) { + var g = + c[d]; + c[d] = null; + try { + g() + } catch (k) { + this.j(k) + } + } + } + this.g = null + }; + e.prototype.j = function(c) { + this.i(function() { + throw c; + }) + }; + b.prototype.j = function() { + function c(k) { + return function(m) { + g || (g = !0, k.call(d, m)) + } + } + var d = this, + g = !1; + return { + resolve: c(this.A), + reject: c(this.l) + } + }; + b.prototype.A = function(c) { + if (c === this) this.l(new TypeError("A Promise cannot resolve to itself")); + else if (c instanceof b) this.C(c); + else { + a: switch (typeof c) { + case "object": + var d = null != c; + break a; + case "function": + d = !0; + break a; + default: + d = !1 + } + d ? this.v(c) : this.m(c) + } + }; + b.prototype.v = function(c) { + var d = void 0; + try { + d = c.then + } catch (g) { + this.l(g); + return + } + "function" == typeof d ? this.D(d, c) : this.m(c) + }; + b.prototype.l = function(c) { + this.u(2, c) + }; + b.prototype.m = function(c) { + this.u(1, c) + }; + b.prototype.u = function(c, d) { + if (0 != this.h) throw Error("Cannot settle(" + c + ", " + d + "): Promise already settled in state" + this.h); + this.h = c; + this.i = d; + 2 === this.h && this.B(); + this.H() + }; + b.prototype.B = function() { + var c = this; + h(function() { + if (c.I()) { + var d = u.console; + "undefined" !== typeof d && d.error(c.i) + } + }, 1) + }; + b.prototype.I = + function() { + if (this.o) return !1; + var c = u.CustomEvent, + d = u.Event, + g = u.dispatchEvent; + if ("undefined" === typeof g) return !0; + "function" === typeof c ? c = new c("unhandledrejection", { + cancelable: !0 + }) : "function" === typeof d ? c = new d("unhandledrejection", { + cancelable: !0 + }) : (c = u.document.createEvent("CustomEvent"), c.initCustomEvent("unhandledrejection", !1, !0, c)); + c.promise = this; + c.reason = this.i; + return g(c) + }; + b.prototype.H = function() { + if (null != this.g) { + for (var c = 0; c < this.g.length; ++c) l.h(this.g[c]); + this.g = null + } + }; + var l = new e; + b.prototype.C = + function(c) { + var d = this.j(); + c.s(d.resolve, d.reject) + }; + b.prototype.D = function(c, d) { + var g = this.j(); + try { + c.call(d, g.resolve, g.reject) + } catch (k) { + g.reject(k) + } + }; + b.prototype.then = function(c, d) { + function g(p, r) { + return "function" == typeof p ? function(E) { + try { + k(p(E)) + } catch (F) { + m(F) + } + } : r + } + var k, m, G = new b(function(p, r) { + k = p; + m = r + }); + this.s(g(c, k), g(d, m)); + return G + }; + b.prototype.catch = function(c) { + return this.then(void 0, c) + }; + b.prototype.s = function(c, d) { + function g() { + switch (k.h) { + case 1: + c(k.i); + break; + case 2: + d(k.i); + break; + default: + throw Error("Unexpected state: " + + k.h); + } + } + var k = this; + null == this.g ? l.h(g) : this.g.push(g); + this.o = !0 + }; + b.resolve = f; + b.reject = function(c) { + return new b(function(d, g) { + g(c) + }) + }; + b.race = function(c) { + return new b(function(d, g) { + for (var k = x(c), m = k.next(); !m.done; m = k.next()) f(m.value).s(d, g) + }) + }; + b.all = function(c) { + var d = x(c), + g = d.next(); + return g.done ? f([]) : new b(function(k, m) { + function G(E) { + return function(F) { + p[E] = F; + r--; + 0 == r && k(p) + } + } + var p = [], + r = 0; + do p.push(void 0), r++, f(g.value).s(G(p.length - 1), m), g = d.next(); while (!g.done) + }) + }; + return b + }); + var K = "function" == typeof Object.assign ? Object.assign : function(a, b) { + for (var e = 1; e < arguments.length; e++) { + var f = arguments[e]; + if (f) + for (var h in f) Object.prototype.hasOwnProperty.call(f, h) && (a[h] = f[h]) + } + return a + }; + v("Object.assign", function(a) { + return a || K + }); + var L = this || self; + var M = { + facingMode: "user", + width: 640, + height: 480 + }; + + function N(a, b) { + this.video = a; + this.i = 0; + this.h = Object.assign(Object.assign({}, M), b) + } + N.prototype.stop = function() { + var a = this, + b, e, f, h; + return J(new I(new B(function(l) { + if (a.g) { + b = a.g.getTracks(); + e = x(b); + for (f = e.next(); !f.done; f = e.next()) h = f.value, h.stop(); + a.g = void 0 + } + l.j = 0 + }))) + }; + N.prototype.start = function() { + var a = this, + b; + return J(new I(new B(function(e) { + navigator.mediaDevices && navigator.mediaDevices.getUserMedia || alert("No navigator.mediaDevices.getUserMedia exists."); + b = a.h; + return e.return(navigator.mediaDevices.getUserMedia({ + video: { + facingMode: b.facingMode, + width: b.width, + height: b.height + } + }).then(function(f) { + O(a, f) + }).catch(function(f) { + var h = "Failed to acquire camera feed: " + f; + console.error(h); + alert(h); + throw f; + })) + }))) + }; + + function P(a) { + window.requestAnimationFrame(function() { + Q(a) + }) + } + + function O(a, b) { + a.g = b; + a.video.srcObject = b; + a.video.onloadedmetadata = function() { + a.video.play(); + P(a) + } + } + + function Q(a) { + var b = null; + a.video.paused || a.video.currentTime === a.i || (a.i = a.video.currentTime, b = a.h.onFrame()); + b ? b.then(function() { + P(a) + }) : P(a) + } + var R = ["Camera"], + S = L; + R[0] in S || "undefined" == typeof S.execScript || S.execScript("var " + R[0]); + for (var T; R.length && (T = R.shift());) R.length || void 0 === N ? S[T] && S[T] !== Object.prototype[T] ? S = S[T] : S = S[T] = {} : S[T] = N; +}).call(this); diff --git a/src/webserver/static/hand/control_utils.js b/src/webserver/static/hand/control_utils.js new file mode 100644 index 0000000..40a03de --- /dev/null +++ b/src/webserver/static/hand/control_utils.js @@ -0,0 +1,1294 @@ +(function() { + /* + + Copyright The Closure Library Authors. + SPDX-License-Identifier: Apache-2.0 + */ + 'use strict'; + + function aa(a) { + var b = 0; + return function() { + return b < a.length ? { + done: !1, + value: a[b++] + } : { + done: !0 + } + } + } + var p = "function" == typeof Object.defineProperties ? Object.defineProperty : function(a, b, c) { + if (a == Array.prototype || a == Object.prototype) return a; + a[b] = c.value; + return a + }; + + function ba(a) { + a = ["object" == typeof globalThis && globalThis, a, "object" == typeof window && window, "object" == typeof self && self, "object" == typeof global && global]; + for (var b = 0; b < a.length; ++b) { + var c = a[b]; + if (c && c.Math == Math) return c + } + throw Error("Cannot find global object"); + } + var r = ba(this); + + function t(a, b) { + if (b) a: { + var c = r;a = a.split("."); + for (var d = 0; d < a.length - 1; d++) { + var f = a[d]; + if (!(f in c)) break a; + c = c[f] + } + a = a[a.length - 1];d = c[a];b = b(d);b != d && null != b && p(c, a, { + configurable: !0, + writable: !0, + value: b + }) + } + } + t("Symbol", function(a) { + function b(g) { + if (this instanceof b) throw new TypeError("Symbol is not a constructor"); + return new c(d + (g || "") + "_" + f++, g) + } + + function c(g, e) { + this.g = g; + p(this, "description", { + configurable: !0, + writable: !0, + value: e + }) + } + if (a) return a; + c.prototype.toString = function() { + return this.g + }; + var d = "jscomp_symbol_" + (1E9 * Math.random() >>> 0) + "_", + f = 0; + return b + }); + t("Symbol.iterator", function(a) { + if (a) return a; + a = Symbol("Symbol.iterator"); + for (var b = "Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "), c = 0; c < b.length; c++) { + var d = r[b[c]]; + "function" === typeof d && "function" != typeof d.prototype[a] && p(d.prototype, a, { + configurable: !0, + writable: !0, + value: function() { + return ca(aa(this)) + } + }) + } + return a + }); + + function ca(a) { + a = { + next: a + }; + a[Symbol.iterator] = function() { + return this + }; + return a + } + + function v(a) { + var b = "undefined" != typeof Symbol && Symbol.iterator && a[Symbol.iterator]; + return b ? b.call(a) : { + next: aa(a) + } + } + + function w(a) { + if (!(a instanceof Array)) { + a = v(a); + for (var b, c = []; !(b = a.next()).done;) c.push(b.value); + a = c + } + return a + } + var da = "function" == typeof Object.create ? Object.create : function(a) { + function b() {} + b.prototype = a; + return new b + }, + x; + if ("function" == typeof Object.setPrototypeOf) x = Object.setPrototypeOf; + else { + var y; + a: { + var ea = { + a: !0 + }, + fa = {}; + try { + fa.__proto__ = ea; + y = fa.a; + break a + } catch (a) {} + y = !1 + } + x = y ? function(a, b) { + a.__proto__ = b; + if (a.__proto__ !== b) throw new TypeError(a + " is not extensible"); + return a + } : null + } + var z = x; + + function B() { + this.j = !1; + this.h = null; + this.l = void 0; + this.g = 1; + this.o = 0; + this.i = null + } + + function C(a) { + if (a.j) throw new TypeError("Generator is already running"); + a.j = !0 + } + B.prototype.m = function(a) { + this.l = a + }; + + function D(a, b) { + a.i = { + L: b, + M: !0 + }; + a.g = a.o + } + B.prototype.return = function(a) { + this.i = { + return: a + }; + this.g = this.o + }; + + function F(a, b, c) { + a.g = c; + return { + value: b + } + } + + function ha(a) { + this.g = new B; + this.h = a + } + + function ia(a, b) { + C(a.g); + var c = a.g.h; + if (c) return G(a, "return" in c ? c["return"] : function(d) { + return { + value: d, + done: !0 + } + }, b, a.g.return); + a.g.return(b); + return H(a) + } + + function G(a, b, c, d) { + try { + var f = b.call(a.g.h, c); + if (!(f instanceof Object)) throw new TypeError("Iterator result " + f + " is not an object"); + if (!f.done) return a.g.j = !1, f; + var g = f.value + } catch (e) { + return a.g.h = null, D(a.g, e), H(a) + } + a.g.h = null; + d.call(a.g, g); + return H(a) + } + + function H(a) { + for (; a.g.g;) try { + var b = a.h(a.g); + if (b) return a.g.j = !1, { + value: b.value, + done: !1 + } + } catch (c) { + a.g.l = void 0, D(a.g, c) + } + a.g.j = !1; + if (a.g.i) { + b = a.g.i; + a.g.i = null; + if (b.M) throw b.L; + return { + value: b.return, + done: !0 + } + } + return { + value: void 0, + done: !0 + } + } + + function ja(a) { + this.next = function(b) { + C(a.g); + a.g.h ? b = G(a, a.g.h.next, b, a.g.m) : (a.g.m(b), b = H(a)); + return b + }; + this.throw = function(b) { + C(a.g); + a.g.h ? b = G(a, a.g.h["throw"], b, a.g.m) : (D(a.g, b), b = H(a)); + return b + }; + this.return = function(b) { + return ia(a, b) + }; + this[Symbol.iterator] = function() { + return this + } + } + + function I(a, b) { + b = new ja(new ha(b)); + z && a.prototype && z(b, a.prototype); + return b + } + var ka = "function" == typeof Object.assign ? Object.assign : function(a, b) { + for (var c = 1; c < arguments.length; c++) { + var d = arguments[c]; + if (d) + for (var f in d) Object.prototype.hasOwnProperty.call(d, f) && (a[f] = d[f]) + } + return a + }; + t("Object.assign", function(a) { + return a || ka + }); + t("Promise", function(a) { + function b(e) { + this.h = 0; + this.i = void 0; + this.g = []; + this.o = !1; + var h = this.j(); + try { + e(h.resolve, h.reject) + } catch (k) { + h.reject(k) + } + } + + function c() { + this.g = null + } + + function d(e) { + return e instanceof b ? e : new b(function(h) { + h(e) + }) + } + if (a) return a; + c.prototype.h = function(e) { + if (null == this.g) { + this.g = []; + var h = this; + this.i(function() { + h.l() + }) + } + this.g.push(e) + }; + var f = r.setTimeout; + c.prototype.i = function(e) { + f(e, 0) + }; + c.prototype.l = function() { + for (; this.g && this.g.length;) { + var e = this.g; + this.g = []; + for (var h = 0; h < e.length; ++h) { + var k = + e[h]; + e[h] = null; + try { + k() + } catch (l) { + this.j(l) + } + } + } + this.g = null + }; + c.prototype.j = function(e) { + this.i(function() { + throw e; + }) + }; + b.prototype.j = function() { + function e(l) { + return function(n) { + k || (k = !0, l.call(h, n)) + } + } + var h = this, + k = !1; + return { + resolve: e(this.G), + reject: e(this.l) + } + }; + b.prototype.G = function(e) { + if (e === this) this.l(new TypeError("A Promise cannot resolve to itself")); + else if (e instanceof b) this.I(e); + else { + a: switch (typeof e) { + case "object": + var h = null != e; + break a; + case "function": + h = !0; + break a; + default: + h = !1 + } + h ? this.F(e) : this.m(e) + } + }; + b.prototype.F = function(e) { + var h = void 0; + try { + h = e.then + } catch (k) { + this.l(k); + return + } + "function" == typeof h ? this.J(h, e) : this.m(e) + }; + b.prototype.l = function(e) { + this.u(2, e) + }; + b.prototype.m = function(e) { + this.u(1, e) + }; + b.prototype.u = function(e, h) { + if (0 != this.h) throw Error("Cannot settle(" + e + ", " + h + "): Promise already settled in state" + this.h); + this.h = e; + this.i = h; + 2 === this.h && this.H(); + this.A() + }; + b.prototype.H = function() { + var e = this; + f(function() { + if (e.D()) { + var h = r.console; + "undefined" !== typeof h && h.error(e.i) + } + }, 1) + }; + b.prototype.D = + function() { + if (this.o) return !1; + var e = r.CustomEvent, + h = r.Event, + k = r.dispatchEvent; + if ("undefined" === typeof k) return !0; + "function" === typeof e ? e = new e("unhandledrejection", { + cancelable: !0 + }) : "function" === typeof h ? e = new h("unhandledrejection", { + cancelable: !0 + }) : (e = r.document.createEvent("CustomEvent"), e.initCustomEvent("unhandledrejection", !1, !0, e)); + e.promise = this; + e.reason = this.i; + return k(e) + }; + b.prototype.A = function() { + if (null != this.g) { + for (var e = 0; e < this.g.length; ++e) g.h(this.g[e]); + this.g = null + } + }; + var g = new c; + b.prototype.I = + function(e) { + var h = this.j(); + e.v(h.resolve, h.reject) + }; + b.prototype.J = function(e, h) { + var k = this.j(); + try { + e.call(h, k.resolve, k.reject) + } catch (l) { + k.reject(l) + } + }; + b.prototype.then = function(e, h) { + function k(m, q) { + return "function" == typeof m ? function(E) { + try { + l(m(E)) + } catch (A) { + n(A) + } + } : q + } + var l, n, u = new b(function(m, q) { + l = m; + n = q + }); + this.v(k(e, l), k(h, n)); + return u + }; + b.prototype.catch = function(e) { + return this.then(void 0, e) + }; + b.prototype.v = function(e, h) { + function k() { + switch (l.h) { + case 1: + e(l.i); + break; + case 2: + h(l.i); + break; + default: + throw Error("Unexpected state: " + + l.h); + } + } + var l = this; + null == this.g ? g.h(k) : this.g.push(k); + this.o = !0 + }; + b.resolve = d; + b.reject = function(e) { + return new b(function(h, k) { + k(e) + }) + }; + b.race = function(e) { + return new b(function(h, k) { + for (var l = v(e), n = l.next(); !n.done; n = l.next()) d(n.value).v(h, k) + }) + }; + b.all = function(e) { + var h = v(e), + k = h.next(); + return k.done ? d([]) : new b(function(l, n) { + function u(E) { + return function(A) { + m[E] = A; + q--; + 0 == q && l(m) + } + } + var m = [], + q = 0; + do m.push(void 0), q++, d(k.value).v(u(m.length - 1), n), k = h.next(); while (!k.done) + }) + }; + return b + }); + t("Array.from", function(a) { + return a ? a : function(b, c, d) { + c = null != c ? c : function(h) { + return h + }; + var f = [], + g = "undefined" != typeof Symbol && Symbol.iterator && b[Symbol.iterator]; + if ("function" == typeof g) { + b = g.call(b); + for (var e = 0; !(g = b.next()).done;) f.push(c.call(d, g.value, e++)) + } else + for (g = b.length, e = 0; e < g; e++) f.push(c.call(d, b[e], e)); + return f + } + }); + t("Array.prototype.fill", function(a) { + return a ? a : function(b, c, d) { + var f = this.length || 0; + 0 > c && (c = Math.max(0, f + c)); + if (null == d || d > f) d = f; + d = Number(d); + 0 > d && (d = Math.max(0, f + d)); + for (c = Number(c || 0); c < d; c++) this[c] = b; + return this + } + }); + + function J(a) { + return a ? a : Array.prototype.fill + } + t("Int8Array.prototype.fill", J); + t("Uint8Array.prototype.fill", J); + t("Uint8ClampedArray.prototype.fill", J); + t("Int16Array.prototype.fill", J); + t("Uint16Array.prototype.fill", J); + t("Int32Array.prototype.fill", J); + t("Uint32Array.prototype.fill", J); + t("Float32Array.prototype.fill", J); + t("Float64Array.prototype.fill", J); + + function la(a, b) { + a instanceof String && (a += ""); + var c = 0, + d = !1, + f = { + next: function() { + if (!d && c < a.length) { + var g = c++; + return { + value: b(g, a[g]), + done: !1 + } + } + d = !0; + return { + done: !0, + value: void 0 + } + } + }; + f[Symbol.iterator] = function() { + return f + }; + return f + } + t("Array.prototype.keys", function(a) { + return a ? a : function() { + return la(this, function(b) { + return b + }) + } + }); + t("Object.values", function(a) { + return a ? a : function(b) { + var c = [], + d; + for (d in b) Object.prototype.hasOwnProperty.call(b, d) && c.push(b[d]); + return c + } + }); + var ma = this || self; + + function K(a, b) { + a = a.split("."); + var c = ma; + a[0] in c || "undefined" == typeof c.execScript || c.execScript("var " + a[0]); + for (var d; a.length && (d = a.shift());) a.length || void 0 === b ? c[d] && c[d] !== Object.prototype[d] ? c = c[d] : c = c[d] = {} : c[d] = b + }; + + function L(a, b) { + var c = void 0; + return new(c || (c = Promise))(function(d, f) { + function g(k) { + try { + h(b.next(k)) + } catch (l) { + f(l) + } + } + + function e(k) { + try { + h(b["throw"](k)) + } catch (l) { + f(l) + } + } + + function h(k) { + k.done ? d(k.value) : (new c(function(l) { + l(k.value) + })).then(g, e) + } + h((b = b.apply(a, void 0)).next()) + }) + }; + var na = {}; + + function M(a, b) { + if (b !== na) throw Error("Bad secret"); + this.g = a + } + + function N() {} + M.prototype = da(N.prototype); + M.prototype.constructor = M; + if (z) z(M, N); + else + for (var O in N) + if ("prototype" != O) + if (Object.defineProperties) { + var oa = Object.getOwnPropertyDescriptor(N, O); + oa && Object.defineProperty(M, O, oa) + } else M[O] = N[O]; + M.prototype.toString = function() { + return this.g + }; + + function P(a, b, c) { + a = document.createElement(a); + b && a.classList.add(b); + if (c) + for (b = v(c), c = b.next(); !c.done; c = b.next()) a.appendChild(c.value); + return a + } + + function Q(a, b) { + return P("div", a, b) + } + + function R(a, b) { + return P("span", a, b) + } + + function S(a) { + var b = P("img", "", void 0); + b.src = a || ""; + return b + }; + + function pa(a, b) { + var c = this; + this.g = a; + this.i = {}; + var d, f = Q("dropdown-wrapper", [d = Q("dropdown", [Q("dropdown-trigger", [this.h = R(), Q("arrow")]), this.options = Q("dropdown-options")])]); + f.onclick = function() { + a.C && a.C(); + d.classList.toggle("open"); + d.g = function() { + a.B && a.B() + } + }; + for (var g = {}, e = v(a.options), h = e.next(); !h.done; g = { + s: g.s + }, h = e.next()) g.s = h.value, h = void 0, this.options.appendChild(h = R("dropdown-option")), this.i[g.s.value] = h, h.textContent = g.s.name, g.s.prefix && h.prepend(g.s.prefix), h.setAttribute("data-value", + g.s.value), h.onclick = function(k) { + return function() { + T(c, k.s.value) + } + }(g); + window.addEventListener("click", function(k) { + d.contains(k.target) || d.classList.remove("open") + }); + b.appendChild(f) + } + + function T(a, b) { + for (var c = v(a.g.options), d = c.next(); !d.done; d = c.next()) { + d = d.value; + var f = a.i[d.value]; + if (d.value === b && !f.classList.contains("selected")) return (b = a.options.querySelector(".selected")) && b.classList.remove("selected"), f.classList.add("selected"), a.h.textContent = f.textContent, a.g.onclick(d), !0 + } + return !1 + } + + function qa(a, b) { + var c = a.options.querySelector(".selected"); + c && (c.classList.remove("selected"), a.h.textContent = void 0 === b ? "" : b) + }; + + function U(a) { + this.g = a + } + U.prototype.create = function(a, b, c) { + var d = this, + f = c.appendChild(document.createElement("div")); + f.classList.add("control-panel-entry"); + f.classList.add("control-panel-slider"); + c = f.appendChild(document.createElement("span")); + c.classList.add("label"); + c.textContent = this.g.title; + c = new pa({ + options: this.g.options.map(function(g) { + return Object.assign(Object.assign({}, g), { + data: null + }) + }), + C: function() { + f.style.zIndex = "1000" + }, + onclick: function(g) { + b[d.g.field] = g.value; + a(); + if (d.g.onselectionchanged) d.g.onselectionchanged(g) + }, + B: function() { + f.style.zIndex = + "100" + } + }, f); + 0 < this.g.options.length && T(c, this.g.options[0].value) + }; + U.prototype.update = function() {}; + + function V() { + this.i = this.counter = 0; + this.g = Array.from({ + length: 10 + }).fill(0) + } + V.prototype.create = function(a, b, c) { + b = c.appendChild(document.createElement("div")); + b.classList.add("control-panel-entry"); + b.classList.add("control-panel-fps"); + a = b.appendChild(document.createElement("canvas")); + this.h = b.appendChild(document.createElement("div")); + this.h.classList.add("fps-text"); + c = b.appendChild(document.createElement("div")); + c.classList.add("fps-30"); + c.textContent = "30"; + b = b.appendChild(document.createElement("div")); + b.classList.add("fps-60"); + b.textContent = "60"; + a.width = 100; + a.height = 100; + this.j = a.getContext("2d"); + ra(this, 0) + }; + V.prototype.update = function() {}; + V.prototype.tick = function() { + var a = Math.floor(performance.now() / 1E3); + 1 <= a - this.i && (ra(this, this.counter), this.i = a, this.counter = 0); + ++this.counter + }; + + function ra(a, b) { + a.g.shift(); + a.g.push(b); + var c = a.j; + c.fillStyle = "green"; + c.clearRect(0, 0, c.canvas.width, c.canvas.height); + for (var d = 0; 10 > d; ++d) { + var f = Math.min(100, Math.max(0, a.g[d])); + c.fillRect(10 * d + 1, 100 - f + 1, 8, f) + } + c.setLineDash([2, 2]); + c.strokeStyle = "#a0a0a0a0"; + c.lineWidth = 2; + c.beginPath(); + c.moveTo(0, 30); + c.lineTo(100, 30); + c.stroke(); + c.beginPath(); + c.moveTo(0, 60); + c.lineTo(100, 60); + c.stroke(); + a.h.textContent = b.toFixed(0) + " fps" + }; + + function W(a) { + this.g = a + } + W.prototype.create = function(a, b, c) { + var d = this; + this.options = b; + b = this.g; + c = c.appendChild(document.createElement("div")); + c.classList.add("control-panel-entry"); + c.classList.add("control-panel-slider"); + var f = c.appendChild(document.createElement("span")); + f.classList.add("label"); + (this.h = c.appendChild(document.createElement("span"))).classList.add("callout"); + var g = this.i = c.appendChild(document.createElement("input")); + g.classList.add("value"); + g.type = "range"; + b.range ? (g.min = "" + b.range[0], g.max = "" + b.range[1], + g.step = void 0 === b.step ? "any" : "" + b.step) : b.discrete && (g.min = "0", g.max = "" + (Object.keys(b.discrete).length - 1), g.step = "1"); + g.oninput = function() { + sa(d, Number(g.value)) + }; + g.onchange = function() { + var e = Number(g.value); + d.g.discrete && (e = Object.keys(d.g.discrete)[e], Array.isArray(d.g.discrete) && (e = Number(e))); + d.options[d.g.field] = e; + a() + }; + f.textContent = b.title + }; + W.prototype.update = function() { + var a = this.options[this.g.field]; + a = this.g.discrete && !Array.isArray(this.g.discrete) ? Object.keys(this.g.discrete).indexOf(a) : a; + this.i.value = "" + a; + sa(this, a) + }; + + function sa(a, b) { + b = a.g.discrete ? Object.values(a.g.discrete)[b] : b; + a.h.textContent = "" + b + }; + var ta = { + facingMode: "user", + width: 640, + height: 480 + }, + ua = { + allowVideo: !0, + allowImage: !0, + examples: { + videos: [], + images: [] + } + }; + + function X(a) { + return "https://fonts.gstatic.com/s/i/googlematerialicons/" + a + "/v8/white-24dp/1x/gm_" + a + "_white_24dp.png" + } + + function Y(a) { + this.l = []; + this.A = 0; + this.j = !1; + this.g = Object.assign(Object.assign({}, ua), a); + this.g.cameraOptions = Object.assign(Object.assign({}, this.g.cameraOptions || {}), ta) + } + + function va(a) { + return L(a, function c() { + var d, f, g, e, h; + return I(c, function(k) { + if (1 == k.g) return F(k, navigator.mediaDevices.getUserMedia({ + video: !0 + }), 2); + if (3 != k.g) return F(k, navigator.mediaDevices.enumerateDevices(), 3); + d = k.l; + f = []; + g = v(d); + for (e = g.next(); !e.done; e = g.next()) h = e.value, "" !== h.label && "videoinput" === h.kind && f.push({ + label: h.label, + deviceId: h.deviceId + }); + return k.return(f) + }) + }) + } + + function Z(a) { + window.requestAnimationFrame(function() { + a.tick() + }) + } + Y.prototype.tick = function() { + var a = this, + b = null; + this.j && (this.video.paused || this.video.currentTime === this.A || (this.m || (wa(this, this.video.currentTime / this.video.duration), this.i.time.textContent = xa(this.video.currentTime)), this.A = this.video.currentTime, b = this.g.onFrame ? this.g.onFrame(this.video, { + width: this.video.videoWidth, + height: this.video.videoHeight + }) : null), b ? b.then(function() { + Z(a) + }) : Z(this)) + }; + + function ya(a, b) { + a.video.srcObject = b; + a.video.onloadedmetadata = function() { + a.video.play(); + a.j = !0; + Z(a) + } + } + + function za(a) { + return L(a, function c() { + var d = this, + f, g, e, h; + return I(c, function(k) { + d.i.parent.style.display = "none"; + d.j = !1; + if (d.m) { + f = d.m.getTracks(); + g = v(f); + for (e = g.next(); !e.done; e = g.next()) h = e.value, h.stop(); + d.m = void 0 + } + k.g = 0 + }) + }) + } + + function Aa(a) { + return L(a, function c() { + var d = this, + f, g, e, h; + return I(c, function(k) { + if (1 == k.g) return f = d, F(k, va(d), 2); + g = k.l.map(function(l) { + return { + label: l.label, + type: "webcam", + N: l, + start: function() { + return Ba(f, l) + } + } + }); + e = d.g.examples.videos.map(function(l) { + return { + label: l.name, + type: "video", + video: f.video, + start: function() { + Ca(f, l.src) + } + } + }); + h = d.g.examples.images.map(function(l) { + return { + label: l.name, + type: "image", + image: f.h, + start: function() { + Da(f, l.src) + } + } + }); + return k.return([].concat(w(g), w(e), w(h))) + }) + }) + } + + function Ea(a, b) { + return L(a, function d() { + var f = this; + return I(d, function(g) { + 1 == g.g ? g = F(g, za(f), 2) : 3 != g.g ? f.g.onSourceChanged ? g = F(g, f.g.onSourceChanged(b.label, b.type), 3) : (g.g = 3, g = void 0) : g = F(g, b.start(), 0); + return g + }) + }) + } + + function Fa(a, b) { + return L(a, function d() { + var f = this; + return I(d, function(g) { + f.g && f.g.onFrame ? g = F(g, f.g.onFrame(b, { + width: b.naturalWidth, + height: b.naturalHeight + }), 0) : (g.g = 0, g = void 0); + return g + }) + }) + } + + function Ga(a) { + return L(a, function c() { + var d = this; + return I(c, function(f) { + if (1 == f.g) { + if (!d.g || !d.g.onFrame) { + f.g = 0; + return + } + d.i.parent.style.display = "flex"; + wa(d, 0); + return F(f, d.video.play(), 3) + } + d.D(); + d.j = !0; + Z(d); + f.g = 0 + }) + }) + } + + function Ba(a, b) { + return L(a, function d() { + var f = this, + g, e; + return I(d, function(h) { + g = f; + e = Object.assign({ + video: { + deviceId: b.deviceId + } + }, f.g.cameraOptions ? { + facingMode: f.g.cameraOptions.facingMode, + width: f.g.cameraOptions.width, + height: f.g.cameraOptions.height + } : {}); + return h.return(navigator.mediaDevices.getUserMedia(e).then(function(k) { + g.m = k; + ya(g, k) + }).catch(function(k) { + console.error("Failed to acquire camera feed: " + k); + alert("Failed to acquire camera feed: " + k); + throw k; + })) + }) + }) + } + + function Ha(a, b) { + a.o = new pa({ + options: a.l.map(function(c) { + var d = void 0; + "image" === c.type ? d = S("https://fonts.gstatic.com/s/i/googlematerialicons/image/v12/gm_grey-24dp/1x/gm_image_gm_grey_24dp.png") : "video" === c.type && (d = S("https://fonts.gstatic.com/s/i/googlematerialicons/videocam/v12/gm_grey-24dp/1x/gm_videocam_gm_grey_24dp.png")); + return { + name: c.label, + value: c.label, + data: c, + prefix: d + } + }), + onclick: function(c) { + a.i.parent.style.display = "none"; + c.data.start() + }, + C: function() { + a.u.style.zIndex = "2000" + }, + B: function() { + a.u.style.zIndex = + "100" + } + }, b) + } + + function Ia(a, b) { + var c = b.appendChild(document.createElement("input")); + c.type = "file"; + c.style.display = "none"; + b.appendChild(R("file-selection", [b = Q("", [S(X("file_upload"))])])); + b.onclick = function() { + c.click() + }; + c.onchange = function() { + return L(a, function f() { + var g, e, h, k, l = this; + return I(f, function(n) { + if ((g = c.files) && 0 < g.length) { + e = g[0].type.toLowerCase(); + h = e.substring(0, e.indexOf("/")); + var u = g[0]; + var m = u.type.match(/^([^;]+)(?:;\w+=(?:\w+|"[\w;,= ]+"))*$/i); + if (2 !== (null === m || void 0 === m ? void 0 : m.length) || !(/^image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp|x-icon)$/i.test(m[1]) || + /^video\/(?:mpeg|mp4|ogg|webm|x-matroska|quicktime|x-ms-wmv)$/i.test(m[1]) || /^audio\/(?:3gpp2|3gpp|aac|L16|midi|mp3|mp4|mpeg|oga|ogg|opus|x-m4a|x-matroska|x-wav|wav|webm)$/i.test(m[1]))) throw Error("unsafe blob MIME type: " + u.type); + if (URL && URL.createObjectURL) u = new M(URL.createObjectURL(u), na); + else throw Error("cannot find createObjectURL"); + k = u.toString(); + "image" === h ? (qa(l.o, g[0].name), Da(l, k)) : "video" === h && Ca(l, k) + } + n.g = 0 + }) + }) + } + } + + function Da(a, b) { + a.h.onload = function() { + return L(a, function d() { + var f = this, + g; + return I(d, function(e) { + g = f; + f.g.onFrame ? e = F(e, Ea(f, { + label: "file", + type: "image", + image: f.h, + start: function() { + return L(g, function k() { + var l = this; + return I(k, function(n) { + return F(n, Fa(l, l.h), 0) + }) + }) + } + }), 0) : (e.g = 0, e = void 0); + return e + }) + }) + }; + a.h.src = b + } + + function Ca(a, b) { + a.video.onloadedmetadata = function() { + return L(a, function d() { + var f = this, + g; + return I(d, function(e) { + g = f; + f.video.loop = !0; + f.g.onFrame ? e = F(e, Ea(f, { + label: "file", + type: "video", + video: f.video, + start: function() { + return Ga(g) + } + }), 0) : (e.g = 0, e = void 0); + return e + }) + }) + }; + a.video.srcObject = null; + a.video.src = b + } + Y.prototype.create = function(a, b, c) { + var d = this, + f = this.u = c.appendChild(document.createElement("div")); + f.classList.add("control-panel-entry"); + f.classList.add("control-panel-source-picker"); + var g = Q("source-selection"); + f.append(g); + Aa(this).then(function(e) { + d.l = e; + Ha(d, g); + Ia(d, g); + e = g.appendChild(document.createElement("div")); + e.classList.add("inputs"); + d.video = e.appendChild(document.createElement("video")); + d.video.setAttribute("crossorigin", "anonymous"); + d.video.setAttribute("playsinline", "true"); + d.h = e.appendChild(document.createElement("img")); + d.h.setAttribute("crossorigin", "anonymous"); + Ja(d, f); + 0 < d.l.length && (e = d.l[0], T(d.o, e.label) || qa(d.o), e.start()) + }) + }; + + function Ja(a, b) { + var c = X("pause"), + d = X("play_arrow"), + f, g, e, h; + b.append(e = Q("video-controls", [h = S(c), g = Q("video-track"), f = Q("video-slider-ball"), b = R("video-time")])); + a.i = { + parent: e, + K: f, + track: g, + time: b + }; + b.textContent = "00:00"; + f.style.display = "inline-block"; + f.onmousedown = function(k) { + function l() { + k.preventDefault(); + document.removeEventListener("mousemove", n); + u || a.video.play(); + document.removeEventListener("mouseup", l) + } + + function n(m) { + k.preventDefault(); + var q = e.getBoundingClientRect(), + E = f.getBoundingClientRect(), + A = g.getBoundingClientRect(); + m = m.clientX - q.left - E.width / 2; + q = A.left - q.left; + m < q ? m = q : m > q + A.width && (m = q + A.width); + f.style.left = m + "px"; + a.video.currentTime = (m - q) / A.width * a.video.duration + } + k.preventDefault(); + var u = a.video.paused; + a.video.pause(); + document.addEventListener("mousemove", n); + document.addEventListener("mouseup", l) + }; + h.onclick = function() { + a.video.paused ? (a.video.play(), h.src = c) : (a.video.pause(), h.src = d) + }; + a.D = function() { + a.video.paused && (h.src = d); + h.src = c + } + } + + function wa(a, b) { + var c = a.i.K, + d = a.i.track.getBoundingClientRect(); + a = a.i.parent.getBoundingClientRect(); + c.style.left = d.left - a.left + d.width * b + "px" + } + + function xa(a) { + var b = Math.floor(a % 60).toString(); + b = 1 === b.length ? "0" + b : b; + a = Math.floor(a / 60).toString(); + a = 1 === a.length ? "0" + a : a; + return a + ":" + b + } + Y.prototype.update = function() { + if (this.h && !this.j && this.g.onFrame) this.g.onFrame(this.h, { + width: this.h.naturalWidth, + height: this.h.naturalHeight + }) + }; + + function Ka(a) { + this.g = a + } + Ka.prototype.create = function(a, b, c) { + a = c.appendChild(document.createElement("div")); + a.classList.add("control-panel-entry"); + a.classList.add("control-panel-text"); + a.textContent = this.g.title + }; + Ka.prototype.update = function() {}; + + function La(a) { + this.h = a + } + La.prototype.create = function(a, b, c) { + var d = this; + this.i = a; + this.options = b; + this.g = c.appendChild(document.createElement("div")); + this.g.classList.add("control-panel-entry"); + this.g.classList.add("control-panel-toggle"); + this.g.onclick = function() { + d.options[d.h.field] = !d.options[d.h.field]; + d.i() + }; + a = this.g.appendChild(document.createElement("span")); + a.classList.add("label"); + this.value = this.g.appendChild(document.createElement("span")); + this.value.classList.add("value"); + a.textContent = this.h.title + }; + La.prototype.update = function() { + this.options[this.h.field] ? (this.value.textContent = "Yes", this.g.classList.add("yes"), this.g.classList.remove("no")) : (this.value.textContent = "No", this.g.classList.add("no"), this.g.classList.remove("yes")) + }; + + function Ma(a, b) { + this.parent = a; + this.options = b; + this.g = []; + this.h = this.parent.appendChild(document.createElement("div")); + this.h.classList.add("control-panel") + } + Ma.prototype.add = function(a) { + var b = this; + a = v(a); + for (var c = a.next(); !c.done; c = a.next()) c = c.value, this.g.push(c), c.create(function() { + Na(b) + }, this.options, this.h); + Na(this); + return this + }; + Ma.prototype.on = function(a) { + this.i = a; + Na(this); + return this + }; + + function Na(a) { + for (var b = v(a.g), c = b.next(); !c.done; c = b.next()) c.value.update(); + a.i && a.i(a.options) + } + K("ControlPanel", Ma); + K("Slider", W); + K("StaticText", Ka); + K("Toggle", La); + K("SourcePicker", Y); + K("FPS", V); + K("DropDownControl", U); +}).call(this);