yigit-serin / laravel-openvidu
Laravel客户端,用于从OpenVidu服务器控制视频通话。
1.1.4.6
2020-05-04 07:37 UTC
Requires
- php: ^7.1
- ext-json: *
- guzzlehttp/guzzle: ~6.0
- illuminate/cache: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/config: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/database: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/events: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/http: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/routing: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/support: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/translation: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
- illuminate/validation: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0
README
这是一个包装OpenVidu服务器REST API的Laravel包
安装
您可以通过Composer安装此包
composer require squareetlabs/laravel-openvidu
添加服务提供者与外观
对于Laravel 5.5+
添加包后,服务提供者和外观将自动发现。
对于Laravel旧版本
将ServiceProvider添加到config/app.php文件中的providers数组
SquareetLabs\LaravelOpenVidu\Providers\OpenViduServiceProvider::class,
将Facade添加到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 ] ...
如果您想调试从Guzzle客户端消耗OpenVidu API,请将debug设置为true
您还必须将openvidu缓存驱动程序添加到您的config/cache.php文件中
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- 强制某些用户取消发布流。
---------------------------------------------------------------------------------
Method: DELETE
---------------------------------------------------------------------------------
Route name: openvidu.sessions.session.forceUnpublish
---------------------------------------------------------------------------------
Uri: openvidu/session/{sessionId}/forceUnpublish/{streamId}
---------------------------------------------------------------------------------
Sample return:
'unpublished': true
7- 强制具有连接ID的用户离开会话
---------------------------------------------------------------------------------
Method: DELETE
---------------------------------------------------------------------------------
Route name: openvidu.sessions.session.forceDisconnect
---------------------------------------------------------------------------------
Uri: openvidu/session/{sessionId}/forceDisconnect/{connectionId}
---------------------------------------------------------------------------------
Sample return:
'disconnected': true
8- 优雅地关闭会话:取消发布所有流并驱逐每个
---------------------------------------------------------------------------------
Method: PATCH
---------------------------------------------------------------------------------
Route name: openvidu.sessions.session.close
---------------------------------------------------------------------------------
Uri: openvidu/session/{sessionId}/close
---------------------------------------------------------------------------------
Sample return:
'closed': true
9- 检查会话是否正在录制
--------------------------------------------------------------------------------- Method: GET|HEAD --------------------------------------------------------------------------------- Route name: openvidu.sessions.session.isBeingRecording --------------------------------------------------------------------------------- Uri: openvidu/session/{sessionId}/isBeingRecording --------------------------------------------------------------------------------- Sample return: 'isBeingRecording': true
10- 开始录制会话
---------------------------------------------------------------------------------
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"
}
}
11- 停止录制会话
---------------------------------------------------------------------------------
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"
}
}
12- 获取会话的录制
--------------------------------------------------------------------------------- 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" } }
13- 删除会话的录制
---------------------------------------------------------------------------------
Method: DELETE
---------------------------------------------------------------------------------
Route name: openvidu.recording.delete
---------------------------------------------------------------------------------
Uri: openvidu/recording/{recordingId}
---------------------------------------------------------------------------------
Returns nothing
使用OpenVidu外观
为新的或现有的会话创建令牌
use SquareetLabs\LaravelOpenVidu\Facades\OpenVidu; use SquareetLabs\LaravelOpenVidu\SessionProperties; 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();
强制某些用户取消发布流。
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; ... /** @var string */ $recordingName = "Recording of my session"; $recordingProperties = new RecordingProperties($customSessionId, true,true, $recordingName, OutputMode::INDIVIDUAL) $recording = OpenVidu::startRecording($customSessionId);
停止录制会话
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);
可用事件
在启动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 } }
最后,请记得将它们添加到您的 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', ], ... ];
OpenVidu
访问 OpenVidu 文档 获取更多信息。
支持
请随时在问题部分发布您的问题。
致谢
许可协议
MIT 许可协议(MIT)。请参阅 许可文件 获取更多信息。