pub struct OcreChannel { /* private fields */ }Expand description
The Durable Object class behind each realtime channel, exported by Ocre under the name OcreChannel.
One instance per channel name holds that channel’s WebSockets. It
accepts them with the WebSocket Hibernation API, so it is evicted from
memory between broadcasts while browsers stay connected (hibernated
sockets cost no duration), and it stores nothing but each socket’s
attachment (its identity and whether it may publish). What subscribers
send is ignored, or relayed to the others as JSON for sockets connected
with WebSocketUpgrade::rebroadcast;
it completes the closing handshakes browsers start. Apps never
call it directly: they use broadcast and
WebSocketUpgrade::connect.
Free plan: Durable Objects must be SQLite-backed (storage: "sqlite");
one object accepts up to 32,768 WebSockets. cloudflare.config.ts declares it
(ocre g scaffold ... --realtime adds this, with demo as the app name):
// worker.env
CHANNELS: bindings.durableObject({ worker: "demo", exportName: "OcreChannel" }),
// worker.exports
OcreChannel: exports.durableObject({ storage: "sqlite" }),Implementations§
Source§impl OcreChannel
impl OcreChannel
pub fn new(state: DurableObjectState, env: Env) -> Self
pub async fn fetch(&self, req: Request) -> Result<JsValue, JsValue>
pub async fn websocket_message( &self, ws: WebSocket, message: JsValue, ) -> Result<JsValue, JsValue>
pub async fn websocket_close( &self, ws: WebSocket, code: usize, reason: String, was_clean: bool, ) -> Result<JsValue, JsValue>
pub async fn websocket_error( &self, ws: WebSocket, error: JsValue, ) -> Result<JsValue, JsValue>
Trait Implementations§
Source§impl DurableObject for OcreChannel
impl DurableObject for OcreChannel
Source§async fn fetch(&self, req: Request) -> Result<Response>
async fn fetch(&self, req: Request) -> Result<Response>
POST: send the body to every socket, answer how many got it.
Anything else: a WebSocket handshake forwarded by connect.
Source§async fn websocket_message(
&self,
ws: WebSocket,
message: WebSocketIncomingMessage,
) -> Result<()>
async fn websocket_message( &self, ws: WebSocket, message: WebSocketIncomingMessage, ) -> Result<()>
Relays text from sockets allowed to publish to every other socket; ignores the rest.
Source§async fn websocket_close(
&self,
ws: WebSocket,
code: usize,
reason: String,
_clean: bool,
) -> Result<()>
async fn websocket_close( &self, ws: WebSocket, code: usize, reason: String, _clean: bool, ) -> Result<()>
Completes the closing handshake the browser started.
Source§fn new(state: State, _env: Env) -> Self
fn new(state: State, _env: Env) -> Self
State::block_concurrency_while] here without awaiting it: the runtime blocks
delivery of all events until the initialization future completes.async fn websocket_error(&self, ws: WebSocket, _error: Error) -> Result<()>
§async fn connect(&self, socket: Socket) -> Result<(), Error>
async fn connect(&self, socket: Socket) -> Result<(), Error>
Stub::connect]. The socket is
closed when this future completes, so it must live for the whole
connection: when handing the socket to a listener, await
[Socket::handle_as_node_connection] rather than spawning it or
returning early.async fn alarm(&self) -> Result<Response, Error>
Source§impl From<OcreChannel> for JsValue
impl From<OcreChannel> for JsValue
Source§fn from(value: OcreChannel) -> Self
fn from(value: OcreChannel) -> Self
Source§impl FromWasmAbi for OcreChannel
impl FromWasmAbi for OcreChannel
Source§impl IntoWasmAbi for OcreChannel
impl IntoWasmAbi for OcreChannel
Source§impl LongRefFromWasmAbi for OcreChannel
impl LongRefFromWasmAbi for OcreChannel
Source§type Abi = WasmPtr<WasmRefCell<OcreChannel>>
type Abi = WasmPtr<WasmRefCell<OcreChannel>>
RefFromWasmAbi::AbiSource§type Anchor = RcRef<OcreChannel>
type Anchor = RcRef<OcreChannel>
RefFromWasmAbi::AnchorSource§unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiSource§impl OptionFromWasmAbi for OcreChannel
impl OptionFromWasmAbi for OcreChannel
Source§impl OptionIntoWasmAbi for OcreChannel
impl OptionIntoWasmAbi for OcreChannel
Source§impl RefFromWasmAbi for OcreChannel
impl RefFromWasmAbi for OcreChannel
Source§type Abi = WasmPtr<WasmRefCell<OcreChannel>>
type Abi = WasmPtr<WasmRefCell<OcreChannel>>
Self are recovered from.Source§type Anchor = RcRef<OcreChannel>
type Anchor = RcRef<OcreChannel>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for OcreChannel
impl RefMutFromWasmAbi for OcreChannel
Source§type Abi = WasmPtr<WasmRefCell<OcreChannel>>
type Abi = WasmPtr<WasmRefCell<OcreChannel>>
RefFromWasmAbi::AbiSource§type Anchor = RcRefMut<OcreChannel>
type Anchor = RcRefMut<OcreChannel>
RefFromWasmAbi::AnchorSource§unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiimpl SupportsConstructor for OcreChannel
impl SupportsInstanceProperty for OcreChannel
impl SupportsStaticProperty for OcreChannel
Source§impl TryFromJsValue for OcreChannel
impl TryFromJsValue for OcreChannel
Source§impl VectorFromWasmAbi for OcreChannel
impl VectorFromWasmAbi for OcreChannel
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[OcreChannel]>
Source§impl VectorIntoWasmAbi for OcreChannel
impl VectorIntoWasmAbi for OcreChannel
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[OcreChannel]>) -> Self::Abi
Source§impl WasmDescribeVector for OcreChannel
impl WasmDescribeVector for OcreChannel
Auto Trait Implementations§
impl Freeze for OcreChannel
impl RefUnwindSafe for OcreChannel
impl Send for OcreChannel
impl Sync for OcreChannel
impl Unpin for OcreChannel
impl UnsafeUnpin for OcreChannel
impl UnwindSafe for OcreChannel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.