createMeeting([ * 'title' => 'Client Video Call', * 'waiting_room_enabled' => true, * 'recording_enabled' => true * ]); * * // Generate embed token for iframe * $embed = $client->generateEmbedToken($meeting['data']['uuid'], 'Jane Doe', 'guest'); * echo $embed['embed_url']; */ class ScreenChirpClient { private $apiKey; private $baseUrl; private $timeout; public function __construct(string $apiKey, string $baseUrl = 'https://screenchirp.com/api/v1', int $timeout = 15) { $this->apiKey = trim($apiKey); $this->baseUrl = rtrim($baseUrl, '/'); $this->timeout = $timeout; } /** * Send HTTP request to Screen Chirp API */ private function request(string $method, string $path, array $data = [], array $queryParams = []): array { $url = $this->baseUrl . '/' . ltrim($path, '/'); if (!empty($queryParams)) { $url .= '?' . http_build_query($queryParams); } $ch = curl_init($url); $headers = [ 'Authorization: Bearer ' . $this->apiKey, 'Content-Type: application/json', 'Accept: application/json', 'User-Agent: ScreenChirp-PHP-SDK/1.0' ]; curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => $this->timeout, CURLOPT_HTTPHEADER => $headers, CURLOPT_CUSTOMREQUEST => strtoupper($method) ]); if (in_array(strtoupper($method), ['POST', 'PUT', 'PATCH']) && !empty($data)) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); } $response = curl_exec($ch); $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); if ($response === false) { throw new \RuntimeException('ScreenChirp API connection failed: ' . $error); } $decoded = json_decode($response, true); if ($statusCode >= 400) { $msg = $decoded['error'] ?? 'API error (HTTP ' . $statusCode . ')'; throw new \RuntimeException($msg, $statusCode); } return $decoded ?: []; } // ── Authentication & Ping ──────────────────────────────────────────────── public function ping(): array { return $this->request('GET', '/ping'); } // ── Meetings ───────────────────────────────────────────────────────────── public function listMeetings(array $filters = []): array { return $this->request('GET', '/meetings', [], $filters); } public function createMeeting(array $params = []): array { return $this->request('POST', '/meetings', $params); } public function getMeeting(string $uuid): array { return $this->request('GET', '/meetings/' . urlencode($uuid)); } public function updateMeeting(string $uuid, array $params = []): array { return $this->request('PATCH', '/meetings/' . urlencode($uuid), $params); } public function deleteMeeting(string $uuid): array { return $this->request('DELETE', '/meetings/' . urlencode($uuid)); } public function endMeeting(string $uuid): array { return $this->request('POST', '/meetings/' . urlencode($uuid) . '/end'); } public function lockMeeting(string $uuid, bool $lock = true): array { return $this->request('POST', '/meetings/' . urlencode($uuid) . '/lock', ['locked' => $lock]); } public function getMeetingCost(string $uuid): array { return $this->request('GET', '/meetings/' . urlencode($uuid) . '/cost'); } public function generateEmbedToken(string $uuid, string $userName, string $role = 'guest', array $options = []): array { $payload = array_merge([ 'user_name' => $userName, 'role' => $role ], $options); return $this->request('POST', '/meetings/' . urlencode($uuid) . '/embed-tokens', $payload); } public function generateJoinUrl(string $uuid, string $userName, string $role = 'guest'): array { return $this->request('POST', '/meetings/' . urlencode($uuid) . '/join-url', [ 'user_name' => $userName, 'role' => $role ]); } // ── Participants ───────────────────────────────────────────────────────── public function listParticipants(string $meetingUuid, string $status = 'all'): array { return $this->request('GET', '/meetings/' . urlencode($meetingUuid) . '/participants', [], ['status' => $status]); } public function admitParticipant(string $meetingUuid, int $participantId): array { return $this->request('POST', '/meetings/' . urlencode($meetingUuid) . '/participants/' . $participantId . '/admit'); } public function kickParticipant(string $meetingUuid, int $participantId): array { return $this->request('POST', '/meetings/' . urlencode($meetingUuid) . '/participants/' . $participantId . '/kick'); } // ── Chat (Chirps) ──────────────────────────────────────────────────────── public function listChirps(string $meetingUuid): array { return $this->request('GET', '/meetings/' . urlencode($meetingUuid) . '/chirps'); } public function sendChirp(string $meetingUuid, string $body, string $displayName = 'System'): array { return $this->request('POST', '/meetings/' . urlencode($meetingUuid) . '/chirps', [ 'body' => $body, 'display_name' => $displayName ]); } public function exportChirps(string $meetingUuid): array { return $this->request('GET', '/meetings/' . urlencode($meetingUuid) . '/chirps/export'); } // ── Meeting Decisions ──────────────────────────────────────────────────── public function listDecisions(string $meetingUuid): array { return $this->request('GET', '/meetings/' . urlencode($meetingUuid) . '/decisions'); } public function addDecision(string $meetingUuid, string $decisionText, string $category = 'general', string $authorName = 'API'): array { return $this->request('POST', '/meetings/' . urlencode($meetingUuid) . '/decisions', [ 'decision_text' => $decisionText, 'category' => $category, 'author_name' => $authorName ]); } public function deleteDecision(string $meetingUuid, int $decisionId): array { return $this->request('DELETE', '/meetings/' . urlencode($meetingUuid) . '/decisions/' . $decisionId); } // ── Action Items & Tasks ───────────────────────────────────────────────── public function listActionItems(string $meetingUuid): array { return $this->request('GET', '/meetings/' . urlencode($meetingUuid) . '/action-items'); } public function addActionItem(string $meetingUuid, string $title, ?string $assigneeName = null, ?string $dueDate = null): array { return $this->request('POST', '/meetings/' . urlencode($meetingUuid) . '/action-items', [ 'title' => $title, 'assignee_name' => $assigneeName, 'due_date' => $dueDate ]); } public function toggleActionItem(string $meetingUuid, int $itemId, string $status = 'completed'): array { return $this->request('PATCH', '/meetings/' . urlencode($meetingUuid) . '/action-items/' . $itemId, [ 'status' => $status ]); } // ── Smart Recaps & Summaries ───────────────────────────────────────────── public function getRecap(string $meetingUuid): array { return $this->request('GET', '/meetings/' . urlencode($meetingUuid) . '/recap'); } public function generateRecap(string $meetingUuid): array { return $this->request('POST', '/meetings/' . urlencode($meetingUuid) . '/recap/generate'); } // ── Recordings & Transcripts ───────────────────────────────────────────── public function listRecordings(array $filters = []): array { return $this->request('GET', '/recordings', [], $filters); } public function getRecording(int $recordingId): array { return $this->request('GET', '/recordings/' . $recordingId); } public function getTranscript(int $recordingId): array { return $this->request('GET', '/recordings/' . $recordingId . '/transcript'); } public function queueTranscription(int $recordingId): array { return $this->request('POST', '/recordings/' . $recordingId . '/transcribe'); } // ── Costs & Metered Usage ──────────────────────────────────────────────── public function getUsage(?string $startDate = null, ?string $endDate = null): array { $params = []; if ($startDate) $params['start_date'] = $startDate; if ($endDate) $params['end_date'] = $endDate; return $this->request('GET', '/costs/usage', [], $params); } public function getRates(): array { return $this->request('GET', '/costs/rates'); } // ── Webhooks ───────────────────────────────────────────────────────────── public function listWebhooks(): array { return $this->request('GET', '/webhooks'); } public function createWebhook(string $url, array $events, ?string $secret = null): array { $payload = [ 'url' => $url, 'events' => $events ]; if ($secret) $payload['secret'] = $secret; return $this->request('POST', '/webhooks', $payload); } public function deleteWebhook(int $webhookId): array { return $this->request('DELETE', '/webhooks/' . $webhookId); } public function testWebhook(int $webhookId): array { return $this->request('POST', '/webhooks/' . $webhookId . '/test'); } /** * Verify incoming HMAC-SHA256 signature from a Screen Chirp webhook */ public static function verifyWebhookSignature(string $rawPayload, string $signatureHeader, string $webhookSecret): bool { $computed = 'sha256=' . hash_hmac('sha256', $rawPayload, $webhookSecret); return hash_equals($computed, $signatureHeader); } }