Skip to main content Link Search Menu Expand Document (external link)

Socket overview

Added in v1.0.0


Table of contents


combinators

toChannel

Signature

export declare const toChannel: <IE>(
  self: Socket
) => Channel.Channel<
  Chunk.Chunk<Uint8Array>,
  Chunk.Chunk<string | Uint8Array | CloseEvent>,
  SocketError | IE,
  IE,
  void,
  unknown
>

Added in v1.0.0

toChannelWith

Signature

export declare const toChannelWith: <IE = never>() => (
  self: Socket
) => Channel.Channel<
  Chunk.Chunk<Uint8Array>,
  Chunk.Chunk<string | Uint8Array | CloseEvent>,
  SocketError | IE,
  IE,
  void,
  unknown
>

Added in v1.0.0

constructors

fromWebSocket

Signature

export declare const fromWebSocket: (
  acquire: Effect.Effect<globalThis.WebSocket, SocketError, Scope.Scope>,
  options?:
    | { readonly closeCodeIsError?: ((code: number) => boolean) | undefined; readonly openTimeout?: any }
    | undefined
) => Effect.Effect<Socket>

Added in v1.0.0

makeChannel

Signature

export declare const makeChannel: <IE = never>() => Channel.Channel<
  Chunk.Chunk<Uint8Array>,
  Chunk.Chunk<string | Uint8Array | CloseEvent>,
  SocketError | IE,
  IE,
  void,
  unknown,
  Socket
>

Added in v1.0.0

makeWebSocket

Signature

export declare const makeWebSocket: (
  url: string | Effect.Effect<string>,
  options?:
    | { readonly closeCodeIsError?: ((code: number) => boolean) | undefined; readonly openTimeout?: any }
    | undefined
) => Effect.Effect<Socket>

Added in v1.0.0

makeWebSocketChannel

Signature

export declare const makeWebSocketChannel: <IE = never>(
  url: string,
  options?: { readonly closeCodeIsError?: ((code: number) => boolean) | undefined } | undefined
) => Channel.Channel<
  Chunk.Chunk<Uint8Array>,
  Chunk.Chunk<string | Uint8Array | CloseEvent>,
  SocketError | IE,
  IE,
  void,
  unknown
>

Added in v1.0.0

errors

SocketCloseError (class)

Signature

export declare class SocketCloseError

Added in v1.0.0

is (static method)

Signature

static is(u: unknown): u is SocketCloseError

Added in v1.0.0

isClean (static method)

Signature

static isClean(isClean: (code: number) => boolean)

Added in v1.0.0

SocketError (type alias)

Signature

export type SocketError = SocketGenericError | SocketCloseError

Added in v1.0.0

SocketGenericError (class)

Signature

export declare class SocketGenericError

Added in v1.0.0

layers

layerWebSocket

Signature

export declare const layerWebSocket: (
  url: string,
  options?: { readonly closeCodeIsError?: ((code: number) => boolean) | undefined } | undefined
) => Layer.Layer<Socket>

Added in v1.0.0

models

CloseEvent (class)

Signature

export declare class CloseEvent { constructor(readonly code = 1000, readonly reason?: string) }

Added in v1.0.0

toString (method)

Signature

toString()

Added in v1.0.0

[CloseEventTypeId] (property)

Signature

readonly [CloseEventTypeId]: typeof CloseEventTypeId

Added in v1.0.0

Socket (interface)

Signature

export interface Socket {
  readonly [TypeId]: TypeId
  readonly run: <R, E, _>(handler: (_: Uint8Array) => Effect.Effect<_, E, R>) => Effect.Effect<void, SocketError | E, R>
  readonly runRaw: <R, E, _>(
    handler: (_: string | Uint8Array) => Effect.Effect<_, E, R>
  ) => Effect.Effect<void, SocketError | E, R>
  readonly writer: Effect.Effect<(chunk: Uint8Array | string | CloseEvent) => Effect.Effect<void>, never, Scope.Scope>
}

Added in v1.0.0

refinements

isCloseEvent

Signature

export declare const isCloseEvent: (u: unknown) => u is CloseEvent

Added in v1.0.0

isSocketError

Signature

export declare const isSocketError: (u: unknown) => u is SocketError

Added in v1.0.0

tags

Socket

Signature

export declare const Socket: Context.Tag<Socket, Socket>

Added in v1.0.0

WebSocket

Signature

export declare const WebSocket: Context.Tag<WebSocket, globalThis.WebSocket>

Added in v1.0.0

WebSocket (interface)

Signature

export interface WebSocket {
  readonly _: unique symbol
}

Added in v1.0.0

type ids

CloseEventTypeId

Signature

export declare const CloseEventTypeId: typeof CloseEventTypeId

Added in v1.0.0

CloseEventTypeId (type alias)

Signature

export type CloseEventTypeId = typeof CloseEventTypeId

Added in v1.0.0

SocketErrorTypeId

Signature

export declare const SocketErrorTypeId: typeof SocketErrorTypeId

Added in v1.0.0

SocketErrorTypeId (type alias)

Signature

export type SocketErrorTypeId = typeof SocketErrorTypeId

Added in v1.0.0

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v1.0.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v1.0.0

utils

defaultCloseCodeIsError

Signature

export declare const defaultCloseCodeIsError: (code: number) => boolean

Added in v1.0.0