OSDN Git Service

SkyWayサンプルウィジェット追加。
authornaoki hirata <naoki@magic3.org>
Mon, 30 Apr 2018 14:16:03 +0000 (23:16 +0900)
committernaoki hirata <naoki@magic3.org>
Mon, 30 Apr 2018 14:16:03 +0000 (23:16 +0900)
include/sql/update_widgets.sql
widgets/skyway/admin/index.php [new file with mode: 0644]
widgets/skyway/images/icon32.png [new file with mode: 0644]
widgets/skyway/images/icon64.png [new file with mode: 0644]
widgets/skyway/include/container/admin_skywayWidgetContainer.php [new file with mode: 0644]
widgets/skyway/include/container/skywayWidgetContainer.php [new file with mode: 0644]
widgets/skyway/include/help/index.php [new file with mode: 0644]
widgets/skyway/include/template/admin.tmpl.html [new file with mode: 0644]
widgets/skyway/include/template/index.tmpl.html [new file with mode: 0644]
widgets/skyway/index.php [new file with mode: 0644]

index 9b6c19e..c98a472 100644 (file)
@@ -433,6 +433,10 @@ DELETE FROM _widgets WHERE wd_id = 'slogan';
 INSERT INTO _widgets\r
 (wd_id,   wd_name, wd_version, wd_params, wd_author,      wd_copyright, wd_license, wd_official_level, wd_description, wd_add_script_lib, wd_add_script_lib_a,   wd_has_admin, wd_enable_operation, wd_use_instance_def, wd_initialized, wd_release_dt, wd_install_dt, wd_create_dt) VALUES\r
 ('slogan', 'スローガン',  '1.1.0',    '',        'Naoki Hirata', 'Magic3.org', 'GPL',      10, 'ヘッダ等の前面にメッセージテキストを表示。レスポンシブウェブ対応。',                      'jquery.fittext',         '',        true,         false,                                true,                true,              '2014-08-09', now(),         now());\r
+DELETE FROM _widgets WHERE wd_id = 'skyway';\r
+INSERT INTO _widgets\r
+(wd_id,    wd_name,  wd_version, wd_author,      wd_copyright, wd_license, wd_official_level, wd_status, wd_description,             wd_has_admin, wd_use_instance_def, wd_initialized, wd_release_dt, wd_install_dt, wd_create_dt) VALUES\r
+('skyway', 'SkyWay', '1.0.0',    'Naoki Hirata', 'Magic3.org', 'GPL',      10,                1,         'SkyWayサンプルプログラム', true,         false,               true,           '2018-04-26',  now(),         now());\r
 \r
 -- ウィジェット情報(携帯用/メニュー)\r
 DELETE FROM _widgets WHERE wd_id = 'm/menu';\r
diff --git a/widgets/skyway/admin/index.php b/widgets/skyway/admin/index.php
new file mode 100644 (file)
index 0000000..71f86a6
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * ウィジェット呼び出し用ファイル
+ * index.php
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2007 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id: index.php 18 2007-11-13 10:13:30Z fishbone $
+ * @link       http://www.magic3.org
+ */
+// 直接アクセスの防止
+defined('M3_SYSTEM') or die('Access error: Direct access denied.');
+
+// ウィジェット実行
+global $gLaunchManager;
+$gLaunchManager->goWidget(__FILE__);
+?>
diff --git a/widgets/skyway/images/icon32.png b/widgets/skyway/images/icon32.png
new file mode 100644 (file)
index 0000000..b42b32b
Binary files /dev/null and b/widgets/skyway/images/icon32.png differ
diff --git a/widgets/skyway/images/icon64.png b/widgets/skyway/images/icon64.png
new file mode 100644 (file)
index 0000000..3d9e5eb
Binary files /dev/null and b/widgets/skyway/images/icon64.png differ
diff --git a/widgets/skyway/include/container/admin_skywayWidgetContainer.php b/widgets/skyway/include/container/admin_skywayWidgetContainer.php
new file mode 100644 (file)
index 0000000..5cac483
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+/**
+ * コンテナクラス
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+require_once($gEnvManager->getContainerPath() .                        '/baseAdminWidgetContainer.php');
+
+class admin_skywayWidgetContainer extends BaseAdminWidgetContainer
+{
+       /**
+        * コンストラクタ
+        */
+       function __construct()
+       {
+               // 親クラスを呼び出す
+               parent::__construct();
+       }
+       /**
+        * テンプレートファイルを設定
+        *
+        * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
+        * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
+        * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
+        */
+       function _setTemplate($request, &$param)
+       {
+               return 'admin.tmpl.html';
+       }
+       /**
+        * テンプレートにデータ埋め込む
+        *
+        * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
+        * @param                                                               なし
+        */
+       function _assign($request, &$param)
+       {
+               $act = $request->trimValueOf('act');
+               if ($act == 'update'){          // 設定更新のとき
+                       $apiKey = $request->trimValueOf('item_apikey');                 // APIキー
+                       
+                       // 入力値のエラーチェック
+                       if ($this->getMsgCount() == 0){                 // エラーのないとき
+                               $paramObj = new stdClass;
+                               $paramObj->apiKey = $apiKey;                                            // APIキー
+                               $ret = $this->updateWidgetParamObj($paramObj);
+                               if ($ret){
+                                       $this->setMsg(self::MSG_GUIDANCE, 'データを更新しました');
+                               } else {
+                                       $this->setMsg(self::MSG_APP_ERR, 'データ更新に失敗しました');
+                               }
+                               $this->gPage->updateParentWindow();// 親ウィンドウを更新
+                       }
+               } else {                // 初期表示の場合
+                       // デフォルト値の設定
+                       $apiKey = '';                   // APIキー
+
+                       $paramObj = $this->getWidgetParamObj();
+                       if (!empty($paramObj)){
+                               $apiKey = $paramObj->apiKey;                    // APIキー
+                       }
+               }
+                       
+               // 画面に書き戻す
+               $this->tmpl->addVar("_widget", "apikey", $apiKey);                      // APIキー
+       }
+       /**
+        * テンプレートにデータ埋め込む
+        *
+        * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
+        * @return                                                              なし
+        */
+       function _postAssign($request, &$param)
+       {
+               // メニューバー、パンくずリスト作成(簡易版)
+               $this->createBasicConfigMenubar($request);
+       }
+}
+?>
diff --git a/widgets/skyway/include/container/skywayWidgetContainer.php b/widgets/skyway/include/container/skywayWidgetContainer.php
new file mode 100644 (file)
index 0000000..e6dda91
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * コンテナクラス
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+require_once($gEnvManager->getContainerPath() .                        '/baseWidgetContainer.php');
+class skywayWidgetContainer extends BaseWidgetContainer
+{
+       const DEFAULT_TITLE = 'SkyWayサンプル';                     // デフォルトのウィジェットタイトル
+       
+       /**
+        * コンストラクタ
+        */
+       function __construct()
+       {
+               // 親クラスを呼び出す
+               parent::__construct();
+       }
+       /**
+        * テンプレートファイルを設定
+        *
+        * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
+        * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
+        * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
+        */
+       function _setTemplate($request, &$param)
+       {
+               return 'index.tmpl.html';
+       }
+       /**
+        * テンプレートにデータ埋め込む
+        *
+        * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
+        * @param                                                               なし
+        */
+       function _assign($request, &$param)
+       {
+               // 設定値の取得
+               $apiKey = '';                           // APIキー
+               $paramObj = $this->getWidgetParamObj();
+               if (!empty($paramObj)){
+                       $apiKey = $paramObj->apiKey;                                            // APIキー
+               }
+               
+               $this->tmpl->addVar("_widget", "api_key", $apiKey);                             // APIキー
+       }
+       /**
+        * ウィジェットのタイトルを設定
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
+        * @return string                                               ウィジェットのタイトル名
+        */
+       function _setTitle($request, &$param)
+       {
+               return self::DEFAULT_TITLE;
+       }
+       /**
+        * JavascriptファイルをHTMLヘッダ部に設定
+        *
+        * JavascriptファイルをHTMLのheadタグ内に追加出力する。
+        * _assign()よりも後に実行される。
+        *
+        * @param RequestManager $request               HTTPリクエスト処理クラス
+        * @param object         $param                 任意使用パラメータ。
+        * @return string                                               Javascriptファイル。出力しない場合は空文字列を設定。
+        */
+       function _addScriptFileToHead($request, &$param)
+       {
+               $scriptUrl = '//cdn.webrtc.ecl.ntt.com/skyway-latest.js';
+               return $scriptUrl;
+       }
+}
+?>
diff --git a/widgets/skyway/include/help/index.php b/widgets/skyway/include/help/index.php
new file mode 100644 (file)
index 0000000..4dc88aa
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+/**
+ * ヘルプリソースファイル
+ * index.php
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id: index.php 1984 2009-06-15 09:07:38Z fishbone $
+ * @link       http://www.magic3.org
+ */
+// 直接アクセスの防止
+defined('M3_SYSTEM') or die('Access error: Direct access denied.');
+
+global $HELP;
+
+// ########## SkyWay項目一覧 ##########
+$HELP['untitledtask_apikey']['title'] = 'SkyWay APIキー';
+$HELP['untitledtask_apikey']['body'] = 'SkyWayに登録してAPIキー取得してください。(https://webrtc.ecl.ntt.com/signup.html)';
+?>
diff --git a/widgets/skyway/include/template/admin.tmpl.html b/widgets/skyway/include/template/admin.tmpl.html
new file mode 100644 (file)
index 0000000..1a2e0de
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * 表示データ作成用テンプレート(patTemplate)
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+<patTemplate:tmpl name="_widget">
+<script type="text/javascript">
+//<![CDATA[
+function updateItem(){
+       if (!window.confirm('設定を更新しますか?')) return false;
+       document.main.act.value = 'update';
+       document.main.submit();
+       return true;
+}
+$(function(){
+       // テーブル作成
+       m3SetConfigTable('mainconfig');
+});
+//]]>
+</script>
+<div class="m3config_container">
+<!-- m3:ErrorMessage -->
+<form method="post" name="main">
+<input type="hidden" name="act" />
+<h3 class="m3config_h">基本設定</h3>
+<table id="mainconfig">
+    <tbody>
+    <tr>
+           <th><span {_HELP_UNTITLEDTASK_APIKEY}>SkyWay APIキー</span></th>
+           <td><input type="text" name="item_apikey" value="{APIKEY}" maxlength="100" /></td>
+       </tr>
+    </tbody>
+</table>
+<div class="well m3config_update_buttons">
+<input type="button" class="button" onclick="updateItem();" value="更新" />
+</div>
+</form>
+</div>
+</patTemplate:tmpl>
diff --git a/widgets/skyway/include/template/index.tmpl.html b/widgets/skyway/include/template/index.tmpl.html
new file mode 100644 (file)
index 0000000..97d85e9
--- /dev/null
@@ -0,0 +1,204 @@
+/**
+ * \95\\8e¦\83f\81[\83^\8dì\90¬\97p\83e\83\93\83v\83\8c\81[\83g(patTemplate)
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     \95½\93c\92¼\8bB(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2018 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id$
+ * @link       http://www.magic3.org
+ */
+<patTemplate:tmpl name="_widget">
+<script type="text/javascript">
+//<![CDATA[
+$(function(){
+       window.__SKYWAY_KEY__ = '{API_KEY}';
+       
+  // Peer object
+  const peer = new Peer({
+    key:   window.__SKYWAY_KEY__,
+    debug: 3,
+  });
+
+  let localStream;
+  let existingCall;
+
+  peer.on('open', () => {
+    $('#my-id').text(peer.id);
+    step1();
+  });
+
+  // Receiving a call
+  peer.on('call', call => {
+    // Answer the call automatically (instead of prompting user) for demo purposes
+    call.answer(localStream);
+    step3(call);
+  });
+
+  peer.on('error', err => {
+    alert(err.message);
+    // Return to step 2 if error occurs
+    step2();
+  });
+
+  $('#make-call').on('submit', e => {
+    e.preventDefault();
+    // Initiate a call!
+    console.log($('#callto-id').val());
+    const call = peer.call($('#callto-id').val(), localStream);
+    step3(call);
+  });
+
+  $('#end-call').on('click', () => {
+    existingCall.close();
+    step2();
+  });
+
+  // Retry if getUserMedia fails
+  $('#step1-retry').on('click', () => {
+    $('#step1-error').hide();
+    step1();
+  });
+
+  // set up audio and video input selectors
+  const audioSelect = $('#audioSource');
+  const videoSelect = $('#videoSource');
+  const selectors = [audioSelect, videoSelect];
+
+  navigator.mediaDevices.enumerateDevices()
+    .then(deviceInfos => {
+      const values = selectors.map(select => select.val() || '');
+      selectors.forEach(select => {
+        const children = select.children(':first');
+        while (children.length) {
+          select.remove(children);
+        }
+      });
+
+      for (let i = 0; i !== deviceInfos.length; ++i) {
+        const deviceInfo = deviceInfos[i];
+        const option = $('<option>').val(deviceInfo.deviceId);
+
+        if (deviceInfo.kind === 'audioinput') {
+          option.text(deviceInfo.label ||
+            'Microphone ' + (audioSelect.children().length + 1));
+          audioSelect.append(option);
+        } else if (deviceInfo.kind === 'videoinput') {
+          option.text(deviceInfo.label ||
+            'Camera ' + (videoSelect.children().length + 1));
+          videoSelect.append(option);
+        }
+      }
+
+      selectors.forEach((select, selectorIndex) => {
+        if (Array.prototype.slice.call(select.children()).some(n => {
+          return n.value === values[selectorIndex];
+        })) {
+          select.val(values[selectorIndex]);
+        }
+      });
+
+      videoSelect.on('change', step1);
+      audioSelect.on('change', step1);
+    });
+
+  function step1() {
+    // Get audio/video stream
+    const audioSource = $('#audioSource').val();
+    const videoSource = $('#videoSource').val();
+    const constraints = {
+      audio: {deviceId: audioSource ? {exact: audioSource} : undefined},
+      video: {deviceId: videoSource ? {exact: videoSource} : undefined},
+    };
+
+    navigator.mediaDevices.getUserMedia(constraints).then(stream => {
+      $('#my-video').get(0).srcObject = stream;
+      localStream = stream;
+
+      if (existingCall) {
+        existingCall.replaceStream(stream);
+        return;
+      }
+
+      step2();
+    }).catch(err => {
+      $('#step1-error').show();
+      console.error(err);
+    });
+  }
+
+  function step2() {
+    $('#step1, #step3').hide();
+    $('#step2').show();
+    $('#callto-id').focus();
+  }
+
+  function step3(call) {
+    // Hang up on an existing call if present
+    if (existingCall) {
+      existingCall.close();
+    }
+    // Wait for stream on the call, then set peer video display
+    call.on('stream', stream => {
+      const el = $('#their-video').get(0);
+      el.srcObject = stream;
+      el.play();
+    });
+
+    // UI stuff
+    existingCall = call;
+    $('#their-id').text(call.remoteId);
+    call.on('close', step2);
+    $('#step1, #step2').hide();
+    $('#step3').show();
+  }
+});
+//]]>
+</script>
+  <!-- Video area -->
+<!--  <div class="pure-u-2-3" id="video-container">-->
+    <video id="their-video" autoplay playsinline></video>
+    <video id="my-video" muted="true" autoplay playsinline></video>
+<!--  </div>-->
+
+  <!-- Steps -->
+<!--  <div class="pure-u-1-3">
+    <h2>SkyWay Video Chat</h2>-->
+
+    <div class="select">
+      <label for="audioSource">Audio input source: </label><select id="audioSource"></select>
+    </div>
+
+    <div class="select">
+      <label for="videoSource">Video source: </label><select id="videoSource"></select>
+    </div>
+
+    <!-- Get local audio/video stream -->
+    <div id="step1">
+      <p>Please click `allow` on the top of the screen so we can access your webcam and microphone for calls.</p>
+      <div id="step1-error">
+        <p>Failed to access the webcam and microphone. Make sure to run this demo on an http server and click allow when asked for permission by the browser.</p>
+        <a href="#" class="pure-button pure-button-error" id="step1-retry">Try again</a>
+      </div>
+    </div>
+
+    <!-- Make calls to others -->
+    <div id="step2">
+      <p>Your id: <span id="my-id">...</span></p>
+      <p>Share this id with others so they can call you.</p>
+      <h3>Make a call</h3>
+      <form id="make-call" class="pure-form">
+        <input type="text" placeholder="Call user id..." id="callto-id">
+        <button href="#" class="pure-button pure-button-success" type="submit">Call</button>
+      </form>
+    </div>
+
+    <!-- Call in progress -->
+    <div id="step3">
+      <p>Currently in call with <span id="their-id">...</span></p>
+      <p><a href="#" class="pure-button pure-button-error" id="end-call">End call</a></p>
+    </div>
+<!--  </div>-->
+</patTemplate:tmpl>
\ No newline at end of file
diff --git a/widgets/skyway/index.php b/widgets/skyway/index.php
new file mode 100644 (file)
index 0000000..71f86a6
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * ウィジェット呼び出し用ファイル
+ * index.php
+ *
+ * PHP versions 5
+ *
+ * LICENSE: This source file is licensed under the terms of the GNU General Public License.
+ *
+ * @package    Magic3 Framework
+ * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
+ * @copyright  Copyright 2006-2007 Magic3 Project.
+ * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
+ * @version    SVN: $Id: index.php 18 2007-11-13 10:13:30Z fishbone $
+ * @link       http://www.magic3.org
+ */
+// 直接アクセスの防止
+defined('M3_SYSTEM') or die('Access error: Direct access denied.');
+
+// ウィジェット実行
+global $gLaunchManager;
+$gLaunchManager->goWidget(__FILE__);
+?>