squareetlabs/laravel-openvidu

Laravel客户端,用于从OpenVidu服务器控制视频通话。

1.21 2021-12-09 10:37 UTC

This package is auto-updated.

Last update: 2024-09-09 16:47:45 UTC


README

Quality Score Build Status Code Intelligence Latest Stable Version Total Downloads License

这是一个封装OpenVidu服务器REST API的Laravel包

安装

您可以通过composer安装此包

composer require squareetlabs/laravel-openvidu

添加服务提供者和外观

对于Laravel 5.5+

一旦添加了包,服务提供者和外观将自动发现。

对于旧版本的Laravel

将服务提供者添加到config/app.php文件中的providers数组中

SquareetLabs\LaravelOpenVidu\Providers\OpenViduServiceProvider::class;

将外观添加到config/app.php文件中的aliases数组中

'OpenVidu' => SquareetLabs\LaravelOpenVidu\Facades\LaravelOpenVidu::class;

运行迁移

php artisan migrate

配置

将OpenVidu服务器配置值添加到您的config/services.php文件中

return [   
    ...
    'openvidu' => [
           'app' => env('OPENVIDU_APP'), //At the moment, always "OPENVIDUAPP"
           'domain' => env('OPENVIDU_DOMAIN'), //Your OpenVidu Server machine public IP
           'port' => env('OPENVIDU_PORT'), //Listening port of your OpenVidu server, default 4443
           'secret' => env('OPENVIDU_SECRET'), //The password used to secure your OpenVidu Server
           'debug' => env('OPENVIDU_DEBUG'), // true or false
           'use_routes' => env('OPENVIDU_USE_ROUTES') // true or false
       ]
    ...

如果您想从Guzzle客户端调试OpenVidu API消耗,请将debug设置为true

如果您不想使用默认定义的路由,请将use_routes设置为false

您还必须在config/cache.php文件中添加openvidu缓存驱动程序

return [   
    'stores' => [
            ...
            'openvidu' => [
                   'driver' => 'openvidu',
                   'table' => 'openvidu_cache'
               ]
    ]
    ...

用法

使用端点

LaravelOpenVidu非常易于使用。默认情况下,它公开13个不同的端点。
1- 为新会话或现有会话创建令牌
---------------------------------------------------------------------------------
Method:         POST
---------------------------------------------------------------------------------
Route name:     openvidu.token
---------------------------------------------------------------------------------
Uri:            openvidu/token 
---------------------------------------------------------------------------------
Body:           {
                    "session":{
                       "mediaMode":"MEDIA_MODE",
                       "recordingMode":"RECORDING_MODE",
                       "customSessionId":"CUSTOM_SESSION_ID",
                       "defaultOutputMode":"OUTPUT_MODE",
                       "defaultRecordingLayout":"RECORDING_LAYOUT",
                       "defaultCustomLayout":"CUSTOM_LAYOUT"
                    },
                    "tokenOptions":{
                       "role":"ROLE",
                       "data":"DATA"
                    }
                 }
---------------------------------------------------------------------------------
Sample return:
                 {
                    "token":{
                       "id":"wss://squareet.com:4443?sessionId=zfgmthb8jl9uellk&token=lnlrtnkwm4v8l7uc&role=PUBLISHER&turnUsername=FYYNRC&turnCredential=yfxxs3",
                       "session":"zfgmthb8jl9uellk",
                       "role":"PUBLISHER",
                       "data":"User Data",
                       "token":"wss://squareet.com:4443?sessionId=zfgmthb8jl9uellk&token=lnlrtnkwm4v8l7uc&role=PUBLISHER&turnUsername=FYYNRC&turnCredential=yfxxs3",
                       "kurentoOptions":{
                          "videoMaxSendBandwidth":700,
                          "allowedFilters":[
                             "GStreamerFilter",
                             "ZBarFilter"
                          ]
                       }
                    }
                }
2- 从存储在内存中的数组中获取现有会话
---------------------------------------------------------------------------------
Method:         GET|HEAD
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}
---------------------------------------------------------------------------------
Sample return:
                {
                   "session":{
                      "sessionId":"TestSession",
                      "createdAt":1538482606338,
                      "mediaMode":"ROUTED",
                      "recordingMode":"MANUAL",
                      "defaultOutputMode":"COMPOSED",
                      "defaultRecordingLayout":"BEST_FIT",
                      "customSessionId":"TestSession",
                      "connections":{
                         "numberOfElements":2,
                         "content":[
                            {
                               "connectionId":"vhdxz7abbfirh2lh",
                               "createdAt":1538482606412,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=2ezkertrimk6nttk&role=PUBLISHER&turnUsername=H0EQLL&turnCredential=kjh48u",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient1",
                               "publishers":[
                                  {
                                     "createdAt":1538482606976,
                                     "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                                     "mediaOptions":{
                                        "hasAudio":true,
                                        "audioActive":true,
                                        "hasVideo":true,
                                        "videoActive":true,
                                        "typeOfVideo":"CAMERA",
                                        "frameRate":30,
                                        "videoDimensions":"{\"width\":640,\"height\":480}",
                                        "filter":{
                   
                                        }
                                     }
                                  }
                               ],
                               "subscribers":[
                   
                               ]
                            },
                            {
                               "connectionId":"maxawd3ysuj1rxvq",
                               "createdAt":1538482607659,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=ovj1b4ysuqmcirti&role=PUBLISHER&turnUsername=INOAHN&turnCredential=oujrqd",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient2",
                               "publishers":[
                   
                               ],
                               "subscribers":[
                                  {
                                     "createdAt":1538482607799,
                                     "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                                     "publisher":"vhdxz7abbfirh2lh"
                                  }
                               ]
                            }
                         ]
                      },
                      "recording":false
                   }
               }
3- 从OpenVidu服务器获取现有会话
---------------------------------------------------------------------------------
Method:         GET|HEAD
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session.fetch
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}/fetch
---------------------------------------------------------------------------------
Sample return:
                {
                   "session":{
                      "sessionId":"TestSession",
                      "createdAt":1538482606338,
                      "mediaMode":"ROUTED",
                      "recordingMode":"MANUAL",
                      "defaultOutputMode":"COMPOSED",
                      "defaultRecordingLayout":"BEST_FIT",
                      "customSessionId":"TestSession",
                      "connections":{
                         "numberOfElements":2,
                         "content":[
                            {
                               "connectionId":"vhdxz7abbfirh2lh",
                               "createdAt":1538482606412,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=2ezkertrimk6nttk&role=PUBLISHER&turnUsername=H0EQLL&turnCredential=kjh48u",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient1",
                               "publishers":[
                                  {
                                     "createdAt":1538482606976,
                                     "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                                     "mediaOptions":{
                                        "hasAudio":true,
                                        "audioActive":true,
                                        "hasVideo":true,
                                        "videoActive":true,
                                        "typeOfVideo":"CAMERA",
                                        "frameRate":30,
                                        "videoDimensions":"{\"width\":640,\"height\":480}",
                                        "filter":{
                   
                                        }
                                     }
                                  }
                               ],
                               "subscribers":[
                   
                               ]
                            },
                            {
                               "connectionId":"maxawd3ysuj1rxvq",
                               "createdAt":1538482607659,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=ovj1b4ysuqmcirti&role=PUBLISHER&turnUsername=INOAHN&turnCredential=oujrqd",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient2",
                               "publishers":[
                   
                               ],
                               "subscribers":[
                                  {
                                     "createdAt":1538482607799,
                                     "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                                     "publisher":"vhdxz7abbfirh2lh"
                                  }
                               ]
                            }
                         ]
                      },
                      "recording":false
                   }
               }
4- 返回活动会话列表
---------------------------------------------------------------------------------
Method:         GET|HEAD
---------------------------------------------------------------------------------
Route name:     openvidu.sessions
---------------------------------------------------------------------------------
Uri:            openvidu/sessions
---------------------------------------------------------------------------------
Sample return:
                {
                    'sessions' : [
                      "sessionId":"TestSession",
                      "createdAt":1538482606338,
                      "mediaMode":"ROUTED",
                      "recordingMode":"MANUAL",
                      "defaultOutputMode":"COMPOSED",
                      "defaultRecordingLayout":"BEST_FIT",
                      "customSessionId":"TestSession",
                      "connections":{
                         "numberOfElements":2,
                         "content":[
                            {
                               "connectionId":"vhdxz7abbfirh2lh",
                               "createdAt":1538482606412,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=2ezkertrimk6nttk&role=PUBLISHER&turnUsername=H0EQLL&turnCredential=kjh48u",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient1",
                               "publishers":[
                                  {
                                     "createdAt":1538482606976,
                                     "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                                     "mediaOptions":{
                                        "hasAudio":true,
                                        "audioActive":true,
                                        "hasVideo":true,
                                        "videoActive":true,
                                        "typeOfVideo":"CAMERA",
                                        "frameRate":30,
                                        "videoDimensions":"{\"width\":640,\"height\":480}",
                                        "filter":{
                   
                                        }
                                     }
                                  }
                               ],
                               "subscribers":[
                   
                               ]
                            },
                            {
                               "connectionId":"maxawd3ysuj1rxvq",
                               "createdAt":1538482607659,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=ovj1b4ysuqmcirti&role=PUBLISHER&turnUsername=INOAHN&turnCredential=oujrqd",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient2",
                               "publishers":[
                   
                               ],
                               "subscribers":[
                                  {
                                     "createdAt":1538482607799,
                                     "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                                     "publisher":"vhdxz7abbfirh2lh"
                                  }
                               ]
                            }
                         ]
                      },
                      "recording":false
                   },
                    {
                      "sessionId":"TestSession2",
                      "createdAt":1538482606438,
                      "mediaMode":"ROUTED",
                      "recordingMode":"MANUAL",
                      "defaultOutputMode":"COMPOSED",
                      "defaultRecordingLayout":"BEST_FIT",
                      "customSessionId":"TestSession2",
                      "connections":{
                         "numberOfElements":2,
                         "content":[
                            {
                               "connectionId":"vhdxz7abbfirh2lh",
                               "createdAt":1538482606448,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=2ezkertrimk6nttk&role=PUBLISHER&turnUsername=H0EQLL&turnCredential=kjh48u",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient2",
                               "publishers":[
                                  {
                                     "createdAt":1538482606976,
                                     "streamId":"vhdxz7abbfiras_CAMERA_VAU",
                                     "mediaOptions":{
                                        "hasAudio":true,
                                        "audioActive":true,
                                        "hasVideo":true,
                                        "videoActive":true,
                                        "typeOfVideo":"CAMERA",
                                        "frameRate":30,
                                        "videoDimensions":"{\"width\":640,\"height\":480}",
                                        "filter":{
                   
                                        }
                                     }
                                  }
                               ],
                               "subscribers":[
                   
                               ]
                            },
                            {
                               "connectionId":"ssaxlfaslmcklasdcas",
                               "createdAt":1538482432559,
                               "location":"",
                               "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                               "token":"wss://:4443?sessionId=TestSession&token=ovj1b4ysuqmcirti&role=PUBLISHER&turnUsername=INOAHN&turnCredential=oujrqd",
                               "role":"PUBLISHER",
                               "serverData":"",
                               "clientData":"TestClient3",
                               "publishers":[
                   
                               ],
                               "subscribers":[
                                  {
                                     "createdAt":1538482607799,
                                     "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                                     "publisher":"vhdxz7abbfirh2lh"
                                  }
                               ]
                            }
                         ]
                      },
                      "recording":false
                   }
               }]
                 }
                    
