diff --git a/ChangeLog.md b/ChangeLog.md index ff0ad54..64e6298 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,9 @@ OpenAI APIs for XP ChangeLog ## ?.?.? / ????-??-?? +* Added optional parameter *timeout* to receive() and transmit() methods + (@thekid) + ## 0.8.0 / 2024-11-02 * Made it possible to supply organization and project in OpenAI API URI diff --git a/src/main/php/com/openai/realtime/RealtimeApi.class.php b/src/main/php/com/openai/realtime/RealtimeApi.class.php index 8d63928..7b7b240 100644 --- a/src/main/php/com/openai/realtime/RealtimeApi.class.php +++ b/src/main/php/com/openai/realtime/RealtimeApi.class.php @@ -98,10 +98,11 @@ public function send($payload): void { /** * Receives an answer. Returns NULL if EOF is reached. * + * @param ?int|float $timeout * @return var */ - public function receive() { - $json= $this->ws->receive(); + public function receive($timeout= null) { + $json= $this->ws->receive($timeout); $this->cat && $this->cat->debug('<<<', $json); return null === $json ? null : $this->marshalling->unmarshal(Json::read($json)); } @@ -110,11 +111,12 @@ public function receive() { * Sends a given payload and returns the response to it. * * @param var $payload + * @param ?int|float $timeout * @return var */ - public function transmit($payload) { + public function transmit($payload, $timeout= null) { $this->send($payload); - return $this->receive(); + return $this->receive($timeout); } /** Ensures socket is closed */