stream.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <!doctype html>
  2. <html class="default no-js">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>Stream | @urtc/sdk-web</title>
  7. <meta name="description" content="Documentation for @urtc/sdk-web">
  8. <meta name="viewport" content="width=device-width, initial-scale=1">
  9. <link rel="stylesheet" href="../assets/css/main.css">
  10. </head>
  11. <body>
  12. <header>
  13. <div class="tsd-page-toolbar">
  14. <div class="container">
  15. <div class="table-wrap">
  16. <div class="table-cell" id="tsd-search" data-index="../assets/js/search.json" data-base="..">
  17. <div class="field">
  18. <label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
  19. <input id="tsd-search-field" type="text" />
  20. </div>
  21. <ul class="results">
  22. <li class="state loading">Preparing search index...</li>
  23. <li class="state failure">The search index is not available</li>
  24. </ul>
  25. <a href="../index.html" class="title">@urtc/sdk-web</a>
  26. </div>
  27. <div class="table-cell" id="tsd-widgets">
  28. <div id="tsd-filter">
  29. <a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
  30. <div class="tsd-filter-group">
  31. <div class="tsd-select" id="tsd-filter-visibility">
  32. <span class="tsd-select-label">All</span>
  33. <ul class="tsd-select-list">
  34. <li data-value="public">Public</li>
  35. <li data-value="protected">Public/Protected</li>
  36. <li data-value="private" class="selected">All</li>
  37. </ul>
  38. </div>
  39. <input type="checkbox" id="tsd-filter-inherited" checked />
  40. <label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
  41. <input type="checkbox" id="tsd-filter-externals" checked />
  42. <label class="tsd-widget" for="tsd-filter-externals">Externals</label>
  43. </div>
  44. </div>
  45. <a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="tsd-page-title">
  51. <div class="container">
  52. <ul class="tsd-breadcrumb">
  53. <li>
  54. <a href="../index.html">Globals</a>
  55. </li>
  56. <li>
  57. <a href="stream.html">Stream</a>
  58. </li>
  59. </ul>
  60. <h1>Class Stream</h1>
  61. </div>
  62. </div>
  63. </header>
  64. <div class="container container-main">
  65. <div class="row">
  66. <div class="col-8 col-content">
  67. <section class="tsd-panel tsd-comment">
  68. <div class="tsd-comment tsd-typography">
  69. <div class="lead">
  70. <p>LocalStream 和 RemoteStream 的基类</p>
  71. </div>
  72. </div>
  73. </section>
  74. <section class="tsd-panel tsd-hierarchy">
  75. <h3>Hierarchy</h3>
  76. <ul class="tsd-hierarchy">
  77. <li>
  78. <span class="tsd-signature-type">EventEmitter</span>
  79. <ul class="tsd-hierarchy">
  80. <li>
  81. <span class="target">Stream</span>
  82. <ul class="tsd-hierarchy">
  83. <li>
  84. <a href="localstream.html" class="tsd-signature-type">LocalStream</a>
  85. </li>
  86. <li>
  87. <a href="remotestream.html" class="tsd-signature-type">RemoteStream</a>
  88. </li>
  89. </ul>
  90. </li>
  91. </ul>
  92. </li>
  93. </ul>
  94. </section>
  95. <section class="tsd-panel-group tsd-index-group">
  96. <h2>Index</h2>
  97. <section class="tsd-panel tsd-index-panel">
  98. <div class="tsd-index-content">
  99. <section class="tsd-index-section tsd-is-external">
  100. <h3>Properties</h3>
  101. <ul class="tsd-index-list">
  102. <li class="tsd-kind-property tsd-parent-kind-class tsd-is-external"><a href="stream.html#audiomuted" class="tsd-kind-icon">audio<wbr>Muted</a></li>
  103. <li class="tsd-kind-property tsd-parent-kind-class tsd-is-external"><a href="stream.html#id" class="tsd-kind-icon">id</a></li>
  104. <li class="tsd-kind-property tsd-parent-kind-class tsd-is-external"><a href="stream.html#mediastream" class="tsd-kind-icon">media<wbr>Stream</a></li>
  105. <li class="tsd-kind-property tsd-parent-kind-class tsd-is-external"><a href="stream.html#videomuted" class="tsd-kind-icon">video<wbr>Muted</a></li>
  106. </ul>
  107. </section>
  108. <section class="tsd-index-section tsd-is-external">
  109. <h3>Methods</h3>
  110. <ul class="tsd-index-list">
  111. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#destroy" class="tsd-kind-icon">destroy</a></li>
  112. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#getaudiolevel" class="tsd-kind-icon">get<wbr>Audio<wbr>Level</a></li>
  113. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#getmediatype" class="tsd-kind-icon">get<wbr>Media<wbr>Type</a></li>
  114. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#getstats" class="tsd-kind-icon">get<wbr>Stats</a></li>
  115. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#hasaudio" class="tsd-kind-icon">has<wbr>Audio</a></li>
  116. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#hasvideo" class="tsd-kind-icon">has<wbr>Video</a></li>
  117. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#muteaudio" class="tsd-kind-icon">mute<wbr>Audio</a></li>
  118. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#mutevideo" class="tsd-kind-icon">mute<wbr>Video</a></li>
  119. <li class="tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external"><a href="stream.html#off" class="tsd-kind-icon">off</a></li>
  120. <li class="tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external"><a href="stream.html#on" class="tsd-kind-icon">on</a></li>
  121. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#play" class="tsd-kind-icon">play</a></li>
  122. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#resume" class="tsd-kind-icon">resume</a></li>
  123. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#stop" class="tsd-kind-icon">stop</a></li>
  124. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#unmuteaudio" class="tsd-kind-icon">unmute<wbr>Audio</a></li>
  125. <li class="tsd-kind-method tsd-parent-kind-class tsd-is-external"><a href="stream.html#unmutevideo" class="tsd-kind-icon">unmute<wbr>Video</a></li>
  126. </ul>
  127. </section>
  128. </div>
  129. </section>
  130. </section>
  131. <section class="tsd-panel-group tsd-member-group tsd-is-external">
  132. <h2>Properties</h2>
  133. <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-external">
  134. <a name="audiomuted" class="tsd-anchor"></a>
  135. <h3>audio<wbr>Muted</h3>
  136. <div class="tsd-signature tsd-kind-icon">audio<wbr>Muted<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> = false</span></div>
  137. <aside class="tsd-sources">
  138. </aside>
  139. <div class="tsd-comment tsd-typography">
  140. <div class="lead">
  141. <p>当前流是否 mute 了音频</p>
  142. </div>
  143. </div>
  144. </section>
  145. <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-external">
  146. <a name="id" class="tsd-anchor"></a>
  147. <h3>id</h3>
  148. <div class="tsd-signature tsd-kind-icon">id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
  149. <aside class="tsd-sources">
  150. </aside>
  151. <div class="tsd-comment tsd-typography">
  152. <div class="lead">
  153. <p>当前流ID</p>
  154. </div>
  155. </div>
  156. </section>
  157. <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-external">
  158. <a name="mediastream" class="tsd-anchor"></a>
  159. <h3><span class="tsd-flag ts-flagReadonly">Readonly</span> media<wbr>Stream</h3>
  160. <div class="tsd-signature tsd-kind-icon">media<wbr>Stream<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">MediaStream</span></div>
  161. <aside class="tsd-sources">
  162. </aside>
  163. <div class="tsd-comment tsd-typography">
  164. <div class="lead">
  165. <p>当前流包含的媒体流,关于媒体流,请详见 <a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaStream">MediaStream</a>。</p>
  166. </div>
  167. </div>
  168. </section>
  169. <section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-external">
  170. <a name="videomuted" class="tsd-anchor"></a>
  171. <h3>video<wbr>Muted</h3>
  172. <div class="tsd-signature tsd-kind-icon">video<wbr>Muted<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> = false</span></div>
  173. <aside class="tsd-sources">
  174. </aside>
  175. <div class="tsd-comment tsd-typography">
  176. <div class="lead">
  177. <p>当前流是否 mute 了视频</p>
  178. </div>
  179. </div>
  180. </section>
  181. </section>
  182. <section class="tsd-panel-group tsd-member-group tsd-is-external">
  183. <h2>Methods</h2>
  184. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  185. <a name="destroy" class="tsd-anchor"></a>
  186. <h3>destroy</h3>
  187. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  188. <li class="tsd-signature tsd-kind-icon">destroy<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
  189. </ul>
  190. <ul class="tsd-descriptions">
  191. <li class="tsd-description">
  192. <aside class="tsd-sources">
  193. </aside>
  194. <div class="tsd-comment tsd-typography">
  195. <div class="lead">
  196. <p>销毁当前流,一般在本地流不再被使用时,可调用此方法销毁,解除摄像头或麦克风设备的占用。</p>
  197. <blockquote>
  198. <p>注:远端流,不需要手动调用此方法</p>
  199. </blockquote>
  200. </div>
  201. <dl class="tsd-comment-tags">
  202. <dt>example</dt>
  203. <dd><pre><code class="language-js">stream.destroy();</code></pre>
  204. </dd>
  205. </dl>
  206. </div>
  207. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
  208. </li>
  209. </ul>
  210. </section>
  211. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  212. <a name="getaudiolevel" class="tsd-anchor"></a>
  213. <h3>get<wbr>Audio<wbr>Level</h3>
  214. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  215. <li class="tsd-signature tsd-kind-icon">get<wbr>Audio<wbr>Level<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span></li>
  216. </ul>
  217. <ul class="tsd-descriptions">
  218. <li class="tsd-description">
  219. <aside class="tsd-sources">
  220. </aside>
  221. <div class="tsd-comment tsd-typography">
  222. <div class="lead">
  223. <p>获取当前流的音量大小,只有当本地流或远端流中有音频数据才有效。</p>
  224. </div>
  225. <dl class="tsd-comment-tags">
  226. <dt>example</dt>
  227. <dd><pre><code class="language-js"><span class="hljs-built_in">setInterval</span>(<span class="hljs-function">() =&gt;</span> {
  228. <span class="hljs-keyword">const</span> level = stream.getAudioLevel();
  229. <span class="hljs-keyword">if</span> (level &gt; <span class="hljs-number">0</span>) {
  230. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`user <span class="hljs-subst">${stream.userId}</span> is speaking`</span>);
  231. }
  232. }, <span class="hljs-number">200</span>);</code></pre>
  233. </dd>
  234. </dl>
  235. </div>
  236. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4>
  237. </li>
  238. </ul>
  239. </section>
  240. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  241. <a name="getmediatype" class="tsd-anchor"></a>
  242. <h3>get<wbr>Media<wbr>Type</h3>
  243. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  244. <li class="tsd-signature tsd-kind-icon">get<wbr>Media<wbr>Type<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../index.html#mediatype" class="tsd-signature-type">MediaType</a></li>
  245. </ul>
  246. <ul class="tsd-descriptions">
  247. <li class="tsd-description">
  248. <aside class="tsd-sources">
  249. </aside>
  250. <div class="tsd-comment tsd-typography">
  251. <div class="lead">
  252. <p>获取流的媒体类型</p>
  253. </div>
  254. <dl class="tsd-comment-tags">
  255. <dt>example</dt>
  256. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> type = stream.getMediaType();</code></pre>
  257. </dd>
  258. </dl>
  259. </div>
  260. <h4 class="tsd-returns-title">Returns <a href="../index.html#mediatype" class="tsd-signature-type">MediaType</a></h4>
  261. </li>
  262. </ul>
  263. </section>
  264. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  265. <a name="getstats" class="tsd-anchor"></a>
  266. <h3>get<wbr>Stats</h3>
  267. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  268. <li class="tsd-signature tsd-kind-icon">get<wbr>Stats<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><a href="../interfaces/streamstats.html" class="tsd-signature-type">StreamStats</a><span class="tsd-signature-symbol">&gt;</span></li>
  269. </ul>
  270. <ul class="tsd-descriptions">
  271. <li class="tsd-description">
  272. <aside class="tsd-sources">
  273. </aside>
  274. <div class="tsd-comment tsd-typography">
  275. <div class="lead">
  276. <p>获取流发布或订阅后的统计数据</p>
  277. </div>
  278. <dl class="tsd-comment-tags">
  279. <dt>example</dt>
  280. <dd><pre><code class="language-js">stream
  281. .getStats()
  282. .then(<span class="hljs-function">(<span class="hljs-params">stats</span>) =&gt;</span> {
  283. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;当前流的统计数据为: &#x27;</span>, stats);
  284. });</code></pre>
  285. </dd>
  286. </dl>
  287. </div>
  288. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><a href="../interfaces/streamstats.html" class="tsd-signature-type">StreamStats</a><span class="tsd-signature-symbol">&gt;</span></h4>
  289. </li>
  290. </ul>
  291. </section>
  292. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  293. <a name="hasaudio" class="tsd-anchor"></a>
  294. <h3>has<wbr>Audio</h3>
  295. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  296. <li class="tsd-signature tsd-kind-icon">has<wbr>Audio<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
  297. </ul>
  298. <ul class="tsd-descriptions">
  299. <li class="tsd-description">
  300. <aside class="tsd-sources">
  301. </aside>
  302. <div class="tsd-comment tsd-typography">
  303. <div class="lead">
  304. <p>判断当前流是否有音频</p>
  305. </div>
  306. <dl class="tsd-comment-tags">
  307. <dt>example</dt>
  308. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> result = stream.hasAudio();</code></pre>
  309. </dd>
  310. </dl>
  311. </div>
  312. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
  313. </li>
  314. </ul>
  315. </section>
  316. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  317. <a name="hasvideo" class="tsd-anchor"></a>
  318. <h3>has<wbr>Video</h3>
  319. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  320. <li class="tsd-signature tsd-kind-icon">has<wbr>Video<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
  321. </ul>
  322. <ul class="tsd-descriptions">
  323. <li class="tsd-description">
  324. <aside class="tsd-sources">
  325. </aside>
  326. <div class="tsd-comment tsd-typography">
  327. <div class="lead">
  328. <p>判断当前流是否有视频</p>
  329. </div>
  330. <dl class="tsd-comment-tags">
  331. <dt>example</dt>
  332. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> result = stream.hasVideo();</code></pre>
  333. </dd>
  334. </dl>
  335. </div>
  336. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
  337. </li>
  338. </ul>
  339. </section>
  340. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  341. <a name="muteaudio" class="tsd-anchor"></a>
  342. <h3>mute<wbr>Audio</h3>
  343. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  344. <li class="tsd-signature tsd-kind-icon">mute<wbr>Audio<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
  345. </ul>
  346. <ul class="tsd-descriptions">
  347. <li class="tsd-description">
  348. <aside class="tsd-sources">
  349. </aside>
  350. <div class="tsd-comment tsd-typography">
  351. <div class="lead">
  352. <p>mute 当前流的音频</p>
  353. <ul>
  354. <li>本地流调用此方法时,将不向服务器推送音频数据,远端用户将收到 <code>mute-audio</code> 的事件通知</li>
  355. <li>远端流调用此方法时,仅为不从服务器拉取音频数据,并无事件通知远端用户</li>
  356. </ul>
  357. </div>
  358. <dl class="tsd-comment-tags">
  359. <dt>example</dt>
  360. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> result = stream.muteAudio();
  361. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`stream&#x27;audio is muted <span class="hljs-subst">${stream.audioMuted}</span>`</span>);</code></pre>
  362. </dd>
  363. </dl>
  364. </div>
  365. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
  366. <p>操作是否成功</p>
  367. </li>
  368. </ul>
  369. </section>
  370. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  371. <a name="mutevideo" class="tsd-anchor"></a>
  372. <h3>mute<wbr>Video</h3>
  373. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  374. <li class="tsd-signature tsd-kind-icon">mute<wbr>Video<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
  375. </ul>
  376. <ul class="tsd-descriptions">
  377. <li class="tsd-description">
  378. <aside class="tsd-sources">
  379. </aside>
  380. <div class="tsd-comment tsd-typography">
  381. <div class="lead">
  382. <p>mute 当前流的视频</p>
  383. <ul>
  384. <li>本地流调用此方法时,将不向服务器推送视频数据,远端用户将收到 <code>mute-video</code> 的事件通知</li>
  385. <li>远端流调用此方法时,仅为不从服务器拉取视频数据,并无事件通知远端用户</li>
  386. </ul>
  387. </div>
  388. <dl class="tsd-comment-tags">
  389. <dt>example</dt>
  390. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> result = stream.muteVideo();
  391. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`stream&#x27;s video is muted <span class="hljs-subst">${stream.videoMuted}</span>`</span>);</code></pre>
  392. </dd>
  393. </dl>
  394. </div>
  395. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
  396. <p>操作是否成功</p>
  397. </li>
  398. </ul>
  399. </section>
  400. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external">
  401. <a name="off" class="tsd-anchor"></a>
  402. <h3>off</h3>
  403. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external">
  404. <li class="tsd-signature tsd-kind-icon">off&lt;T&gt;<span class="tsd-signature-symbol">(</span>type<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">T</span>, listener<span class="tsd-signature-symbol">: </span><a href="../interfaces/listener.html" class="tsd-signature-type">Listener</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">EventEmitter</span></li>
  405. </ul>
  406. <ul class="tsd-descriptions">
  407. <li class="tsd-description">
  408. <aside class="tsd-sources">
  409. <p>Inherited from EventEmitter.off</p>
  410. </aside>
  411. <div class="tsd-comment tsd-typography">
  412. <div class="lead">
  413. <p>取消监听流对象事件</p>
  414. </div>
  415. </div>
  416. <h4 class="tsd-type-parameters-title">Type parameters</h4>
  417. <ul class="tsd-type-parameters">
  418. <li>
  419. <h4>T<span class="tsd-signature-symbol">: </span><a href="../index.html#rtceventtype" class="tsd-signature-type">RtcEventType</a><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">"*"</span></h4>
  420. </li>
  421. </ul>
  422. <h4 class="tsd-parameters-title">Parameters</h4>
  423. <ul class="tsd-parameters">
  424. <li>
  425. <h5>type: <span class="tsd-signature-type">T</span></h5>
  426. <div class="tsd-comment tsd-typography">
  427. <p>流对象事件类型,特别的,当为 &#39;*&#39; 时,取消监听所有事件</p>
  428. </div>
  429. </li>
  430. <li>
  431. <h5>listener: <a href="../interfaces/listener.html" class="tsd-signature-type">Listener</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">&gt;</span></h5>
  432. <div class="tsd-comment tsd-typography">
  433. <p>流对象事件监听函数</p>
  434. </div>
  435. </li>
  436. </ul>
  437. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">EventEmitter</span></h4>
  438. </li>
  439. </ul>
  440. </section>
  441. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external">
  442. <a name="on" class="tsd-anchor"></a>
  443. <h3>on</h3>
  444. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external">
  445. <li class="tsd-signature tsd-kind-icon">on&lt;T&gt;<span class="tsd-signature-symbol">(</span>type<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">T</span>, listener<span class="tsd-signature-symbol">: </span><a href="../interfaces/listener.html" class="tsd-signature-type">Listener</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">EventEmitter</span></li>
  446. </ul>
  447. <ul class="tsd-descriptions">
  448. <li class="tsd-description">
  449. <aside class="tsd-sources">
  450. <p>Inherited from EventEmitter.on</p>
  451. </aside>
  452. <div class="tsd-comment tsd-typography">
  453. <div class="lead">
  454. <p>监听流对象事件</p>
  455. </div>
  456. </div>
  457. <h4 class="tsd-type-parameters-title">Type parameters</h4>
  458. <ul class="tsd-type-parameters">
  459. <li>
  460. <h4>T<span class="tsd-signature-symbol">: </span><a href="../index.html#rtceventtype" class="tsd-signature-type">RtcEventType</a></h4>
  461. </li>
  462. </ul>
  463. <h4 class="tsd-parameters-title">Parameters</h4>
  464. <ul class="tsd-parameters">
  465. <li>
  466. <h5>type: <span class="tsd-signature-type">T</span></h5>
  467. <div class="tsd-comment tsd-typography">
  468. <p>流事件类型</p>
  469. </div>
  470. </li>
  471. <li>
  472. <h5>listener: <a href="../interfaces/listener.html" class="tsd-signature-type">Listener</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">&gt;</span></h5>
  473. <div class="tsd-comment tsd-typography">
  474. <p>流事件监听函数</p>
  475. </div>
  476. </li>
  477. </ul>
  478. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">EventEmitter</span></h4>
  479. </li>
  480. </ul>
  481. </section>
  482. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  483. <a name="play" class="tsd-anchor"></a>
  484. <h3>play</h3>
  485. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  486. <li class="tsd-signature tsd-kind-icon">play<span class="tsd-signature-symbol">(</span>container<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">HTMLElement</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span>, opts<span class="tsd-signature-symbol">?: </span><a href="../interfaces/playoptions.html" class="tsd-signature-type">PlayOptions</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></li>
  487. </ul>
  488. <ul class="tsd-descriptions">
  489. <li class="tsd-description">
  490. <aside class="tsd-sources">
  491. </aside>
  492. <div class="tsd-comment tsd-typography">
  493. <div class="lead">
  494. <p>播放当前流</p>
  495. </div>
  496. <dl class="tsd-comment-tags">
  497. <dt>example</dt>
  498. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> container = <span class="hljs-string">&#x27;xxx&#x27;</span>; <span class="hljs-comment">// 比如 id 为 xxx 的 div 元素</span>
  499. stream
  500. .play(container)
  501. .catch(<span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
  502. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`播放失败: <span class="hljs-subst">${err}</span>`</span>); <span class="hljs-comment">// 一般由于浏览器对自动播放的限制导致播放失败</span>
  503. });</code></pre>
  504. </dd>
  505. <dt>reject</dt>
  506. <dd><p><a href="rtcerror.html">RtcError</a></p>
  507. </dd>
  508. </dl>
  509. </div>
  510. <h4 class="tsd-parameters-title">Parameters</h4>
  511. <ul class="tsd-parameters">
  512. <li>
  513. <h5>container: <span class="tsd-signature-type">HTMLElement</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span></h5>
  514. <div class="tsd-comment tsd-typography">
  515. <p>播放音视频时,包裹 video 标签所用的容器元素或容器元素的 ID</p>
  516. </div>
  517. </li>
  518. <li>
  519. <h5><span class="tsd-flag ts-flagOptional">Optional</span> opts: <a href="../interfaces/playoptions.html" class="tsd-signature-type">PlayOptions</a></h5>
  520. <div class="tsd-comment tsd-typography">
  521. <p>其他播放参数,参见<a href="../interfaces/playoptions.html">PlayOptions</a></p>
  522. </div>
  523. </li>
  524. </ul>
  525. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
  526. </li>
  527. </ul>
  528. </section>
  529. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  530. <a name="resume" class="tsd-anchor"></a>
  531. <h3>resume</h3>
  532. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  533. <li class="tsd-signature tsd-kind-icon">resume<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></li>
  534. </ul>
  535. <ul class="tsd-descriptions">
  536. <li class="tsd-description">
  537. <aside class="tsd-sources">
  538. </aside>
  539. <div class="tsd-comment tsd-typography">
  540. <div class="lead">
  541. <p>恢复播放流,一般由于浏览器限制无法自动播放时,可提示用户手动触发该方法进行恢复播放</p>
  542. </div>
  543. <dl class="tsd-comment-tags">
  544. <dt>example</dt>
  545. <dd><pre><code class="language-js">stream
  546. .resume()
  547. .catch(<span class="hljs-function">(<span class="hljs-params">err</span>) =&gt;</span> {
  548. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`恢复播放失败:<span class="hljs-subst">${err}</span>`</span>);
  549. });</code></pre>
  550. </dd>
  551. </dl>
  552. </div>
  553. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
  554. </li>
  555. </ul>
  556. </section>
  557. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  558. <a name="stop" class="tsd-anchor"></a>
  559. <h3>stop</h3>
  560. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  561. <li class="tsd-signature tsd-kind-icon">stop<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
  562. </ul>
  563. <ul class="tsd-descriptions">
  564. <li class="tsd-description">
  565. <aside class="tsd-sources">
  566. </aside>
  567. <div class="tsd-comment tsd-typography">
  568. <div class="lead">
  569. <p>停止播放当前流</p>
  570. </div>
  571. <dl class="tsd-comment-tags">
  572. <dt>example</dt>
  573. <dd><pre><code class="language-js">stream.stop();</code></pre>
  574. </dd>
  575. </dl>
  576. </div>
  577. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
  578. </li>
  579. </ul>
  580. </section>
  581. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  582. <a name="unmuteaudio" class="tsd-anchor"></a>
  583. <h3>unmute<wbr>Audio</h3>
  584. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  585. <li class="tsd-signature tsd-kind-icon">unmute<wbr>Audio<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
  586. </ul>
  587. <ul class="tsd-descriptions">
  588. <li class="tsd-description">
  589. <aside class="tsd-sources">
  590. </aside>
  591. <div class="tsd-comment tsd-typography">
  592. <div class="lead">
  593. <p>unmute 当前流的音频</p>
  594. <ul>
  595. <li>本地流调用此方法时,将向服务器推送音频数据,远端用户将收到 <code>unmute-audio</code> 的事件通知</li>
  596. <li>远端流调用此方法时,会从服务器拉取音频数据,并无事件通知远端用户</li>
  597. </ul>
  598. </div>
  599. <dl class="tsd-comment-tags">
  600. <dt>example</dt>
  601. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> result = stream.unmuteAudio();
  602. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`stream&#x27;s audio is muted <span class="hljs-subst">${stream.audioMuted}</span>`</span>);</code></pre>
  603. </dd>
  604. </dl>
  605. </div>
  606. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
  607. <p>操作是否成功</p>
  608. </li>
  609. </ul>
  610. </section>
  611. <section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external">
  612. <a name="unmutevideo" class="tsd-anchor"></a>
  613. <h3>unmute<wbr>Video</h3>
  614. <ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external">
  615. <li class="tsd-signature tsd-kind-icon">unmute<wbr>Video<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li>
  616. </ul>
  617. <ul class="tsd-descriptions">
  618. <li class="tsd-description">
  619. <aside class="tsd-sources">
  620. </aside>
  621. <div class="tsd-comment tsd-typography">
  622. <div class="lead">
  623. <p>unmute 当前流的视频</p>
  624. <ul>
  625. <li>本地流调用此方法时,将向服务器推送视频数据,远端用户将收到 <code>unmute-video</code> 的事件通知</li>
  626. <li>远端流调用此方法时,会从服务器拉取视频数据,并无事件通知远端用户</li>
  627. </ul>
  628. </div>
  629. <dl class="tsd-comment-tags">
  630. <dt>example</dt>
  631. <dd><pre><code class="language-js"><span class="hljs-keyword">const</span> result = stream.unmuteVideo();
  632. <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`stream&#x27;s video is muted <span class="hljs-subst">${stream.videoMuted}</span>`</span>);</code></pre>
  633. </dd>
  634. </dl>
  635. </div>
  636. <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4>
  637. <p>操作是否成功</p>
  638. </li>
  639. </ul>
  640. </section>
  641. </section>
  642. </div>
  643. <div class="col-4 col-menu menu-sticky-wrap menu-highlight">
  644. <nav class="tsd-navigation primary">
  645. <ul>
  646. <li class="globals ">
  647. <a href="../index.html"><em>Globals</em></a>
  648. </li>
  649. </ul>
  650. </nav>
  651. <nav class="tsd-navigation secondary menu-sticky">
  652. <ul class="before-current">
  653. </ul>
  654. <ul class="current">
  655. <li class="current tsd-kind-class tsd-is-external">
  656. <a href="stream.html" class="tsd-kind-icon">Stream</a>
  657. <ul>
  658. <li class=" tsd-kind-property tsd-parent-kind-class tsd-is-external">
  659. <a href="stream.html#audiomuted" class="tsd-kind-icon">audio<wbr>Muted</a>
  660. </li>
  661. <li class=" tsd-kind-property tsd-parent-kind-class tsd-is-external">
  662. <a href="stream.html#id" class="tsd-kind-icon">id</a>
  663. </li>
  664. <li class=" tsd-kind-property tsd-parent-kind-class tsd-is-external">
  665. <a href="stream.html#mediastream" class="tsd-kind-icon">media<wbr>Stream</a>
  666. </li>
  667. <li class=" tsd-kind-property tsd-parent-kind-class tsd-is-external">
  668. <a href="stream.html#videomuted" class="tsd-kind-icon">video<wbr>Muted</a>
  669. </li>
  670. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  671. <a href="stream.html#destroy" class="tsd-kind-icon">destroy</a>
  672. </li>
  673. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  674. <a href="stream.html#getaudiolevel" class="tsd-kind-icon">get<wbr>Audio<wbr>Level</a>
  675. </li>
  676. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  677. <a href="stream.html#getmediatype" class="tsd-kind-icon">get<wbr>Media<wbr>Type</a>
  678. </li>
  679. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  680. <a href="stream.html#getstats" class="tsd-kind-icon">get<wbr>Stats</a>
  681. </li>
  682. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  683. <a href="stream.html#hasaudio" class="tsd-kind-icon">has<wbr>Audio</a>
  684. </li>
  685. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  686. <a href="stream.html#hasvideo" class="tsd-kind-icon">has<wbr>Video</a>
  687. </li>
  688. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  689. <a href="stream.html#muteaudio" class="tsd-kind-icon">mute<wbr>Audio</a>
  690. </li>
  691. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  692. <a href="stream.html#mutevideo" class="tsd-kind-icon">mute<wbr>Video</a>
  693. </li>
  694. <li class=" tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external">
  695. <a href="stream.html#off" class="tsd-kind-icon">off</a>
  696. </li>
  697. <li class=" tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter tsd-is-inherited tsd-is-external">
  698. <a href="stream.html#on" class="tsd-kind-icon">on</a>
  699. </li>
  700. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  701. <a href="stream.html#play" class="tsd-kind-icon">play</a>
  702. </li>
  703. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  704. <a href="stream.html#resume" class="tsd-kind-icon">resume</a>
  705. </li>
  706. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  707. <a href="stream.html#stop" class="tsd-kind-icon">stop</a>
  708. </li>
  709. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  710. <a href="stream.html#unmuteaudio" class="tsd-kind-icon">unmute<wbr>Audio</a>
  711. </li>
  712. <li class=" tsd-kind-method tsd-parent-kind-class tsd-is-external">
  713. <a href="stream.html#unmutevideo" class="tsd-kind-icon">unmute<wbr>Video</a>
  714. </li>
  715. </ul>
  716. </li>
  717. </ul>
  718. <ul class="after-current">
  719. </ul>
  720. </nav>
  721. </div>
  722. </div>
  723. </div>
  724. <footer class="with-border-bottom">
  725. <div class="container">
  726. <h2>Legend</h2>
  727. <div class="tsd-legend-group">
  728. </div>
  729. </div>
  730. </footer>
  731. <div class="container tsd-generator">
  732. <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
  733. </div>
  734. <div class="overlay"></div>
  735. <script src="../assets/js/main.js"></script>
  736. </body>
  737. </html>