5- 返回会话的活动连接列表
---------------------------------------------------------------------------------
Method:         GET|HEAD
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session.connections
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}/connections
---------------------------------------------------------------------------------
Sample return:
                [
                    {
                       "connectionId":"vhdxz7abbfirh2lh",
                       "createdAt":1538482606412,
                       "location":"",
                       "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                       "token":"wss://:4443?sessionId=TestSession&token=2ezkertrimk6nttk&role=PUBLISHER&turnUsername=H0EQLL&turnCredential=kjh48u",
                       "role":"PUBLISHER",
                       "serverData":"",
                       "clientData":"TestClient1",
                       "publishers":[
                          {
                             "createdAt":1538482606976,
                             "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                             "mediaOptions":{
                                "hasAudio":true,
                                "audioActive":true,
                                "hasVideo":true,
                                "videoActive":true,
                                "typeOfVideo":"CAMERA",
                                "frameRate":30,
                                "videoDimensions":"{\"width\":640,\"height\":480}",
                                "filter":{
           
                                }
                             }
                          }
                       ],
                       "subscribers":[
           
                       ]
                    },
                    {
                       "connectionId":"maxawd3ysuj1rxvq",
                       "createdAt":1538482607659,
                       "location":"",
                       "platform":"Chrome 69.0.3497.100 on Linux 64-bit",
                       "token":"wss://:4443?sessionId=TestSession&token=ovj1b4ysuqmcirti&role=PUBLISHER&turnUsername=INOAHN&turnCredential=oujrqd",
                       "role":"PUBLISHER",
                       "serverData":"",
                       "clientData":"TestClient2",
                       "publishers":[
           
                       ],
                       "subscribers":[
                          {
                             "createdAt":1538482607799,
                             "streamId":"vhdxz7abbfirh2lh_CAMERA_CLVAU",
                             "publisher":"vhdxz7abbfirh2lh"
                          }
                       ]
                    }
                 ]
                    
6- 允许发布流(目前只能为IPCAM)
---------------------------------------------------------------------------------
Method:         POST
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session.publish
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}/publish 
---------------------------------------------------------------------------------
Body:           {
                   "rtspUri":"rtsp://check.squareet.com:1935/live/sys3.stream",
                   "type":"IPCAM",
                   "adaptativeBitrate":true,
                   "onlyPlayWithSubscribers":true,
                   "data":"Reception room"
                 }
---------------------------------------------------------------------------------
Sample return:
                 {
                    "connection: {
                       "connectionId":"ipc_IPCAM_rtsp_A8MJ_91_191_213_49_554_live_mpeg4_sdp",
                       "createdAt":1538482432559,
                       "location":"unknown",
                       "platform":"IPCAM",
                       "token":undefined,
                       "role":"PUBLISHER",
                       "serverData":"Reception room",
                   
                       "publishers":[
                         {
                            "createdAt":1582121476439,
                            "streamId":"str_IPC_XC1W_ipc_IPCAM_rtsp_A8MJ_91_191_213_49_554_live_mpeg4_sdp",
                            "rtspUri":"rtsp://91.191.213.49:554/live_mpeg4.sdp",
                            "mediaOptions":{
                               "hasAudio":true,
                               "audioActive":true,
                               "hasVideo":true,
                               "videoActive":true,
                               "typeOfVideo":"IPCAM",
                               "frameRate":null,
                               "videoDimensions":null,
                               "filter":{
                                  
                               },
                               "adaptativeBitrate":true,
                               "onlyPlayWithSubscribers":true
                            }
                         }
                      ],
                      "subscribers":[
                         
                      ]
                    }
                }
7- 强制某些用户取消发布流。
---------------------------------------------------------------------------------
Method:         DELETE
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session.forceUnpublish
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}/forceUnpublish/{streamId}
---------------------------------------------------------------------------------
Sample return: 'unpublished': true
                    
8- 强制具有连接Id的用户离开会话
---------------------------------------------------------------------------------
Method:         DELETE
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session.forceDisconnect
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}/forceDisconnect/{connectionId}
---------------------------------------------------------------------------------
Sample return: 'disconnected': true
                    
9- 优雅地关闭会话:取消发布所有流并驱逐每个
---------------------------------------------------------------------------------
Method:         PATCH
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session.close
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}/close
---------------------------------------------------------------------------------
Sample return:  'closed': true
                    
10- 检查会话是否正在录制
---------------------------------------------------------------------------------
Method:         GET|HEAD
---------------------------------------------------------------------------------
Route name:     openvidu.sessions.session.isBeingRecording
---------------------------------------------------------------------------------
Uri:            openvidu/session/{sessionId}/isBeingRecording
---------------------------------------------------------------------------------
Sample return:  'isBeingRecording': true
                    
11- 开始录制会话
---------------------------------------------------------------------------------
Method:         POST
---------------------------------------------------------------------------------
Route name:     openvidu.recording.start 
---------------------------------------------------------------------------------
Uri:            openvidu/recording
---------------------------------------------------------------------------------
Body:
                {
                   "session":"SESSION_ID",
                   "name":"NAME",
                   "outputMode":"OUTPUT_MODE",
                   "hasAudio":"HAS_AUDIO",
                   "hasVideo":"HAS_VIDEO",
                   "resolution":"RESOLUTION",
                   "recordingLayout":"RECORDING_LAYOUT",
                   "customLayout":"CUSTOM_LAYOUT"
                }
---------------------------------------------------------------------------------
Sample return:
                {
                    "recording":{
                      "id":"fds4e07mdug1ga3h",
                      "sessionId":"fds4e07mdug1ga3h",
                      "name":"MyRecording",
                      "outputMode":"COMPOSED",
                      "hasAudio":true,
                      "hasVideo":false,
                      "createdAt":1538483606521,
                      "size":3205004,
                      "duration":12.92,
                      "url":null,
                      "status":"started"
                    }
                }
12- 停止录制会话
---------------------------------------------------------------------------------
Method:         POST
---------------------------------------------------------------------------------
Route name:     openvidu.recording.stop 
---------------------------------------------------------------------------------
Uri:            openvidu/recording/{recordingId}
---------------------------------------------------------------------------------
Sample return:
                {
                    "recording":{
                        "id":"fds4e07mdug1ga3h",
                        "sessionId":"fds4e07mdug1ga3h",
                        "name":"MyRecording",
                        "outputMode":"COMPOSED",
                        "hasAudio":true,
                        "hasVideo":false,
                        "createdAt":1538483606521,
                        "size":3205004,
                        "duration":12.92,
                        "url":null,
                        "status":"stopped"
                    }
                }
13- 获取会话的录制
---------------------------------------------------------------------------------
Method:         GET|HEAD
---------------------------------------------------------------------------------
Route name:     openvidu.recording 
---------------------------------------------------------------------------------
Uri:            openvidu/recording/{recordingId}
---------------------------------------------------------------------------------
Sample return:
                {
                   "recording":{
                       "id":"fds4e07mdug1ga3h",
                       "sessionId":"fds4e07mdug1ga3h",
                       "name":"MyRecording",
                       "outputMode":"COMPOSED",
                       "hasAudio":true,
                       "hasVideo":false,
                       "createdAt":1538483606521,
                       "size":3205004,
                       "duration":12.92,
                       "url":"https://squareet/recordings/{recordingId}/{name}.extension,
                       "status":"available"
                   }
               }
14- 删除会话的录制
---------------------------------------------------------------------------------
Method:         DELETE
---------------------------------------------------------------------------------
Route name:     openvidu.recording.delete 
---------------------------------------------------------------------------------
Uri:            openvidu/recording/{recordingId}
---------------------------------------------------------------------------------
Returns nothing
向会话发送信号
---------------------------------------------------------------------------------
Method:         POST
---------------------------------------------------------------------------------
Route name:     openvidu.sendsignal
---------------------------------------------------------------------------------
Uri:            openvidu/sendSignal
---------------------------------------------------------------------------------
Body:
                {
                   "session":"SESSION_ID",
                   "to":["connectionId1", "connectionId2"],
                   "type":"Test type",
                   "data":"This is my signal test data"
                }
---------------------------------------------------------------------------------
Sample return: "sent": true
           

使用OpenVidu外观

为新的或现有的会话创建令牌
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
use SquareetLabs\LaravelOpenVidu\SessionProperties;
use SquareetLabs\LaravelOpenVidu\Enums\MediaMode;
use SquareetLabs\LaravelOpenVidu\Enums\RecordingMode;
use SquareetLabs\LaravelOpenVidu\Enums\OutputMode;
use SquareetLabs\LaravelOpenVidu\Enums\RecordingLayout;
use Illuminate\Support\Str;
...
/** var string */
$customSessionId = Str::random(20);

$sessionProperties = new SessionProperties(MediaMode::ROUTED, RecordingMode::MANUAL, OutputMode::COMPOSED, RecordingLayout::BEST_FIT, $customSessionId);
$session = OpenVidu::createSession($sessionProperties);

