fix(amap):core

This commit is contained in:
wang_yp 2024-10-13 23:30:33 +08:00
parent 144afd93f7
commit 4a7f57bb3c
21 changed files with 271 additions and 69 deletions

58
package-lock.json generated
View File

@ -71,6 +71,7 @@
"react-app-polyfill": "^3.0.0",
"react-dev-utils": "^12.0.1",
"react-dom": "^18.2.0",
"react-player": "^2.16.0",
"react-refresh": "^0.11.0",
"react-router": "^6.4.2",
"react-router-dom": "^6.4.2",
@ -15903,6 +15904,11 @@
"resolved": "https://registry.npmmirror.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
"integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg=="
},
"node_modules/load-script": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/load-script/-/load-script-1.0.0.tgz",
"integrity": "sha512-kPEjMFtZvwL9TaZo0uZ2ml+Ye9HUMmPwbYRJ324qF9tqMejwykJ5ggTyvzmrbBeapCAbk98BSbTeovHEEP1uCA=="
},
"node_modules/loader-runner": {
"version": "4.3.0",
"resolved": "https://registry.npmmirror.com/loader-runner/-/loader-runner-4.3.0.tgz",
@ -16173,6 +16179,11 @@
"node": ">= 4.0.0"
}
},
"node_modules/memoize-one": {
"version": "5.2.1",
"resolved": "https://registry.npmmirror.com/memoize-one/-/memoize-one-5.2.1.tgz",
"integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q=="
},
"node_modules/memory-fs": {
"version": "0.4.1",
"resolved": "https://registry.npmmirror.com/memory-fs/-/memory-fs-0.4.1.tgz",
@ -20268,11 +20279,31 @@
"resolved": "https://registry.npmmirror.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz",
"integrity": "sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg=="
},
"node_modules/react-fast-compare": {
"version": "3.2.2",
"resolved": "https://registry.npmmirror.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz",
"integrity": "sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ=="
},
"node_modules/react-is": {
"version": "17.0.2",
"resolved": "https://registry.npmmirror.com/react-is/-/react-is-17.0.2.tgz",
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="
},
"node_modules/react-player": {
"version": "2.16.0",
"resolved": "https://registry.npmmirror.com/react-player/-/react-player-2.16.0.tgz",
"integrity": "sha512-mAIPHfioD7yxO0GNYVFD1303QFtI3lyyQZLY229UEAp/a10cSW+hPcakg0Keq8uWJxT2OiT/4Gt+Lc9bD6bJmQ==",
"dependencies": {
"deepmerge": "^4.0.0",
"load-script": "^1.0.0",
"memoize-one": "^5.1.1",
"prop-types": "^15.7.2",
"react-fast-compare": "^3.0.1"
},
"peerDependencies": {
"react": ">=16.6.0"
}
},
"node_modules/react-refresh": {
"version": "0.11.0",
"resolved": "https://registry.npmmirror.com/react-refresh/-/react-refresh-0.11.0.tgz",
@ -45134,6 +45165,11 @@
"resolved": "https://registry.npmmirror.com/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
"integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg=="
},
"load-script": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/load-script/-/load-script-1.0.0.tgz",
"integrity": "sha512-kPEjMFtZvwL9TaZo0uZ2ml+Ye9HUMmPwbYRJ324qF9tqMejwykJ5ggTyvzmrbBeapCAbk98BSbTeovHEEP1uCA=="
},
"loader-runner": {
"version": "4.3.0",
"resolved": "https://registry.npmmirror.com/loader-runner/-/loader-runner-4.3.0.tgz",
@ -45363,6 +45399,11 @@
"fs-monkey": "^1.0.4"
}
},
"memoize-one": {
"version": "5.2.1",
"resolved": "https://registry.npmmirror.com/memoize-one/-/memoize-one-5.2.1.tgz",
"integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q=="
},
"memory-fs": {
"version": "0.4.1",
"resolved": "https://registry.npmmirror.com/memory-fs/-/memory-fs-0.4.1.tgz",
@ -48183,11 +48224,28 @@
"resolved": "https://registry.npmmirror.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz",
"integrity": "sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg=="
},
"react-fast-compare": {
"version": "3.2.2",
"resolved": "https://registry.npmmirror.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz",
"integrity": "sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ=="
},
"react-is": {
"version": "17.0.2",
"resolved": "https://registry.npmmirror.com/react-is/-/react-is-17.0.2.tgz",
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="
},
"react-player": {
"version": "2.16.0",
"resolved": "https://registry.npmmirror.com/react-player/-/react-player-2.16.0.tgz",
"integrity": "sha512-mAIPHfioD7yxO0GNYVFD1303QFtI3lyyQZLY229UEAp/a10cSW+hPcakg0Keq8uWJxT2OiT/4Gt+Lc9bD6bJmQ==",
"requires": {
"deepmerge": "^4.0.0",
"load-script": "^1.0.0",
"memoize-one": "^5.1.1",
"prop-types": "^15.7.2",
"react-fast-compare": "^3.0.1"
}
},
"react-refresh": {
"version": "0.11.0",
"resolved": "https://registry.npmmirror.com/react-refresh/-/react-refresh-0.11.0.tgz",

View File

@ -66,6 +66,7 @@
"react-app-polyfill": "^3.0.0",
"react-dev-utils": "^12.0.1",
"react-dom": "^18.2.0",
"react-player": "^2.16.0",
"react-refresh": "^0.11.0",
"react-router": "^6.4.2",
"react-router-dom": "^6.4.2",

View File

@ -16,7 +16,7 @@ export default function MapContainer() {
const Amap = await AMapLoader.load({
key: "d58999d072ed7e5897d3900a769cfda0", // 申请好的Web端开发者Key首次调用 load 时必填
version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: ["AMap.Scale","AMap.MoveAnimation"],
plugins: ["AMap.Scale","AMap.MoveAnimation","AMap.Weather"],
});
amap = new Amap.Map("container", {
@ -30,9 +30,10 @@ export default function MapContainer() {
// addMaket(Amap,amap);
MapUtl.loadMap = Amap;
MapUtl.amap = amap;
var weather = new Amap.Weather();
MapUtl.wecherInfo = weather
amap.setFitView();
};
return <div id="container" style={{ height: "100vh" }}></div>;
}

View File

@ -47,6 +47,7 @@ export default function MapFrom(props:any) {
});
mouseTool.marker();
});
setmaps(Amap);
};

