From 9543b46dfbaaeaeb75a2f06a6819acf7d6d49c8e Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sat, 2 Nov 2024 10:15:22 +0100 Subject: [PATCH] Add RealtimeApi::socket() to access the underlying network socket --- ChangeLog.md | 2 ++ src/main/php/com/openai/realtime/RealtimeApi.class.php | 3 +++ src/test/php/com/openai/unittest/RealtimeApiTest.class.php | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 58d5682..cd6880e 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,8 @@ OpenAI APIs for XP ChangeLog ## ?.?.? / ????-??-?? +* Added `RealtimeApi::socket()` to access the underlying network socket + (@thekid) * Merged PR #17: Move the `Tools` class to the com.openai.tools package (@thekid) diff --git a/src/main/php/com/openai/realtime/RealtimeApi.class.php b/src/main/php/com/openai/realtime/RealtimeApi.class.php index 3fe2d61..8d63928 100644 --- a/src/main/php/com/openai/realtime/RealtimeApi.class.php +++ b/src/main/php/com/openai/realtime/RealtimeApi.class.php @@ -43,6 +43,9 @@ public function __construct($endpoint) { }); } + /** @return peer.Socket */ + public function socket() { return $this->ws->socket(); } + /** @param ?util.log.LogCategory $cat */ public function setTrace($cat) { $this->cat= $cat; diff --git a/src/test/php/com/openai/unittest/RealtimeApiTest.class.php b/src/test/php/com/openai/unittest/RealtimeApiTest.class.php index e42702a..8a6fbbd 100755 --- a/src/test/php/com/openai/unittest/RealtimeApiTest.class.php +++ b/src/test/php/com/openai/unittest/RealtimeApiTest.class.php @@ -2,6 +2,7 @@ use com\openai\realtime\RealtimeApi; use lang\IllegalStateException; +use peer\Socket; use test\{Assert, Expect, Test, Values}; class RealtimeApiTest { @@ -26,6 +27,11 @@ public function initially_not_connected() { Assert::false($c->connected()); } + #[Test] + public function socket_accessor() { + Assert::instance(Socket::class, (new RealtimeApi(self::URI))->socket()); + } + #[Test] public function connect() { $c= new RealtimeApi(new TestingSocket([self::SESSION_CREATED]));