$tokenOptions = new TokenOptions(OpenViduRole::PUBLISHER);
$token = $session->generateToken($tokenOptions);
获取所有活动会话
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
...
$session = OpenVidu::getActiveSessions();
获取现有会话
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
...
$session = OpenVidu::getSession($customSessionId);
获取会话的所有活动连接
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
...
$session = $session = OpenVidu::getSession($customSessionId);
$connections = $session->getActiveConnections();
关闭会话
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
...
$session = OpenVidu::getSession($customSessionId);
$closed = $session->close();
在会话上发布流(目前只能为IPCAM)
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
use SquareetLabs\LaravelOpenVidu\IPCameraOptions;
...
/** @var string */
$rtspUri = "rtsp://check.squareet.com:1935/live/sys3.stream";
/** @var string */
$type = "IPCAM";
/** @var bool */
$adaptativeBitrate = true;
/** @var bool */
$onlyPlayWithSubscribers = true;
/** @var string */
$data = "Reception room";
$ipCamera = new IPCameraOptions($rtspUri,$type,$adaptativeBitrate,$onlyPlayWithSubscribers,$data);
$session = OpenVidu::getSession($customSessionId);
$connection = $session->publish($ipCamera);
强制某些用户取消发布流。
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
...
$session = OpenVidu::getSession($customSessionId);
$unpublished = $session->forceUnpublish($streamId);
强制具有连接Id的用户离开会话。
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
...
$session = OpenVidu::getSession($customSessionId);
$disconnect = $session->forceDisconnect($connectionId);
检查会话是否正在录制
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
...
$session = OpenVidu::getSession($customSessionId);
$isBeingRecording = $session->isBeingRecording($connectionId);
开始录制会话
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
use SquareetLabs\LaravelOpenVidu\Enums\OutputMode;
use SquareetLabs\LaravelOpenVidu\RecordingProperties;
...
/** @var string */
$recordingName = "Recording of my session";
$recordingProperties = new RecordingProperties($customSessionId, $recordingName, OutputMode::INDIVIDUAL, RecordingLayout::BEST_FIT, '1920x1080', true, true, $customLayout)
$recording = OpenVidu::startRecording($recordingProperties);
停止录制会话
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
use SquareetLabs\LaravelOpenVidu\Enums\OutputMode;
...
$recording = OpenVidu::stopRecording($recordingId);
获取会话的录制
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
use SquareetLabs\LaravelOpenVidu\Enums\OutputMode;
...
$recording = OpenVidu::getRecording($recordingId);
删除会话的录制
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
use SquareetLabs\LaravelOpenVidu\Enums\OutputMode;
...
OpenVidu::deleteRecording($recordingId);
向会话发送信号
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu;
use SquareetLabs\LaravelOpenVidu\SignalProperties;
...
/** @var string */
$session = "SESSION_ID";
/** @var array */
$to = ["connectionId1", "connectionId2"];
/** @var string */
$type = "Test type";
/** @var string */
$data = "This is my signal test data";
$signalProperties = new SignalProperties($session,  $data, $type, $to);
$sent = OpenVidu::sendSignal($signalProperties);

可用事件

在启动OpenVidu服务器时,我们可以指示多个配置选项,其中一个选项是是否想使用webhook服务在端点接收事件。在我们的案例中,默认端点是'/openvidu/webhook'

事件ParticipantJoined在用户连接到会话时启动。使用示例
use SquareetLabs\LaravelOpenVidu\Events\ParticipantJoined;

class ParticipantJoinedListener
{
    /**
     * Handle the event.
     *
     * @param  ParticipantJoined  $event
     * @return void
     */
    public function handle(ParticipantJoined $event)
    {
        $event->sessionId;      // Session for which the event was triggered, a string with the session unique identifier
        $event->timestamp;      // Time when the event was triggered, UTC milliseconds
        $event->participantId;  // Identifier of the participant, a string with the participant unique identifier
        $event->platform;       // Complete description of the platform used by the participant to connect to the session
        $event->clientData;     // Additional data added client side while connecting to Session
        $event->serverData;     // Additional data added server side while generating Token
    }
}
事件ParticipantLeft在用户离开会话时启动。使用示例
use SquareetLabs\LaravelOpenVidu\Events\ParticipantLeft;

