From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../connect_event/index.html | 100 ++++++++++++++++ .../ja/web/api/sharedworkerglobalscope/index.html | 132 +++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 files/ja/web/api/sharedworkerglobalscope/connect_event/index.html create mode 100644 files/ja/web/api/sharedworkerglobalscope/index.html (limited to 'files/ja/web/api/sharedworkerglobalscope') diff --git a/files/ja/web/api/sharedworkerglobalscope/connect_event/index.html b/files/ja/web/api/sharedworkerglobalscope/connect_event/index.html new file mode 100644 index 0000000000..d1c934b398 --- /dev/null +++ b/files/ja/web/api/sharedworkerglobalscope/connect_event/index.html @@ -0,0 +1,100 @@ +--- +title: 'SharedWorkerGlobalScope: connect イベント' +slug: Web/API/SharedWorkerGlobalScope/connect_event +tags: + - API + - Event + - Reference + - SharedWorkerGlobalScope + - connect + - events + - イベント +translation_of: Web/API/SharedWorkerGlobalScope/connect_event +--- +
{{APIRef}}
+ +

connect イベントは、新しいクライアントが接続したときに共有ワーカーの {{domxref("SharedWorkerGlobalScope")}} に発生します。

+ + + + + + + + + + + + + + + + + + + + +
バブリングなし
キャンセル可能いいえ
インターフェイス{{DOMxRef("MessageEvent")}}
イベントハンドラープロパティ{{domxref("SharedWorkerGlobalScope.onconnect")}}
+ +

+ +

この例は共有ワーカーファイルを示しています。メインスレッドから {{domxref("MessagePort")}} を通して Worker へのコネクションが発生したとき、 onconnect イベントハンドラーが呼び出されます。イベントオブジェクトは {{domxref("MessageEvent")}} です。

+ +

接続しようとしているポート番号は、イベントオブジェクトの ports 引数で参照することができます。この参照にはポートを通じて来るメッセージを扱うために割り当てられた onmessage ハンドラーがあり、その postMessage() メソッドに Worker を使用してメインスレッドにメッセージを送り返すために使用することができます。

+ +
self.onconnect = function(e) {
+    var port = e.ports[0];
+
+    port.onmessage = function(e) {
+      var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
+      port.postMessage(workerResult);
+    }
+
+    port.start();
+}
+ +

実行している例を完成させるには、 Basic shared worker example (共有ワーカーを実行) をご覧ください。

+ +

addEventListener による同等の処理

+ +

{{domxref("EventTarget/addEventListener", "addEventListener()")}} メソッドを使用してイベントハンドラーを設定することもできます。

+ +
self.addEventListener('connect', function(e) {
+  var port = e.ports[0];
+
+  port.onmessage = function(e) {
+    var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
+    port.postMessage(workerResult);
+  }
+
+});
+ +

仕様書

+ + + + + + + + + + + + + + +
仕様書状態
{{SpecName('HTML WHATWG', "indices.html#event-workerglobalscope-connect", "connect event")}}{{Spec2('HTML WHATWG')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.SharedWorkerGlobalScope.connect_event")}}

+ +

関連情報

+ + diff --git a/files/ja/web/api/sharedworkerglobalscope/index.html b/files/ja/web/api/sharedworkerglobalscope/index.html new file mode 100644 index 0000000000..f3cb612e08 --- /dev/null +++ b/files/ja/web/api/sharedworkerglobalscope/index.html @@ -0,0 +1,132 @@ +--- +title: SharedWorkerGlobalScope +slug: Web/API/SharedWorkerGlobalScope +tags: + - API + - Interface + - Reference + - SharedWorkerGlobalScope + - Web Workers + - インターフェイス + - ウェブワーカー +translation_of: Web/API/SharedWorkerGlobalScope +--- +
{{APIRef("Web Workers API")}}
+ +

SharedWorkerGlobalScope オブジェクト ( {{domxref("SharedWorker")}} グローバルスコープ) は、 {{domxref("window.self","self")}} キーワードでアクセスできます。一部の追加のグローバル関数、名前空間オブジェクト、コンストラクターは、通常はワーカーのグローバルスコープに関連付けられていませんが、利用することができ、 JavaScript リファレンスに列挙されています。ワーカーで利用できる機能の完全なリストを参照してください。

+ +

プロパティ

+ +

このインターフェイスは {{domxref("WorkerGlobalScope")}}、またその親の {{domxref("EventTarget")}} インターフェイスからプロパティを継承しており、したがって {{domxref("WindowTimers")}}, {{domxref("WindowBase64")}}, {{domxref("WindowEventHandlers")}} のプロパティを実装しています。

+ +
+
{{domxref("SharedWorkerGlobalScope.name")}} {{readOnlyinline}}
+
The name that the {{domxref("SharedWorker")}} was (optionally) given when it was created using the {{domxref("SharedWorker.SharedWorker", "SharedWorker()")}} constructor. This is mainly useful for debugging purposes.
+
{{domxref("SharedWorkerGlobalScope.applicationCache")}} {{readOnlyinline}} {{deprecated_inline}}
+
This property returns the {{domxref("ApplicationCache")}} object for the worker (see Using the application cache).
+
+ +

WorkerGlobalScope から継承しているプロパティ

+ +
+
{{domxref("WorkerGlobalScope.self")}}
+
Returns an object reference to the DedicatedWorkerGlobalScope object itself.
+
{{domxref("WorkerGlobalScope.console")}} {{readOnlyinline}}
+
Returns the {{domxref("Console")}} associated with the worker.
+
{{domxref("WorkerGlobalScope.location")}} {{readOnlyinline}}
+
Returns the {{domxref("WorkerLocation")}} associated with the worker. WorkerLocation is a specific location object, mostly a subset of the {{domxref("Location")}} for browsing scopes, but adapted to workers.
+
{{domxref("WorkerGlobalScope.navigator")}} {{readOnlyinline}}
+
Returns the {{domxref("WorkerNavigator")}} associated with the worker. WorkerNavigator is a specific navigator object, mostly a subset of the {{domxref("Navigator")}} for browsing scopes, but adapted to workers.
+
{{domxref("WorkerGlobalScope.performance")}} {{readOnlyinline}} {{Non-standard_inline}}
+
Returns the {{domxref("Performance")}} object associated with the worker, which is a regular performance object, but with a subset of its properties and methods available.
+
+ +

イベントハンドラー

+ +

This interface inherits event handlers from the {{domxref("WorkerGlobalScope")}} interface, and its parent {{domxref("EventTarget")}}, and therefore implements event handlers from {{domxref("WindowTimers")}}, {{domxref("WindowBase64")}}, and {{domxref("WindowEventHandlers")}}.

+ +
+
{{domxref("SharedWorkerGlobalScope.onconnect")}}
+
Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("connect")}} event is raised — that is, when a {{domxref("MessagePort")}} connection is opened between the associated {{domxref("SharedWorker")}} and the main thread.
+
+ +

メソッド

+ +

This interface inherits methods from the {{domxref("WorkerGlobalScope")}} interface, and its parent {{domxref("EventTarget")}}, and therefore implements methods from {{domxref("WindowTimers")}}, {{domxref("WindowBase64")}}, and {{domxref("WindowEventHandlers")}}.

+ +
+
{{domxref("SharedWorkerGlobalScope.close()")}}
+
Discards any tasks queued in the SharedWorkerGlobalScope's event loop, effectively closing this particular scope.
+
+ +

WorkerGlobalScope から継承したもの

+ +
+
{{domxref("WorkerGlobalScope.close()")}} {{deprecated_inline}}
+
Discards any tasks queued in the WorkerGlobalScope's event loop, effectively closing this particular scope.
+
{{domxref("WorkerGlobalScope.dump()")}} {{non-standard_inline}}
+
Allows you to write a message to stdout — i.e. in your terminal. This is the same as Firefox's {{domxref("window.dump")}}, but for workers.
+
{{domxref("WorkerGlobalScope.importScripts()")}}
+
Imports one or more scripts into the worker's scope. You can specify as many as you'd like, separated by commas. For example: importScripts('foo.js', 'bar.js');
+
+ +

他の場所から実装したもの

+ +
+
{{domxref("WindowBase64.atob()")}}
+
Decodes a string of data which has been encoded using base-64 encoding.
+
{{domxref("WindowBase64.btoa()")}}
+
Creates a base-64 encoded ASCII string from a string of binary data.
+
{{domxref("WindowTimers.clearInterval()")}}
+
Cancels the repeated execution set using {{domxref("WindowTimers.setInterval()")}}.
+
{{domxref("WindowTimers.clearTimeout()")}}
+
Cancels the repeated execution set using {{domxref("WindowTimers.setTimeout()")}}.
+
{{domxref("WindowTimers.setInterval()")}}
+
Schedules the execution of a function every X milliseconds.
+
{{domxref("WindowTimers.setTimeout()")}}
+
Sets a delay for executing a function.
+
+ +

イベント

+ +

Listen to this event using addEventListener() or by assigning an event listener to the oneventname property of this interface.

+ +
+
connect
+
Fired on shared workers when a new client connects.
+ Also available via the onconnect property.
+
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('HTML WHATWG', '#sharedworkerglobalscope', 'SharedWorkerGlobalScope')}}{{Spec2('HTML WHATWG')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.SharedWorkerGlobalScope")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf