Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web/API/WebSockets_API/Writing_WebSocket_client_applications を更新 #25796

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: WebSocket クライアントアプリケーションを書く
slug: Web/API/WebSockets_API/Writing_WebSocket_client_applications
l10n:
sourceCommit: 4bd2e8957a40a8f31484f9aea3725bdfe78a921a
sourceCommit: 9a4005caa5cc13f5174e3b8981eeec5631ed83d1
---

{{DefaultAPISidebar("WebSockets API")}} {{AvailableInWorkers}}
Expand Down Expand Up @@ -135,7 +135,7 @@ exampleSocket.onmessage = (event) => {

```js
exampleSocket.onmessage = (event) => {
const f = document.getElementById("chatbox").contentDocument;
const f = document.getElementById("chat-box").contentDocument;
let text = "";
const msg = JSON.parse(event.data);
const time = new Date(msg.date);
Expand All @@ -152,17 +152,17 @@ exampleSocket.onmessage = (event) => {
case "message":
text = `(${timeStr}) ${msg.name} : ${msg.text} <br>`;
break;
case "rejectusername":
case "reject-username":
text = `Your username has been set to <em>${msg.name}</em> because the name you chose is in use.<br>`;
break;
case "userlist":
document.getElementById("userlistbox").innerText = msg.users.join("\n");
case "user-list":
document.getElementById("user-list-box").innerText = msg.users.join("\n");
break;
}

if (text.length) {
f.write(text);
document.getElementById("chatbox").contentWindow.scrollByPages(1);
document.getElementById("chat-box").contentWindow.scrollByPages(1);
}
};
```
Expand All @@ -186,5 +186,5 @@ exampleSocket.close();

## セキュリティの考慮事項

混合コンテンツ環境では WebSocket を使用しないでください。つまり、 HTTPS を使用もしくはそうでない方法でもロードされたページから、セキュアでない WebSocket 接続を開くべきではありません。
混在コンテンツ環境では WebSocket を使用しないでください。つまり、 HTTPS を使用もしくはそうでない方法でもロードされたページから、セキュアでない WebSocket 接続を開くべきではありません。
最近のブラウザーは安全な WebSocket 接続のみを許可し、また安全ではないコンテキストでの使用には対応しなくなってきています。