New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

atv-companion

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atv-companion

TypeScript SDK for Apple TV Companion protocol - scan, pair, and remote control

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
10
100%
Maintainers
1
Weekly downloads
 
Created
Source

ATV-Companion

English | 中文

English

A TypeScript SDK for Apple TV Companion protocol - scan, pair, and remote control Apple TV devices.

About

This project is a TypeScript port of the Companion protocol implementation from pyatv.

Code generated by AI (cc)

Original Python code forked from: pyatv by @postlund

Features

  • Device Discovery: Scan for Apple TV devices on your local network via mDNS/Bonjour
  • Pairing: Pair with Apple TV using PIN-based authentication (SRP)
  • Remote Control: Send HID commands (Up, Down, Left, Right, Menu, Select, Home, etc.)
  • Media Control: Play, Pause, Next/Previous track, Volume control
  • App Launch: Launch apps by bundle ID or deep link URL
  • Event Subscription: Subscribe to device events

Installation

npm install atv-companion
# or
pnpm add atv-companion

Requirements

  • Node.js >= 18.0.0

Quick Start

1. Scan for devices

import { scan } from 'atv-companion';

const devices = await scan({ timeout: 5000 });
console.log(devices);

2. Pair with Apple TV

import {
  CompanionConnection,
  CompanionProtocol,
  CompanionPairSetupProcedure,
} from 'atv-companion';

const connection = new CompanionConnection('192.168.1.100', 49152);
const protocol = new CompanionProtocol(connection);

await connection.connect();

const pairSetup = new CompanionPairSetupProcedure(protocol);
await pairSetup.startPairing();

// Enter the PIN shown on Apple TV screen
const credentials = await pairSetup.finishPairing('1234');
console.log('Credentials:', credentials);

connection.close();

3. Remote Control

import { CompanionAPI, HidCommand } from 'atv-companion';

const api = new CompanionAPI('192.168.1.100', 49152, credentials);
await api.connect();

// Send button commands
await api.pressButton(HidCommand.Menu);
await api.pressButton(HidCommand.Up);
await api.pressButton(HidCommand.Select);

// Media control
await api.play();
await api.pause();
await api.setVolume(0.5);

// Launch app
await api.launchApp('com.apple.TVWatchList');

await api.disconnect();

API Reference

HidCommand

CommandDescription
UpNavigate up
DownNavigate down
LeftNavigate left
RightNavigate right
MenuMenu button
SelectSelect/OK button
HomeHome button
VolumeUpVolume up
VolumeDownVolume down
SiriActivate Siri
PlayPausePlay/Pause toggle

Examples

Run the examples:

# Scan for devices
pnpm run example:scan

# Pair with Apple TV
ATV_HOST=192.168.1.100 ATV_PIN=1234 pnpm run example:pair

# Remote control
ATV_HOST=192.168.1.100 ATV_CREDENTIALS=<base64> pnpm run example:remote

License

MIT

中文

Apple TV Companion 协议的 TypeScript SDK - 扫描、配对和远程控制 Apple TV 设备。

关于

本项目是 pyatv 中 Companion 协议实现的 TypeScript 移植版本。

代码由 AI (cc) 生成

原始 Python 代码来自: pyatv by @postlund

功能特性

  • 设备发现: 通过 mDNS/Bonjour 扫描局域网内的 Apple TV 设备
  • 配对: 使用 PIN 码认证 (SRP) 与 Apple TV 配对
  • 遥控器: 发送 HID 命令 (上、下、左、右、菜单、选择、主页等)
  • 媒体控制: 播放、暂停、上/下一曲、音量控制
  • 启动应用: 通过 Bundle ID 或深度链接 URL 启动应用
  • 事件订阅: 订阅设备事件

安装

npm install atv-companion
# 或
pnpm add atv-companion

系统要求

  • Node.js >= 18.0.0

快速开始

1. 扫描设备

import { scan } from 'atv-companion';

const devices = await scan({ timeout: 5000 });
console.log(devices);

2. 与 Apple TV 配对

import {
  CompanionConnection,
  CompanionProtocol,
  CompanionPairSetupProcedure,
} from 'atv-companion';

const connection = new CompanionConnection('192.168.1.100', 49152);
const protocol = new CompanionProtocol(connection);

await connection.connect();

const pairSetup = new CompanionPairSetupProcedure(protocol);
await pairSetup.startPairing();

// 输入 Apple TV 屏幕上显示的 PIN 码
const credentials = await pairSetup.finishPairing('1234');
console.log('凭证:', credentials);

connection.close();

3. 遥控器控制

import { CompanionAPI, HidCommand } from 'atv-companion';

const api = new CompanionAPI('192.168.1.100', 49152, credentials);
await api.connect();

// 发送按钮命令
await api.pressButton(HidCommand.Menu);
await api.pressButton(HidCommand.Up);
await api.pressButton(HidCommand.Select);

// 媒体控制
await api.play();
await api.pause();
await api.setVolume(0.5);

// 启动应用
await api.launchApp('com.apple.TVWatchList');

await api.disconnect();

API 参考

HidCommand

命令描述
Up向上导航
Down向下导航
Left向左导航
Right向右导航
Menu菜单按钮
Select选择/确认按钮
Home主页按钮
VolumeUp音量增加
VolumeDown音量减少
Siri激活 Siri
PlayPause播放/暂停切换

示例

运行示例:

# 扫描设备
pnpm run example:scan

# 与 Apple TV 配对
ATV_HOST=192.168.1.100 ATV_PIN=1234 pnpm run example:pair

# 遥控器控制
ATV_HOST=192.168.1.100 ATV_CREDENTIALS=<base64> pnpm run example:remote

许可证

MIT

Keywords

apple-tv

FAQs

Package last updated on 07 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts