2021-01-10 21:59:07 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2020-09-19 19:17:35 -04:00
|
|
|
use crate::permissions::Permissions;
|
2021-01-06 10:57:28 -05:00
|
|
|
use deno_websocket::op_ws_check_permission;
|
|
|
|
use deno_websocket::op_ws_close;
|
|
|
|
use deno_websocket::op_ws_create;
|
|
|
|
use deno_websocket::op_ws_next_event;
|
|
|
|
use deno_websocket::op_ws_send;
|
|
|
|
use deno_websocket::WsCaData;
|
|
|
|
use deno_websocket::WsUserAgent;
|
2020-12-11 12:49:26 -05:00
|
|
|
|
2020-12-11 18:36:18 -05:00
|
|
|
pub fn init(
|
|
|
|
rt: &mut deno_core::JsRuntime,
|
|
|
|
user_agent: String,
|
2021-01-06 10:57:28 -05:00
|
|
|
ca_data: Option<Vec<u8>>,
|
2020-12-11 18:36:18 -05:00
|
|
|
) {
|
2020-12-11 12:49:26 -05:00
|
|
|
{
|
|
|
|
let op_state = rt.op_state();
|
|
|
|
let mut state = op_state.borrow_mut();
|
2021-01-06 10:57:28 -05:00
|
|
|
state.put::<WsUserAgent>(WsUserAgent(user_agent));
|
2021-01-04 18:15:52 -05:00
|
|
|
if let Some(ca_data) = ca_data {
|
|
|
|
state.put::<WsCaData>(WsCaData(ca_data));
|
2020-12-11 12:49:26 -05:00
|
|
|
}
|
|
|
|
}
|
2021-04-12 15:55:05 -04:00
|
|
|
super::reg_sync(
|
2021-01-06 10:57:28 -05:00
|
|
|
rt,
|
|
|
|
"op_ws_check_permission",
|
|
|
|
op_ws_check_permission::<Permissions>,
|
|
|
|
);
|
2021-04-12 15:55:05 -04:00
|
|
|
super::reg_async(rt, "op_ws_create", op_ws_create::<Permissions>);
|
|
|
|
super::reg_async(rt, "op_ws_send", op_ws_send);
|
|
|
|
super::reg_async(rt, "op_ws_close", op_ws_close);
|
|
|
|
super::reg_async(rt, "op_ws_next_event", op_ws_next_event);
|
2020-09-05 10:39:25 -04:00
|
|
|
}
|