ラベル

AI Forecast 8306MUFG (213) Social (75) life (70) Financial (62) IT (57) Proposal (56) idea (50) Fund Management (48) Trading (43) economics (42) Covid-19 (40) AI (38) Hedge Fund (36) Risk (36) Culture (31) BOJ (29) Science (26) hobby (24) accounting (17) Apps (16) career (11) job (7) Travel (6) Hiking (5) emotion (5) music (3) Statarb (2) piano (2)

2019年10月8日火曜日

Webアプリから実行環境情報取得 PC Info retrieval from Web application


Webアプリからの実行環境情報取得

PC Info retrieval from Web application





Web上で走るプログラム(JavaScript)側から、実行環境を調べる必要が出てくる。例えばビデオ入力。カメラの位置(表か裏か)を知るため、実行環境がPCか、スマートフォン/タブレットかを知る必要がある。Sometimes we need to find out local machine information from web application(JavaScript). Video input is one example. Program needs to know if local machine is PC or smart phone/tablet to find out hardware location of Cameras(front/rear).

因みに、次のリスト(Computer Information)は、今このブログが実行されている端末の情報である。For reference, below list(Computer Information) shows local machine information where current blog is running on.

            document.writeln(navigator.platform)
            document.writeln(navigator.appVersion)
            document.writeln(navigator.oscpu)
            document.writeln(navigator.navigator)
            document.writeln(navigator.platform.indexOf("Linux"))
            document.writeln(navigator.platform.indexOf("iPhone"))
            document.writeln(navigator.platform.indexOf("iPad"))



Android、iPad、PCについて上記の情報をチェックした結果、Android端末を検出するにはnavigator.platformに文字Linux、iPhoneは文字iPhone、iPadは文字iPadがあるかないかで判定できるであろうことが推測できた。下は、これらの情報を用いた利用例である。I checked the above information for Android, iPad, iPhone and found out that characters Linux, iPhone, iPad can be used to detect Android, iPhone, iPad respectively retrieving from navigator.platform. Below is one example.

    if(navigator.platform.indexOf("Linux")!=-1 || navigator.platform.indexOf("iPhone")!=-1 || navigator.platform.indexOf("iPad")!=-1) {
      video = createCapture({audio:falsevideo:{facingMode:{exact:"environment"}}}); }
      else {video = createCapture(VIDEO);}


ここで「できるであろう」と書いたのは、Androidなのに、文字Androidが入っている場合とない場合があるようで、確固とした業界基準がないように見受けられたからだ。I wrote "can be" since I see a case where there is no character 'Android' even though machine is definitely Android, hence it looks there is no clear standard.