From 81794ea5f927b2563cde22f6140238e0edd41af7 Mon Sep 17 00:00:00 2001 From: hibna Date: Fri, 13 Feb 2026 05:48:20 +0300 Subject: [PATCH] docs: rewrite README and DOCUMENTATION for modular player API --- DOCUMENTATION.md | 3174 +++++++++------------------------------------- README.md | 632 ++------- 2 files changed, 743 insertions(+), 3063 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 788b25d..f5439e0 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -1,2669 +1,699 @@ -# 🎬 @source/player - Tam Dökümantasyon +# @source/player Documentation -**Modern, zengin özellikli ve hafif React video oynatıcı kütüphanesi** +This document reflects the current codebase in this repository (`version 3.1.0`) and replaces older, drifted documentation. -[![npm version](https://img.shields.io/npm/v/@source/player.svg?style=flat-square)](https://www.npmjs.com/package/@source/player) -[![Bundle Size](https://img.shields.io/bundlephobia/minzip/@source/player?style=flat-square)](https://bundlephobia.com/package/@source/player) -[![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue?style=flat-square)](https://www.typescriptlang.org/) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT) +## Table of contents ---- +1. [Overview](#1-overview) +2. [Architecture](#2-architecture) +3. [Installation and setup](#3-installation-and-setup) +4. [Quick usage](#4-quick-usage) +5. [Streaming and protocol handling](#5-streaming-and-protocol-handling) +6. [Subtitles and subtitle style editor](#6-subtitles-and-subtitle-style-editor) +7. [Customization and modular composition](#7-customization-and-modular-composition) +8. [Keyboard and touch interaction](#8-keyboard-and-touch-interaction) +9. [Internationalization](#9-internationalization) +10. [API reference](#10-api-reference) +11. [Public exports](#11-public-exports) +12. [Error handling and reliability](#12-error-handling-and-reliability) +13. [Browser behavior and known limitations](#13-browser-behavior-and-known-limitations) +14. [Testing and development](#14-testing-and-development) -## 📑 İçindekiler +## 1. Overview -- [Genel Bakış](#-genel-bakış) -- [Kurulum](#-kurulum) - - [NPM/PNPM ile Kurulum](#1-npmpnpm-ile-kurulum) - - [.npmrc Yapılandırması](#2-npmrc-yapılandırması) - - [Kütüphaneyi Yükleme](#3-kütüphaneyi-yükleme) -- [Hızlı Başlangıç](#-hızlı-başlangıç) -- [Mimari ve Yapı](#-mimari-ve-yapı) -- [Özellikler](#-özellikler) - - [Video Format Desteği](#video-format-desteği) - - [Altyazı Sistemi](#altyazı-sistemi) - - [Ses Parça Yönetimi](#ses-parça-yönetimi) - - [Kalite Seviyesi Kontrolü](#kalite-seviyesi-kontrolü) - - [Klavye Kısayolları](#klavye-kısayolları) - - [Dokunmatik Jestler](#dokunmatik-jestler) -- [API Referansı](#-api-referansı) - - [VideoPlayer Props](#videoplayer-props) - - [Exported Components](#exported-components) - - [Exported Hooks](#exported-hooks) - - [Exported Utilities](#exported-utilities) - - [Type Definitions](#type-definitions) -- [Kullanım Örnekleri](#-kullanım-örnekleri) -- [Gelişmiş Kullanım](#-gelişmiş-kullanım) -- [State Yönetimi](#-state-yönetimi) -- [Tema ve Özelleştirme](#-tema-ve-özelleştirme) -- [Uluslararasılaştırma (i18n)](#-uluslararasılaştırma-i18n) -- [Performans](#-performans) -- [Tarayıcı Uyumluluğu](#-tarayıcı-uyumluluğu) -- [Hata Yönetimi](#-hata-yönetimi) -- [Geliştirme](#-geliştirme) -- [Katkıda Bulunma](#-katkıda-bulunma) -- [Lisans](#-lisans) +`@source/player` is a React video player library with: ---- +- Protocol-aware playback (`native`, `hls`, `rtmp/flv`, `mpegts`) +- Built-in controls with settings menus (speed, quality, subtitles, subtitle styling, audio tracks) +- Modular extension points for custom controls and overlays +- Strong TypeScript API (props, handle types, context types, utility exports) +- Runtime loading strategy for optional stream engines (`hls.js`, `flv.js`, `mpegts.js`) -## 🌟 Genel Bakış +## 2. Architecture -`@source/player`, React uygulamaları için özel olarak tasarlanmış, modern bir video oynatıcı kütüphanesidir. HLS streaming, RTMP/FLV desteği, çoklu altyazı ve ses parçaları, kalite değiştirme ve daha fazlası gibi gelişmiş özellikleri içerir. +The player is split into focused modules. -### Neden @source/player? +### 2.1 High-level component graph -| Özellik | @source/player | video.js | react-player | plyr | -|---------|---------------------|----------|--------------|------| -| **Paket Boyutu (gzipped)** | **~15KB** ✅ | ~500KB ❌ | ~50KB ⚠️ | ~30KB ⚠️ | -| **Runtime Bağımlılıkları** | **0** ✅ | Çok ❌ | Az ⚠️ | Az ⚠️ | -| **React (Web)** | **Evet** ✅ | Wrapper ⚠️ | **Evet** ✅ | Wrapper ⚠️ | -| **TypeScript Native** | **Evet** ✅ | Types ⚠️ | Kısmi ⚠️ | Types ⚠️ | -| **HLS Desteği** | **Evet** ✅ | Evet ✅ | Evet ✅ | Hayır ❌ | -| **RTMP/FLV Desteği** | **Evet** ✅ | Hayır ❌ | Hayır ❌ | Hayır ❌ | -| **Kalite Değiştirme** | **Evet** ✅ | Evet ✅ | Sınırlı ⚠️ | Hayır ❌ | -| **Dokunmatik Jestler** | **15+** ✅ | Sınırlı ⚠️ | Hayır ❌ | Sınırlı ⚠️ | -| **Klavye Kısayolları** | **15+** ✅ | ~8 ⚠️ | Temel ⚠️ | ~10 ⚠️ | -| **i18n Desteği** | **Evet** ✅ | Evet ✅ | Hayır ❌ | Evet ✅ | +- `VideoPlayer` +- `PlayerErrorBoundary` +- `PlayerProvider` (context + state + actions + i18n) +- `VideoElement` (media element, protocol setup, media events, subtitle rendering) +- `ControlsLayer` (controls visibility, settings menu, keyboard/touch integration) +- `SettingsMenu` (lazy-loaded, menu subviews) -### Ana Avantajlar +### 2.2 Core responsibilities -- 📦 **%97 daha küçük** - video.js'e göre sadece 15KB (500KB yerine) -- ⚡ **Çok hızlı** - Sıfır runtime bağımlılık, daha hızlı yükleme -- 🎯 **React-first** - React için özel yapılmış, wrapper değil -- 🔧 **Tam TypeScript** - Box'tan çıktığı gibi tam tip güvenliği -- 🎨 **Kolay özelleştirme** - CSS değişkenleri ile tema desteği -- 📱 **Mobil hazır** - Kapsamlı dokunmatik jest desteği -- 🌍 **Uluslararasılaştırılmış** - İngilizce ve Türkçe yerleşik i18n -- ♿ **Erişilebilir** - ARIA etiketleri ve klavye navigasyonu -- 🎬 **Çoklu format** - MP4, WebM, HLS (.m3u8), RTMP/FLV desteği -- 🔒 **Güvenli** - CORS hatası tespiti ve yardımcı hata mesajları +- `VideoPlayer` +- Normalizes props and default values +- Resolves subtitle style editor config (`enabled` + `storageKey`) +- Wraps content with `PlayerErrorBoundary` and `PlayerProvider` +- Exposes imperative API via ref (`VideoPlayerHandle`) ---- +- `PlayerProvider` +- Owns central `videoState`, `uiState`, and `settings` +- Manages subtitle style draft/commit/persist lifecycle +- Merges built-in translations with custom translations +- Exposes playback and UI actions through context -## 📦 Kurulum +- `VideoElement` +- Validates URL and detects protocol +- Initializes and tears down stream engine instances +- Subscribes to media events and forwards callbacks +- Converts `.srt` subtitles to VTT Blob URLs +- Renders subtitles using a custom overlay (native rendering disabled) -Bu kütüphane, Gitea üzerinde barındırılan özel bir npm registry'de yayınlanmaktadır. Kurulum için aşağıdaki adımları takip edin. +- `ControlsLayer` +- Handles auto-hide controls behavior +- Loads `SettingsMenu` lazily +- Enables keyboard shortcuts and touch gestures hooks +- Renders center play, spinner, progress, volume, settings, PIP, fullscreen -### 1. NPM/PNPM ile Kurulum +## 3. Installation and setup -Öncelikle projenizde npm veya pnpm kurulu olduğundan emin olun: +This package is published to a private registry. -```bash -# npm kurulu mu kontrol et -npm --version +1. Add `.npmrc`: -# pnpm kurulu mu kontrol et (opsiyonel, hızlı alternatif) -pnpm --version - -# pnpm kurulu değilse -npm install -g pnpm -``` - -### 2. .npmrc Yapılandırması - -`@source` scope'lu paketlerin Gitea registry'den çekilmesi için projenizin kök dizininde bir `.npmrc` dosyası oluşturmanız gerekir. - -#### Adım 2.1: .npmrc Dosyası Oluşturma - -Projenizin **kök dizininde** (package.json dosyasının bulunduğu yerde) `.npmrc` adlı bir dosya oluşturun: - -```bash -# Linux/Mac -touch .npmrc - -# Windows (PowerShell) -New-Item -Path .npmrc -ItemType File -``` - -#### Adım 2.2: .npmrc İçeriği - -`.npmrc` dosyasını aşağıdaki içerikle doldurun: - -```ini -# @source scope'u için private registry'yi kullan -@source:registry=https://gits.hibna.com.tr/api/packages/hibna/npm/ - -# Authentication token -# Token'ınızı almak için: https://gits.hibna.com.tr/user/settings/applications -# "Generate New Token" butonuna tıklayın ve "read:package" yetkisini seçin -//gits.hibna.com.tr/api/packages/hibna/npm/:_authToken=YOUR_TOKEN_HERE -``` - -**ÖNEMLİ:** `YOUR_TOKEN_HERE` kısmını kendi Gitea access token'ınız ile değiştirin! - -#### Adım 2.3: Gitea Access Token Alma - -1. Gitea hesabınıza giriş yapın: https://gits.hibna.com.tr -2. Sağ üst köşeden profil ikonuna tıklayın → **Settings** -3. Sol menüden **Applications** seçeneğine tıklayın -4. **Manage Access Tokens** bölümünde **Generate New Token** butonuna tıklayın -5. Token için bir isim verin (örn: "video-player-npm") -6. **Select permissions** bölümünde şu yetkileri seçin: - - `read:package` - Paketleri okuma yetkisi - - (Yayınlayacaksanız) `write:package` - Paket yayınlama yetkisi -7. **Generate Token** butonuna tıklayın -8. Oluşturulan token'ı kopyalayın (bu token sadece bir kez gösterilir!) -9. Token'ı `.npmrc` dosyasındaki `YOUR_TOKEN_HERE` yerine yapıştırın - -#### Adım 2.4: .npmrc'yi .gitignore'a Ekleyin - -**ÇOK ÖNEMLİ:** Token'ınızı Git'e commit etmeyin! `.npmrc` dosyasını `.gitignore`'a ekleyin: - -```bash -# .gitignore dosyasına ekleyin -echo ".npmrc" >> .gitignore -``` - -`.gitignore` dosyanız şöyle görünmeli: - -``` -node_modules/ -dist/ -.npmrc # ← Bu satırı ekleyin -.env -``` - -#### Alternatif: Environment Variable Kullanımı (Önerilen - Daha Güvenli) - -Daha güvenli bir yöntem için token'ı environment variable olarak saklayabilirsiniz: - -**.npmrc dosyası:** ```ini @source:registry=https://gits.hibna.com.tr/api/packages/hibna/npm/ //gits.hibna.com.tr/api/packages/hibna/npm/:_authToken=${GITS_NPM_TOKEN} ``` -**Environment variable ayarlama:** +2. Install package: ```bash -# Linux/Mac (.bashrc veya .zshrc dosyasına ekleyin) -export GITS_NPM_TOKEN=your-actual-token-here - -# Windows (PowerShell) -$env:GITS_NPM_TOKEN="your-actual-token-here" - -# Windows (Kalıcı - Sistem Environment Variables) -# Sistem Özellikler → Gelişmiş → Ortam Değişkenleri → Yeni -# Değişken adı: GITS_NPM_TOKEN -# Değişken değeri: your-actual-token-here -``` - -**CI/CD için (GitHub Actions, GitLab CI, vb.):** - -Repository settings → Secrets → `GITS_NPM_TOKEN` adında bir secret oluşturun. - -### 3. Kütüphaneyi Yükleme - -`.npmrc` dosyası yapılandırıldıktan sonra, kütüphaneyi yükleyebilirsiniz: - -```bash -# npm ile npm install @source/player - -# veya pnpm ile (önerilen - daha hızlı) +# or pnpm add @source/player - -# veya yarn ile +# or yarn add @source/player ``` -### 4. Peer Dependencies +3. Ensure app already includes React and ReactDOM (`>=18`). -Kütüphane, React 18+ gerektirir. Eğer projenizde yoksa: +4. Import player styles: + +```tsx +import '@source/player/styles.css' +``` + +Optional local dependencies (instead of CDN fallback): ```bash -npm install react@^18.0.0 react-dom@^18.0.0 -# veya -pnpm add react@^18.0.0 react-dom@^18.0.0 +npm install hls.js flv.js mpegts.js ``` -### 5. Optional Dependencies (Otomatik) +## 4. Quick usage -HLS ve RTMP/FLV desteği için gerekli kütüphaneler, ihtiyaç duyulduğunda **otomatik olarak lazy-load** edilir: - -- `hls.js` - HLS streaming için (.m3u8 dosyaları) -- `flv.js` - RTMP/FLV streaming için - -Bu kütüphaneler manuel kuruluma gerek yoktur. Ancak bundle size'ı azaltmak için isterseniz kurabilirsiniz: - -```bash -npm install --save-optional hls.js flv.js -``` - -### Kurulum Doğrulama - -Kurulumun başarılı olduğunu doğrulamak için: - -```bash -npm list @source/player -# veya -pnpm list @source/player -``` - -Çıktı şöyle olmalı: -``` -your-project@1.0.0 -└─┬ @source/player@0.1.5 -``` - -### Sorun Giderme - -**Problem: "401 Unauthorized" hatası** -- `.npmrc` dosyasındaki token'ın doğru olduğundan emin olun -- Token'ın `read:package` yetkisine sahip olduğundan emin olun -- Token'ın süresi dolmamış olduğundan emin olun - -**Problem: "404 Not Found" hatası** -- Registry URL'inin doğru olduğundan emin olun -- `@source:registry=https://gits.hibna.com.tr/api/packages/hibna/npm/` -- İnternet bağlantınızı kontrol edin -- Gitea sunucusunun erişilebilir olduğundan emin olun - -**Problem: "Cannot find module '@source/player'"** -- `node_modules` klasörünü silin ve yeniden yükleyin: - ```bash - rm -rf node_modules package-lock.json - npm install - ``` - ---- - -## 🚀 Hızlı Başlangıç - -### Temel Kullanım +### 4.1 Minimal usage ```tsx import { VideoPlayer } from '@source/player' import '@source/player/styles.css' -function App() { - return ( - - ) +export function App() { + return } ``` -### HLS Streaming ile Kullanım - -```tsx - -``` - -### Event Handler'lar ile Kullanım +### 4.2 With subtitles + editor ```tsx console.log('Video oynatılmaya başladı')} - onPause={() => console.log('Video durakladı')} - onEnded={() => console.log('Video bitti')} - onTimeUpdate={(time) => console.log('Geçerli zaman:', time)} - onError={(error) => console.error('Video hatası:', error)} + subtitles={[ + { src: '/subs/en.vtt', lang: 'en', label: 'English', default: true }, + { src: '/subs/tr.srt', lang: 'tr', label: 'Turkish' }, + ]} + subtitleStyleEditor={{ enabled: true, storageKey: 'player-subtitle-style' }} /> ``` -### Tema Özelleştirmesi +### 4.3 With theme and modular controls ```tsx -``` - ---- - -## 🏗️ Mimari ve Yapı - -### Proje Yapısı - -``` -video-player/ -├── src/ -│ ├── components/ # React UI bileşenleri -│ │ ├── controls/ # Kontrol butonları (Play, Pause, vb.) -│ │ │ ├── PlayPauseButton.tsx -│ │ │ ├── ProgressBar.tsx -│ │ │ ├── VolumeControl.tsx -│ │ │ ├── TimeDisplay.tsx -│ │ │ ├── FullscreenButton.tsx -│ │ │ ├── PIPButton.tsx -│ │ │ ├── SettingsButton.tsx -│ │ │ └── CenterPlayButton.tsx -│ │ ├── menus/ # Ayar menüleri -│ │ │ └── SettingsMenu.tsx -│ │ ├── overlays/ # Overlay bileşenleri -│ │ │ └── LoadingSpinner.tsx -│ │ ├── VideoPlayer.tsx # Ana wrapper bileşen -│ │ ├── VideoElement.tsx # Video element handler -│ │ └── ControlsLayer.tsx # Kontrol katmanı -│ ├── contexts/ # React Context -│ │ └── PlayerContext.tsx -│ ├── hooks/ # Custom React hooks -│ │ ├── useKeyboardShortcuts.ts -│ │ └── useTouchGestures.ts -│ ├── utils/ # Utility fonksiyonlar -│ │ ├── hlsSetup.ts # HLS.js setup -│ │ ├── hlsLoader.ts # HLS.js lazy loading -│ │ ├── hlsControl.ts # HLS kalite/ses kontrolü -│ │ ├── rtmpSetup.ts # FLV.js setup -│ │ ├── rtmpLoader.ts # FLV.js lazy loading -│ │ ├── videoProtocol.ts # Protokol tespiti -│ │ ├── m3u8Parser.ts # M3U8 manifest parsing -│ │ ├── subtitles.ts # SRT/VTT altyazı işleme -│ │ ├── corsHelper.ts # CORS doğrulama -│ │ ├── time.ts # Zaman formatlama -│ │ └── polyfills.ts # Tarayıcı uyumluluk -│ ├── icons/ # SVG icon bileşenleri -│ │ └── index.tsx -│ ├── styles/ # CSS değişkenleri -│ │ └── variables.css -│ ├── i18n/ # Uluslararasılaştırma -│ │ └── index.ts # İngilizce & Türkçe -│ ├── types/ # TypeScript tanımları -│ │ └── index.ts -│ └── index.ts # Ana export dosyası -├── examples/ # Demo uygulaması -│ ├── App.tsx -│ └── main.tsx -├── dist/ # Build çıktısı -├── package.json -├── vite.config.ts # Geliştirme config -├── vite.config.lib.ts # Kütüphane build config -└── tsconfig.json -``` - -### Bileşen Hiyerarşisi - -``` -VideoPlayer (Main) -├── PlayerProvider (Context) -│ ├── VideoElement (Video handler) -│ │ └──