diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/api/websocket | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/ja/web/api/websocket')
18 files changed, 1133 insertions, 0 deletions
diff --git a/files/ja/web/api/websocket/binarytype/index.html b/files/ja/web/api/websocket/binarytype/index.html new file mode 100644 index 0000000000..d851b58608 --- /dev/null +++ b/files/ja/web/api/websocket/binarytype/index.html @@ -0,0 +1,50 @@ +--- +title: WebSocket.binaryType +slug: Web/API/WebSocket/binaryType +translation_of: Web/API/WebSocket/binaryType +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.binaryType</code></strong> は、コネクションによって送信されているバイナリデータの型を返すプロパティです。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate"><em>var binaryType</em> = aWebSocket.binaryType;</pre> + +<h2 id="値">値</h2> + +<p>{{DOMXref("DOMString")}}:</p> + +<dl> + <dt><code>"blob"</code></dt> + <dd>{{domxref("Blob")}} オブジェクトが使われている場合</dd> + <dt><code>"arraybuffer"</code></dt> + <dd>{{jsxref("ArrayBuffer")}} オブジェクトが使われている場合 + + </dd> +</dl> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket-binarytype', 'WebSocket: binaryType')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ互換性">ブラウザ互換性</h2> + + + +<p>{{Compat("api.WebSocket.binaryType")}}</p> diff --git a/files/ja/web/api/websocket/bufferedamount/index.html b/files/ja/web/api/websocket/bufferedamount/index.html new file mode 100644 index 0000000000..1f74c94df2 --- /dev/null +++ b/files/ja/web/api/websocket/bufferedamount/index.html @@ -0,0 +1,41 @@ +--- +title: WebSocket.bufferedAmount +slug: Web/API/WebSocket/bufferedAmount +translation_of: Web/API/WebSocket/bufferedAmount +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.bufferedAmount</code></strong> は {{manch("send")}} の呼び出しによってキューに入れられてはいますが、まだネットワークに送信されていないデータのバイト数を返す読み取り専用のプロパティです。この値は、一度キューに入れられたデータすべてが送信されると 0 にリセットされます。なお、コネクションが閉じられたときは、 0 にリセットされません。{{manch("send")}} を呼び出し続けると、この値は大きくなっていきます。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate"><em>var bufferedAmount</em> = aWebSocket.bufferedAmount;</pre> + +<h2 id="値">値</h2> + +<p><code>符号なしのロング型</code></p> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket-bufferedamount', 'WebSocket: bufferedAmount')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ互換性">ブラウザ互換性</h2> + + + +<p>{{Compat("api.WebSocket.bufferedAmount")}}</p> diff --git a/files/ja/web/api/websocket/close/index.html b/files/ja/web/api/websocket/close/index.html new file mode 100644 index 0000000000..e81076b85a --- /dev/null +++ b/files/ja/web/api/websocket/close/index.html @@ -0,0 +1,58 @@ +--- +title: WebSocket.close() +slug: Web/API/WebSocket/close +translation_of: Web/API/WebSocket/close +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.close()</code></strong> メソッドは、{{domxref("WebSocket")}} の接続、もしくは接続試行(存在した場合)を閉じます。接続がすでに <code>CLOSED</code> だった場合、このメソッドは何もしません。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate">WebSocket.close();</pre> + +<h3 id="引数">引数</h3> + +<dl> + <dt><code>code</code> {{optional_inline}}</dt> + <dd>接続が閉じられている理由を説明するためのステータスコードを示す数値を指定します。このパラメータを指定しない場合、デフォルト値として 1005 が指定されます。許可されている値については{{domxref("CloseEvent")}}の<a href="/ja/docs/Web/API/CloseEvent">ステータスコードの一覧</a>を参照してください。</dd> + <dt><code>reason</code> {{optional_inline}}</dt> + <dd>接続が閉じられている理由を説明するための人間が読める文字列を指定します。この文字列は UTF-8 テキスト (文字<strong>ではありません</strong>) で 123 バイトを超えていけません。</dd> +</dl> + +<h3 id="投げられる例外">投げられる例外</h3> + +<dl> + <dt><code>INVALID_ACCESS_ERR</code></dt> + <dd>無効な <code>code</code> が指定された場合</dd> + <dt><code>SYNTAX_ERR</code></dt> + <dd><code>reason</code> に指定した文字列が長すぎるか、ペアリングされていないサロゲートを含んでいる場合</dd> +</dl> + +<div class="note"> +<p><strong>注意:</strong> Gecko において、Gecko 8.0 {{geckoRelease("8.0")}} 以前は、このメソッドはいづれのパラメータもサポートしていませんでした。</p> +</div> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th>仕様書</th> + <th>状態</th> + <th>備考</th> + </tr> + <tr> + <td><a class="external external-icon" href="https://html.spec.whatwg.org/multipage/web-sockets.html#dom-websocket-close" hreflang="en" lang="en">HTML Living Standard<br> + <small lang="en-US">The definition of 'WebSocket.close()' in that specification.</small></a></td> + <td><span class="spec-Living">Living Standard</span></td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザの互換性">ブラウザの互換性</h2> + + + +<p>{{Compat("api.WebSocket.close")}}</p> diff --git a/files/ja/web/api/websocket/close_event/index.html b/files/ja/web/api/websocket/close_event/index.html new file mode 100644 index 0000000000..136ceea555 --- /dev/null +++ b/files/ja/web/api/websocket/close_event/index.html @@ -0,0 +1,80 @@ +--- +title: 'WebSocket: close イベント' +slug: Web/API/WebSocket/close_event +tags: + - Reference + - Web + - WebSocket + - close + - events + - イベント +translation_of: Web/API/WebSocket/close_event +--- +<div>{{APIRef}}</div> + +<p><code>close</code> イベントは、 <code>WebSocket</code> のコネクションが閉じられたときに発生します。</p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">バブリング</th> + <td>なし</td> + </tr> + <tr> + <th scope="row">キャンセル</th> + <td>不可</td> + </tr> + <tr> + <th scope="row">インターフェイス</th> + <td>{{domxref("Event")}}</td> + </tr> + <tr> + <th scope="row">イベントハンドラープロパティ</th> + <td>{{ domxref("WebSocket.onclose","onclose")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<p>コネクションが閉じられる時が分かれば、 UI を更新させたり、閉じたコネクションについてのデータを保存したりすることができます。以下の例では <code>exampleSocket</code> と呼ばれる変数が開かれた <code>WebSocket</code> を参照しており、このハンドラーが、ソケットが閉じられた場面を扱います。</p> + +<pre class="brush: js">exampleSocket.addEventListener('close', (event) => { + console.log('The connection has been closed successfully.'); +)};</pre> + +<p>同じことを、イベントハンドラープロパティを用いて行うこともできます。</p> + +<pre class="brush: js">exampleSocket.onclose = function (event) { + console.log('The connection has been closed successfully.'); +};</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "web-sockets.html#event-close", "WebSocket close")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<p>{{Compat("api.WebSocket.close_event")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="/ja/docs/Web/API/WebSocket/error_event">WebSocket: error イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/message_event">WebSocket: message イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/open_event">WebSocket: open イベント</a></li> + <li><a href="/ja/docs/WebSockets/Writing_WebSocket_client_applications">WebSocket クライアントアプリケーションを書く</a></li> +</ul> diff --git a/files/ja/web/api/websocket/error_event/index.html b/files/ja/web/api/websocket/error_event/index.html new file mode 100644 index 0000000000..e833c7fdcf --- /dev/null +++ b/files/ja/web/api/websocket/error_event/index.html @@ -0,0 +1,77 @@ +--- +title: 'WebSocket: error イベント' +slug: Web/API/WebSocket/error_event +tags: + - API + - Error + - Event + - Reference + - Web + - WebSocket + - イベント +translation_of: Web/API/WebSocket/error_event +--- +<div>{{APIRef}}</div> + +<p><code>error</code> イベントは、 <code>WebSocket</code> のコネクションがエラーによって閉じられた (例えば一部のデータを送信できなかった) ときに発生します。</p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">バブリング</th> + <td>なし</td> + </tr> + <tr> + <th scope="row">キャンセル</th> + <td>不可</td> + </tr> + <tr> + <th scope="row">インターフェイス</th> + <td>{{domxref("Event")}}</td> + </tr> + <tr> + <th scope="row">イベントハンドラープロパティ</th> + <td>{{ domxref("WebSocket.onerror","onerror")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<pre class="brush: js notranslate">// Create WebSocket connection +const socket = new WebSocket('ws://localhost:8080'); + +// Listen for possible errors +socket.addEventListener('error', function (event) { + console.log('WebSocket error: ', event); +});</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "web-sockets.html#event-open", "WebSocket open")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<p>{{Compat("api.WebSocket.error_event")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="/ja/docs/Web/API/WebSocket/close_event">WebSocket: close イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/message_event">WebSocket: message イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/open_event">WebSocket: open イベント</a></li> + <li><a href="/ja/docs/WebSockets/Writing_WebSocket_client_applications">WebSocket クライアントアプリケーションを書く</a></li> +</ul> diff --git a/files/ja/web/api/websocket/extensions/index.html b/files/ja/web/api/websocket/extensions/index.html new file mode 100644 index 0000000000..38a9035de6 --- /dev/null +++ b/files/ja/web/api/websocket/extensions/index.html @@ -0,0 +1,41 @@ +--- +title: WebSocket.extensions +slug: Web/API/WebSocket/extensions +translation_of: Web/API/WebSocket/extensions +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.extensions</code></strong> は、サーバーによって選択された拡張機能を返す読み取り専用のプロパティです。現在は、空の文字列か、接続によってネゴシエートされた拡張機能のリストのみを返します。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate"><em>var extensions</em> = aWebSocket.extensions;</pre> + +<h2 id="値">値</h2> + +<p>{{domxref("DOMString")}}</p> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket-extensions', 'WebSocket: extensions')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ互換性">ブラウザ互換性</h2> + + + +<p>{{Compat("api.WebSocket.extensions")}}</p> diff --git a/files/ja/web/api/websocket/index.html b/files/ja/web/api/websocket/index.html new file mode 100644 index 0000000000..cf61c05a16 --- /dev/null +++ b/files/ja/web/api/websocket/index.html @@ -0,0 +1,150 @@ +--- +title: WebSocket +slug: Web/API/WebSocket +tags: + - API + - Interface + - NeedsContent + - WebSocket + - WebSockets + - インターフェイス +translation_of: Web/API/WebSocket +--- +<div>{{APIRef("Web Sockets API")}}</div> + +<p><code>WebSocket</code> オブジェクトは、サーバーへの <a href="/ja/docs/Web/API/WebSockets_API">WebSocket</a> 接続の作成と管理、および接続上のデータの送受信に使用する API を提供します。</p> + +<p><code>WebSocket</code> を構築するには、 <code><a href="/ja/docs/Web/API/WebSocket/WebSocket">WebSocket()</a></code> コンストラクターを使用してください。</p> + +<h2 id="Constructor" name="Constructor">コンストラクター</h2> + +<dl> + <dt>{{domxref("WebSocket.WebSocket", "WebSocket(url[, protocols])")}}</dt> + <dd>新しく作成された <code>WebSocket</code> オブジェクトを返します。</dd> +</dl> + +<h2 id="Constants" name="Constants">定数</h2> + +<table class="standard-table"> + <tbody> + <tr> + <td class="header">定数</td> + <td class="header">値</td> + </tr> + <tr> + <td><code>WebSocket.CONNECTING</code></td> + <td><code>0</code></td> + </tr> + <tr> + <td><code>WebSocket.OPEN</code></td> + <td><code>1</code></td> + </tr> + <tr> + <td><code>WebSocket.CLOSING</code></td> + <td><code>2</code></td> + </tr> + <tr> + <td><code>WebSocket.CLOSED</code></td> + <td><code>3</code></td> + </tr> + </tbody> +</table> + +<h2 id="Properties" name="Properties">プロパティ</h2> + +<dl> + <dt>{{domxref("WebSocket.binaryType")}}</dt> + <dd>接続で使用されるバイナリデータ型。</dd> + <dt>{{domxref("WebSocket.bufferedAmount")}} {{readonlyinline}}</dt> + <dd>キューに入れられたデータのバイト数。</dd> + <dt>{{domxref("WebSocket.extensions")}} {{readonlyinline}}</dt> + <dd>サーバーによって選択された拡張機能。</dd> + <dt>{{domxref("WebSocket.onclose")}}</dt> + <dd>接続が閉じられたときに呼び出されるイベントリスナー。</dd> + <dt>{{domxref("WebSocket.onerror")}}</dt> + <dd>エラーが発生したときに呼び出されるイベントリスナー。</dd> + <dt>{{domxref("WebSocket.onmessage")}}</dt> + <dd>サーバーからメッセージを受信したときに呼び出されるイベントリスナー。</dd> + <dt>{{domxref("WebSocket.onopen")}}</dt> + <dd>接続が開かれたときに呼び出されるイベントリスナー。</dd> + <dt>{{domxref("WebSocket.protocol")}} {{readonlyinline}}</dt> + <dd>サーバーによって選択されたサブプロトコル。</dd> + <dt>{{domxref("WebSocket.readyState")}} {{readonlyinline}}</dt> + <dd>接続の現在の状態。</dd> + <dt>{{domxref("WebSocket.url")}} {{readonlyinline}}</dt> + <dd>WebSocket の絶対 URL。</dd> +</dl> + +<h2 id="Methods" name="Methods">メソッド</h2> + +<dl> + <dt>{{domxref("WebSocket.close", "WebSocket.close([code[, reason]])")}}</dt> + <dd>接続を閉じます。</dd> + <dt>{{domxref("WebSocket.send", "WebSocket.send(data)")}}</dt> + <dd>送信するデータをキューに入れます。</dd> +</dl> + +<h2 id="Events" name="Events">イベント</h2> + +<p>これらのイベントを待ち受けするには、 <code>addEventListener()</code> を使用するか、イベントリスナーをこのインターフェイスの <code>on<em>eventname</em></code> プロパティへ代入します。</p> + +<dl> + <dt>{{domxref("WebSocket/close_event", "close")}}</dt> + <dd><code>WebSocket</code> による接続が閉じたときに発生します。<br> + {{domxref("WebSocket/onclose", "onclose")}} プロパティからも利用できます。</dd> + <dt>{{domxref("WebSocket/error_event", "error")}}</dt> + <dd><code>WebSocket</code> による接続が、データの一部が送信できなかったなどのエラーのために閉じた時に発生します。<br> + {{domxref("WebSocket/onerror", "onerror")}} プロパティからも利用できます。</dd> + <dt>{{domxref("WebSocket/message_event", "message")}}</dt> + <dd><code>WebSocket</code> を通じてデータを受信したときに発生します。<br> + {{domxref("WebSocket/onmessage", "onmessage")}} プロパティからも利用できます。</dd> + <dt>{{domxref("WebSocket/open_event", "open")}}</dt> + <dd><code>WebSocket</code> による接続が開いたときに発生します。<br> + {{domxref("WebSocket/onopen", "onopen")}} プロパティからも利用できます。</dd> +</dl> + +<h2 id="Examples" name="Examples">例</h2> + +<pre class="brush: js notranslate">// WebSocket 接続を作成 +const socket = new WebSocket('ws://localhost:8080'); + +// 接続が開いたときのイベント +socket.addEventListener('open', function (event) { + socket.send('Hello Server!'); +}); + +// メッセージの待ち受け +socket.addEventListener('message', function (event) { + console.log('Message from server ', event.data); +});</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "#network", "WebSocket")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div> +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("api.WebSocket")}}</p> +</div> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="/ja/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications">WebSocket クライアントアプリケーションを書く</a></li> +</ul> diff --git a/files/ja/web/api/websocket/message_event/index.html b/files/ja/web/api/websocket/message_event/index.html new file mode 100644 index 0000000000..c268e079c0 --- /dev/null +++ b/files/ja/web/api/websocket/message_event/index.html @@ -0,0 +1,74 @@ +--- +title: 'WebSocket: message イベント' +slug: Web/API/WebSocket/message_event +tags: + - Event + - Reference + - WebSocket + - message +translation_of: Web/API/WebSocket/message_event +--- +<div>{{APIRef}}</div> + +<p><code>message</code> ハンドラーは、 <code>WebSocket</code> を通してデータを受け取ったときに発生します。</p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">バブリング</th> + <td>なし</td> + </tr> + <tr> + <th scope="row">キャンセル</th> + <td>不可</td> + </tr> + <tr> + <th scope="row">インターフェイス</th> + <td>{{domxref("MessageEvent")}}</td> + </tr> + <tr> + <th scope="row">イベントハンドラープロパティ</th> + <td>{{ domxref("WebSocket.onmessage","onmessage")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<pre class="brush: js line-numbers language-js">// Create WebSocket connection. +const socket = new WebSocket('ws://localhost:8080'); + +// Listen for messages +socket.addEventListener('message', function (event) { + console.log('Message from server ', event.data); +});</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "web-sockets.html#event-message", "WebSocket message")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<p>{{Compat("api.WebSocket.message_event")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="/ja/docs/Web/API/WebSocket/close_event">WebSocket: close イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/error_event">WebSocket: error イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/open_event">WebSocket: open イベント</a></li> + <li><a href="/ja/docs/WebSockets/Writing_WebSocket_client_applications">WebSocket クライアントアプリケーションを書く</a></li> +</ul> diff --git a/files/ja/web/api/websocket/onclose/index.html b/files/ja/web/api/websocket/onclose/index.html new file mode 100644 index 0000000000..311998e44c --- /dev/null +++ b/files/ja/web/api/websocket/onclose/index.html @@ -0,0 +1,37 @@ +--- +title: WebSocket.onclose +slug: Web/API/WebSocket/onclose +translation_of: Web/API/WebSocket/onclose +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><code><strong>WebSocket.onclose</strong></code> プロパティは、WebSocket コネクションの {{domxref("WebSocket.readyState","readyState")}} が {{domxref("WebSocket.readyState","CLOSED")}} に変わったときに呼ばれる {{domxref("EventHandler")}} です。{{domxref("CloseEvent")}} と一緒に呼び出されます。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate"><em>aWebSocket</em>.onclose = function(event) { + console.log("WebSocket is closed now."); +};</pre> + +<h2 id="値">値</h2> + +<p>{{domxref("EventListener")}}.</p> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#handler-websocket-onclose', 'WebSocket: onclose')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> diff --git a/files/ja/web/api/websocket/onerror/index.html b/files/ja/web/api/websocket/onerror/index.html new file mode 100644 index 0000000000..717a0ae735 --- /dev/null +++ b/files/ja/web/api/websocket/onerror/index.html @@ -0,0 +1,61 @@ +--- +title: WebSocket.onerror +slug: Web/API/WebSocket/onerror +tags: + - API + - Connection + - Error + - Error Handler + - Networking + - Property + - Reference + - Web API + - WebSocket + - onerror + - プロパティ +translation_of: Web/API/WebSocket/onerror +--- +<div>{{APIRef("Web Sockets API")}}</div> + +<p><span class="seoSummary">{{domxref("WebSocket")}} インターフェイスの <code><strong>onerror</strong></code> イベントハンドラープロパティは、 WebSocket でエラーが発生したときに呼び出される関数です。</span></p> + +<p><code>error</code> イベントハンドラーは {{domxref("EventTarget.addEventListener", "addEventListener()")}} で追加することもできます。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox"><em>webSocket</em>.onerror = <em>eventHandler</em>;</pre> + +<h3 id="Value" name="Value">値</h3> + +<p>関数または {{domxref("EventHandler")}} で、 WebSocket コネクションで <code>error</code> イベントが発生するたびに呼び出されるものです。</p> + +<h2 id="Example" name="Example">例</h2> + +<pre class="brush: js"><em>webSocket</em>.onerror = function(event) { + console.error("WebSocket error observed:", event); +};</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#handler-websocket-onerror', 'WebSocket: onerror')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("api.WebSocket.onerror")}}</p> diff --git a/files/ja/web/api/websocket/onmessage/index.html b/files/ja/web/api/websocket/onmessage/index.html new file mode 100644 index 0000000000..fc69900854 --- /dev/null +++ b/files/ja/web/api/websocket/onmessage/index.html @@ -0,0 +1,50 @@ +--- +title: WebSocket.onmessage +slug: Web/API/WebSocket/onmessage +tags: + - API + - Property + - Reference + - Web API + - WebSocket + - プロパティ +translation_of: Web/API/WebSocket/onmessage +--- +<div>{{APIRef("Web Sockets API")}}</div> + +<p><strong><code>WebSocket.onmessage</code></strong> プロパティは、サーバーからメッセージが届いたときに呼び出されるイベントハンドラー ({{domxref("EventHandler")}}) です。これは {{domxref("MessageEvent")}} で呼び出されます。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><em>aWebSocket</em>.onmessage = function(event) { + console.debug("WebSocket message received:", event); +};</pre> + +<h2 id="Value" name="Value">値</h2> + +<p>{{domxref("EventListener")}} です。</p> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#handler-websocket-onmessage', 'WebSocket: onmessage')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("api.WebSocket.onmessage")}}</p> diff --git a/files/ja/web/api/websocket/onopen/index.html b/files/ja/web/api/websocket/onopen/index.html new file mode 100644 index 0000000000..cf8006465e --- /dev/null +++ b/files/ja/web/api/websocket/onopen/index.html @@ -0,0 +1,50 @@ +--- +title: WebSocket.onopen +slug: Web/API/WebSocket/onopen +tags: + - API + - Property + - Reference + - Web API + - WebSocket + - プロパティ +translation_of: Web/API/WebSocket/onopen +--- +<div>{{APIRef("Web Sockets API")}}</div> + +<p><strong><code>WebSocket.onopen</code></strong> プロパティはイベントハンドラー ({{domxref("EventHandler")}}) で、 {{domxref("WebSocket")}} のコネクションの {{domxref("WebSocket.readyState","readyState")}} が {{domxref("WebSocket.readyState","1")}} に変化したときに呼び出されます。これは、コネクションでデータを送信したり受信したりする準備ができたことを示します。これは {{domxref("Event")}} を伴って呼び出されます。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><em>aWebSocket</em>.onopen = function(event) { + console.log("WebSocket is open now."); +};</pre> + +<h2 id="Value" name="Value">値</h2> + +<p>{{domxref("EventListener")}} です。</p> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#handler-websocket-onopen', 'WebSocket: onopen')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("api.WebSocket.onopen")}}</p> diff --git a/files/ja/web/api/websocket/open_event/index.html b/files/ja/web/api/websocket/open_event/index.html new file mode 100644 index 0000000000..9f2780b504 --- /dev/null +++ b/files/ja/web/api/websocket/open_event/index.html @@ -0,0 +1,74 @@ +--- +title: 'WebSocket: open イベント' +slug: Web/API/WebSocket/open_event +tags: + - API + - WebSocket + - events + - open +translation_of: Web/API/WebSocket/open_event +--- +<div>{{APIRef}}</div> + +<p><code>open</code> イベントは、 <code>WebSocket</code> のコネクションが開かれたときに発生します。</p> + +<table class="properties"> + <tbody> + <tr> + <th scope="row">バブリング</th> + <td>なし</td> + </tr> + <tr> + <th scope="row">キャンセル</th> + <td>不可</td> + </tr> + <tr> + <th scope="row">インターフェイス</th> + <td>{{domxref("Event")}}</td> + </tr> + <tr> + <th scope="row">イベントハンドラープロパティ</th> + <td>{{ domxref("WebSocket.onopen","onopen")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Examples" name="Examples">例</h2> + +<pre class="brush: js">// Create WebSocket connection. +const socket = new WebSocket('ws://localhost:8080'); + +// Connection opened +socket.addEventListener('open', (event) => { + socket.send('Hello Server!'); +});</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "web-sockets.html#event-open", "WebSocket open")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<p>{{Compat("api.WebSocket.open_event")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li><a href="/ja/docs/Web/API/WebSocket/close_event">WebSocket: close イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/error_event">WebSocket: error イベント</a></li> + <li><a href="/ja/docs/Web/API/WebSocket/message_event">WebSocket: message イベント</a></li> + <li><a href="/ja/docs/WebSockets/Writing_WebSocket_client_applications">WebSocket クライアントアプリケーションを書く</a></li> +</ul> diff --git a/files/ja/web/api/websocket/protocol/index.html b/files/ja/web/api/websocket/protocol/index.html new file mode 100644 index 0000000000..542e7247a0 --- /dev/null +++ b/files/ja/web/api/websocket/protocol/index.html @@ -0,0 +1,41 @@ +--- +title: WebSocket.protocol +slug: Web/API/WebSocket/protocol +translation_of: Web/API/WebSocket/protocol +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.protocol</code></strong> は、サーバーが選択したサブプロトコル名を返す読み取り専用のプロパティです。これは {{domxref("WebSocket")}} オブジェクトが作成されるときに、引数の <code>protocols</code> で指定された文字列のいづれかになりますが、もし接続が確立されていない場合は、空の文字列となります。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate">var protocol = <em>aWebSocket</em>.protocol;</pre> + +<h2 id="値">値</h2> + +<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString" title="DOMString is a UTF-16 String. As JavaScript already uses such strings, DOMString is mapped directly to a String."><code>DOMString</code></a></p> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket-protocol', 'WebSocket: protocol')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ互換性">ブラウザ互換性</h2> + + + +<p>{{Compat("api.WebSocket.protocol")}}</p> diff --git a/files/ja/web/api/websocket/readystate/index.html b/files/ja/web/api/websocket/readystate/index.html new file mode 100644 index 0000000000..82f6db18e9 --- /dev/null +++ b/files/ja/web/api/websocket/readystate/index.html @@ -0,0 +1,79 @@ +--- +title: WebSocket.readyState +slug: Web/API/WebSocket/readyState +translation_of: Web/API/WebSocket/readyState +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.readyState</code></strong> は、{{domxref("WebSocket")}} の「現在」の接続状態を返す読み取り専用のプロパティです。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate">var readyState = <em>aWebSocket</em>.readyState;</pre> + +<h2 id="値">値</h2> + +<p>以下のいづれかの <code>符号なしショート型</code> の値を返します。</p> + +<table class="standard-table"> + <tbody> + <tr> + <td class="header">Value</td> + <td class="header">State</td> + <td class="header">Description</td> + </tr> + <tr> + <td><code>0</code></td> + <td><code>CONNECTING</code></td> + <td> + <p>ソケットは作成されているが、まだコネクションが開いていない状態</p> + </td> + </tr> + <tr> + <td><code>1</code></td> + <td><code>OPEN</code></td> + <td> + <p>コネクションが開き、通信の準備ができている状態</p> + </td> + </tr> + <tr> + <td><code>2</code></td> + <td><code>CLOSING</code></td> + <td> + <p>コネクションが閉じる過程にある状態</p> + </td> + </tr> + <tr> + <td><code>3</code></td> + <td><code>CLOSED</code></td> + <td> + <p>コネクションが閉じられたか、もしくは開けていなかった状態</p> + </td> + </tr> + </tbody> +</table> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket-readystate', 'WebSocket: readyState')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザの互換性">ブラウザの互換性</h2> + + + +<p>{{Compat("api.WebSocket.readyState")}}</p> diff --git a/files/ja/web/api/websocket/send/index.html b/files/ja/web/api/websocket/send/index.html new file mode 100644 index 0000000000..a2f17d7c36 --- /dev/null +++ b/files/ja/web/api/websocket/send/index.html @@ -0,0 +1,71 @@ +--- +title: WebSocket.send() +slug: Web/API/WebSocket/send +translation_of: Web/API/WebSocket/send +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.send()</code></strong> は WebSocket 接続を介してサーバーに送るために指定されたデータを、格納するために必要なバイト数だけ <code>bufferedAmount</code> の値を増加させながら、キューに入れるメソッドです。もしデータが送信できなかった場合(例えば、バッファリングが必要ですが、バッファが一杯であるなどの理由で)、ソケットは自動的に閉じられます。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate">WebSocket.send("Hello server!");</pre> + +<h3 id="引数">引数</h3> + +<dl> + <dt><code>data</code></dt> + <dd>サーバーに送信するデータです。以下のいづれかのタイプのデータを指定します。</dd> + <dd> + <dl> + <dt>{{domxref("USVString")}}</dt> + <dd>テキスト文字列。文字列は、UTF-8 形式でバッファに追加され、<code>bufferedAmount</code> の値は UTF-8 の文字列を表すのに必要とされるバイト数だけ増えます。</dd> + <dt>{{domxref("ArrayBuffer")}}</dt> + <dd>型付きの配列オブジェクトで使用される基本的なバイナリデータを送信することができます。このバイナリデータのコンテンツは,必要なバイト数だけ <code>bufferedAmount</code> の値を増やして、バッファのキューに入れられます。</dd> + <dt>{{domxref("Blob")}}</dt> + <dd>Blob を指定すると、バイナリフレームで送信される blob の生データをキューに入れます。<code>bufferedAmount</code> の値は、その生データのバイトサイズだけ増えます。</dd> + <dt>{{domxref("ArrayBufferView")}}</dt> + <dd><a href="/ja/docs/Web/JavaScript/Typed_arrays">JavaScriptで型付けされた配列</a>オブジェクトをバイナリフレームとして送信することができます。このバイナリデータのコンテンツは,必要なバイト数だけ <code>bufferedAmount</code> の値を増やして、バッファのキューに入れられます。</dd> + </dl> + </dd> +</dl> + +<h3 id="投げられる例外">投げられる例外</h3> + +<dl> + <dt><code>INVALID_STATE_ERR</code></dt> + <dd>接続が <code>OPEN</code> になっていない場合</dd> + <dt><code>SYNTAX_ERR</code></dt> + <dd>データが、ペアリングされていないサロゲートを持つ文字列の場合</dd> +</dl> + +<div class="note"> +<p><strong>注意:</strong> Gecko の <code>send()</code> メソッドの実装は、{{Gecko("6.0")}} の仕様とは多少異なります。 Geckoは、接続がまだ開いているかどうか(さらに、extension によって、データが正常にキューに入れられたか、もしくは送信されたかどうか)を示す <code>boolean</code> を返します。これは {{Gecko("8.0")}} で修正されています。</p> + +<p>{{Gecko("11.0")}} では、{{jsxref("ArrayBuffer")}} のサポートは実装されていますが、{{domxref("Blob")}} データ型はサポートされていません。</p> +</div> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket-send', 'WebSocket: send')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ互換性">ブラウザ互換性</h2> + + + +<p>{{Compat("api.WebSocket.send")}}</p> diff --git a/files/ja/web/api/websocket/url/index.html b/files/ja/web/api/websocket/url/index.html new file mode 100644 index 0000000000..4fec72f012 --- /dev/null +++ b/files/ja/web/api/websocket/url/index.html @@ -0,0 +1,43 @@ +--- +title: WebSocket.url +slug: Web/API/WebSocket/url +translation_of: Web/API/WebSocket/url +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><strong><code>WebSocket.url</code></strong> は、コンストラクタによって解決された {{domxref("WebSocket")}} の絶対 URL を返す読み取り専用のプロパティです。</p> + +<h2 id="構文">構文</h2> + +<pre class="syntaxbox notranslate"><em>var url</em> = aWebSocket.url;</pre> + + + +<h2 id="値">値</h2> + +<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString" title="DOMString is a UTF-16 String. As JavaScript already uses such strings, DOMString is mapped directly to a String."><code>DOMString</code></a></p> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状態</th> + <th scope="col">備考</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket-url', 'WebSocket: url')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>初回定義</td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ互換性">ブラウザ互換性</h2> + + + +<p>{{Compat("api.WebSocket.url")}}</p> diff --git a/files/ja/web/api/websocket/websocket/index.html b/files/ja/web/api/websocket/websocket/index.html new file mode 100644 index 0000000000..77289d22ba --- /dev/null +++ b/files/ja/web/api/websocket/websocket/index.html @@ -0,0 +1,56 @@ +--- +title: WebSocket() +slug: Web/API/WebSocket/WebSocket +translation_of: Web/API/WebSocket/WebSocket +--- +<p>{{APIRef("Web Sockets API")}}</p> + +<p><code><strong>WebSocket()</strong></code><strong> </strong>コンストラクタは新しい{{domxref("WebSocket")}} オブジェクトを返します。</p> + +<h2 id="構文">構文</h2> + +<pre class="notranslate">var <em>aWebSocket</em> = new WebSocket(<em>url</em> [, protocols]);</pre> + +<h3 id="引数">引数</h3> + +<dl> + <dt><code>url</code></dt> + <dd>接続先のURL。WebSocketサーバが応答するURLでなければならない。</dd> + <dt><code>protocols</code> {{optional_inline}}</dt> + <dd>プロトコル文字列ひとつもしくはその配列。サーバは複数のWebSocketサブプロトコルを実装することもでき、その文字列はサブプロトコルを指定するために使われる(例えば、一つのサーバが指定された<code>protocol</code>に応じて異なるタイプのやりとりを扱うようにしたい場合)。プロトコル文字列を指定しない場合は空文字列と見なされる。</dd> +</dl> + +<h3 id="投げられる例外">投げられる例外</h3> + +<dl> + <dt><code>SECURITY_ERR</code></dt> + <dd>接続が試みられているポートがブロックされている場合</dd> +</dl> + +<dl> + <dt><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError">SyntaxError</a></dt> + <dd>URLが無効だった場合</dd> +</dl> + +<h2 id="仕様書">仕様書</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">仕様書</th> + <th scope="col">状況</th> + <th scope="col">コメント</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-websocket', 'the WebSocket constructor')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="ブラウザ互換性">ブラウザ互換性</h2> + + + +<p>{{Compat("api.WebSocket.WebSocket")}}</p> |