|null */ public function findBySource(string $app, string $entityId): ?array { try { $response = $this->client()->get('rooms/by-source', [ 'source_app' => $app, 'entity_id' => $entityId, 'owner_ref' => $this->ownerRef, ]); } catch (ConnectionException) { return null; } if ($response->status() === 404) { return null; } if ($response->failed()) { return null; } return (array) $response->json(); } /** * @param array $data * @return array */ public function upsertRoom(array $data): array { return $this->post('rooms', array_merge($data, [ 'owner_ref' => $this->ownerRef, 'host_user_ref' => $data['host_user_ref'] ?? $this->ownerRef, ])); } /** * @param array $data * @return array */ public function updateRoom(string $roomUuid, array $data): array { return $this->patch("rooms/{$roomUuid}", array_merge($data, [ 'owner_ref' => $this->ownerRef, 'host_user_ref' => $data['host_user_ref'] ?? $this->ownerRef, ])); } public function cancelRoom(string $roomUuid, ?string $hostUserRef = null): array { return $this->post("rooms/{$roomUuid}/cancel", [ 'owner_ref' => $this->ownerRef, 'host_user_ref' => $hostUserRef ?? $this->ownerRef, ]); } private function client(): PendingRequest { return Http::baseUrl((string) config('meet.url')) ->withToken((string) config('meet.key')) ->acceptJson() ->asJson() ->connectTimeout(10) ->timeout(20); } /** * @return array */ private function post(string $path, array $data): array { return $this->request('post', $path, $data); } /** * @return array */ private function patch(string $path, array $data): array { return $this->request('patch', $path, $data); } /** * @return array */ private function request(string $method, string $path, array $data): array { try { $response = $this->client()->{$method}($path, $data); } catch (ConnectionException) { throw new \RuntimeException('Could not reach the Meet service.'); } if ($response->failed()) { throw new \RuntimeException('Meet service error: '.($response->json('message') ?? $response->body())); } return (array) $response->json(); } }