Last active: a year ago
tokio http simple server
use anyhow::Result;
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<()> {
let listener = TcpListener::bind("localhost:4000").await?;
loop {
let (mut socket, _) = listener.accept().await?;
tokio::spawn(async move {
let (reader, mut write) = socket.split();
let mut buf = BufReader::new(reader);
let mut req = String::new();
loop {
let count = buf.read_line(&mut req).await.unwrap();
dbg!(count);
if count < 3 {
Last active: 2 years ago
Zego redux slice
import { Message } from '@/projects/court/hooks/zego/useMessage';
import { FileListData, FileListDatum } from '@/utils/api/chat';
import { createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit';
import { nanoid } from 'nanoid';
import { ZegoStreamList } from 'zego-express-engine-webrtc/sdk/code/zh/ZegoExpressEntity.web';
import { ZegoUser } from 'zego-express-engine-webrtc/sdk/src/common/zego.entity';
import { ZegoBroadcastMessageInfo } from 'zego-express-engine-webrtm/sdk/code/zh/ZegoExpressEntity';
import { RootState } from '..';
export type RoomState = {
// 即构 APP ID
appID: number;
// 当前房间 ID
roomId: string;
// 即构当前用户 ID 与参展商手机号相同
userId: string;
// 用户名
userName: string;
// 用户角色
userType: '' | 'judege' | 'normal';
Last active: a year ago
unicodeAndAscii
/**
* 将 Unicode 编码为 ASCII
*/
export const toBinary = (target: string): string => {
const codeUnits = new Uint16Array(target.length);
for (let i = 0; i < codeUnits.length; i++) {
codeUnits[i] = target.charCodeAt(i);
}
const charCodes = new Uint8Array(codeUnits.buffer);
let result = '';
for (let i = 0; i < charCodes.byteLength; i++) {
result += String.fromCharCode(charCodes[i]);
}
return result;
};
/**
* 将 toBinary 编码过的 ASCII 解码为 Unicode
*/
export const fromBinary = (target: string): string => {
Last active: 2 years ago
import { Message } from '@/projects/court/hooks/zego/useMessage';
import { ZegoBroadcastMessageInfo } from 'zego-express-engine-webrtm/sdk/code/zh/ZegoExpressEntity';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { ZegoStreamList } from 'zego-express-engine-webrtc/sdk/code/zh/ZegoExpressEntity.web';
import { ZegoUser } from 'zego-express-engine-webrtc/sdk/src/common/zego.entity';
import { nanoid } from 'nanoid';
import { RoomState } from '@/projects/court/hooks/zego/useZego';
import { RootState } from '..';
export const initRoomState = {
appID: 0,
roomId: '',
// 用户 id 为当前登陆展台的手机号,必须先登陆
userId: '',
userName: '',
token: '',
id: '',
};
export type RoomUserMsg = {
Last active: 2 years ago
import LabelItem from '@/components/LabelItem';
import { globalSelectDone } from '@/projects/editor/data';
import { SearchData, SearchDataContent } from '@/show/interface';
import { SceneInfo, SpotBase } from '@/show/lib';
import { useAppDispatch, useAppSelector } from '@/store';
import { addSearchData, delSearchData } from '@/store/core/slice';
import { resetWithTarget, setShowSceneLibrary } from '@/store/ui/slice';
import { searchTypeList, serializeList } from '@/utils/api/search-list';
import { DeleteOutlined, DownOutlined } from '@ant-design/icons';
import { useBoolean, useRequest } from 'ahooks';
import { Button, Cascader, Dropdown, Empty, Menu, Popover } from 'antd';
import { useMemo, useState } from 'react';
import { MarkItem } from '../SandTable/Style';
import { Content } from './index.styles';
// 名称 map
export const typeMap = {
scene: '场景',
spot: '热点',
};
Last active: 2 years ago
/**
* 虚拟法院
*
* 分类搜索
*/
addSearchData(
state,
action: PayloadAction<{
list: number[];
data: SearchDataContent;
}>
) {
const searchData = state.proj.data.searchData;
const { list, data } = action.payload;
const len = list.length;
const defaultItem = {
id: 0,
pid: 0,
};
Last active: 2 years ago
import { useImmer } from 'use-immer';
import { ZegoDeviceInfo } from 'zego-express-engine-webrtc/sdk/code/zh/ZegoExpressEntity.web';
import { useCallback, useRef } from 'react';
import { ZegoExpressEngine } from 'zego-express-engine-webrtc';
/**
* 枚举并检测设备权限
* @param zg
* @returns
*/
const useDevices = (zg: ZegoExpressEngine | null) => {
// 设备列表 状态
const [device, setDevice] = useImmer<{
audioDeviceList: ZegoDeviceInfo[];
videoDeviceList: ZegoDeviceInfo[];
microphoneDevicesVal: string;
cameraDevicesVal: string;
}>({
audioDeviceList: [],
videoDeviceList: [],
Last active: 2 years ago
const setDepth = <T extends 'hide' | 'opacity'>(
type: T,
value: T extends 'opacity' ? string : boolean
) => {}
Last active: 2 years ago
use anyhow::Result;
use tokio::io;
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<()> {
let listener = TcpListener::bind("localhost:6142").await?;
loop {
let (socket, _) = listener.accept().await?;
let (mut read, mut write) = io::split(socket);
tokio::spawn(async move {
io::copy(&mut read, &mut write).await?;
Ok::<_, io::Error>(())
});
}
}
Last active: 2 years ago
use anyhow::Result;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
#[tokio::main]
async fn main() -> Result<()> {
let listener = TcpListener::bind("localhost:6142").await?;
loop {
let (mut socket, _) = listener.accept().await?;
tokio::spawn(async move {
let mut buffer = vec![0; 10];
loop {
dbg!(&buffer);
match socket.read(&mut buffer).await {
Ok(0) => (),
Ok(_bytes) => (),
Err(_err) => (),
}
Last active: 2 years ago
/// Read http request to string.
pub fn read_request(reader: &mut BufReader<&mut &TcpStream>) -> Result<String> {
let mut request_string = String::new();
loop {
let byte = reader.read_line(&mut request_string)?;
if byte < 3 {
break;
}
}
Ok(request_string)
}