Skip to content

Commit

Permalink
docs(std): add some missing JSDoc ws/mod.ts (denoland#8428)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThenMorning authored Nov 25, 2020
1 parent adbbd85 commit bfd1da4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions std/ws/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface WebSocketCloseEvent {
reason?: string;
}

/** Returns true if input value is a WebSocketCloseEvent, false otherwise. */
export function isWebSocketCloseEvent(
a: WebSocketEvent,
): a is WebSocketCloseEvent {
Expand All @@ -39,6 +40,7 @@ export function isWebSocketCloseEvent(

export type WebSocketPingEvent = ["ping", Uint8Array];

/** Returns true if input value is a WebSocketPingEvent, false otherwise. */
export function isWebSocketPingEvent(
a: WebSocketEvent,
): a is WebSocketPingEvent {
Expand All @@ -47,6 +49,7 @@ export function isWebSocketPingEvent(

export type WebSocketPongEvent = ["pong", Uint8Array];

/** Returns true if input value is a WebSocketPongEvent, false otherwise. */
export function isWebSocketPongEvent(
a: WebSocketEvent,
): a is WebSocketPongEvent {
Expand Down Expand Up @@ -102,7 +105,7 @@ export function unmask(payload: Uint8Array, mask?: Uint8Array): void {
}
}

/** Write websocket frame to given writer */
/** Write WebSocket frame to inputted writer. */
export async function writeFrame(
frame: WebSocketFrame,
writer: Deno.Writer,
Expand Down Expand Up @@ -385,7 +388,7 @@ class WebSocketImpl implements WebSocket {
}
}

/** Return whether given headers is acceptable for websocket */
/** Returns true if input headers are usable for WebSocket, otherwise false. */
export function acceptable(req: { headers: Headers }): boolean {
const upgrade = req.headers.get("upgrade");
if (!upgrade || upgrade.toLowerCase() !== "websocket") {
Expand All @@ -401,15 +404,15 @@ export function acceptable(req: { headers: Headers }): boolean {

const kGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";

/** Create sec-websocket-accept header value with given nonce */
/** Create value of Sec-WebSocket-Accept header from inputted nonce. */
export function createSecAccept(nonce: string): string {
const sha1 = new Sha1();
sha1.update(nonce + kGUID);
const bytes = sha1.digest();
return btoa(String.fromCharCode(...bytes));
}

/** Upgrade given TCP connection into websocket connection */
/** Upgrade inputted TCP connection into WebSocket connection. */
export async function acceptWebSocket(req: {
conn: Deno.Conn;
bufWriter: BufWriter;
Expand Down Expand Up @@ -439,7 +442,7 @@ export async function acceptWebSocket(req: {

const kSecChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.~_";

/** Create WebSocket-Sec-Key. Base64 encoded 16 bytes string */
/** Returns base64 encoded 16 bytes string for Sec-WebSocket-Key header. */
export function createSecKey(): string {
let key = "";
for (let i = 0; i < 16; i++) {
Expand Down

0 comments on commit bfd1da4

Please sign in to comment.