|
1 | | -use deno_broadcast_channel::InMemoryBroadcastChannel; |
2 | 1 | use deno_core::{extension, Extension}; |
| 2 | +use deno_web::InMemoryBroadcastChannel; |
3 | 3 |
|
4 | 4 | use super::ExtensionTrait; |
5 | 5 |
|
6 | 6 | mod wrapper; |
7 | | -pub use wrapper::BroadcastChannelWrapper; |
| 7 | +pub use wrapper::{BroadcastChannel, BroadcastChannelWrapper}; |
8 | 8 |
|
9 | 9 | extension!( |
10 | 10 | init_broadcast_channel, |
11 | 11 | deps = [rustyscript], |
12 | 12 | esm_entry_point = "ext:init_broadcast_channel/init_broadcast_channel.js", |
13 | 13 | esm = [ dir "src/ext/broadcast_channel", "init_broadcast_channel.js" ], |
14 | 14 | ); |
| 15 | + |
| 16 | +extension!( |
| 17 | + deno_broadcast_channel, |
| 18 | + deps = [deno_web], |
| 19 | + esm = [ dir "src/ext/broadcast_channel", "01_broadcast_channel.js" ], |
| 20 | +); |
| 21 | + |
15 | 22 | impl ExtensionTrait<()> for init_broadcast_channel { |
16 | 23 | fn init((): ()) -> Extension { |
17 | 24 | init_broadcast_channel::init() |
18 | 25 | } |
19 | 26 | } |
20 | | -impl ExtensionTrait<InMemoryBroadcastChannel> for deno_broadcast_channel::deno_broadcast_channel { |
21 | | - fn init(channel: InMemoryBroadcastChannel) -> Extension { |
22 | | - deno_broadcast_channel::deno_broadcast_channel::init(channel) |
| 27 | + |
| 28 | +impl ExtensionTrait<()> for deno_broadcast_channel { |
| 29 | + fn init((): ()) -> Extension { |
| 30 | + deno_broadcast_channel::init() |
23 | 31 | } |
24 | 32 | } |
25 | 33 |
|
26 | | -pub fn extensions(channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> { |
| 34 | +// Note: broadcast_channel functionality is now integrated into deno_web |
| 35 | +// No separate initialization is needed as it's handled by deno_web extension |
| 36 | +pub fn extensions(_channel: InMemoryBroadcastChannel, is_snapshot: bool) -> Vec<Extension> { |
27 | 37 | vec![ |
28 | | - deno_broadcast_channel::deno_broadcast_channel::build(channel, is_snapshot), |
| 38 | + deno_broadcast_channel::build((), is_snapshot), |
29 | 39 | init_broadcast_channel::build((), is_snapshot), |
30 | 40 | ] |
31 | 41 | } |
32 | | - |
33 | | -#[cfg(test)] |
34 | | -mod test { |
35 | | - use deno_core::PollEventLoopOptions; |
36 | | - |
37 | | - use crate::{module, BroadcastChannelWrapper, Module, Runtime, RuntimeOptions}; |
38 | | - |
39 | | - static TEST_MOD: Module = module!( |
40 | | - "test.js", |
41 | | - " |
42 | | - const channel = new BroadcastChannel('my_channel'); |
43 | | - channel.onmessage = (event) => { |
44 | | - channel.postMessage('Received: ' + event.data); |
45 | | - }; |
46 | | - " |
47 | | - ); |
48 | | - |
49 | | - #[test] |
50 | | - fn test_broadcast_channel() { |
51 | | - let options = RuntimeOptions::default(); |
52 | | - let channel = options.extension_options.broadcast_channel.clone(); |
53 | | - |
54 | | - let mut runtime = Runtime::new(options).unwrap(); |
55 | | - let tokio_runtime = runtime.tokio_runtime(); |
56 | | - |
57 | | - let channel = BroadcastChannelWrapper::new(&channel, "my_channel").unwrap(); |
58 | | - |
59 | | - tokio_runtime |
60 | | - .block_on(runtime.load_module_async(&TEST_MOD)) |
61 | | - .unwrap(); |
62 | | - |
63 | | - channel.send_sync(&mut runtime, "foo").unwrap(); |
64 | | - |
65 | | - runtime |
66 | | - .block_on_event_loop( |
67 | | - PollEventLoopOptions::default(), |
68 | | - Some(std::time::Duration::from_secs(1)), |
69 | | - ) |
70 | | - .unwrap(); |
71 | | - |
72 | | - let value = channel |
73 | | - .recv_sync::<String>(&mut runtime, Some(std::time::Duration::from_secs(1))) |
74 | | - .unwrap() |
75 | | - .unwrap(); |
76 | | - |
77 | | - assert_eq!(value, "Received: foo"); |
78 | | - } |
79 | | -} |
0 commit comments