public function getLiveCourse() { $user = $this->controller->getUserByToken($this->request); if (!$user->isLogin()) { return $this->createErrorResponse('not_login', "您尚未登录!"); } $courseId = $this->getParam("courseId", 0); $lessonId = $this->getParam("lessonId", 0); $lesson = $this->controller->getCourseService()->getCourseLesson($courseId, $lessonId); $now = time(); $params = array(); $params['email'] = 'live-' . $user['id'] . '@edusoho.net'; $params['nickname'] = $user['nickname']; $params['sign'] = "c{$lesson['courseId']}u{$user['id']}t{$now}"; $params['sign'] .= 's' . $this->makeSign($params['sign']); $params['liveId'] = $lesson['mediaId']; $params['provider'] = $lesson["liveProvider"]; $params['role'] = 'student'; $params['user'] = $params['email']; $client = new EdusohoLiveClient(); if (isset($lesson['replayStatus']) && $lesson['replayStatus'] == 'generated') { $result = $client->entryReplay($params, 'root'); } else { $result = $client->getRoomUrl($params, 'root'); } return array('data' => array('lesson' => $lesson, 'result' => $result)); }
public function getClassroomUrlAction(Request $request, $courseId, $lessonId) { $user = $this->getCurrentUser(); if (!$user->isLogin()) { throw $this->createAccessDeniedException('尚未登入!'); } $lesson = $this->getCourseService()->getCourseLesson($courseId, $lessonId); if (empty($lesson)) { throw $this->createAccessDeniedException('课时不存在!'); } if (empty($lesson['mediaId'])) { // throw $this->createAccessDeniedException('直播教室不存在!'); } if ($lesson['startTime'] - time() > 7200) { throw $this->createAccessDeniedException('直播还没开始!'); } if ($lesson['endTime'] < time()) { throw $this->createAccessDeniedException('直播已结束!'); } $params = array('liveId' => $lesson['mediaId'], 'provider' => $lesson['liveProvider'], 'user' => $user['email'], 'nickname' => $user['nickname']); if ($this->getCourseService()->isCourseTeacher($courseId, $user['id'])) { $params['role'] = 'teacher'; } else { if ($this->getCourseService()->isCourseStudent($courseId, $user['id'])) { $params['role'] = 'student'; } else { throw $this->createAccessDeniedException('您不是课程学员,不能参加直播!'); } } $client = new EdusohoLiveClient(); $result = $client->getRoomUrl($params); if (empty($result) || isset($result['error'])) { return $this->createJsonResponse($result); } return $this->createJsonResponse(array('url' => $result['url'], 'param' => isset($result['param']) ? $result['param'] : null)); }