class ParticipantLeftListener
{
    /**
     * Handle the event.
     *
     * @param  ParticipantLeft  $event
     * @return void
     */
    public function handle(ParticipantLeft $event)
    {
        $event->sessionId;      // Session for which the event was triggered
        $event->timestamp;      // Time when the event was triggered
        $event->participantId;  // Identifier of the participant
        $event->platform;       // Complete description of the platform used by the participant to connect to the session
        $event->clientData;     // Additional data added client side while connecting to Session
        $event->serverData;     // Additional data added server side while generating Token
        $event->startTime;      // Time when the participant joined the session
        $event->duration;       // Total duration of the participant's connection to the session
        $event->reason;         // How the participant left the session.
    }
}
事件RecordingStatusChanged在录制状态改变时启动。状态可能是:已开始、已停止、就绪、失败。使用示例
use SquareetLabs\LaravelOpenVidu\Events\RecordingStatusChanged;

class RecordingStatusChangedListener
{
    /**
     * Handle the event.
     *
     * @param  RecordingStatusChanged  $event
     * @return void
     */
    public function handle(RecordingStatusChanged $event)
    {
       $event->sessionId;	    // Session for which the event was triggered
       $event->timestamp;	    // Time when the event was triggered
       $event->startTime;	    // Time when the recording started
       $event->id;	            // Unique identifier of the recording
       $event->name;	        // Name given to the recording file
       $event->outputMode;	    // Output mode of the recording
       $event->hasAudio;	    // Wheter the recording file has audio or not
       $event->hasVideo;	    // Wheter the recording file has video or not
       $event->recordingLayout;	// The type of layout used in the recording. Only defined if outputMode is COMPOSED and hasVideo is true
       $event->resolution;	    // Resolution of the recorded file. Only defined if outputMode is COMPOSED and hasVideo is true	
       $event->size;            // The size of the video file. 0 until status is stopped
       $event->duration;	    //  Duration of the video file. 0 until status is stopped
       $event->status;	        // Status of the recording
       $event->reason;	        // Why the recording stopped. Only defined when status is stopped or ready
    }
}
当创建新的会话时,会触发事件 SessionCreated。使用示例
use SquareetLabs\LaravelOpenVidu\Events\SessionCreated;

class SessionCreatedListener
{
    /**
     * Handle the event.
     *
     * @param  SessionCreated  $event
     * @return void
     */
    public function handle(SessionCreated $event)
    {
        $event->sessionId; // Session for which the event was triggered
        $event->timestamp; // Time when the event was triggered
    }
}
当会话结束时,会触发事件 SessionDestroyed。使用示例
use SquareetLabs\LaravelOpenVidu\Events\SessionDestroyed;

class SessionDestroyedListener
{
    /**
     * Handle the event.
     *
     * @param  SessionCreated  $event
     * @return void
     */
    public function handle(SessionDestroyed $event)
    {
        $event->sessionId;      // Session for which the event was triggered
        $event->timestamp;      // Time when the event was triggered
        $event->startTime;	    // Time when the session started
        $event->duration;	    // Total duration of the session
        $event->reason;	        // Why the session was destroyed
    }
}
当建立新的媒体流时,会触发事件 WebRTCConnectionCreated。可以是“INBOUND”连接(用户从会话的发布者接收流)或“OUTBOUND”连接(用户向会话发布流)。使用示例
use SquareetLabs\LaravelOpenVidu\Events\WebRTCConnectionCreated;

class WebRTCConnectionCreatedListener
{
    /**
     * Handle the event.
     *
     * @param  WebRTCConnectionCreated  $event
     * @return void
     */
    public function handle(WebRTCConnectionCreated $event)
    {
       $event->sessionId;        // Session for which the event was triggered
       $event->timestamp;        // Time when the event was triggered	UTC milliseconds
       $event->participantId;    // Identifier of the participant	
       $event->connection;       // Whether the media connection is an inbound connection (the participant is receiving media from OpenVidu) or an outbound connection (the participant is sending media to OpenVidu)	["INBOUND","OUTBOUND"]
       $event->receivingFrom;    // If connection is "INBOUND", the participant from whom the media stream is being received	
       $event->audioEnabled;     // Whether the media connection has negotiated audio or not
       $event->videoEnabled;     // Whether the media connection has negotiated video or not
       $event->videoSource;      // If videoEnabled is true, the type of video that is being transmitted
       $event->videoFramerate;   // If videoEnabled is true, the framerate of the transmitted video
       $event->videoDimensions;  // If videoEnabled is true, the dimensions transmitted video
    }
}
当任何媒体流连接关闭时,会触发事件 WebRTCConnectionCreated。使用示例
use SquareetLabs\LaravelOpenVidu\Events\WebRTCConnectionDestroyed;

