Initial commit
This commit is contained in:
commit
b2beba22d1
24 files changed
+7289
No files matched your search
@@ -0,0 +1 @@
|
||||
github: [php-webrtc]
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: "🐛 Bug Report"
|
||||
about: Report a reproducible bug in the PHP library
|
||||
title: "[Bug] "
|
||||
labels: bug
|
||||
---
|
||||
|
||||
## Description
|
||||
|
||||
A clear and concise description of the problem.
|
||||
|
||||
## Steps to Reproduce
|
||||
|
||||
List the steps to reproduce the behavior:
|
||||
|
||||
1. ...
|
||||
2. ...
|
||||
3. ...
|
||||
|
||||
## Expected Behavior
|
||||
|
||||
Describe what you expected to happen.
|
||||
|
||||
## Actual Behavior
|
||||
|
||||
Describe what actually happened.
|
||||
|
||||
## Environment
|
||||
|
||||
- PHP version: (e.g., 8.2.5)
|
||||
- Operating System: (e.g., Ubuntu 22.04, macOS 13)
|
||||
- Framework (if any): (e.g., Laravel 10, Symfony 6)
|
||||
- Composer version: (e.g., 2.7.0)
|
||||
- Additional packages used: (e.g., psr/log, monolog/monolog)
|
||||
|
||||
## Additional Context
|
||||
|
||||
Add any other context about the problem here, including screenshots, error logs, or related issues if applicable.
|
||||
|
||||
## Possible Fix (optional)
|
||||
|
||||
Suggest a fix or point to the code that might be related to the issue.
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
name: "🚀 Feature Request"
|
||||
about: Suggest an enhancement for the PHP library
|
||||
title: "[Feature] "
|
||||
labels: enhancement
|
||||
---
|
||||
|
||||
## Feature Description
|
||||
|
||||
Clearly and concisely describe the feature you would like to see implemented.
|
||||
|
||||
## Use Case / Motivation
|
||||
|
||||
What problem does this feature solve or what benefit does it bring to users of the PHP library?
|
||||
|
||||
## Related Context
|
||||
|
||||
- PHP version(s): (e.g., PHP 8.1, 8.2)
|
||||
- Frameworks: (e.g., Laravel, Symfony)
|
||||
- Related packages: (e.g., `psr/log`, `guzzlehttp/guzzle`)
|
||||
- Environment: (e.g., CLI, web, Swoole, ReactPHP)
|
||||
|
||||
## Suggested Implementation (optional)
|
||||
|
||||
If you have an idea of how this feature could be implemented, feel free to share it here.
|
||||
@@ -0,0 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [1.0.0] - 2025-05-17
|
||||
|
||||
### Added
|
||||
- First release
|
||||
@@ -0,0 +1,115 @@
|
||||
# Code of Conduct - WebRTC Examples
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to make participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behaviour that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologising to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behaviour include:
|
||||
|
||||
* The use of sexualised language or imagery, and sexual attention or advances
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying and enforcing our standards of
|
||||
acceptable behaviour and will take appropriate and fair corrective action in
|
||||
response to any behaviour that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will
|
||||
communicate reasons for moderation decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behaviour may be
|
||||
reported to the community leaders responsible for enforcement at <github@aminyazdanpanah.com>.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behaviour deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behaviour was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behaviour. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behaviour.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behaviour, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](https://contributor-covenant.org/), version
|
||||
[1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct/code_of_conduct.md) and
|
||||
[2.0](https://www.contributor-covenant.org/version/2/0/code_of_conduct/code_of_conduct.md),
|
||||
and was generated by [contributing.md](https://contributing.md/generator).
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
<!-- omit in toc -->
|
||||
# Contributing to PHP WebRTC Examples
|
||||
|
||||
First off, thanks for taking the time to contribute! ❤️
|
||||
|
||||
All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉
|
||||
|
||||
> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
|
||||
> - Star the project
|
||||
> - Tweet about it
|
||||
> - Refer this project in your project's readme
|
||||
> - Mention the project at local meetups and tell your friends/colleagues
|
||||
|
||||
<!-- omit in toc -->
|
||||
## Table of Contents
|
||||
|
||||
- [Code of Conduct](#code-of-conduct)
|
||||
- [I Have a Question](#i-have-a-question)
|
||||
- [I Want To Contribute](#i-want-to-contribute)
|
||||
- [Reporting Bugs](#reporting-bugs)
|
||||
- [Suggesting Enhancements](#suggesting-enhancements)
|
||||
- [Your First Code Contribution](#your-first-code-contribution)
|
||||
- [Improving The Documentation](#improving-the-documentation)
|
||||
- [Styleguides](#styleguides)
|
||||
- [Commit Messages](#commit-messages)
|
||||
- [Join The Project Team](#join-the-project-team)
|
||||
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
This project and everyone participating in it is governed by the
|
||||
[PHP - WebRTC Code of Conduct](https://github.com/PHP-WebRTC/examples/blob/main/CODE_OF_CONDUCT.md).
|
||||
By participating, you are expected to uphold this code. Please report unacceptable behavior
|
||||
to <github@aminyazdanpanah.com>.
|
||||
|
||||
|
||||
## I Have a Question
|
||||
|
||||
> If you want to ask a question, we assume that you have read the available [Documentation](https://www.quasarstream.com/php-webrtc).
|
||||
|
||||
Before you ask a question, it is best to search for existing [Issues](https://github.com/PHP-WebRTC/examples/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.
|
||||
|
||||
If you then still feel the need to ask a question and need clarification, we recommend the following:
|
||||
|
||||
- Open an [Issue](https://github.com/PHP-WebRTC/examples/issues/new).
|
||||
- Provide as much context as you can about what you're running into.
|
||||
- Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.
|
||||
|
||||
We will then take care of the issue as soon as possible.
|
||||
|
||||
<!--
|
||||
You might want to create a separate issue tag for questions and include it in this description. People should then tag their issues accordingly.
|
||||
|
||||
Depending on how large the project is, you may want to outsource the questioning, e.g. to Stack Overflow or Gitter. You may add additional contact and information possibilities:
|
||||
- IRC
|
||||
- Slack
|
||||
- Gitter
|
||||
- Stack Overflow tag
|
||||
- Blog
|
||||
- FAQ
|
||||
- Roadmap
|
||||
- E-Mail List
|
||||
- Forum
|
||||
-->
|
||||
|
||||
## I Want To Contribute
|
||||
|
||||
> ### Legal Notice <!-- omit in toc -->
|
||||
> When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project licence.
|
||||
|
||||
### Reporting Bugs
|
||||
|
||||
<!-- omit in toc -->
|
||||
#### Before Submitting a Bug Report
|
||||
|
||||
A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.
|
||||
|
||||
- Make sure that you are using the latest version.
|
||||
- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://www.quasarstream.com/php-webrtc). If you are looking for support, you might want to check [this section](#i-have-a-question)).
|
||||
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/PHP-WebRTC/examples/issues?q=label%3Abug).
|
||||
- Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue.
|
||||
- Collect information about the bug:
|
||||
- Stack trace (Traceback)
|
||||
- OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
|
||||
- Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant.
|
||||
- Possibly your input and the output
|
||||
- Can you reliably reproduce the issue? And can you also reproduce it with older versions?
|
||||
|
||||
<!-- omit in toc -->
|
||||
#### How Do I Submit a Good Bug Report?
|
||||
|
||||
> You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to <github@aminyazdanpanah.com>.
|
||||
<!-- You may add a PGP key to allow the messages to be sent encrypted as well. -->
|
||||
|
||||
We use GitHub issues to track bugs and errors. If you run into an issue with the project:
|
||||
|
||||
- Open an [Issue](https://github.com/PHP-WebRTC/examples/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
|
||||
- Explain the behavior you would expect and the actual behavior.
|
||||
- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
|
||||
- Provide the information you collected in the previous section.
|
||||
|
||||
Once it's filed:
|
||||
|
||||
- The project team will label the issue accordingly.
|
||||
- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced.
|
||||
- If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](#your-first-code-contribution).
|
||||
|
||||
<!-- You might want to create an issue template for bugs and errors that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
|
||||
|
||||
|
||||
### Suggesting Enhancements
|
||||
|
||||
This section guides you through submitting an enhancement suggestion for PHP - WebRTC, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions.
|
||||
|
||||
<!-- omit in toc -->
|
||||
#### Before Submitting an Enhancement
|
||||
|
||||
- Make sure that you are using the latest version.
|
||||
- Read the [documentation](https://www.quasarstream.com/php-webrtc) carefully and find out if the functionality is already covered, maybe by an individual configuration.
|
||||
- Perform a [search](https://github.com/PHP-WebRTC/examples/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
|
||||
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
|
||||
|
||||
<!-- omit in toc -->
|
||||
#### How Do I Submit a Good Enhancement Suggestion?
|
||||
|
||||
Enhancement suggestions are tracked as [GitHub issues](https://github.com/PHP-WebRTC/examples/issues).
|
||||
|
||||
- Use a **clear and descriptive title** for the issue to identify the suggestion.
|
||||
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
|
||||
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
|
||||
- You may want to **include screenshots or screen recordings** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [LICEcap](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and the built-in [screen recorder in GNOME](https://help.gnome.org/users/gnome-help/stable/screen-shot-record.html.en) or [SimpleScreenRecorder](https://github.com/MaartenBaert/ssr) on Linux. <!-- this should only be included if the project has a GUI -->
|
||||
- **Explain why this enhancement would be useful** to most WebRTC Essentials users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
|
||||
|
||||
<!-- You might want to create an issue template for enhancement suggestions that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
|
||||
|
||||
### Your First Code Contribution
|
||||
<!-- TODO
|
||||
include Setup of env, IDE and typical getting started instructions?
|
||||
|
||||
-->
|
||||
|
||||
### Improving The Documentation
|
||||
<!-- TODO
|
||||
Updating, improving and correcting the documentation
|
||||
|
||||
-->
|
||||
|
||||
## Styleguides
|
||||
### Commit Messages
|
||||
<!-- TODO
|
||||
|
||||
-->
|
||||
|
||||
## Join The Project Team
|
||||
<!-- TODO -->
|
||||
|
||||
<!-- omit in toc -->
|
||||
## Attribution
|
||||
This guide is based on the [contributing.md](https://contributing.md/generator)!
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
FROM php:8.4-apache
|
||||
|
||||
# Enable required Apache modules
|
||||
RUN a2enmod ssl rewrite headers
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libzip-dev \
|
||||
openssl \
|
||||
libgmp-dev \
|
||||
apache2-utils \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install PHP extensions
|
||||
RUN docker-php-ext-install -j$(nproc) gmp zip
|
||||
RUN docker-php-ext-enable gmp
|
||||
|
||||
# Configure Apache SSL
|
||||
RUN mkdir -p /etc/apache2/ssl && \
|
||||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
|
||||
-keyout /etc/apache2/ssl/server.key \
|
||||
-out /etc/apache2/ssl/server.crt \
|
||||
-subj "/C=US/ST=State/L=City/O=Organization/CN=localhost"
|
||||
|
||||
# Copy Apache config after enabling modules
|
||||
COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
RUN a2ensite 000-default.conf
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# Copy application files
|
||||
COPY . /var/www/html/
|
||||
|
||||
# Copy and set permissions for the startup script
|
||||
COPY docker/startup.sh /usr/local/bin/startup.sh
|
||||
RUN chmod +x /usr/local/bin/startup.sh
|
||||
|
||||
# Set file permissions
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
|
||||
# Expose HTTP and HTTPS ports
|
||||
EXPOSE 80 443
|
||||
|
||||
# Start Apache with the startup script
|
||||
CMD ["/usr/local/bin/startup.sh"]
|
||||
@@ -0,0 +1,29 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2025, Amin Yazdanpanah
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,106 @@
|
||||
|
||||
# PHP WebRTC Examples Collection
|
||||
|
||||
A collection of WebRTC examples with PHP-based signaling backends.
|
||||
|
||||
## Requirements
|
||||
|
||||
- PHP 8.4 or higher
|
||||
- Linux environment (required for manual setup)
|
||||
- Modern web browser with WebRTC support (Chrome, Firefox, Edge, Safari)
|
||||
- HTTPS connection (required by WebRTC for secure contexts)
|
||||
|
||||
## Running the Examples
|
||||
|
||||
### Option 1: Run with Docker (Recommended)
|
||||
|
||||
A preconfigured Docker setup is provided for easy local development with HTTPS support.
|
||||
|
||||
```bash
|
||||
# Build and start the Docker container
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
Once running, access the examples at:
|
||||
👉 **https://localhost**
|
||||
|
||||
> The Docker environment automatically generates a self-signed certificate for HTTPS access.
|
||||
|
||||
---
|
||||
|
||||
### Option 2: Manual Setup (Linux Only)
|
||||
|
||||
> ⚠️ Manual setup is currently supported only on Linux systems.
|
||||
|
||||
#### 1. Clone the Repository
|
||||
|
||||
```bash
|
||||
git clone https://github.com/PHP-WebRTC/examples.git
|
||||
```
|
||||
|
||||
#### 2. Install System Dependencies
|
||||
|
||||
```bash
|
||||
# Make the installer executable and run it
|
||||
cd examples
|
||||
chmod +x install_deps.sh
|
||||
./scripts/install_deps.sh
|
||||
```
|
||||
you may need to run as root if you don't have permission to install deps `sudo ./scripts/install_deps.sh`
|
||||
|
||||
#### 3. Navigate to an Example and Install PHP Dependencies
|
||||
|
||||
```bash
|
||||
cd examples/[example_directory] # e.g. cd examples/echo
|
||||
|
||||
# Install PHP dependencies using Composer
|
||||
composer install
|
||||
```
|
||||
|
||||
#### 4. Start the Signaling Server
|
||||
|
||||
```bash
|
||||
php server.php
|
||||
```
|
||||
|
||||
#### 5. Serve the Client via PHP's Built-In Web Server
|
||||
|
||||
```bash
|
||||
php -S localhost:8000
|
||||
```
|
||||
|
||||
Now, open your browser and go to:
|
||||
👉 **https://localhost:8000**
|
||||
|
||||
---
|
||||
|
||||
## Important Notes
|
||||
|
||||
- WebRTC requires a secure (HTTPS) context. You may need to accept your browser's warning about self-signed certificates during local development.
|
||||
- Be sure to grant access to your camera and microphone when prompted.
|
||||
- If something isn't working, check the browser console for errors or permission issues.
|
||||
|
||||
---
|
||||
|
||||
## Credits
|
||||
|
||||
### Authors
|
||||
|
||||
- **Amin Yazdanpanah**
|
||||
- Website: [aminyazdanpanah.com](https://www.aminyazdanpanah.com)
|
||||
- Email: [github@aminyazdanpanah.com](mailto:github@aminyazdanpanah.com)
|
||||
|
||||
- **Sana Moniri**
|
||||
- GtiHub: [sanamoniri](https://github.com/sanamoniri)
|
||||
|
||||
---
|
||||
|
||||
## Reporting Issues
|
||||
|
||||
Found a bug? Please report it on our [issues](https://github.com/php-webrtc/webrtc/issues).
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
BSD 3-Clause License. See [LICENSE](LICENSE) for details.
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
# Security Policy
|
||||
|
||||
If you believe you have discovered a security vulnerability in this library, we ask that you report it to us privately and responsibly through coordinated disclosure.
|
||||
|
||||
**Do not report security issues through GitHub issues, discussions, or pull requests.**
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please email your findings to: **[github@aminyazdanpanah.com](mailto:github@aminyazdanpanah.com)**
|
||||
|
||||
To help us assess and resolve the issue efficiently, please include as much of the following information as possible:
|
||||
|
||||
- **Type of vulnerability** (e.g., buffer overflow, unauthorized access)
|
||||
- **Affected source files** and relevant paths
|
||||
- **Location in code** (e.g., tag, branch, commit hash, or direct URL)
|
||||
- **Any special configuration** or environment needed to reproduce
|
||||
- **Step-by-step reproduction instructions**
|
||||
- **Proof-of-concept or exploit code**, if available
|
||||
- **Potential impact** and how an attacker might exploit the issue
|
||||
|
||||
Your report will be reviewed promptly. We appreciate responsible disclosure and will work with you to address any confirmed issues.
|
||||
|
||||
Thank you for helping keep this project and its users secure.
|
||||
@@ -0,0 +1,36 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- .:/var/www/html
|
||||
environment:
|
||||
- PHP_FPM_USER=www-data
|
||||
- PHP_FPM_GROUP=www-data
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '2'
|
||||
memory: 2G
|
||||
|
||||
echo-server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: echo/Dockerfile
|
||||
network_mode: host
|
||||
volumes:
|
||||
- ./echo:/var/www/echo
|
||||
- ./echo/logs:/var/log/echo
|
||||
environment:
|
||||
- PHP_CLI_USER=www-data
|
||||
- PHP_CLI_GROUP=www-data
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '2'
|
||||
memory: 2G
|
||||
restart: unless-stopped
|
||||
@@ -0,0 +1,36 @@
|
||||
<VirtualHost *:80>
|
||||
ServerName localhost
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /var/www/html
|
||||
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTPS} off
|
||||
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:443>
|
||||
ServerName localhost
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /var/www/html
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile /etc/apache2/ssl/server.crt
|
||||
SSLCertificateKeyFile /etc/apache2/ssl/server.key
|
||||
|
||||
<Directory /var/www/html>
|
||||
Options -Indexes +FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
# Security headers (now working)
|
||||
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
|
||||
Header always set X-Content-Type-Options "nosniff"
|
||||
Header always set X-Frame-Options "SAMEORIGIN"
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/ssl-error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/ssl-access.log combined
|
||||
</VirtualHost>
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Start Apache
|
||||
echo "Starting Apache..."
|
||||
apache2-foreground
|
||||
@@ -0,0 +1,91 @@
|
||||
FROM php:8.4-cli
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
apt-transport-https ca-certificates \
|
||||
gnupg \
|
||||
autoconf \
|
||||
automake \
|
||||
build-essential \
|
||||
cmake \
|
||||
git \
|
||||
libtool \
|
||||
pkg-config \
|
||||
yasm \
|
||||
nasm \
|
||||
wget \
|
||||
unzip \
|
||||
libzip-dev \
|
||||
openssl \
|
||||
libgmp-dev \
|
||||
libssl-dev \
|
||||
libsrtp2-dev \
|
||||
libx264-dev \
|
||||
libffi-dev \
|
||||
libprotobuf-dev \
|
||||
python3 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Download and install FFmpeg 7.1.1
|
||||
WORKDIR /tmp
|
||||
RUN wget https://ffmpeg.org/releases/ffmpeg-7.1.1.tar.bz2 && \
|
||||
tar xjf ffmpeg-7.1.1.tar.bz2 && \
|
||||
cd ffmpeg-7.1.1 && \
|
||||
./configure --enable-shared --enable-gpl --enable-libx264 && \
|
||||
make -j$(nproc) && \
|
||||
make install && \
|
||||
ldconfig && \
|
||||
rm -rf /tmp/*
|
||||
|
||||
# Build and install libopus 1.4.0
|
||||
WORKDIR /tmp
|
||||
RUN wget https://github.com/xiph/opus/releases/download/v1.4/opus-1.4.tar.gz && \
|
||||
tar xzvf opus-1.4.tar.gz && \
|
||||
cd opus-1.4 && \
|
||||
./configure --prefix=/usr/local --enable-shared && \
|
||||
make -j$(nproc) && \
|
||||
make install && \
|
||||
ldconfig && \
|
||||
rm -rf /tmp/*
|
||||
|
||||
# Build and install libvpx 1.15.0
|
||||
WORKDIR /tmp
|
||||
RUN wget https://github.com/webmproject/libvpx/archive/refs/tags/v1.15.0.tar.gz && \
|
||||
tar xzvf v1.15.0.tar.gz && \
|
||||
cd libvpx-1.15.0 && \
|
||||
./configure --prefix=/usr/local --enable-shared --disable-examples && \
|
||||
make -j$(nproc) && \
|
||||
make install && \
|
||||
ldconfig && \
|
||||
rm -rf /tmp/*
|
||||
|
||||
# Install PHP extensions
|
||||
RUN docker-php-ext-install -j$(nproc) gmp zip ffi \
|
||||
&& pecl install protobuf \
|
||||
&& docker-php-ext-enable gmp protobuf \
|
||||
&& echo "ffi.enable=true" > /usr/local/etc/php/conf.d/ffi.ini
|
||||
|
||||
# Install Composer
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# Application setup
|
||||
WORKDIR /var/www/echo
|
||||
COPY ./echo/composer.json .
|
||||
COPY ./echo/server.php .
|
||||
COPY ./echo/docker/startup.sh /usr/local/bin/
|
||||
|
||||
VOLUME /var/log/echo
|
||||
|
||||
# Dependencies and permissions
|
||||
RUN composer install --no-dev --optimize-autoloader \
|
||||
&& mkdir -p /var/log/echo \
|
||||
&& chown -R www-data:www-data /var/log/echo \
|
||||
&& chmod -R 775 /var/log/echo \
|
||||
&& chmod +x /usr/local/bin/startup.sh \
|
||||
&& chmod +x /var/www/echo/server.php
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s \
|
||||
CMD ps aux | grep '[p]hp /var/www/echo/server.php' || exit 1
|
||||
|
||||
CMD ["/usr/local/bin/startup.sh"]
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "quasarstream/examples",
|
||||
"description": "A collection of WebRTC examples with PHP backends for signaling.",
|
||||
"require": {
|
||||
"php": "^8.4",
|
||||
"ext-ffi": "*",
|
||||
"ext-gmp": "*",
|
||||
"quasarstream/webrtc": "^1.0",
|
||||
"quasarstream/signaling": "^1.0"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Amin Yazdanpanah",
|
||||
"email": "github@aminyazdanpanah.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Create log directory with correct permissions
|
||||
mkdir -p /var/log/echo
|
||||
chown www-data:www-data /var/log/echo
|
||||
chmod 775 /var/log/echo
|
||||
|
||||
# Quick dependency version check
|
||||
echo "Echo Server Startup"
|
||||
echo "========================"
|
||||
echo "PHP: $(php -v | head -n 1)"
|
||||
echo "OpenSSL: $(openssl version 2>/dev/null)"
|
||||
echo "SRTP: $(pkg-config --modversion libsrtp2 2>/dev/null)"
|
||||
echo "FFmpeg: $(ffmpeg -version 2>/dev/null | head -n 1)"
|
||||
echo "libvpx: $(pkg-config --modversion vpx 2>/dev/null)"
|
||||
echo ""
|
||||
|
||||
# Check required PHP extensions
|
||||
echo "Required PHP Extensions:"
|
||||
php -m | grep -E 'FFI|gmp|protobuf|zip'
|
||||
echo ""
|
||||
|
||||
# Verify critical extensions
|
||||
REQUIRED_EXTS=("FFI" "gmp" "protobuf" "zip")
|
||||
MISSING_EXTS=()
|
||||
|
||||
for ext in "${REQUIRED_EXTS[@]}"; do
|
||||
if ! php -m | grep -q "$ext"; then
|
||||
MISSING_EXTS+=("$ext")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#MISSING_EXTS[@]} -gt 0 ]; then
|
||||
echo "ERROR: Missing required PHP extensions: ${MISSING_EXTS[*]}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install composer dependencies if needed
|
||||
cd /var/www/echo
|
||||
composer install --no-dev --optimize-autoloader
|
||||
|
||||
# Start server
|
||||
echo "Starting Echo Server..."
|
||||
|
||||
# Set up logging
|
||||
LOG_FILE="/var/log/echo/$(date +%Y%m%d-%H%M%S).log"
|
||||
touch "$LOG_FILE"
|
||||
chown www-data:www-data "$LOG_FILE"
|
||||
|
||||
# Start server as www-data user
|
||||
echo "Starting PHP server..."
|
||||
exec su -s /bin/sh www-data -c "cd /var/www/echo && php server.php > \"$LOG_FILE\" 2>&1"
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
// WebRTC variables
|
||||
let localStream;
|
||||
let peerConnection;
|
||||
let dataChannel;
|
||||
const signaling = new RTCSignaling();
|
||||
|
||||
|
||||
// DOM elements
|
||||
const localVideo = document.getElementById('localVideo');
|
||||
const remoteVideo = document.getElementById('remoteVideo');
|
||||
const localAudio = document.getElementById('localAudio');
|
||||
const remoteAudio = document.getElementById('remoteAudio');
|
||||
const localDataText = document.getElementById('localDataText');
|
||||
const remoteDataText = document.getElementById('remoteDataText');
|
||||
const startButton = document.getElementById('startButton');
|
||||
const connectButton = document.getElementById('connectButton');
|
||||
const hangupButton = document.getElementById('hangupButton');
|
||||
const sendLocalDataBtn = document.getElementById('sendLocalData');
|
||||
const clearLocalDataBtn = document.getElementById('clearLocalData');
|
||||
const clearRemoteDataBtn = document.getElementById('clearRemoteData');
|
||||
|
||||
// Configuration for ICE servers
|
||||
const configuration = {
|
||||
sdpSemantics: 'unified-plan',
|
||||
// iceServers: [{urls: 'stun:stun.l.google.com:19302'}],
|
||||
// iceTransportPolicy: 'all'
|
||||
};
|
||||
|
||||
// Button event listeners
|
||||
startButton.addEventListener('click', startStream);
|
||||
connectButton.addEventListener('click', connectPeers);
|
||||
hangupButton.addEventListener('click', hangUp);
|
||||
sendLocalDataBtn.addEventListener('click', sendData);
|
||||
clearLocalDataBtn.addEventListener('click', () => localDataText.value = '');
|
||||
clearRemoteDataBtn.addEventListener('click', () => remoteDataText.value = '');
|
||||
|
||||
// Start local stream
|
||||
async function startStream() {
|
||||
try {
|
||||
localStream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});
|
||||
localVideo.srcObject = localStream;
|
||||
localAudio.srcObject = localStream;
|
||||
|
||||
startButton.disabled = true;
|
||||
connectButton.disabled = false;
|
||||
|
||||
console.log('Local stream started');
|
||||
} catch (error) {
|
||||
console.error('Error starting local stream:', error);
|
||||
alert(`Error accessing media devices: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function createDatachannel() {
|
||||
// Set up data channel
|
||||
dataChannel = peerConnection.createDataChannel('echo');
|
||||
setupDataChannel(dataChannel);
|
||||
|
||||
// Listen for the data channel on the remote side
|
||||
peerConnection.ondatachannel = (event) => {
|
||||
const receiveChannel = event.channel;
|
||||
receiveChannel.onmessage = (event) => {
|
||||
remoteDataText.value += event.data + '\n';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function monitorStats() {
|
||||
// Handle ICE candidates
|
||||
peerConnection.onicecandidate = (event) => {
|
||||
console.log('ICE candidate event fired:', event);
|
||||
if (event.candidate) {
|
||||
console.log('ICE candidate:', event.candidate);
|
||||
} else {
|
||||
console.log('ICE gathering complete (null candidate)');
|
||||
}
|
||||
};
|
||||
|
||||
peerConnection.onicegatheringstatechange = () => {
|
||||
console.log('ICE gathering state changed to:', peerConnection.iceGatheringState);
|
||||
|
||||
// Check if we're seeing any state changes at all
|
||||
if (peerConnection.iceGatheringState === 'gathering') {
|
||||
console.log('ICE gathering has started');
|
||||
}
|
||||
|
||||
if (peerConnection.iceGatheringState === 'complete') {
|
||||
console.log('ICE gathering is complete');
|
||||
}
|
||||
};
|
||||
|
||||
// Handle connection state changes
|
||||
peerConnection.onconnectionstatechange = () => {
|
||||
console.log('Connection state:', peerConnection.connectionState);
|
||||
};
|
||||
|
||||
// Handle signaling state changes
|
||||
peerConnection.onsignalingstatechange = () => {
|
||||
console.log('Signaling state:', peerConnection.signalingState);
|
||||
};
|
||||
}
|
||||
|
||||
function handleTracks() {
|
||||
localStream.getTracks().forEach(track => {
|
||||
peerConnection.addTrack(track, localStream);
|
||||
});
|
||||
|
||||
// Handle receiving remote stream
|
||||
peerConnection.ontrack = (event) => {
|
||||
if (event.streams && event.streams[0]) {
|
||||
remoteVideo.srcObject = event.streams[0];
|
||||
remoteAudio.srcObject = event.streams[0];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Set up peer connection and data channel
|
||||
function connectPeers() {
|
||||
peerConnection = new RTCPeerConnection(configuration);
|
||||
|
||||
monitorStats()
|
||||
createDatachannel()
|
||||
handleTracks()
|
||||
createOffer();
|
||||
|
||||
connectButton.disabled = true;
|
||||
hangupButton.disabled = false;
|
||||
}
|
||||
|
||||
// Setup data channel and event handlers
|
||||
function setupDataChannel(channel) {
|
||||
channel.onopen = () => {
|
||||
console.log('Data channel opened');
|
||||
sendLocalDataBtn.disabled = false;
|
||||
};
|
||||
|
||||
channel.onclose = () => {
|
||||
console.log('Data channel closed');
|
||||
sendLocalDataBtn.disabled = true;
|
||||
};
|
||||
|
||||
channel.onmessage = (event) => {
|
||||
console.log('Received message:', event.data);
|
||||
remoteDataText.value += event.data + '\n';
|
||||
};
|
||||
|
||||
channel.onerror = (error) => {
|
||||
console.error('Data channel error:', error);
|
||||
};
|
||||
}
|
||||
|
||||
async function completeIceGathering() {
|
||||
return new Promise((resolve) => {
|
||||
if (peerConnection.iceGatheringState === 'complete') {
|
||||
resolve();
|
||||
} else {
|
||||
function checkState() {
|
||||
if (peerConnection.iceGatheringState === 'complete') {
|
||||
peerConnection.removeEventListener('icegatheringstatechange', checkState);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
peerConnection.addEventListener('icegatheringstatechange', checkState);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function createOffer() {
|
||||
return peerConnection.createOffer()
|
||||
.then((offer) => peerConnection.setLocalDescription(offer))
|
||||
.then(() => completeIceGathering())
|
||||
.then(() => signaling.request(peerConnection.localDescription))
|
||||
.then((answer) => peerConnection.setRemoteDescription(answer))
|
||||
.then(() => console.log('Created and set local offer'))
|
||||
.catch((e) => console.error('failed to create offer', e));
|
||||
}
|
||||
|
||||
// Send data over the data channel
|
||||
function sendData() {
|
||||
if (dataChannel && dataChannel.readyState === 'open') {
|
||||
const message = localDataText.value.trim();
|
||||
if (message) {
|
||||
dataChannel.send(message);
|
||||
localDataText.value = '';
|
||||
}
|
||||
} else {
|
||||
console.warn('Data channel not open');
|
||||
}
|
||||
}
|
||||
|
||||
// Hang up and clean resources
|
||||
function hangUp() {
|
||||
if (peerConnection) {
|
||||
peerConnection.close();
|
||||
peerConnection = null;
|
||||
}
|
||||
|
||||
if (dataChannel) {
|
||||
dataChannel.close();
|
||||
dataChannel = null;
|
||||
}
|
||||
|
||||
if (localStream) {
|
||||
localStream.getTracks().forEach(track => track.stop());
|
||||
localVideo.srcObject = null;
|
||||
localAudio.srcObject = null;
|
||||
}
|
||||
|
||||
remoteVideo.srcObject = null;
|
||||
remoteAudio.srcObject = null;
|
||||
|
||||
startButton.disabled = false;
|
||||
connectButton.disabled = true;
|
||||
hangupButton.disabled = true;
|
||||
|
||||
console.log('Connection closed');
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>WebRTC Echo Example</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css">
|
||||
<style>
|
||||
.stream-container {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.video-container {
|
||||
background-color: #f8f9fa;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
audio {
|
||||
display: none;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.btn-group {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.btn-back {
|
||||
text-decoration: none;
|
||||
color: #fff;
|
||||
background: #b7b7b7;
|
||||
padding: 11px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-5">
|
||||
<h1 class="text-center mb-4">WebRTC Echo Example</h1>
|
||||
<h4 class="text-left mb-4"><a href="/" class="btn-back">🔙 Back to examples</a></h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="stream-container">
|
||||
<h3>Local Stream</h3>
|
||||
<div class="video-container">
|
||||
<video id="localVideo" autoplay muted playsinline></video>
|
||||
</div>
|
||||
|
||||
<audio id="localAudio" controls muted></audio>
|
||||
|
||||
<div class="data-channel mt-4">
|
||||
<h5>Data Channel</h5>
|
||||
<div class="mb-3">
|
||||
<textarea id="localDataText" class="form-control" rows="4"
|
||||
placeholder="Type message to send to remote peer..."></textarea>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button id="sendLocalData" class="btn btn-primary">Send Message</button>
|
||||
<button id="clearLocalData" class="btn btn-secondary">Clear</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="stream-container">
|
||||
<h3>Remote Stream (Echo)</h3>
|
||||
<div class="video-container">
|
||||
<video id="remoteVideo" autoplay playsinline></video>
|
||||
</div>
|
||||
|
||||
<audio id="remoteAudio" controls></audio>
|
||||
|
||||
<div class="data-channel mt-4">
|
||||
<h5>Received Data</h5>
|
||||
<div class="mb-3">
|
||||
<textarea id="remoteDataText" class="form-control" rows="4"
|
||||
placeholder="Messages received will appear here..." readonly></textarea>
|
||||
</div>
|
||||
<button id="clearRemoteData" class="btn btn-secondary">Clear</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-12 text-center">
|
||||
<div class="btn-group">
|
||||
<button id="startButton" class="btn btn-success">Start Stream</button>
|
||||
<button id="connectButton" class="btn btn-primary" disabled>Connect</button>
|
||||
<button id="hangupButton" class="btn btn-danger" disabled>Hang Up</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
include '../footer.php'
|
||||
?>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
|
||||
<script type="application/javascript" src="signaling.global.js"></script>
|
||||
<script type="application/javascript" src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Webrtc\DataChannel\RTCDataChannel;
|
||||
use Webrtc\RTP\MediaStreamTrack\MediaStreamTrack;
|
||||
use Webrtc\SDP\RTCSessionDescription;
|
||||
use Webrtc\Signaling\Adapters\WebSocketSignalingAdapter;
|
||||
use Webrtc\Signaling\Request;
|
||||
use Webrtc\Signaling\RTCSignaling;
|
||||
use Webrtc\Webrtc\Enum\ConnectionState;
|
||||
use Webrtc\Webrtc\RTCPeerConnection;
|
||||
use function React\Async\async;
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
function createOffer(Request $request): void
|
||||
{
|
||||
// TODO: If you want to authorize user before accessing to the WebRTC
|
||||
// if ($request->getClientId() !== "SECRET_CLIENT_ID") {
|
||||
// $request->respondError("Your client doesn't have a permission to access this service", 403);
|
||||
// return;
|
||||
// }
|
||||
|
||||
async(function () use ($request) {
|
||||
$pc = new RTCPeerConnection();
|
||||
|
||||
$pc->on("datachannel", function (RTCDataChannel $channel) {
|
||||
$channel->on("message", function (string $message) use ($channel) {
|
||||
$channel->send($message);
|
||||
});
|
||||
});
|
||||
|
||||
$pc->on("connectionstatechange", function () use ($pc) {
|
||||
echo sprintf("connectionstatechange: %s\n", $pc->getConnectionState()->name);
|
||||
if ($pc->getConnectionState() === ConnectionState::failed) {
|
||||
$pc->close();
|
||||
}
|
||||
});
|
||||
|
||||
$pc->on("track", function (MediaStreamTrack $track) use ($pc) {
|
||||
// var_dump($track->getKind()->name . " => " . spl_object_id($track));
|
||||
$pc->addTrack($track);
|
||||
|
||||
// $event->track->on("ended", function () use ($pc) {
|
||||
// echo "track ended\n";
|
||||
// });
|
||||
});
|
||||
|
||||
$pc->setRemoteDescription($request->getOffer())
|
||||
->then(fn() => $pc->createAnswer())
|
||||
->then(fn(RTCSessionDescription $description) => $pc->setLocalDescription($description))
|
||||
->then(fn() => $request->sendOffer($pc->getLocalDescription()))
|
||||
->catch(fn(Throwable $e) => $request->respondError($e->getMessage(), 400));
|
||||
})();
|
||||
}
|
||||
|
||||
$adapter = new WebSocketSignalingAdapter();
|
||||
$signaling = new RTCSignaling($adapter);
|
||||
$signaling->onOfferRequest(fn(Request $request) => createOffer($request));
|
||||
$signaling->start();
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../node_modules/@protobufjs/aspromise/index.js","../node_modules/@protobufjs/base64/index.js","../node_modules/@protobufjs/eventemitter/index.js","../node_modules/@protobufjs/float/index.js","../node_modules/@protobufjs/inquire/index.js","../node_modules/@protobufjs/utf8/index.js","../node_modules/@protobufjs/pool/index.js","../node_modules/protobufjs/src/util/longbits.js","../node_modules/protobufjs/src/util/minimal.js","../node_modules/protobufjs/src/writer.js","../node_modules/protobufjs/src/writer_buffer.js","../node_modules/protobufjs/src/reader.js","../node_modules/protobufjs/src/reader_buffer.js","../node_modules/protobufjs/src/rpc/service.js","../node_modules/protobufjs/src/rpc.js","../node_modules/protobufjs/src/roots.js","../node_modules/protobufjs/src/index-minimal.js","../node_modules/@protobufjs/codegen/index.js","../node_modules/@protobufjs/fetch/index.js","../node_modules/@protobufjs/path/index.js","../node_modules/protobufjs/src/namespace.js","../node_modules/protobufjs/src/mapfield.js","../node_modules/protobufjs/src/method.js","../node_modules/protobufjs/src/service.js","../node_modules/protobufjs/src/message.js","../node_modules/protobufjs/src/decoder.js","../node_modules/protobufjs/src/verifier.js","../node_modules/protobufjs/src/converter.js","../node_modules/protobufjs/src/wrappers.js","../node_modules/protobufjs/src/type.js","../node_modules/protobufjs/src/root.js","../node_modules/protobufjs/src/util.js","../node_modules/protobufjs/src/types.js","../node_modules/protobufjs/src/field.js","../node_modules/protobufjs/src/oneof.js","../node_modules/protobufjs/src/object.js","../node_modules/protobufjs/src/enum.js","../node_modules/protobufjs/src/encoder.js","../node_modules/protobufjs/src/index-light.js","../node_modules/protobufjs/src/tokenize.js","../node_modules/protobufjs/src/parse.js","../node_modules/protobufjs/src/common.js","../node_modules/protobufjs/src/index.js","../node_modules/protobufjs/index.js","../src/index.ts","../src/RTCSignaling.ts","../proto/SignalProtocol.json"],"sourcesContent":["\"use strict\";\r\nmodule.exports = asPromise;\r\n\r\n/**\r\n * Callback as used by {@link util.asPromise}.\r\n * @typedef asPromiseCallback\r\n * @type {function}\r\n * @param {Error|null} error Error, if any\r\n * @param {...*} params Additional arguments\r\n * @returns {undefined}\r\n */\r\n\r\n/**\r\n * Returns a promise from a node-style callback function.\r\n * @memberof util\r\n * @param {asPromiseCallback} fn Function to call\r\n * @param {*} ctx Function context\r\n * @param {...*} params Function arguments\r\n * @returns {Promise<*>} Promisified function\r\n */\r\nfunction asPromise(fn, ctx/*, varargs */) {\r\n var params = new Array(arguments.length - 1),\r\n offset = 0,\r\n index = 2,\r\n pending = true;\r\n while (index < arguments.length)\r\n params[offset++] = arguments[index++];\r\n return new Promise(function executor(resolve, reject) {\r\n params[offset] = function callback(err/*, varargs */) {\r\n if (pending) {\r\n pending = false;\r\n if (err)\r\n reject(err);\r\n else {\r\n var params = new Array(arguments.length - 1),\r\n offset = 0;\r\n while (offset < params.length)\r\n params[offset++] = arguments[offset];\r\n resolve.apply(null, params);\r\n }\r\n }\r\n };\r\n try {\r\n fn.apply(ctx || null, params);\r\n } catch (err) {\r\n if (pending) {\r\n pending = false;\r\n reject(err);\r\n }\r\n }\r\n });\r\n}\r\n","\"use strict\";\r\n\r\n/**\r\n * A minimal base64 implementation for number arrays.\r\n * @memberof util\r\n * @namespace\r\n */\r\nvar base64 = exports;\r\n\r\n/**\r\n * Calculates the byte length of a base64 encoded string.\r\n * @param {string} string Base64 encoded string\r\n * @returns {number} Byte length\r\n */\r\nbase64.length = function length(string) {\r\n var p = string.length;\r\n if (!p)\r\n return 0;\r\n var n = 0;\r\n while (--p % 4 > 1 && string.charAt(p) === \"=\")\r\n ++n;\r\n return Math.ceil(string.length * 3) / 4 - n;\r\n};\r\n\r\n// Base64 encoding table\r\nvar b64 = new Array(64);\r\n\r\n// Base64 decoding table\r\nvar s64 = new Array(123);\r\n\r\n// 65..90, 97..122, 48..57, 43, 47\r\nfor (var i = 0; i < 64;)\r\n s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;\r\n\r\n/**\r\n * Encodes a buffer to a base64 encoded string.\r\n * @param {Uint8Array} buffer Source buffer\r\n * @param {number} start Source start\r\n * @param {number} end Source end\r\n * @returns {string} Base64 encoded string\r\n */\r\nbase64.encode = function encode(buffer, start, end) {\r\n var parts = null,\r\n chunk = [];\r\n Line truncated
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<footer class="bg-light text-center text-lg-start mt-5">
|
||||
<div class="container p-4">
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 mb-4 mb-md-0">
|
||||
<h5 class="text-uppercase">PHP WebRTC Examples</h5>
|
||||
<p>
|
||||
A collection of examples demonstrating various WebRTC capabilities using PHP backends.
|
||||
Each example contains detailed explanation and full source code.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-3 col-md-6 mb-4 mb-md-0">
|
||||
<h5 class="text-uppercase">Resources</h5>
|
||||
<ul class="list-unstyled mb-0">
|
||||
<li><a href="https://quasarstream.com/webrtc" class="text-dark">WebRTC Documentation</a></li>
|
||||
<li><a href="https://github.com/PHP-WebRTC" class="text-dark">GitHub Repository</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-3 col-md-6 mb-4 mb-md-0">
|
||||
<h5 class="text-uppercase">Get Help</h5>
|
||||
<ul class="list-unstyled mb-0">
|
||||
<li><a href="https://github.com/PHP-WebRTC/webrtc/issues" class="text-dark">Issues</a></li>
|
||||
<li><a href="https://quasarstream.com/webrtc?r=faq" class="text-dark">FAQ</a></li>
|
||||
<li><a href="https://quasarstream.com/contact" class="text-dark">Contact</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.05);">
|
||||
© 2025 <a href="https://www.quasarstream.com" class="text-dark">Quasar Stream</a>
|
||||
</div>
|
||||
</footer>
|
||||
@@ -0,0 +1,169 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>PHP WebRTC Examples Collection</title>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style>
|
||||
.card {
|
||||
height: 100%;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
.card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 10px 20px rgba(0,0,0,0.2);
|
||||
}
|
||||
.card-header {
|
||||
font-weight: bold;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
.example-link {
|
||||
text-decoration: none;
|
||||
}
|
||||
.jumbotron {
|
||||
background-color: #f8f9fa;
|
||||
padding: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
border-radius: 0.3rem;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-4">
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-4">PHP WebRTC Examples</h1>
|
||||
<p class="lead">A collection of practical WebRTC implementations using PHP backend</p>
|
||||
<hr class="my-4">
|
||||
<p>Explore various WebRTC functionalities through these interactive examples</p>
|
||||
</div>
|
||||
|
||||
<div class="row row-cols-1 row-cols-md-3 g-4">
|
||||
<div class="col">
|
||||
<a href="/echo" class="example-link">
|
||||
<div class="card">
|
||||
<div class="card-header">Echo Test</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">This example illustrates a basic audio/video echo where your own media stream is reflected back to you, demonstrating the core WebRTC media capture functionality.</p>
|
||||
<div class="d-flex justify-content-end">
|
||||
<small class="text-muted">View Example →</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">Peer Connection</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Demonstrates establishing a connection between two peers using WebRTC's RTCPeerConnection API with PHP signaling server implementation.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">Data Channel</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Shows how to establish a WebRTC data channel for peer-to-peer text messaging without going through a server after the initial connection setup.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">Screen Sharing</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Demonstrates how to capture and share your screen with other peers through WebRTC using a PHP signaling server.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">Video Room</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">A multi-user video conferencing room where multiple participants can join and communicate using WebRTC with PHP handling the signaling.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">File Transfer</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">This example shows how to transfer files directly between browsers using WebRTC data channels with PHP handling the initial connection.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">Audio Only Chat</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Demonstrates how to set up an audio-only communication channel between peers using WebRTC with PHP signaling.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">Media Recording</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Shows how to record WebRTC media streams on the client side and optionally upload the recordings to the PHP server.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<div class="card-header">PHP WebSocket Signaling</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">Implements a WebRTC connection with real-time signaling through PHP-based WebSockets using Ratchet or similar libraries.</p>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="badge bg-warning">Coming Soon</span>
|
||||
<small class="text-muted">Under Development</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
include 'footer.php';
|
||||
?>
|
||||
|
||||
<!-- Bootstrap JS Bundle with Popper -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.2/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,106 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "🔧 Updating system and installing base dependencies..."
|
||||
apt-get update && apt-get install -y \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
gnupg \
|
||||
autoconf \
|
||||
automake \
|
||||
build-essential \
|
||||
cmake \
|
||||
git \
|
||||
libtool \
|
||||
pkg-config \
|
||||
yasm \
|
||||
nasm \
|
||||
wget \
|
||||
unzip \
|
||||
curl \
|
||||
libzip-dev \
|
||||
libgmp-dev \
|
||||
libssl-dev \
|
||||
libsrtp2-dev \
|
||||
libx264-dev \
|
||||
libffi-dev \
|
||||
libprotobuf-dev \
|
||||
php-dev \
|
||||
php-pear \
|
||||
php-gmp \
|
||||
php-zip \
|
||||
php-ffi \
|
||||
php-cli \
|
||||
php-mbstring \
|
||||
php-curl \
|
||||
php-xml \
|
||||
php-bcmath \
|
||||
php-tokenizer \
|
||||
php-dom \
|
||||
php-pcov \
|
||||
php-sqlite3 \
|
||||
php-pdo \
|
||||
php-json \
|
||||
php-opcache \
|
||||
php-readline \
|
||||
php-soap \
|
||||
php-intl \
|
||||
php-exif \
|
||||
php-fileinfo \
|
||||
php-phar \
|
||||
php-fpm \
|
||||
php-common \
|
||||
php-iconv \
|
||||
php-posix \
|
||||
php-sockets \
|
||||
php-pcntl \
|
||||
python3 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
echo "✅ Base system dependencies installed."
|
||||
|
||||
echo "📦 Installing PHP Protobuf extension..."
|
||||
pecl install protobuf
|
||||
echo "extension=protobuf.so" > /etc/php/8.4/cli/conf.d/30-protobuf.ini
|
||||
echo "✅ Protobuf extension installed and enabled."
|
||||
|
||||
echo "⚙️ Enabling PHP FFI..."
|
||||
echo "ffi.enable=true" > /etc/php/8.4/cli/conf.d/30-ffi.ini
|
||||
echo "✅ FFI enabled."
|
||||
|
||||
echo "🎬 Building and installing FFmpeg 7.1.1..."
|
||||
cd /tmp
|
||||
wget https://ffmpeg.org/releases/ffmpeg-7.1.1.tar.bz2
|
||||
tar xjf ffmpeg-7.1.1.tar.bz2
|
||||
cd ffmpeg-7.1.1
|
||||
./configure --enable-shared --enable-gpl --enable-libx264 --enable-libopus --enable-libvpx
|
||||
make -j$(nproc)
|
||||
make install
|
||||
ldconfig
|
||||
cd /tmp && rm -rf ffmpeg-7.1.1*
|
||||
echo "✅ FFmpeg 7.1.1 installed."
|
||||
|
||||
echo "🎧 Building and installing libopus 1.4..."
|
||||
cd /tmp
|
||||
wget https://github.com/xiph/opus/releases/download/v1.4/opus-1.4.tar.gz
|
||||
tar xzvf opus-1.4.tar.gz
|
||||
cd opus-1.4
|
||||
./configure --prefix=/usr/local --enable-shared
|
||||
make -j$(nproc)
|
||||
make install
|
||||
ldconfig
|
||||
cd /tmp && rm -rf opus-1.3.1*
|
||||
echo "✅ libopus 1.3.1 installed."
|
||||
|
||||
echo "🎥 Building and installing libvpx 1.15.0..."
|
||||
cd /tmp
|
||||
wget https://github.com/webmproject/libvpx/archive/refs/tags/v1.15.0.tar.gz
|
||||
tar xzvf v1.15.0.tar.gz
|
||||
cd libvpx-1.15.0
|
||||
./configure --prefix=/usr/local --enable-shared --disable-examples
|
||||
make -j$(nproc)
|
||||
make install
|
||||
ldconfig
|
||||
cd /tmp && rm -rf libvpx-1.15.0*
|
||||
echo "✅ libvpx 1.15.0 installed."
|
||||
|
||||
echo "🎉 All dependencies installed successfully!"
|
||||
Reference in new issue
Block a user