close

BroadcastChannel インターフェイス (DOM)

仕様書

文脈

[16] BroadcastChannel インターフェイスは、文書環境ワーカー環境晒されています >>13

状態

[19] BroadcastChannel オブジェクトは、 EventTarget としての状態に加えて、 次の状態を持ちます。

通信路名
文字列
BroadcastChannel設定群オブジェクト (BroadcastChannel settings object)
環境設定群オブジェクト
閉じ済みフラグ
ブール型。 初期値は

コンストラクター

[14] BroadcastChannel コンストラクターは、 次のようにしなければなりません >>13

  1. [15] 名前を、必須の第1引数を DOMString と解釈した結果に設定します。
  2. [20] 新しい BroadcastChannel オブジェクトを返します。
    [21] BroadcastChannel
    通信路名
    名前
    BroadcastChannel設定群オブジェクト
    現職設定群オブジェクト

メンバー

[17] BroadcastChannel インターフェイスメンバー

BroadcastChannel インターフェイス name 属性

[22] BroadcastChannel インターフェイスname IDL属性は、 次のようにしなければなりません >>13

  1. [23] 文脈オブジェクト通信路名を返します。

[24] BroadcastChannel オブジェクトは、 通信路名 (channel name) を持ちます >>13コンストラクターで指定された値が設定されます。この値は以後変更されることはありません。

BroadcastChannel インターフェイス close 属性

[31] BroadcastChannel インターフェイスclose メソッドは、 次のようにしなければなりません >>13

  1. [32] 文脈オブジェクト閉じ済みフラグを、に設定します。
  2. [34] 文脈オブジェクトBroadcastChannel設定群オブジェクト大域オブジェクトBroadcastChannelから、 文脈オブジェクトを削除します。
  3. [49] イベントループBroadcastChannelから、 文脈オブジェクトを削除します。

[33] BroadcastChannel オブジェクトは、 閉じ済みフラグ (closed flag) を持ちます >>13。 初期値はです。


[25] 大域オブジェクトは、BroadcastChannelという集合を持ちます。 初期状態は空です。

[46] イベントループは、BroadcastChannelという集合 (重複のない順序付きリスト) を持ちます。初期状態は空です。 この集合から項目への参照は弱い参照とし、ごみ収集されたら除去するものとします。

[26] BroadcastChannel BCイベントリスナーが追加され、 そのイベント型message の場合、次のようにしなければなりません >>13

  1. [27] BC閉じ済みフラグなら、
    1. [28] BCBroadcastChannel設定群オブジェクト大域オブジェクトBroadcastChannelに、 BC を追加します。
    2. [47] イベントループBroadcastChannelに、 BC を追加します。

[29] BroadcastChannel BC からイベント型messageイベントリスナーがすべて削除された場合、次のようにしなければなりません >>13

  1. [30] BCBroadcastChannel設定群オブジェクト大域オブジェクトBroadcastChannelから、 BC を削除します。
  2. [48] イベントループBroadcastChannelから、 BC を削除します。


[35] BroadcastChannel を作成して messageイベントリスナーを登録すると、大域オブジェクトにも登録されることになります。 スクリプトから BroadcastChannel への参照を削除しても、 (まだイベントリスナーが呼び出される可能性が残るため) 大域オブジェクトからの参照は破棄されず、残ったままになります。 このため、必要がなくなったら明示的に close メソッドを呼び出すことが強く推奨 (strongly encouraged) されています >>13

送受信

[66] 送受信の処理全体については、 postMessage を参照。

送信先の決定

[37] postMessage は、指定されたメッセージを受信する BroadcastChannel を、次のように決定します。

[38] 始点設定群始点通信路BroadcastChannelすべてのリストとは、 次の条件をすべて満たすもののリストとしなければなりません >>13

[50] このリストにおいては、BroadcastChannel設定群オブジェクト有責イベントループが同じもの同士は古い順としなければなりません >>13

[67] なお、対象検索の範囲は、Webブラウザーが1つの利用者エージェントであるとみなす範囲に当然に限定されるものと思われます。 例えば private browsing モードと通常モードとでは異なる利用者エージェントに属すると考えられ、 BroadcastChannel によってその境界を超えることはできません。

[68] Chrome は通常シークレットウィンドウのどちらも BroadcastChannel を実装していますが、相互に通信することはできません。


[51] このリストの作成は、次のように等価に書き換えることができます。

  1. [58] 結果を、空のリストに設定します。
  2. [53] 起源を、始点設定群起源に設定します。
  3. [54]
    イベントループ群を、利用者エージェントで現在実行中の起源を扱うイベントループをすべて集めた結果に設定します。
  4. [55] イベントループ群の各イベントループについて、
    1. [56] リストを、イベントループBroadcastChannelの複製に設定します。
    2. [57] リストから、BroadcastChannel設定群オブジェクト起源起源同じ起源でないものを除去します。
    3. [52] リストから、次のいずれも満たさないものを除去します。
    4. [63] リストから、通信路名始点通信路でないものを除去します。
    5. [59] 結果リストの全項目を順に追加します。
  5. [60] 結果を返します。

実装

[64] ChromeFirefox が対応しています。

[65] EdgeSafari は未実装です。

歴史

[1] Web Applications 1.0 r8274 New BroadcastChannel feature to send messages to other tabs in the same origin, so you don't have to abuse the onstorage event, and don't need to use a heavy shared worker for something otherwise trivial. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8273&to=8274

[2] Web Applications 1.0 r8450 Oops, forgot to make BroadcastChannel inherit from EventTarget ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8449&to=8450

[3] [whatwg] BroadcastChannel should support structured clones ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2014-April/254182.html

[4] Web Applications 1.0 r8590 Make BroadcastChannel support structured clones ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8589&to=8590

[5] Web Applications 1.0 r8593 Change the sort order for broadcast channel messages to be easier to implement ( ( 版)) http://html5.org/tools/web-apps-tracker?from=8592&to=8593

[7] Re: [whatwg] BroadcastChannel memory leak ( (Ian Hickson 著, 版)) http://lists.w3.org/Archives/Public/public-whatwg-archive/2014Jun/0034.html

[8] Web Applications 1.0 r8661 Add BroadcastChannel.close() ( ( 版)) http://html5.org/r/8661

[9] 966439 – Implement BroadcastChannel API ( ( 版)) https://bugzilla.mozilla.org/show_bug.cgi?id=966439

[10] Reduce the number of terms BroadcastChannel introductory text uses · whatwg/html@f363b95 ( 版) https://github.com/whatwg/html/commit/f363b9585a7d48c67f0b06895545db588d093ce8

[11] Clarify settings object, realm, and global relationships · whatwg/html@0866f1b ( 版) https://github.com/whatwg/html/commit/0866f1b3f4b4ea5a99a30909e9bbe557dea0b460

[12] Chromium Blog: Chrome 54 Beta: Custom Elements V1, BroadcastChannel, and media platform improvements ( ()) https://blog.chromium.org/2016/09/chrome-54-beta-custom-elements-v1.html

[69] Make BroadcastChannel work in workers, part 2 (annevk著, ) https://github.com/whatwg/html/commit/4bf5ccd8abacc1c6efe48fb7375266d559a8a83b

[18] should BroadcastChannel be disabled if a window does not have access to storage? · Issue #3054 · whatwg/html () https://github.com/whatwg/html/issues/3054