How to use the decoders.optional function in decoders

To help you get started, we’ve selected a few decoders examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github purecloudlabs / iframe-coordinator / src / messages / Lifecycle.ts View on Github external
msg: SetupData;
}

/* @external */
const envDecoder: Decoder = object({
  msgType: constant<'env_init'>('env_init'),
  msg: object({
    locale: string,
    hostRootUrl: string,
    assignedRoute: string,
    registeredKeys: optional(
      array(
        object({
          key: string,
          altKey: optional(boolean),
          ctrlKey: optional(boolean),
          metaKey: optional(boolean),
          shiftKey: optional(boolean)
        })
      )
    ),
    custom: mixed
  })
});

export { startedDecoder, envDecoder };

/**
 * Handles new environmental data events.
 */
export type EnvDataHandler = (envData: EnvData) => void;
github purecloudlabs / iframe-coordinator / src / messages / Lifecycle.ts View on Github external
}

/* @external */
const envDecoder: Decoder = object({
  msgType: constant<'env_init'>('env_init'),
  msg: object({
    locale: string,
    hostRootUrl: string,
    assignedRoute: string,
    registeredKeys: optional(
      array(
        object({
          key: string,
          altKey: optional(boolean),
          ctrlKey: optional(boolean),
          metaKey: optional(boolean),
          shiftKey: optional(boolean)
        })
      )
    ),
    custom: mixed
  })
});

export { startedDecoder, envDecoder };

/**
 * Handles new environmental data events.
 */
export type EnvDataHandler = (envData: EnvData) => void;

/**
github purecloudlabs / iframe-coordinator / src / messages / KeyDown.ts View on Github external
/** Key details */
  msg: NativeKey;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
  msg: object({
    altKey: optional(boolean),
    charCode: optional(number),
    code: optional(string),
    ctrlKey: optional(boolean),
    key: string,
    keyCode: optional(number),
    metaKey: optional(boolean),
    shiftKey: optional(boolean)
  })
});

export { decoder };
github purecloudlabs / iframe-coordinator / src / workers / worker-manager.ts View on Github external
* Handler for messages received from workers which should be handled by the host
 */
export type WorkerToHostMessageHandler = (event: WorkerToHost) => void;

/**
 * Configuration options for the WorkerManager
 */
export interface WorkerManagerConfig
  extends ErrorWindowConfig,
    WorkerTerminateConfig {
  onWorkerToHostMessage?: WorkerToHostMessageHandler;
}

const validateWorkerManagerConfig: Guard = guard(
  object({
    errorWindowMillis: optional(integer),
    errorWindowCountThreshold: optional(integer),
    notifyBeforeTerminate: optional(boolean),
    terminateReadyWaitMillis: optional(integer)
  })
);

const DEFAULT_ERROR_WINDOW_CONFIG: ErrorWindowConfig = {
  errorWindowMillis: 30000,
  errorWindowCountThreshold: 10
};

/**
 * Minimum number of millis that can be set to allow a worker (spawn or spawned)
 * to terminate.
 */
const MIN_WORKERS_TERMINATE_CONFIG = 10000;
github purecloudlabs / iframe-coordinator / src / messages / KeyDown.ts View on Github external
* A message used to send key information
 * to the host application.
 * @external
 */
export interface LabeledKeyDown extends LabeledMsg {
  /** Message identifier */
  msgType: 'registeredKeyFired';
  /** Key details */
  msg: NativeKey;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
  msg: object({
    altKey: optional(boolean),
    charCode: optional(number),
    code: optional(string),
    ctrlKey: optional(boolean),
    key: string,
    keyCode: optional(number),
    metaKey: optional(boolean),
    shiftKey: optional(boolean)
  })
});

export { decoder };
github purecloudlabs / iframe-coordinator / src / messages / KeyDown.ts View on Github external
* to the host application.
 * @external
 */
export interface LabeledKeyDown extends LabeledMsg {
  /** Message identifier */
  msgType: 'registeredKeyFired';
  /** Key details */
  msg: NativeKey;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
  msg: object({
    altKey: optional(boolean),
    charCode: optional(number),
    code: optional(string),
    ctrlKey: optional(boolean),
    key: string,
    keyCode: optional(number),
    metaKey: optional(boolean),
    shiftKey: optional(boolean)
  })
});

export { decoder };
github purecloudlabs / iframe-coordinator / src / workers / worker-manager.ts View on Github external
/**
 * Configuration options for the WorkerManager
 */
export interface WorkerManagerConfig
  extends ErrorWindowConfig,
    WorkerTerminateConfig {
  onWorkerToHostMessage?: WorkerToHostMessageHandler;
}

const validateWorkerManagerConfig: Guard = guard(
  object({
    errorWindowMillis: optional(integer),
    errorWindowCountThreshold: optional(integer),
    notifyBeforeTerminate: optional(boolean),
    terminateReadyWaitMillis: optional(integer)
  })
);

const DEFAULT_ERROR_WINDOW_CONFIG: ErrorWindowConfig = {
  errorWindowMillis: 30000,
  errorWindowCountThreshold: 10
};

/**
 * Minimum number of millis that can be set to allow a worker (spawn or spawned)
 * to terminate.
 */
const MIN_WORKERS_TERMINATE_CONFIG = 10000;

const DEFAULT_WORKER_TERMINATE_CONFIG: WorkerTerminateConfig = {
  notifyBeforeTerminate: true,
github purecloudlabs / iframe-coordinator / src / workers / worker-manager.ts View on Github external
export type WorkerToHostMessageHandler = (event: WorkerToHost) => void;

/**
 * Configuration options for the WorkerManager
 */
export interface WorkerManagerConfig
  extends ErrorWindowConfig,
    WorkerTerminateConfig {
  onWorkerToHostMessage?: WorkerToHostMessageHandler;
}

const validateWorkerManagerConfig: Guard = guard(
  object({
    errorWindowMillis: optional(integer),
    errorWindowCountThreshold: optional(integer),
    notifyBeforeTerminate: optional(boolean),
    terminateReadyWaitMillis: optional(integer)
  })
);

const DEFAULT_ERROR_WINDOW_CONFIG: ErrorWindowConfig = {
  errorWindowMillis: 30000,
  errorWindowCountThreshold: 10
};

/**
 * Minimum number of millis that can be set to allow a worker (spawn or spawned)
 * to terminate.
 */
const MIN_WORKERS_TERMINATE_CONFIG = 10000;

const DEFAULT_WORKER_TERMINATE_CONFIG: WorkerTerminateConfig = {
github purecloudlabs / iframe-coordinator / src / messages / KeyDown.ts View on Github external
/** Message identifier */
  msgType: 'registeredKeyFired';
  /** Key details */
  msg: NativeKey;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
  msg: object({
    altKey: optional(boolean),
    charCode: optional(number),
    code: optional(string),
    ctrlKey: optional(boolean),
    key: string,
    keyCode: optional(number),
    metaKey: optional(boolean),
    shiftKey: optional(boolean)
  })
});

export { decoder };
github purecloudlabs / iframe-coordinator / src / messages / KeyDown.ts View on Github external
msgType: 'registeredKeyFired';
  /** Key details */
  msg: NativeKey;
}

/** @external */
const decoder: Decoder = object({
  msgType: constant<'registeredKeyFired'>('registeredKeyFired'),
  msg: object({
    altKey: optional(boolean),
    charCode: optional(number),
    code: optional(string),
    ctrlKey: optional(boolean),
    key: string,
    keyCode: optional(number),
    metaKey: optional(boolean),
    shiftKey: optional(boolean)
  })
});

export { decoder };