{"id":952,"date":"2023-05-22T17:15:36","date_gmt":"2023-05-22T09:15:36","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=952"},"modified":"2023-05-23T13:17:55","modified_gmt":"2023-05-23T05:17:55","slug":"webrtc-%e5%bf%ab%e9%80%9f%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=952","title":{"rendered":"WebRTC \u5feb\u901f\u6d4b\u8bd5"},"content":{"rendered":"<h1>\u642d\u5efa\u6d4b\u8bd5\u73af\u5883<\/h1>\n<p>\u542f\u52a8\u6d4b\u8bd5\u7a0b\u5e8f<\/p>\n<pre><code>git clone git@github.com:walterfan\/webrtc_video_chat.git\ncd webrtc_video_chat\n.\/start.sh<\/code><\/pre>\n<p>\u542f\u52a8\u6d4f\u89c8\u5668<\/p>\n<pre><code>cd \/Applications\/Google\\ Chrome\\ Canary.app\/Contents\/MacOS\/\n.\/Google\\ Chrome\\ Canary --disable-webrtc-encryption<\/code><\/pre>\n<p>Chrome \u6709\u4e9b WebRTC \u76f8\u5173\u7684\u6d4b\u8bd5\u5f00\u5173\u5f88\u6709\u7528<\/p>\n<ul>\n<li>\n<p><code>--allow-file-access-from-files<\/code> allows getUserMedia() to be called from file:\/\/ URLs.<\/p>\n<\/li>\n<li>\n<p><code>--disable-gesture-requirement-for-media-playback<\/code> removes the need to tap a <code>&lt;video&gt;<\/code> element to start it playing on Android.<\/p>\n<\/li>\n<li>\n<p><code>--use-fake-ui-for-media-stream<\/code> avoids the need to grant camera\/microphone permissions.<\/p>\n<\/li>\n<li>\n<p><code>--use-fake-device-for-media-stream<\/code> feeds a test pattern to getUserMedia() instead of live camera input.<\/p>\n<\/li>\n<li>\n<p><code>--use-file-for-fake-video-capture=path\/to\/file.y4m<\/code> feeds a Y4M test file to getUserMedia() instead of live camera input.<\/p>\n<\/li>\n<\/ul>\n<p>\u4f7f\u7528 Selenium Webdriver \u7684\u57fa\u672c\u6b65\u9aa4\u5982\u4e0b<\/p>\n<ul>\n<li>Basic Steps in a Selenium WebDriver Script<\/li>\n<li>Create a WebDriver instance.<\/li>\n<li>Navigate to a webpage.<\/li>\n<li>Locate a web element on the webpage via locators in selenium.<\/li>\n<li>Perform one or more user actions on the element.<\/li>\n<li>Preload the expected output\/browser response to the action.<\/li>\n<li>Run test.<\/li>\n<li>Record results and compare results from them to the expected output.<\/li>\n<\/ul>\n<pre><code>#!\/usr\/bin\/env python3\n\nimport random\nimport pytest\nimport os\nimport sys\nfrom time import sleep\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support.ui import Select\nfrom selenium.webdriver.support import expected_conditions as EC\nimport json\nimport logging\nimport signal\nimport uuid\n\nclass TestClient:\n    def __init__(self, name, node_url):\n        self._name = name\n        self._node_url = node_url\n\n        self._config = {\n            &quot;ice_server_url&quot;: &quot;stun:www.fanyamin.com:3478&quot;\n        }\n\n        self._driver = self.create_driver(self._node_url)\n        self._driver.maximize_window()\n        self._driver.implicitly_wait(20)\n\n    def create_driver(self, node_url):\n\n        chrome_options = webdriver.ChromeOptions()\n        chrome_options.add_argument(&#039;--ignore-ssl-errors=yes&#039;)\n        chrome_options.add_argument(&#039;--ignore-certificate-errors&#039;)\n\n        chrome_options.add_argument(&#039;--allow-file-access-from-files&#039;)\n        chrome_options.add_argument(&#039;--enable-local-file-accesses&#039;)\n        chrome_options.add_argument(&#039;--enable-media-stream&#039;)\n        chrome_options.add_argument(&#039;--disable-webrtc-encryption&#039;)\n        chrome_options.add_argument(&#039;--no-default-browser-check&#039;)\n        chrome_options.add_argument(&#039;--use-fake-ui-for-media-stream&#039;)\n        chrome_options.add_argument(&#039;--use-fake-device-for-media-stream&#039;)\n\n        driver = webdriver.Remote(\n            command_executor=node_url,\n            options=chrome_options\n        )\n\n        return driver\n\n    def join(self, room_id, site_url, room_url):\n\n        self._driver.get(site_url)\n        self._config[&quot;room_url&quot;] = room_url\n\n        room_id_txt = self._driver.find_element(By.ID, &quot;roomId&quot;)\n        room_id_txt.clear()\n        room_id_txt.send_keys(room_id)\n\n        config_txt = self._driver.find_element(By.ID, &quot;cfgMessage&quot;)\n        config_txt.clear()\n        config_txt.send_keys(json.dumps(self._config, indent = 4))\n\n        join_btn = self._driver.find_element_by_id(&quot;joinRoom&quot;)\n        join_btn.click()\n\n        start_btn = self._driver.find_element_by_id(&quot;startMedia&quot;)\n        start_btn.click()\n\n        call_btn = self._driver.find_element_by_id(&quot;call&quot;)\n        call_btn.click()\n\n    def leave(self):\n        self._driver.quit()\n\nclass TestCall:\n    def setup(self):\n        self.clients = {}\n        self.clients[&quot;Alice&quot;] = TestClient(&#039;Alice&#039;, &#039;http:\/\/10.224.85.4:4444\/wd\/hub&#039;)\n        self.clients[&quot;Bob&quot;]   = TestClient(&#039;Bob&#039;, &#039;http:\/\/10.224.85.242:4444\/wd\/hub&#039;)\n\n    def test_call(self):\n\n        site_url = &#039;https:\/\/10.224.85.4:8043&#039;\n        room_url = &quot;wss:\/\/10.224.85.4:8003&quot;\n        room_id = str(uuid.uuid4())\n        self.clients[&quot;Alice&quot;].join(room_id, site_url, room_url)\n        self.clients[&quot;Bob&quot;].join(room_id, site_url, room_url)\n\n        for name, client in self.clients.items():\n            print(&quot;{} join room {}\/{} on {}&quot;.format(name, room_id, room_url, site_url))\n            client.join(room_id, site_url, room_url)\n\n        sleep(900)\n\n    def teardown(self):\n        for name, client in self.clients.items():\n            print(&quot;{} leave room&quot;.format(name))\n            client.leave()\n\nif __name__ == &#039;__main__&#039;:\n    pytest.main([&#039;-s&#039;, &#039;-q&#039;, &#039;--html=.\/report.html&#039;])\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u642d\u5efa\u6d4b\u8bd5\u73af\u5883 \u542f\u52a8\u6d4b\u8bd5\u7a0b\u5e8f git clone git@github.com:walterfan\/webrtc_video_chat.git cd webrtc_video_chat .\/start.sh \u542f\u52a8\u6d4f\u89c8\u5668 cd \/Applications\/Google\\ Chrome\\ Canary.app\/Contents\/MacOS\/ .\/Google\\ Chrome\\ Canary &#8211;disable-webrtc-encryption Chrome \u6709\u4e9b WebRTC \u76f8\u5173\u7684\u6d4b\u8bd5\u5f00\u5173\u5f88\u6709\u7528 &#8211;allow-file-access-from-files allows getUserMedia() to be called from file:\/\/ URLs. &#8211;disable-gesture-requirement-for-media-playback removes the need to tap a &lt;video&gt; element to start it playing on Android. &#8211;use-fake-ui-for-media-stream avoids the need to grant camera\/microphone permissions. &#8211;use-fake-device-for-media-stream feeds [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=952\" title=\"Permanent Link to: WebRTC \u5feb\u901f\u6d4b\u8bd5\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-952","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/952"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=952"}],"version-history":[{"count":5,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/952\/revisions"}],"predecessor-version":[{"id":957,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/952\/revisions\/957"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}