View File

@ -2,6 +2,7 @@ class MapUtl {
static makerList: any[] = [];
static amap: any = null;
static loadMap: any = null;
static wecherInfo: any = null;
static addMaker(data: any) {
const { lng, lat, title, users } = data;
@ -61,12 +62,14 @@ class MapUtl {
});
MapUtl.amap.setFitView();
marker.moveAlong(lineArr, {
// 每一段的时长
duration: 500,//可根据实际采集时间间隔设置
// JSAPI2.0 是否延道路自动设置角度在 moveAlong 里设置
autoRotation: true,
});
}
static getWecher(){
}
}
export default MapUtl;

View File

@ -84,7 +84,7 @@ const OrgChartSelf = (props: Store) => {
backgroundColor: "#fff",
}}
width={50}
// src="https://img1.baidu.com/it/u=1746619441,3368766734&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400"
src="https://pic.aigexing.net/uploads/5/1253/3721116011/92968290915/8785297.jpg"
alt=""
/>
<span className="userNmae">{v1.user_name}</span>
@ -103,7 +103,7 @@ const OrgChartSelf = (props: Store) => {
backgroundColor: "#fff",
}}
width={50}
// src="https://img1.baidu.com/it/u=1746619441,3368766734&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400"
src="https://pic.aigexing.net/uploads/5/1253/3721116011/92968290915/8785297.jpg"
alt=""
/>
<span className="userNmae">{v1.user_name}</span>
@ -140,7 +140,7 @@ const OrgChartSelf = (props: Store) => {
backgroundColor: "#fff",
}}
width={50}
// src="https://img1.baidu.com/it/u=1746619441,3368766734&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400"
src="https://pic.aigexing.net/uploads/5/1253/3721116011/92968290915/8785297.jpg"
alt=""
/>
<span className="userNmae">{v1.user_name}</span>

