Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Cloudflare Stream Integration for Moodle

This plugin provides seamless integration between Moodle and Cloudflare Stream, automatically uploading video files to Cloudflare's video streaming service and replacing them with optimized Stream players.

Features

  • Automatic Video Upload: Videos uploaded to Moodle are automatically sent to Cloudflare Stream
  • Seamless Player Integration: Stream videos are displayed using Cloudflare's optimized video player
  • Background Processing: Video uploads happen asynchronously using Moodle's task system
  • Configurable Settings: Full control over player behavior and upload options
  • Multiple Video Formats: Supports MP4, AVI, MOV, WMV, WebM, and OGG formats
  • Optional File Cleanup: Choose whether to keep or delete original files after Stream upload

Requirements

  • Moodle 4.5 or later
  • Cloudflare account with Stream service enabled
  • PHP cURL extension
  • Valid Cloudflare Stream API credentials

Installation

  1. Download or clone this plugin to your Moodle installation:

    cd /path/to/moodle/local/
    git clone https://github.com/yourusername/moodle-local_cloudflarestream.git cloudflarestream
  2. Run the Moodle upgrade process:

    php admin/cli/upgrade.php

    Or visit your Moodle site as an administrator and follow the upgrade prompts.

Configuration

  1. Navigate to Site Administration > Plugins > Local plugins > Cloudflare Stream Integration

  2. Configure the following settings:

General Settings

  • Account ID: Your Cloudflare Account ID (found in your Cloudflare dashboard)
  • API Token: Your Cloudflare Stream API Token with Stream:Edit permission
  • Enable Cloudflare Stream: Toggle to enable/disable the integration
  • Delete original file: Choose whether to delete the original video file after successful Stream upload

Player Settings

  • Show player controls: Display video player controls
  • Auto-play videos: Automatically start playing videos when loaded
  • Loop videos: Loop videos when they finish playing

Getting Your Cloudflare Credentials

  1. Account ID:

    • Log into your Cloudflare dashboard
    • Select your domain
    • Account ID is shown in the right sidebar
  2. API Token:

    • Go to My Profile > API Tokens
    • Click Create Token
    • Use the Custom token template
    • Set permissions: Zone:Stream:Edit
    • Add your account as a resource
    • Click Continue to summary and Create Token

How It Works

  1. File Upload Detection: When a video file is uploaded to Moodle, the plugin detects it via event observers
  2. Background Upload: An asynchronous task uploads the video to Cloudflare Stream
  3. Database Tracking: The plugin maintains a mapping between Moodle files and Stream video IDs
  4. Player Replacement: When videos are displayed, they're automatically replaced with Stream players
  5. Status Updates: Video processing status is tracked and updated from the Stream API

Supported Video Formats

  • MP4 (video/mp4)
  • MPEG (video/mpeg)
  • QuickTime (video/quicktime)
  • AVI (video/x-msvideo)
  • WMV (video/x-ms-wmv)
  • WebM (video/webm)
  • OGG (video/ogg)

Database Tables

The plugin creates one database table:

  • local_cloudflarestream_videos: Maps Moodle file IDs to Cloudflare Stream video IDs and stores metadata

Development

Running Tests

# Unit tests
php admin/tool/phpunit/cli/util.php --buildconfig
php admin/tool/phpunit/cli/util.php --install
vendor/bin/phpunit local/cloudflarestream/tests/

# Behat tests
php admin/tool/behat/cli/init.php
vendor/bin/behat --config /path/to/moodle/behatdata/behat/behat.yml --tags="@local_cloudflarestream"

API Classes

  • \local_cloudflarestream\api: Handles all Cloudflare Stream API interactions
  • \local_cloudflarestream\video_manager: Manages video records and player generation
  • \local_cloudflarestream\observer: Event observer for file uploads
  • \local_cloudflarestream\task\upload_video: Asynchronous upload task

Troubleshooting

Videos Not Uploading

  1. Check that the plugin is enabled in settings
  2. Verify your Cloudflare credentials are correct
  3. Check the Moodle task queue: Site Administration > Server > Tasks > Scheduled tasks
  4. Look for error messages in the Moodle logs

Players Not Displaying

  1. Ensure videos have finished processing on Cloudflare Stream
  2. Check browser console for JavaScript errors
  3. Verify your Cloudflare account ID is correct

API Errors

Common API errors and solutions:

  • 401 Unauthorized: Check your API token has the correct permissions
  • 403 Forbidden: Verify the account ID matches your API token
  • 413 Payload Too Large: Video file exceeds Cloudflare's size limits
  • 429 Too Many Requests: API rate limit exceeded, uploads will retry automatically

Security

  • API tokens are stored securely in Moodle's config system
  • File uploads are validated for video formats only
  • Signed URLs can be generated for private video access
  • All API communications use HTTPS

Support

For issues and questions:

  1. Check the Moodle logs for error messages
  2. Verify your Cloudflare Stream configuration
  3. Review the troubleshooting section above
  4. Submit issues to the project repository

License

This plugin is licensed under the GNU General Public License v3.0 or later.

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

Changelog

Version 1.0.0

  • Initial release
  • Automatic video upload to Cloudflare Stream
  • Configurable player settings
  • Background processing with task queue
  • Comprehensive test suite
  • Behat integration tests

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages