定制 homedoctor-es/opentok-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

homedoctor-es/opentok-laravel

最新稳定版本:v3.0.0

Composer 安装命令:

composer require homedoctor-es/opentok-laravel

包简介

A laravel bundle for the OpenTok PHP SDK

README 文档

README

This is a Laravel 8 wrapper library for the OpenTok SDK. OpenTok is a product by TokBox which utilizes WebRTC to enable peer to peer video, audio and messaging. Please note: this repository is in NO WAY associated with TokBox.

Installation

To get the latest version of OpenTok Laravel, simply require the project using Composer:

$ composer homedoctor-es/opentok-laravel

Instead, you may of course manually update your require block and run composer update if you so choose:

{
	"require": {
		"homedoctor-es/opentok-laravel": "^2.0"
	}
}

Once OpenTok Laravel is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.

  • HomedoctorEs\OpentokLaravel\ServiceProvider::class

You can register the OpentokApi facade in the aliases key of your config/app.php file if you like.

  • 'OpentokApi' => HomedoctorEs\OpentokLaravel\Facades\OpentokApi::class

Configuration

The defaults are set in `config/cors.php'. Copy this file to your own config directory to modify the values. You can publish the config using this command:

php artisan vendor:publish --provider="HomedoctorEs\OpentokLaravel\ServiceProvider"

Get your api_key and api_secret from your OpenTok account and replace the placeholders in your config file.

Before you dive in...

Although it's very tempting to dive straight in, to avoid frustration, I would highly recommend that you take a look at the Intro to OpenTok and also click around the site and read their docs. My documentation is terrible and only intended to make it easier to use for laravel developers and in no way is it a replacement for the OpenTok documentation (which is really good).

It's definitely a good idea to get to grips with the general flow, the technologies used and also their definitions e.g. session, publisher, subscriber, token etc.

General Usage

First you need to create a session so your subscribers and/or publishers have something to associate with

// new session
$session    = OpentokApi::createSession();
$sessionId  = $session->getSessionId();

// check if it's been created or not (could have failed)
if (empty($sessionId)) {
    throw new \Exception("An open tok session could not be created");
}

Now we need to create a token for your publisher to use so they can actually publish Please note that you will need to API key on the client side to use in the JS so something like this would be fine: (saves you hardcoding in your JS file or template)

// use the necessary files
use HomedoctorEs\OpentokLaravel\Facades\OpentokApi;
use OpenTok\Role;
use OpenTokException;

// get your API key from config
$api_key = Config::get('opentok.api_key');
        
// then create a token (session created in previous step)
try {
    // note we're create a publisher token here, for subscriber tokens we would specify.. yep 'subscriber' instead
    $token = OpentokApi::generateToken($sessionId,
        array(
            'role' => Role::PUBLISHER
        )
    );
} catch(OpenTokException $e) {
    // do something here for failure
}

// pass these to your view where you're broadcasting from as you'll need them...
return View::make('your/view')
    ->with('session_id', $sessionId)
    ->with('api_key', $api_key)
    ->with('token', $token)

For the JS/HTML etc. for publishing video/audio/messages please see the OpenTok Quick Start Guide and Documentation and take a browse around their How To examples etc. they're pretty good!

Hopefully you will find this library useful, if so please feel free to let me know, and feel free to drop any comments, questions or suggestions to improve!

统计信息

  • 总下载量: 3.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固