LoginSignup
13
7

More than 1 year has passed since last update.

初心者でも安心。agora.io SDKでビデオ通話アプリの開発(WebRTC版)

Last updated at Posted at 2018-11-19

シンプルなビデオ通話の実装

利用SDK:AgoraVideoSDK for Web
SDKバージョン:3.1.2

SDKの入手

こちらからWebRTC用のSDKをダウンロードします。
サンプルコードも内包されています。
キャプチャ.PNG

FireFoxやChromeであれば直接index.htmlをブラウザで開くと動作確認ができます。
image.png

各種入力フォーム及びボタンの説明

App ID:ご利用のIDを入力します。
Channel:チャネル名を入力します。参加者同士が出会う為の部屋名のようなものです。
Host:自映像/音声を配信する場合はチェックします。
Join:チャネルに接続します。
Leave:チャネルから切断します。
Publish:自映像/音声を配信します。
Unpublish:自映像/音声を配信を停止します。チャネルには接続した状態です。

コードの説明

クライアントの生成

index.html
client = AgoraRTC.createClient({mode: 'live'});

クライアントの初期化

index.html
client.init(appId.value, function () {
//中略
}, function (err) {
});

チャネルへの接続

index.html
client.join(channel_key, channel.value, null, function(uid) {
//中略
}, function (err) {
});

ローカル映像の準備

index.html
localStream = AgoraRTC.createStream({streamID: uid, audio: true, cameraId: camera, microphoneId: microphone, video: document.getElementById("video").checked, screen: false});

ローカル映像の再生と配信

index.html
localStream.init(function() {
  localStream.play('agora_local');
  client.publish(localStream, function (err) {
  });
}, function (err) {
});

他拠点映像の再生

index.html
client.on('stream-added', function (evt) {
  client.subscribe(stream, function (err) {
  });
});

client.on('stream-subscribed', function (evt) {
  var stream = evt.stream;
  if ($('div#video #agora_remote'+stream.getId()).length === 0) {
    $('div#video').append('<div id="agora_remote'+stream.getId()+'" style="float:left; width:810px;height:607px;display:inline-block;"></div>');
  }
  stream.play('agora_remote' + stream.getId());
});

必要最低限の実装はこれだけです。
サーバを用意する必要はなく、これだけのコード量で低遅延のビデオ通話アプリが構築可能です。

[関連リンク]
クイックスタートガイドはありますか?
agora.ioサンプルコードのリポジトリはどこにありますか?
APIリファレンス、SDKはどこからダウンロードできますか?

最後に

agora.ioに関するお問い合わせはこちらから
スクリーンショット 0001-08-15 13.41.56.png

13
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
7