openmeetings_gateway.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. $this->sessionId = $response;
  96. $url = $this->getRestUrl("UserService")
  97. . "loginUser?"
  98. . "SID=".$this->sessionId
  99. . "&username=".$this->_user
  100. . "&userpass=".$this->_pass;
  101. $result = $this->rest->call($url);
  102. if ($this->rest->getError()) {
  103. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  104. } else {
  105. $err = $this->rest->getError();
  106. if ($err) {
  107. error_log('Error '.$err);
  108. } else {
  109. $returnValue = $result;
  110. }
  111. }
  112. }
  113. }
  114. if ($returnValue > 0) {
  115. return true;
  116. } else {
  117. return false;
  118. }
  119. }
  120. /**
  121. * @param Room $room
  122. * @return array|bool|int|null
  123. */
  124. public function updateRoomWithModeration($room)
  125. {
  126. $err = $this->rest->getError();
  127. if ($err) {
  128. error_log('Constructor error: '.$err);
  129. error_log('Debug: '.$this->rest->getDebug());
  130. exit();
  131. }
  132. $isModeratedRoom = false;
  133. if ($room->isModeratedRoom == 1) {
  134. $isModeratedRoom = true;
  135. }
  136. $url = $this->getRestUrl($this->getRestUrl("RoomService")
  137. . "updateRoomWithModeration?SID=".$this->sessionId
  138. . "&room_id=".$room->room_id
  139. . "&name=".urlencode($room->name)
  140. . "&roomtypes_id=".$room->roomtypes_id
  141. . "&comment=".$room->comment
  142. . "&numberOfPartizipants=".$room->numberOfPartizipants
  143. . "&ispublic=false"
  144. . "&appointment=false"
  145. . "&isDemoRoom=false"
  146. . "&demoTime=0"
  147. . "&isModeratedRoom=".$this->var_to_str($isModeratedRoom));
  148. $result = $this->rest->call($url);
  149. if ($result->fault) {
  150. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  151. } else {
  152. $err = $this->rest->getError();
  153. if ($err) {
  154. error_log('Error: '.$err);
  155. } else {
  156. return $result;
  157. }
  158. }
  159. return -1;
  160. }
  161. /**
  162. * @param $username
  163. * @param $firstname
  164. * @param $lastname
  165. * @param $userId
  166. * @param $systemType
  167. * @param $recording_id
  168. * @return array|bool|int|null
  169. */
  170. public function setUserObjectAndGenerateRecordingHashByURL($username, $firstname, $lastname, $userId, $systemType, $recording_id)
  171. {
  172. $result = $this->rest->call($this->getRestUrl("UserService")
  173. . 'setUserObjectAndGenerateRecordingHashByURL?'
  174. . 'SID='.$this->sessionId
  175. . '&username='.urlencode($username)
  176. . '&firstname='.urlencode($firstname)
  177. . '&lastname='.urlencode($lastname)
  178. . '&externalUserId='.$userId
  179. . '&externalUserType='.urlencode($systemType)
  180. . '&recording_id='.$recording_id, 'return');
  181. if ($result->fault) {
  182. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  183. } else {
  184. $err = $this->rest->getError();
  185. if ($err) {
  186. error_log('Error: '.$err);
  187. } else {
  188. return $result;
  189. }
  190. }
  191. return -1;
  192. }
  193. /**
  194. * @param $username
  195. * @param $firstname
  196. * @param $lastname
  197. * @param $profilePictureUrl
  198. * @param $email
  199. * @param $userId
  200. * @param $systemType
  201. * @param $room_id
  202. * @param $becomeModerator
  203. * @param $allowRecording
  204. * @return array|bool|int|null
  205. */
  206. public function setUserObjectAndGenerateRoomHashByURLAndRecFlag($username, $firstname, $lastname, $profilePictureUrl, $email, $userId, $systemType, $room_id, $becomeModerator, $allowRecording)
  207. {
  208. $err = $this->rest->getError();
  209. if ($err) {
  210. error_log('Constructor error: '.$err);
  211. error_log('Debug: '.$this->rest->getDebug()); ;
  212. exit();
  213. }
  214. $result = $this->rest->call($this->getRestUrl("UserService")
  215. . "setUserObjectAndGenerateRoomHashByURLAndRecFlag?"
  216. . "SID=".$this->sessionId
  217. . "&username=".urlencode($username)
  218. . "&firstname=".urlencode($firstname)
  219. . "&lastname=".urlencode($lastname)
  220. . "&profilePictureUrl=".urlencode($profilePictureUrl)
  221. . "&email=".urlencode($email)
  222. . "&externalUserId=".urlencode($userId)
  223. . "&externalUserType=".urlencode($systemType)
  224. . "&room_id=".urlencode($room_id)
  225. . "&becomeModeratorAsInt=".$becomeModerator
  226. . "&showAudioVideoTestAsInt=1"
  227. . "&allowRecording=".$this->var_to_str($allowRecording));
  228. if ($result->fault) {
  229. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  230. } else {
  231. $err = $this->rest->getError();
  232. if ($err) {
  233. error_log('Error: '.$err);
  234. } else {
  235. // echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
  236. return $result;
  237. }
  238. }
  239. return -1;
  240. }
  241. /**
  242. * @param Room $openmeetings
  243. * @return array|bool|int|null
  244. */
  245. public function deleteRoom($openmeetings)
  246. {
  247. $err = $this->rest->getError();
  248. if ($err) {
  249. error_log('Constructor error: '.$err);
  250. error_log('Debug: '.$this->rest->getDebug());
  251. exit();
  252. }
  253. $url = $this->getRestUrl("RoomService")."deleteRoom?SID=".$this->sessionId."&rooms_id=".$openmeetings->room_id;
  254. $result = $this->rest->call($url);
  255. if ($result->fault) {
  256. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  257. } else {
  258. $err = $this->rest->getError();
  259. if ($err) {
  260. error_log('Error: '.$err);
  261. } else {
  262. // echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
  263. // return $result["return"];
  264. return $result;
  265. }
  266. }
  267. return -1;
  268. }
  269. /**
  270. * Generate a new room hash for entering a conference room
  271. */
  272. public function setUserObjectAndGenerateRoomHash($username, $firstname, $lastname, $profilePictureUrl, $email, $externalUserId, $externalUserType, $room_id, $becomeModeratorAsInt, $showAudioVideoTestAsInt)
  273. {
  274. $result = $this->rest->call($this->getRestUrl("UserService")
  275. . "setUserObjectAndGenerateRoomHash?"
  276. . "SID=".$this->sessionId
  277. . "&username=".urlencode($username)
  278. . "&firstname=".urlencode($firstname)
  279. . "&lastname=".urlencode($lastname)
  280. . "&profilePictureUrl=".urlencode($profilePictureUrl)
  281. . "&email=".urlencode($email)
  282. . "&externalUserId=".urlencode($externalUserId)
  283. . "&externalUserType=".urlencode($externalUserType)
  284. . "&room_id=".$room_id
  285. . "&becomeModeratorAsInt=".$becomeModeratorAsInt
  286. . "&showAudioVideoTestAsInt=".$showAudioVideoTestAsInt);
  287. if ($result->getError()) {
  288. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  289. } else {
  290. $err = $this->rest->getError();
  291. if ($err) {
  292. error_log('Error: '.$err);
  293. } else {
  294. // echo '<h2>Result</h2><pre>'; print_r($result["return"]); echo '</pre>';
  295. return $result;
  296. }
  297. }
  298. return -1;
  299. }
  300. /**
  301. * Create a new conference room
  302. * @param Room The room object
  303. * @return The REST call's result
  304. */
  305. public function createRoomWithModAndType($room)
  306. {
  307. $service = 'addRoomWithModerationAndExternalType';
  308. if ($room->allowRecording) {
  309. $service = 'addRoomWithModerationAndRecordingFlags';
  310. } elseif ($room->isAudioOnly) {
  311. $service = 'addRoomWithModerationExternalTypeAndAudioType';
  312. }
  313. $url = $this->getRestUrl("RoomService")
  314. . $service.'?'
  315. . 'SID='.$room->SID
  316. . '&name='.$room->name
  317. . '&roomtypes_id='.$room->roomtypes_id
  318. . '&comment='.$room->comment
  319. . '&numberOfPartizipants='.$room->numberOfPartizipants
  320. . '&ispublic='.$this->var_to_str($room->ispublic)
  321. . '&appointment='.$this->var_to_str($room->appointment)
  322. . '&isDemoRoom='.$this->var_to_str($room->isDemoRoom)
  323. . '&demoTime='.$room->demoTime
  324. . '&isModeratedRoom='.$this->var_to_str($room->isModeratedRoom)
  325. . '&externalRoomType='.$room->externalRoomType;
  326. if ($room->allowRecording) {
  327. $url .= '&allowUserQuestions='.$this->var_to_str($room->allowUserQuestions)
  328. . '&isAudioOnly='.$this->var_to_str($room->isAudioOnly)
  329. . '&waitForRecording='.$this->var_to_str($room->waitForRecording)
  330. . '&allowRecording='.$this->var_to_str($room->allowRecording);
  331. } elseif ($room->isAudioOnly) {
  332. $url .= '&isAudioOnly='.$this->var_to_str($room->isAudioOnly);
  333. }
  334. $result = $this->rest->call($url);
  335. if ($this->rest->fault) {
  336. error_log('Fault (Expect - The request contains an invalid SOAP body) '.print_r($result, 1));
  337. } else {
  338. $err = $this->rest->getError();
  339. if ($err) {
  340. error_log('Error: '.$err);
  341. } else {
  342. return $result;
  343. }
  344. }
  345. return -1;
  346. }
  347. /**
  348. * Gets the list of open rooms of type "Chamilo"
  349. * @param string $type The type of external system connecting to OpenMeetings
  350. * @return bool
  351. */
  352. public function getRoomsWithCurrentUsersByType($type = 'chamilolms')
  353. {
  354. //$this->loginUser();
  355. if (empty($this->sessionId)) {
  356. return false;
  357. }
  358. $url = $this->getRestUrl("RoomService")."getRoomsWithCurrentUsersByListAndType?SID=".$this->sessionId
  359. . "&start=1&max=1000&orderby=name&asc=true&externalRoomType=chamilolms";
  360. //$url = $this->getRestUrl("RoomService")
  361. // . "getRoomTypes?"
  362. // . "SID=" . $this->sessionId;
  363. //$url = $this->getRestUrl('JabberService') . 'getAvailableRooms?SID=' . $this->sessionId;
  364. $result = $this->rest->call($url, "return");
  365. $rooms = array();
  366. foreach ($result as $room) {
  367. if ($room['externalRoomType'] == $type && count($room['currentusers']) > 0) {
  368. $rooms[] = $room;
  369. }
  370. }
  371. return $result;
  372. }
  373. /**
  374. * Gets details of a remote room by room ID
  375. * @param int $roomId The ID of the room, as of plugin_openmeetings.room_id
  376. * @return mixed Room object
  377. */
  378. public function getRoomById($roomId = 0)
  379. {
  380. //$this->loginUser();
  381. if (empty($this->sessionId) or empty($roomId)) {
  382. return false;
  383. }
  384. $roomId = intval($roomId);
  385. $url = $this->getRestUrl("RoomService")
  386. . "getRoomById?"
  387. . "SID=".$this->sessionId
  388. . "&rooms_id=".$roomId;
  389. $result = $this->rest->call($url, "return");
  390. return $result;
  391. }
  392. /**
  393. * Get list of available recordings made by this instance
  394. */
  395. public function getRecordingsByExternalRooms()
  396. {
  397. $url = $this->getRestUrl("RoomService")
  398. . "getFlvRecordingByExternalRoomType?"
  399. . "SID=".$this->sessionId
  400. . "&externalRoomType=".urlencode($this->config["moduleKey"]);
  401. $result = $this->rest->call($url, "return");
  402. return $result;
  403. }
  404. /**
  405. * Get the recording from the room
  406. * @param int $id Room ID
  407. * @return array
  408. */
  409. public function getFlvRecordingByRoomId($id)
  410. {
  411. $url = $this->getRestUrl("RoomService")
  412. . "getFlvRecordingByRoomId?"
  413. . "SID=".$this->sessionId
  414. . "&roomId=".urlencode($id);
  415. $result = $this->rest->call($url, "return");
  416. return $result;
  417. }
  418. /**
  419. * Get list of available recordings made by user
  420. */
  421. public function getRecordingsByExternalUser($id)
  422. {
  423. $url = $this->getRestUrl("RoomService")
  424. . "getFlvRecordingByExternalUserId?"
  425. . "SID=".$this->sessionId
  426. . "&externalUserId=".$id;
  427. $result = $this->rest->call($url, "return");
  428. return $result;
  429. }
  430. }