class WebRTCConnectionDestroyedListener
{
    /**
     * Handle the event.
     *
     * @param  WebRTCConnectionDestroyed  $event
     * @return void
     */
    public function handle(WebRTCConnectionDestroyed $event)
    {
       $event->sessionId;        // Session for which the event was triggered
       $event->timestamp;        // Time when the event was triggered	UTC milliseconds
       $event->participantId;    // Identifier of the participant	
       $event->connection;       // Whether the media connection is an inbound connection (the participant is receiving media from OpenVidu) or an outbound connection (the participant is sending media to OpenVidu)	["INBOUND","OUTBOUND"]
       $event->receivingFrom;    // If connection is "INBOUND", the participant from whom the media stream is being received	
       $event->audioEnabled;     // Whether the media connection has negotiated audio or not
       $event->videoEnabled;     // Whether the media connection has negotiated video or not
       $event->videoSource;      // If videoEnabled is true, the type of video that is being transmitted
       $event->videoFramerate;   // If videoEnabled is true, the framerate of the transmitted video
       $event->videoDimensions;  // If videoEnabled is true, the dimensions transmitted video
       $event->startTime;        // Time when the media connection was established	UTC milliseconds
       $event->duration;         // Total duration of the media connection	Seconds
       $event->reason;           // How the WebRTC connection was destroyed
    }
}
当分发过滤事件时,会触发事件 FilterEventDispatched。只有当对流应用了过滤并添加了对过滤提供的特定事件的监听器时,此事件才会被触发。使用示例
use SquareetLabs\LaravelOpenVidu\Events\FilterEventDispatched;

class FilterEventDispatchedListener
{
    /**
     * Handle the event.
     *
     * @param  FilterEventDispatched  $event
     * @return void
     */
    public function handle(FilterEventDispatched $event)
    {
        $event->sessionId;      // Session for which the event was triggered
        $event->timestamp;      // Time when the event was triggered
        $event->participantId;	// Identifier of the participant
        $event->streamId;	    // Identifier of the stream for which the filter is applied
        $event->filterType;	    // Type of the filter applied to the stream
        $event->data;	        // Data of the filter event
    }
}

最后,请记得将它们添加到您的 EventServiceProvider

protected $listen = [
        ...
        'SquareetLabs\LaravelOpenVidu\Events\ParticipantJoined' => [
            'App\Listeners\ParticipantJoinedListener',
        ],
        'SquareetLabs\LaravelOpenVidu\Events\ParticipantLeft' => [
            'App\Listeners\ParticipantLeftListener',
        ],
        'SquareetLabs\LaravelOpenVidu\Events\RecordingStatusChanged' => [
            'App\Listeners\RecordingStatusChangedListener',
        ],
        'SquareetLabs\LaravelOpenVidu\Events\SessionCreated' => [
            'App\Listeners\SessionCreatedListener',
        ],
        'SquareetLabs\LaravelOpenVidu\Events\SessionDestroyed' => [
            'App\Listeners\SessionDestroyedListener',
        ],
        'SquareetLabs\LaravelOpenVidu\Events\WebRTCConnectionCreated' => [
            'App\Listeners\WebRTCConnectionCreatedListener',
        ],
        'SquareetLabs\LaravelOpenVidu\Events\WebRTCConnectionDestroyed' => [
            'App\Listeners\WebRTCConnectionDestroyedListener',
        ],
        'SquareetLabs\LaravelOpenVidu\Events\FilterEventDispatched' => [
            'App\Listeners\FilterEventDispatchedListener',
        ],
        ...
    ];

OpenVidu

访问 OpenVidu 文档 获取更多信息。

支持

您可以在问题部分自由发布您的问题。

鸣谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 获取更多信息。