openmeetings_gateway.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License") + you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. /**
  21. * @package chamilo.plugin.openmeetings
  22. */
  23. /**
  24. * Init
  25. */
  26. require_once ('openmeetings_rest_service.php');
  27. /**
  28. * Class OpenMeetingsGateway
  29. */
  30. class OpenMeetingsGateway
  31. {
  32. public $sessionId = "";
  33. public $config;
  34. private $rest;
  35. private $_user;
  36. private $_pass;
  37. private $_url;
  38. public function __construct($host, $user, $pass)
  39. {
  40. $this->_user = urlencode($user);
  41. $this->_pass = urlencode($pass);
  42. $this->_url = $host;
  43. if (substr($this->_url, -1, 1) == '/') {
  44. $this->_url = substr($this->_url, 0, -1);
  45. }
  46. $this->rest = new OpenMeetingsRestService();
  47. $err = $this->rest->getError();
  48. if ($err) {
  49. error_log('Constructor error: ' . $err);
  50. error_log('Debug: ' . $this->rest->getDebug());;
  51. exit();
  52. }
  53. }
  54. /**
  55. * @param string $name
  56. * @return string
  57. */
  58. public function getRestUrl($name)
  59. {
  60. return $this->getUrl() . "/services/" . $name . "/";
  61. }
  62. /**
  63. * @return string
  64. */
  65. public function getUrl()
  66. {
  67. return $this->_url;
  68. }
  69. /**
  70. * @param bool $in
  71. * @return string
  72. */
  73. public function var_to_str($in)
  74. {
  75. if (is_bool($in)) {
  76. return $in ? "true" : "false";
  77. } else {
  78. return $in;
  79. }
  80. }
  81. /**
  82. * TODO: Get Error Service and show detailed Error Message
  83. */
  84. public function loginUser()
  85. {
  86. $returnValue = 0;
  87. $response = $this->rest->call($this->getRestUrl("UserService") . "getSession", "session_id");
  88. if ($this->rest->getError()) {
  89. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($response, 1));
  90. } else {
  91. $err = $this->rest->getError();
  92. if ($err) {
  93. error_log('Error: ' . $err);
  94. } else {
  95. //error_log('getSession returned '.$response. ' - Storing as sessionId');
  96. $this->sessionId = $response;
  97. $url = $this->getRestUrl("UserService")
  98. . "loginUser?"
  99. . "SID=" . $this->sessionId
  100. . "&username=" . $this->_user
  101. . "&userpass=" . $this->_pass;
  102. $result = $this->rest->call($url);
  103. if ($this->rest->getError()) {
  104. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  105. } else {
  106. $err = $this->rest->getError();
  107. if ($err) {
  108. error_log('Error '. $err);
  109. } else {
  110. $returnValue = $result;
  111. }
  112. }
  113. }
  114. }
  115. if ($returnValue > 0) {
  116. return true;
  117. } else {
  118. return false;
  119. }
  120. }
  121. /**
  122. * @param Room $room
  123. * @return array|bool|int|null
  124. */
  125. public function updateRoomWithModeration($room)
  126. {
  127. $err = $this->rest->getError();
  128. if ($err) {
  129. error_log('Constructor error: ' . $err);
  130. error_log('Debug: ' . $this->rest->getDebug());
  131. exit();
  132. }
  133. $isModeratedRoom = false;
  134. if ($room->isModeratedRoom == 1) {
  135. $isModeratedRoom = true;
  136. }
  137. $url = $this->getRestUrl($this->getRestUrl("RoomService")
  138. . "updateRoomWithModeration?SID=" . $this->sessionId
  139. . "&room_id=" . $room->room_id
  140. . "&name=" . urlencode($room->name)
  141. . "&roomtypes_id=" . $room->roomtypes_id
  142. . "&comment=" . $room->comment
  143. . "&numberOfPartizipants=" . $room->numberOfPartizipants
  144. . "&ispublic=false"
  145. . "&appointment=false"
  146. . "&isDemoRoom=false"
  147. . "&demoTime=0"
  148. . "&isModeratedRoom=" . $this->var_to_str($isModeratedRoom));
  149. //error_log($url);
  150. $result = $this->rest->call($url);
  151. if ($result->fault) {
  152. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  153. } else {
  154. $err = $this->rest->getError();
  155. if ($err) {
  156. error_log('Error: ' . $err);
  157. } else {
  158. // echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
  159. //error_log('Room updated successfully '.print_r($result,1));
  160. return $result;
  161. }
  162. }
  163. return - 1;
  164. }
  165. /**
  166. * @param $username
  167. * @param $firstname
  168. * @param $lastname
  169. * @param $userId
  170. * @param $systemType
  171. * @param $recording_id
  172. * @return array|bool|int|null
  173. */
  174. public function setUserObjectAndGenerateRecordingHashByURL($username, $firstname, $lastname, $userId, $systemType, $recording_id)
  175. {
  176. $result = $this->rest->call($this->getRestUrl("UserService")
  177. . 'setUserObjectAndGenerateRecordingHashByURL?'
  178. . 'SID=' . $this->sessionId
  179. . '&username=' . urlencode($username)
  180. . '&firstname=' . urlencode($firstname)
  181. . '&lastname=' . urlencode($lastname)
  182. . '&externalUserId=' . $userId
  183. . '&externalUserType=' . urlencode($systemType)
  184. . '&recording_id=' . $recording_id, 'return');
  185. if ($result->fault) {
  186. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  187. } else {
  188. $err = $this->rest->getError();
  189. if ($err) {
  190. error_log('Error: '.$err);
  191. } else {
  192. return $result;
  193. }
  194. }
  195. return - 1;
  196. }
  197. /**
  198. * @param $username
  199. * @param $firstname
  200. * @param $lastname
  201. * @param $profilePictureUrl
  202. * @param $email
  203. * @param $userId
  204. * @param $systemType
  205. * @param $room_id
  206. * @param $becomeModerator
  207. * @param $allowRecording
  208. * @return array|bool|int|null
  209. */
  210. public function setUserObjectAndGenerateRoomHashByURLAndRecFlag($username, $firstname, $lastname, $profilePictureUrl, $email, $userId, $systemType, $room_id, $becomeModerator, $allowRecording)
  211. {
  212. $err = $this->rest->getError();
  213. if ($err) {
  214. error_log('Constructor error: ' . $err);
  215. error_log('Debug: ' . $this->rest->getDebug());;
  216. exit();
  217. }
  218. $result = $this->rest->call($this->getRestUrl("UserService")
  219. . "setUserObjectAndGenerateRoomHashByURLAndRecFlag?"
  220. . "SID=" . $this->sessionId
  221. . "&username=" . urlencode($username)
  222. . "&firstname=" . urlencode($firstname)
  223. . "&lastname=" . urlencode($lastname)
  224. . "&profilePictureUrl=" . urlencode($profilePictureUrl)
  225. . "&email=" . urlencode($email)
  226. . "&externalUserId=" . urlencode($userId)
  227. . "&externalUserType=" . urlencode($systemType)
  228. . "&room_id=" . urlencode($room_id)
  229. . "&becomeModeratorAsInt=" . $becomeModerator
  230. . "&showAudioVideoTestAsInt=1"
  231. . "&allowRecording=" . $this->var_to_str($allowRecording));
  232. if ($result->fault) {
  233. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
  234. } else {
  235. $err = $this->rest->getError();
  236. if ($err) {
  237. error_log('Error: '.$err);
  238. } else {
  239. // echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
  240. return $result;
  241. }
  242. }
  243. return - 1;
  244. }
  245. /**
  246. * @param Room $openmeetings
  247. * @return array|bool|int|null
  248. */
  249. public function deleteRoom($openmeetings)
  250. {
  251. $err = $this->rest->getError();
  252. if ($err) {
  253. error_log('Constructor error: ' . $err);
  254. error_log('Debug: ' . $this->rest->getDebug());
  255. exit();
  256. }
  257. $url = $this->getRestUrl("RoomService")."deleteRoom?SID=".$this->sessionId."&rooms_id=".$openmeetings->room_id;
  258. $result = $this->rest->call($url);
  259. if ($result->fault) {
  260. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
  261. } else {
  262. $err = $this->rest->getError();
  263. if ($err) {
  264. error_log('Error: '.$err);
  265. } else {
  266. // echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
  267. // return $result["return"];
  268. return $result;
  269. }
  270. }
  271. return - 1;
  272. }
  273. /**
  274. * Generate a new room hash for entering a conference room
  275. */
  276. public function setUserObjectAndGenerateRoomHash($username, $firstname, $lastname, $profilePictureUrl, $email, $externalUserId, $externalUserType, $room_id, $becomeModeratorAsInt, $showAudioVideoTestAsInt)
  277. {
  278. $result = $this->rest->call($this->getRestUrl("UserService")
  279. . "setUserObjectAndGenerateRoomHash?"
  280. . "SID=" . $this->sessionId
  281. . "&username=" . urlencode($username)
  282. . "&firstname=" . urlencode($firstname)
  283. . "&lastname=" . urlencode($lastname)
  284. . "&profilePictureUrl=" . urlencode($profilePictureUrl)
  285. . "&email=" . urlencode($email)
  286. . "&externalUserId=" . urlencode($externalUserId)
  287. . "&externalUserType=" . urlencode($externalUserType)
  288. . "&room_id=" . $room_id
  289. . "&becomeModeratorAsInt=" . $becomeModeratorAsInt
  290. . "&showAudioVideoTestAsInt=" . $showAudioVideoTestAsInt);
  291. if ($result->getError()) {
  292. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
  293. } else {
  294. $err = $this->rest->getError();
  295. if ($err) {
  296. error_log('Error: '.$err);
  297. } else {
  298. // echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
  299. return $result;
  300. }
  301. }
  302. return - 1;
  303. }
  304. /**
  305. * Create a new conference room
  306. * @param Room The room object
  307. * @return The REST call's result
  308. */
  309. public function createRoomWithModAndType($room)
  310. {
  311. $service = 'addRoomWithModerationAndExternalType';
  312. if ($room->allowRecording) {
  313. $service = 'addRoomWithModerationAndRecordingFlags';
  314. } elseif ($room->isAudioOnly) {
  315. $service = 'addRoomWithModerationExternalTypeAndAudioType';
  316. }
  317. $url = $this->getRestUrl("RoomService")
  318. . $service.'?'
  319. . 'SID=' . $room->SID
  320. . '&name=' . $room->name
  321. . '&roomtypes_id=' . $room->roomtypes_id
  322. . '&comment='. $room->comment
  323. . '&numberOfPartizipants=' . $room->numberOfPartizipants
  324. . '&ispublic=' . $this->var_to_str($room->ispublic)
  325. . '&appointment=' . $this->var_to_str($room->appointment)
  326. . '&isDemoRoom=' . $this->var_to_str($room->isDemoRoom)
  327. . '&demoTime=' . $room->demoTime
  328. . '&isModeratedRoom=' . $this->var_to_str($room->isModeratedRoom)
  329. . '&externalRoomType=' . $room->externalRoomType;
  330. if ($room->allowRecording) {
  331. $url .= '&allowUserQuestions=' . $this->var_to_str($room->allowUserQuestions)
  332. . '&isAudioOnly=' . $this->var_to_str($room->isAudioOnly)
  333. . '&waitForRecording=' . $this->var_to_str($room->waitForRecording)
  334. . '&allowRecording=' . $this->var_to_str($room->allowRecording);
  335. } elseif ($room->isAudioOnly) {
  336. $url .= '&isAudioOnly=' . $this->var_to_str($room->isAudioOnly);
  337. }
  338. $result = $this->rest->call($url);
  339. if ($this->rest->fault) {
  340. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result,1));
  341. } else {
  342. $err = $this->rest->getError();
  343. if ($err) {
  344. error_log('Error: '.$err);
  345. } else {
  346. //error_log('Creation of a new room succeeded: ID '.print_r($result,1));
  347. return $result;
  348. }
  349. }
  350. return -1;
  351. }
  352. /**
  353. * Gets the list of open rooms of type "Chamilo"
  354. * @param string $type The type of external system connecting to OpenMeetings
  355. * @return bool
  356. */
  357. public function getRoomsWithCurrentUsersByType($type = 'chamilolms')
  358. {
  359. //$this->loginUser();
  360. if (empty($this->sessionId)) {
  361. return false;
  362. }
  363. $url = $this->getRestUrl("RoomService") . "getRoomsWithCurrentUsersByListAndType?SID=" . $this->sessionId
  364. . "&start=1&max=1000&orderby=name&asc=true&externalRoomType=chamilolms";
  365. //$url = $this->getRestUrl("RoomService")
  366. // . "getRoomTypes?"
  367. // . "SID=" . $this->sessionId;
  368. //$url = $this->getRestUrl('JabberService') . 'getAvailableRooms?SID=' . $this->sessionId;
  369. //error_log(__FILE__.'+'.__LINE__.' Calling WS: '.$url);
  370. $result = $this->rest->call($url, "return");
  371. $rooms = array();
  372. foreach ($result as $room) {
  373. //error_log(__FILE__.'+'.__LINE__.': one room found on remote: '.print_r($room,1));
  374. if ($room['externalRoomType'] == $type && count($room['currentusers']) > 0 ) {
  375. $rooms[] = $room;
  376. }
  377. }
  378. return $result;
  379. }
  380. /**
  381. * Gets details of a remote room by room ID
  382. * @param int $roomId The ID of the room, as of plugin_openmeetings.room_id
  383. * @return mixed Room object
  384. */
  385. public function getRoomById($roomId = 0)
  386. {
  387. //$this->loginUser();
  388. if (empty($this->sessionId) or empty($roomId)) {
  389. return false;
  390. }
  391. $roomId = intval($roomId);
  392. $url = $this->getRestUrl("RoomService")
  393. . "getRoomById?"
  394. . "SID=" . $this->sessionId
  395. . "&rooms_id=".$roomId;
  396. //error_log(__FILE__.'+'.__LINE__.' Calling WS: '.$url);
  397. $result = $this->rest->call($url, "return");
  398. return $result;
  399. }
  400. /**
  401. * Get list of available recordings made by this instance
  402. */
  403. public function getRecordingsByExternalRooms()
  404. {
  405. $url = $this->getRestUrl("RoomService")
  406. . "getFlvRecordingByExternalRoomType?"
  407. . "SID=" . $this->sessionId
  408. . "&externalRoomType=" . urlencode($this->config["moduleKey"]);
  409. $result = $this->rest->call($url, "return");
  410. return $result;
  411. }
  412. /**
  413. * Get the recording from the room
  414. * @param int $id Room ID
  415. * @return array
  416. */
  417. public function getFlvRecordingByRoomId($id)
  418. {
  419. $url = $this->getRestUrl("RoomService")
  420. . "getFlvRecordingByRoomId?"
  421. . "SID=" . $this->sessionId
  422. . "&roomId=" . urlencode($id);
  423. $result = $this->rest->call($url, "return");
  424. return $result;
  425. }
  426. /**
  427. * Get list of available recordings made by user
  428. */
  429. public function getRecordingsByExternalUser($id)
  430. {
  431. $url = $this->getRestUrl("RoomService")
  432. . "getFlvRecordingByExternalUserId?"
  433. . "SID=" . $this->sessionId
  434. . "&externalUserId=" . $id;
  435. $result = $this->rest->call($url, "return");
  436. return $result;
  437. }
  438. }