Skip to Content
Motoko

The socket protocol

@chia1104/motoko-wire/socket holds the frames of the socket transport, the one module its server (@chia1104/motoko-cloudflare's MotokoCapability) and its client (@chia1104/motoko-client's webSocketTransport) both import. Each frame is a JSON text frame whose type starts with motoko:, so it rides one socket beside the frames of the Agents SDK and of the app:

  • callFrameSchema: the client's motoko:call, with an id, a method and its params;
  • serverFrameSchema: the server's motoko:result and motoko:error for a call's id, and motoko:event and motoko:ended (followedEventSchema and followEndedSchema, with their type) for a session the connection follows;
  • motokoCalls: callSchemas and the socket's own two calls, subscribe (sessionId, from?) and unsubscribe (sessionId), which exist because one socket follows several sessions;
  • motokoErrorCodeSchema: the call error codes and the socket's own, too_many_subscriptions;
  • motokoFrame(message): a text frame of Motoko's as JSON, or undefined for the SDK's or the app's.

MotokoMethod, MotokoParams<M>, MotokoResult<M>, MotokoCall and MotokoErrorCode are their types. The Cloudflare package's README describes how a follow runs over them.