-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add websocket server nodejs extension which depends on third-pa…
…rty packages (#504) * feat: add websocket server nodejs extension which depends on third-party packages * fix: avoid properties overwriten in http server nodejs extension * feat: add test case for mixing python and nodejs * fix: python dependency * fix: cleanup in the final stage of nodejs testing cases * fix: fix asan detect error * feat: add Python websocket extension and test case * fix: refine codes --------- Co-authored-by: Hu Yueh-Wei <[email protected]>
- Loading branch information
Showing
108 changed files
with
2,554 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
from . import main | ||
|
||
print("pil demo extension loaded") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
import("//build/feature/ten_package.gni") | ||
import("//build/ten_runtime/feature/publish.gni") | ||
import("//build/ten_runtime/glob.gni") | ||
import("//build/ten_runtime/options.gni") | ||
|
||
ten_package("simple_echo_python") { | ||
package_kind = "extension" | ||
|
||
resources = [ | ||
"__init__.py", | ||
"addon.py", | ||
"extension.py", | ||
"manifest.json", | ||
"property.json", | ||
"requirements.txt", | ||
] | ||
|
||
deps = [ "//core/src/ten_runtime" ] | ||
} | ||
|
||
if (ten_enable_ten_manager) { | ||
ten_package_publish("upload_simple_echo_python_to_server") { | ||
base_dir = | ||
rebase_path("${root_out_dir}/ten_packages/extension/simple_echo_python") | ||
deps = [ ":simple_echo_python" ] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright © 2025 Agora | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
from . import addon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
from ten import ( | ||
Addon, | ||
register_addon_as_extension, | ||
TenEnv, | ||
) | ||
from .extension import SimpleEchoExtension | ||
|
||
|
||
@register_addon_as_extension("simple_echo_python") | ||
class SimpleEchoExtensionAddon(Addon): | ||
def on_create_instance(self, ten_env: TenEnv, name: str, context) -> None: | ||
ten_env.on_create_instance_done(SimpleEchoExtension(name), context) |
102 changes: 102 additions & 0 deletions
102
packages/example_extensions/simple_echo_python/extension.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
from ten import ( | ||
AudioFrame, | ||
VideoFrame, | ||
AsyncExtension, | ||
AsyncTenEnv, | ||
Cmd, | ||
StatusCode, | ||
CmdResult, | ||
Data, | ||
) | ||
|
||
|
||
class SimpleEchoExtension(AsyncExtension): | ||
async def on_init(self, ten_env: AsyncTenEnv) -> None: | ||
ten_env.log_debug("on_init") | ||
|
||
async def on_start(self, ten_env: AsyncTenEnv) -> None: | ||
ten_env.log_debug("on_start") | ||
|
||
# TODO: read properties, initialize resources | ||
|
||
async def on_stop(self, ten_env: AsyncTenEnv) -> None: | ||
ten_env.log_debug("on_stop") | ||
|
||
# TODO: clean up resources | ||
|
||
async def on_deinit(self, ten_env: AsyncTenEnv) -> None: | ||
ten_env.log_debug("on_deinit") | ||
|
||
async def on_cmd(self, ten_env: AsyncTenEnv, cmd: Cmd) -> None: | ||
cmd_name = cmd.get_name() | ||
ten_env.log_debug("on_cmd name {}".format(cmd_name)) | ||
|
||
cmd_result = CmdResult.create(StatusCode.OK) | ||
cmd_result.set_property_string("detail", cmd_name + ", too") | ||
|
||
await ten_env.return_result(cmd_result, cmd) | ||
|
||
async def on_data(self, ten_env: AsyncTenEnv, data: Data) -> None: | ||
data_name = data.get_name() | ||
ten_env.log_debug("on_data name {}".format(data_name)) | ||
|
||
buf = data.get_buf() | ||
|
||
new_data = Data.create(data_name) | ||
new_data.alloc_buf(len(buf)) | ||
new_buf = new_data.lock_buf() | ||
new_buf[:] = buf | ||
new_data.unlock_buf(new_buf) | ||
|
||
await ten_env.send_data(new_data) | ||
|
||
async def on_audio_frame( | ||
self, ten_env: AsyncTenEnv, audio_frame: AudioFrame | ||
) -> None: | ||
audio_frame_name = audio_frame.get_name() | ||
ten_env.log_debug("on_audio_frame name {}".format(audio_frame_name)) | ||
|
||
buf = audio_frame.get_buf() | ||
new_audio_frame = AudioFrame.create(audio_frame_name) | ||
new_audio_frame.alloc_buf(len(buf)) | ||
new_buf = new_audio_frame.lock_buf() | ||
new_buf[:] = buf | ||
new_audio_frame.unlock_buf(new_buf) | ||
|
||
new_audio_frame.set_bytes_per_sample(audio_frame.get_bytes_per_sample()) | ||
new_audio_frame.set_sample_rate(audio_frame.get_sample_rate()) | ||
new_audio_frame.set_data_fmt(audio_frame.get_data_fmt()) | ||
new_audio_frame.set_eof(audio_frame.is_eof()) | ||
new_audio_frame.set_line_size(audio_frame.get_line_size()) | ||
new_audio_frame.set_number_of_channels( | ||
audio_frame.get_number_of_channels() | ||
) | ||
new_audio_frame.set_timestamp(audio_frame.get_timestamp()) | ||
|
||
await ten_env.send_audio_frame(new_audio_frame) | ||
|
||
async def on_video_frame( | ||
self, ten_env: AsyncTenEnv, video_frame: VideoFrame | ||
) -> None: | ||
video_frame_name = video_frame.get_name() | ||
ten_env.log_debug("on_video_frame name {}".format(video_frame_name)) | ||
|
||
buf = video_frame.get_buf() | ||
new_video_frame = VideoFrame.create(video_frame_name) | ||
new_video_frame.alloc_buf(len(buf)) | ||
new_buf = new_video_frame.lock_buf() | ||
new_buf[:] = buf | ||
new_video_frame.unlock_buf(new_buf) | ||
|
||
new_video_frame.set_eof(video_frame.is_eof()) | ||
new_video_frame.set_height(video_frame.get_height()) | ||
new_video_frame.set_width(video_frame.get_width()) | ||
new_video_frame.set_timestamp(video_frame.get_timestamp()) | ||
new_video_frame.set_pixel_fmt(video_frame.get_pixel_fmt()) | ||
|
||
await ten_env.send_video_frame(new_video_frame) |
13 changes: 13 additions & 0 deletions
13
packages/example_extensions/simple_echo_python/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"type": "extension", | ||
"name": "simple_echo_python", | ||
"version": "0.1.0", | ||
"dependencies": [ | ||
{ | ||
"type": "system", | ||
"name": "ten_runtime_python", | ||
"version": "0.6.0" | ||
} | ||
], | ||
"api": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Empty file.
32 changes: 32 additions & 0 deletions
32
packages/example_extensions/websocket_server_nodejs/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
import("//build/feature/ten_package.gni") | ||
import("//build/ten_runtime/feature/publish.gni") | ||
import("//build/ten_runtime/glob.gni") | ||
import("//build/ten_runtime/options.gni") | ||
|
||
ten_package("websocket_server_nodejs") { | ||
package_kind = "extension" | ||
|
||
resources = [ | ||
"BUILD.gn", | ||
"manifest.json", | ||
"package.json", | ||
"property.json", | ||
"src/index.ts", | ||
"tsconfig.json", | ||
] | ||
|
||
deps = [ "//core/src/ten_runtime" ] | ||
} | ||
|
||
if (ten_enable_ten_manager) { | ||
ten_package_publish("upload_websocket_server_nodejs_to_server") { | ||
base_dir = rebase_path( | ||
"${root_out_dir}/ten_packages/extension/websocket_server_nodejs") | ||
deps = [ ":websocket_server_nodejs" ] | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/example_extensions/websocket_server_nodejs/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright © 2025 Agora | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
23 changes: 23 additions & 0 deletions
23
packages/example_extensions/websocket_server_nodejs/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"type": "extension", | ||
"name": "websocket_server_nodejs", | ||
"version": "0.6.0", | ||
"dependencies": [ | ||
{ | ||
"type": "system", | ||
"name": "ten_runtime_nodejs", | ||
"version": "0.6.0" | ||
} | ||
], | ||
"package": { | ||
"include": [ | ||
"manifest.json", | ||
"property.json", | ||
"BUILD.gn", | ||
"src/**", | ||
"tsconfig.json", | ||
"package.json" | ||
] | ||
}, | ||
"api": {} | ||
} |
Oops, something went wrong.