View File

@ -16,7 +16,6 @@ const Dep = (props: Store) => {
const formRef = React.useRef<FormInstance>(null);
const [record, setRecord] = useState<any>(null);
const [tagId, setId] = useState<Number | null>(null);
const [stoList, setStolist] = useState<any>([]);
const columns: ColumnsType<UserDataType> = [
{ title: "部门名称", dataIndex: "dep_name" },
{ title: "部门描述", dataIndex: "remark" },
@ -51,7 +50,6 @@ const Dep = (props: Store) => {
},
];
const edit = (record) => {
let data = {
...record,
head_img: [{ url: record.head_img }],
@ -71,9 +69,7 @@ const Dep = (props: Store) => {
setIsModalOpen(false);
};
useEffect(() => {
depStore.getlist().then(() => {
setStolist(depStore.list);
});
depStore.getlist();
}, [depStore]);
const defaultConfig = [
{
@ -132,7 +128,7 @@ const Dep = (props: Store) => {
open={isModalOpen}
afterClose={() => formRef.current?.resetFields()}
onOk={() => formRef.current?.submit()}
okText="确定"
okText="确定"
cancelText="取消"
onCancel={() => {
setId(null);
@ -153,13 +149,9 @@ const Dep = (props: Store) => {
onFinishFailed={onFinishFailed}
>
<>
<Form.Item
key="pdep_id"
label="上级部门"
name="pdep_id"
>
<Form.Item key="pdep_id" label="上级部门" name="pdep_id">
<Select placeholder="">
{stoList?.map((v: any) => {
{depStore.list?.map((v: any) => {
return (
<Option key={v.id} value={v.id}>
{v.dep_name}

View File

@ -0,0 +1,44 @@
import BTable from "@/components/b_table";
import { UserDataType } from "@/model/userModel";
import { Store } from "antd/es/form/interface";
import { ColumnsType } from "antd/lib/table";
import { inject, observer } from "mobx-react";
import { useEffect, useState } from "react";
interface EmUser {
emergencyStore?: Store;
id?: string;
}
const EmUser = (props: EmUser) => {
const { emergencyStore, id } = props;
const [ulist, setUlist] = useState<number | null>(0);
useEffect(() => {
emergencyStore?.getUserlist(id).then((e) => {
setUlist(e.data.record);
});
}, [emergencyStore, id]);
const _columns: ColumnsType<UserDataType> = [
{ title: "民兵名称", dataIndex: "user_name" },
{ title: "民兵描述", dataIndex: "remark" },
{ title: "民兵账号", dataIndex: "account" },
{ title: "是否接收任务", dataIndex: "is_accept",render(value, record, index) {
return value ? "是" : "否";
}, },
];
return (
<>
<div style={{ display: "flex", justifyContent: "space-between" }}>
<p></p>
</div>
<BTable
store={emergencyStore}
columns={_columns}
dataSource={ulist}
selectCallback={(e) => {}}
/>
</>
);
};
export default inject("emergencyStore")(observer(EmUser));

View File

@ -20,12 +20,16 @@ import baseHttp from "@/service/base";
import MinusCircleOutlined from "@ant-design/icons/lib/icons/MinusCircleOutlined";
import { EmConfig } from "./em_column";
import TaskArchives from "../training/task_archives";
import EmUser from "./emUser";
const Emergency = (props: Store) => {
const { emergencyStore } = props;
const { emergencyStore, trainingStore } = props;
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [emUserModel, setEmUserModel] = useState<boolean>(false);
const [projectConfig, setProjectConfig] = useState<any>([]);
const formRef = React.useRef<FormInstance>(null);
const [record, setRecord] = useState<any>(null);
const [identity, setIdentity] = useState<any>(null);
const [tagId, setId] = useState<Number | null>(null);
const [userList, setUserList] = useState<Array<any>>([]);
const [data, setData] = useState<SelectProps["options"]>([]);
@ -46,6 +50,12 @@ const Emergency = (props: Store) => {
<span style={{ color: "green" }}></span>
),
},
{
title: "物资归还状态",
dataIndex: "supplies_status",
render: (supplies_status) =>
supplies_status === 2 ? "已归还" : "未归还",
},
{
title: "操作",
dataIndex: "id",
@ -60,17 +70,17 @@ const Emergency = (props: Store) => {
>
</Button>
{
record.status === 0 ? <Button
type="dashed"
size="small"
onClick={() => {
emergencyStore.fish(record.identity);
}}
>
</Button>:null
}
{record.status === 0 ? (
<Button
type="dashed"
size="small"
onClick={() => {
emergencyStore.fish(record.identity);
}}
>
</Button>
) : null}
<Button
type="dashed"
danger
@ -81,17 +91,31 @@ const Emergency = (props: Store) => {
>
</Button>
<TaskArchives taskId={record?.identity} category_identity={record.archives_category_identity}/>
<TaskArchives
taskId={record?.identity}
category_identity={record.archives_category_identity}
/>
<Button
type="dashed"
size="small"
onClick={() => {
// trainingStore.id = record?.identity;
// setIsModalOpenUser(true);
setIdentity(record?.identity);
setEmUserModel(true);
}}
>
</Button>
{record.supplies_status === 2 ? null : (
<Button
type="dashed"
size="small"
onClick={() => {
trainingStore.back(record?.identity, 1);
}}
>
</Button>
)}
</Space>
),
},
@ -170,6 +194,17 @@ const Emergency = (props: Store) => {
columns={columns}
dataSource={emergencyStore.list}
/>
<Modal
title="训练人员"
width={1200}
open={emUserModel}
footer={null}
onCancel={() => {
setEmUserModel(false);
}}
>
<EmUser id={identity} />
</Modal>
<Modal
title={!tagId ? "任务发布" : "任务编辑"}
width={1200}
@ -257,4 +292,4 @@ const Emergency = (props: Store) => {
);
};
export default inject("emergencyStore")(observer(Emergency));
export default inject("emergencyStore", "trainingStore")(observer(Emergency));

View File

@ -27,7 +27,7 @@
display: inline-block;
animation: scrollText 10s linear infinite; /* 动画 */
}
:hover >span{
:hover > span {
animation-play-state: paused;
}
}
@ -56,7 +56,7 @@
width: 20px;
height: 20px;
}
.on_to{
.on_to {
transform: rotate(-180deg) rotateY(0deg);
}
.twp {
@ -91,10 +91,11 @@
}
}
.map_container_t_r {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
text-align: right;
padding-right: 10px;
}
@ -148,3 +149,12 @@
}
}
}
.map_video_container {
position: absolute;
width: 200px;
height: 400px;
top: 40px;
z-index: 9;
right: 288px;
}

View File

@ -8,9 +8,13 @@ import image2 from "@/static/title_line@1x.png";
import { SettingOutlined } from "@ant-design/icons";
import { useNavigate } from "react-router";
import { useEffect, useState } from "react";
import MapUtl from "@/components/map/mapUtil";
import ReactPlayer from "react-player";
const Home = observer(() => {
const navigate = useNavigate();
const [times, setTimes] = useState<any>();
const [wechaer, setWechaer] = useState<any>();
const updateTime = () => {
const date = new Date();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
@ -26,6 +30,11 @@ const Home = observer(() => {
// 每秒钟更新一次时间
useEffect(() => {
let tim = setInterval(updateTime, 1000);
setTimeout(() => {
MapUtl.wecherInfo?.getLive("双流区", (err, data) => {
setWechaer(data);
});
}, 2000);
return () => {
clearInterval(tim);
};
@ -42,6 +51,20 @@ const Home = observer(() => {
<img className="twp" src={image2} alt="" />
</div>
<div className="map_container_t_r">
<div
style={{
flex: "1",
display: "flex",
alignItems: "center",
justifyContent: "space-around",
color: "#fff",
}}
>
<p>:{wechaer?.weather}</p>
<p>:{wechaer?.windDirection}</p>
<p>:{wechaer?.windPower}</p>
<p>湿:{wechaer?.humidity}</p>
</div>
<SettingOutlined
onClick={() => {
navigate("admin/user");
@ -63,6 +86,16 @@ const Home = observer(() => {
<HomeLeft />
</div>
<MapContainer />
<div className="map_video_container">
{/* <ReactPlayer
className="react-player"
url="https://www.119.gov.cn/images/qmxfxw/expd/2024/07/01/1719818550990010367.mp4" //地址
width="100%" //宽度
height="100%" //高度
playing={true} //是否自动播放
controls //控制
/> */}
</div>
<div className="map_container_r">
<HomeRight />
</div>

View File

@ -3,8 +3,6 @@ import Orgin from "./orgin";
import Pover from "./pover";
import Turn from './turn';
const HomeLeft = () => {
// const openDispatch = () => {
// 位置移动
// MapUtl.makerList[0].setPosition([103.55, 30.342]);

View File

@ -73,6 +73,7 @@ const Turn = (props: Store) => {
{trainingStore.list?.map((item) => {
return (
<p
key={item.identity}
style={{
color: item.identity === taskId ? "blue" : "#fff",
cursor: "pointer",

View File

@ -104,7 +104,7 @@ const Trainings = (props: Store) => {
type="dashed"
size="small"
onClick={() => {
trainingStore.back(record?.identity);
trainingStore.back(record?.identity,2);
}}
>

View File

@ -8,6 +8,7 @@ import React from "react";
import { columns, defaultConfig } from "./user_config";
import "./user.less";
import Move from "./move";
import dayjs from "dayjs";
const { Option } = Select;
const User = (props: Store) => {
@ -24,15 +25,16 @@ const User = (props: Store) => {
const edit = (record) => {
record = {
...record,
vet_in_time: dayjs(record.vet_in_time),
vet_out_time: dayjs(record.vet_out_time),
imageUrl: [{ url: record.imageUrl }],
};
setProjectConfig(defaultConfig(team, per));
setIsModalOpen(true);
formRef.current?.setFieldsValue(record);
setRecord(record);
setId(record.id);
};
const onFinish = (values: any) => {
const onFinish = async (values: any) => {
let data = {
...values,
};
@ -42,10 +44,17 @@ const User = (props: Store) => {
data.head_img = "";
}
if (!userId) {
usrStore.add(data);
let res = await usrStore.add(data);
console.log(res);
if (res) {
setIsModalOpen(false);
}
} else {
let res = await usrStore.putItem(userId, data);
if (res) {
setIsModalOpen(false);
}
}
setIsModalOpen(false);
};
useEffect(() => {
usrStore.getlist();
@ -74,6 +83,7 @@ const User = (props: Store) => {
const addHandler = () => {
setProjectConfig(defaultConfig(team, per));
setId(null);
setRecord(null)
setIsModalOpen(true);
};
const onFinishFailed = () => {};
@ -104,7 +114,6 @@ const User = (props: Store) => {
</Button>
<Move />
<Button
type="dashed"
danger

View File

@ -1,5 +1,6 @@
import baseHttp from "@/service/base";
import { Pages } from "@/util/model/interface";
import { message } from "antd";
import { action, makeObservable, observable, runInAction } from "mobx";
interface BaseStoreInterface<T> {
list: Array<T>
@ -47,20 +48,31 @@ class BaseStore<B> implements BaseStoreInterface<B> {
this.getlist()
}
// 添加
async add(param: any,listParam?:any) {
async add(param: any, listParam?: any) {
try {
await baseHttp.post(this.urlConfig.ADD, param)
let res = await baseHttp.post(this.urlConfig.ADD, param)
if (res.code !== 200) {
message.error(res.msg)
return false
}
this.getlist(listParam)
return true;
} catch (error) {
console.log(error);
}
}
// 更新
async putItem(id: string, param: any,listParam?:any) {
async putItem(id: string, param: any, listParam?: any) {
try {
await baseHttp.put(this.urlConfig.EDIT + "/" + id, param)
let res = await baseHttp.put(this.urlConfig.EDIT + "/" + id, param)
if (res.code !== 200) {
message.error(res.msg)
return false
}
this.getlist(listParam)
return true;
} catch (error) {
}

View File

@ -12,6 +12,7 @@ class EmergencyConfig {
static EDIT: string = "emerg"
static ACCESS: string = "emerg/accept"
static fish: string = "emerg/fish"
static USERLIST: string = "emerg/user"
}
class EmergencyStore extends BaseStore<TagDataType> {
@ -29,6 +30,9 @@ class EmergencyStore extends BaseStore<TagDataType> {
await baseHttp.put(EmergencyConfig.fish + "/" + id, {})
this.getlist()
}
async getUserlist(id: string) {
return await baseHttp.get(EmergencyConfig.USERLIST + "/" + id, {})
}
}
export const emergencyStore = new EmergencyStore()

View File

@ -49,8 +49,8 @@ class TrainingStore extends BaseStore<TagDataType> {
return await baseHttp.post(TrainingConfig.addAchives, param)
}
// 添加档案到培训
async back(id: string) {
return await baseHttp.put(TrainingConfig.back + "/" + id, {task_type:2})
async back(id: string,task_type:number) {
return await baseHttp.put(TrainingConfig.back + "/" + id, {task_type})
}
async getUserListByTraning() {
let res = await baseHttp.get(TrainingConfig.tran_user + "/" + this.id, null)

View File

@ -6,7 +6,7 @@ class Config {
static ws = "ws://127.0.0.1:12214/ws?id=admin";
static baseUrl = "http://127.0.0.1:12214/";
static uploadUrl = "http://127.0.0.1:12214/";
// static ws = "wss://rw.quwanya.cn/ws";
static rtc = "wss://rw.quwanya.cn/ws";
}
export default Config;

View File

@ -14,7 +14,7 @@ export type AutoReconnectOptions = boolean | {
class SocketService {
private static instance: SocketService | null = null
private ws: WebSocket | null = null
private adminws: WebSocket | null = null
private listeners: Record<string, Function[]> = {}
private autoReconnect: AutoReconnectOptions = true
private times: any = null
@ -37,18 +37,18 @@ export type AutoReconnectOptions = boolean | {
}
public connect() {
this.ws = new WebSocket(Config.ws)
this.ws.onopen = () => {
this.adminws = new WebSocket(Config.ws)
this.adminws.onopen = () => {
this.connectionStatus = ConnectionStatus.Connected
this.emit('connected', null)
this.hert()
}
this.ws.onerror = () => {
this.adminws.onerror = () => {
this.connectionStatus = ConnectionStatus.Error
clearTimeout(this.times)
this.emit('error', null)
}
this.ws.onclose = () => {
this.adminws.onclose = () => {
this.connectionStatus = ConnectionStatus.Disconnected
clearTimeout(this.times)
this.emit('disconnected', null)
@ -56,7 +56,7 @@ export type AutoReconnectOptions = boolean | {
setTimeout(() => this.connect(), this.getRetryInterval())
}
}
this.ws.onmessage = (event) => {
this.adminws.onmessage = (event) => {
this.emit('message', event.data)
}
}
@ -92,16 +92,16 @@ export type AutoReconnectOptions = boolean | {
}
public send(data: any) {
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
this.ws.send(JSON.stringify(data))
if (this.adminws && this.adminws.readyState === WebSocket.OPEN) {
this.adminws.send(JSON.stringify(data))
} else {
console.error('WebSocket 连接未打开')
}
}
public close() {
if (this.ws) {
this.ws.close()
if (this.adminws) {
this.adminws.close()
SocketService.instance = null
}
}

View File

@ -17,7 +17,7 @@ class WebRtc {
}))
}
async init() {
this.ws = new WebSocket(Config.ws)
this.ws = new WebSocket(Config.rtc)
this.ws.addEventListener('open', this.open);
let that = this;
this.createOffer()
@ -147,8 +147,8 @@ class WebRtc {
}
}
));
(this.mediaStream as MediaStream)?.getTracks().forEach(track => track.stop());
this.ws?.close()
}
}