fix(amap):core
This commit is contained in:
parent
622bc2ea8b
commit
bb81cda972
18
src/App.tsx
18
src/App.tsx
|
@ -1,10 +1,10 @@
|
|||
import { Outlet } from "react-router";
|
||||
import MapUtl from "./components/map/mapUtil";
|
||||
import { useEffect } from "react";
|
||||
// import SocketService from "./util/socket";
|
||||
// const socketService = SocketService.getInstance();
|
||||
import SocketService from "./util/socket";
|
||||
const socketService = SocketService.getInstance();
|
||||
const onMessage = (e: any) => {
|
||||
let data = JSON.parse(e);
|
||||
console.log(data)
|
||||
if (data.type === "accpt") {
|
||||
let body = JSON.parse(data.content.body);
|
||||
MapUtl.addMaker({
|
||||
|
@ -23,9 +23,19 @@ const onMessage = (e: any) => {
|
|||
});
|
||||
maker?.setPosition([body.long, body.lat]);
|
||||
}
|
||||
else if (data.type === "move") {
|
||||
let maker: any = null;
|
||||
let body = JSON.parse(data.content.body);
|
||||
MapUtl.makerList?.forEach((e) => {
|
||||
if (e.userIdentity === body?.user_identity) {
|
||||
maker = e.marker;
|
||||
}
|
||||
});
|
||||
maker?.setPosition([body.long, body.lat]);
|
||||
}
|
||||
};
|
||||
|
||||
// socketService.on("message", onMessage);
|
||||
socketService.on("message", onMessage);
|
||||
const App = () => {
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -48,7 +48,7 @@ const Ec = (props: Store) => {
|
|||
{userList.map((item: any) => {
|
||||
return (
|
||||
<div key={item.account}>
|
||||
<div>姓名:{item.account} : 未在线</div>
|
||||
<div>姓名:{item.user_name} : 未在线</div>
|
||||
<p></p>
|
||||
<div>
|
||||
点击呼叫:
|
||||
|
|
|
@ -23,7 +23,6 @@ export const columns: ColumnsType<UserDataType> = [
|
|||
];
|
||||
|
||||
export const defaultConfig = [
|
||||
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "法规标题",
|
||||
|
@ -31,21 +30,26 @@ export const defaultConfig = [
|
|||
value: "",
|
||||
rules: [{ required: true, message: "请输入法规标题!" }],
|
||||
},
|
||||
|
||||
{
|
||||
type: FormType.inputNumber,
|
||||
label: "等级排序",
|
||||
name: "level",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "法规副标题",
|
||||
name: "sub_title",
|
||||
value: "",
|
||||
rules: [{ required: true, message: "请输入法规副标题!" }],
|
||||
},
|
||||
{
|
||||
type: "editor",
|
||||
type: FormType.editor,
|
||||
label: "内容",
|
||||
name: "content",
|
||||
value: "",
|
||||
rules: [{ required: true, message: "请填写内容" }],
|
||||
},
|
||||
|
||||
{
|
||||
type: "upload",
|
||||
label: "附件图片",
|
||||
|
|
|
@ -7,17 +7,7 @@ import SimpleForm from "@/components/form/simple_form";
|
|||
import React from "react";
|
||||
import { columns, defaultCatConfig } from "./dict_column";
|
||||
const { Option } = Select;
|
||||
const list = [
|
||||
{ id: 1, name: "婚姻" },
|
||||
{ id: 2, name: "政治面貌" },
|
||||
{ id: 3, name: "文化程度" },
|
||||
{ id: 4, name: "民族" },
|
||||
{ id: 5, name: "单位性质" },
|
||||
{ id: 6, name: "服役军兵种" },
|
||||
{ id: 7, name: "军衔" },
|
||||
{ id: 8, name: "技术职称" },
|
||||
{ id: 9, name: "职务级别" },
|
||||
];
|
||||
|
||||
const Dict = (props: Store) => {
|
||||
const { sysStore } = props;
|
||||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
||||
|
@ -130,7 +120,7 @@ const Dict = (props: Store) => {
|
|||
<>
|
||||
<Form.Item key="drop_type" label="类型" name="drop_type" rules={[]}>
|
||||
<Select placeholder="">
|
||||
{list?.map((v: any) => {
|
||||
{sysStore.list?.map((v: any) => {
|
||||
return (
|
||||
<Option key={v.id} value={v.id}>
|
||||
{v.name}
|
||||
|
|
|
@ -2,8 +2,7 @@ import { FormType } from "@/components/form/interface";
|
|||
import { UserDataType } from "@/model/userModel";
|
||||
import { ColumnsType } from "antd/lib/table";
|
||||
import { Image } from "antd";
|
||||
export const defaultConfig =(team,per)=>
|
||||
[
|
||||
export const defaultConfig = (team, per) => [
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "用户名",
|
||||
|
@ -16,14 +15,8 @@ export const defaultConfig =(team,per)=>
|
|||
label: "性别",
|
||||
name: "sex",
|
||||
radioData: [
|
||||
{
|
||||
key: "男",
|
||||
val: 1,
|
||||
},
|
||||
{
|
||||
key: "女",
|
||||
val: 2,
|
||||
},
|
||||
{ key: "男", val: 1 },
|
||||
{ key: "女", val: 2 },
|
||||
],
|
||||
value: 0,
|
||||
rules: [{ required: true, message: "请选择性别" }],
|
||||
|
@ -49,7 +42,7 @@ export const defaultConfig =(team,per)=>
|
|||
value: "",
|
||||
rules: [{ required: true, message: "请输入登录账号" }],
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "家庭住址",
|
||||
|
@ -57,7 +50,7 @@ export const defaultConfig =(team,per)=>
|
|||
value: "",
|
||||
rules: [{ required: true, message: "请输入家庭住址" }],
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "担任职务",
|
||||
|
@ -72,7 +65,7 @@ export const defaultConfig =(team,per)=>
|
|||
value: "",
|
||||
rules: [{ required: true, message: "请输入通讯地址" }],
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "贯籍",
|
||||
|
@ -80,7 +73,7 @@ export const defaultConfig =(team,per)=>
|
|||
value: "",
|
||||
rules: [{ required: true, message: "请输入贯籍" }],
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "联系电话",
|
||||
|
@ -99,7 +92,7 @@ export const defaultConfig =(team,per)=>
|
|||
type: FormType.cehckboxGroup,
|
||||
label: "所属队伍",
|
||||
name: "team_link_user",
|
||||
checkboxData:team,
|
||||
checkboxData: team,
|
||||
value: "",
|
||||
rules: [{ required: true, message: "请选择所属队伍" }],
|
||||
},
|
||||
|
@ -107,7 +100,7 @@ export const defaultConfig =(team,per)=>
|
|||
type: FormType.cehckboxGroup,
|
||||
label: "个人身份属性",
|
||||
name: "pers_link_user",
|
||||
checkboxData:per,
|
||||
checkboxData: per,
|
||||
value: "",
|
||||
rules: [{ required: true, message: "请选择个人身份属性" }],
|
||||
},
|
||||
|
@ -145,7 +138,6 @@ export const defaultConfig =(team,per)=>
|
|||
],
|
||||
rules: [{ required: true, message: "单位类型不能为空" }],
|
||||
},
|
||||
|
||||
{
|
||||
type: FormType.radio,
|
||||
label: "民兵类型",
|
||||
|
@ -198,7 +190,7 @@ export const defaultConfig =(team,per)=>
|
|||
name: "serv_unit",
|
||||
value: "",
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
type: FormType.input,
|
||||
label: "专业特长",
|
||||
|
@ -212,72 +204,6 @@ export const defaultConfig =(team,per)=>
|
|||
name: "email",
|
||||
value: "",
|
||||
},
|
||||
{
|
||||
type: FormType.radio,
|
||||
label: "积极力量",
|
||||
name: "a_member",
|
||||
value: 1,
|
||||
radioData: [
|
||||
{
|
||||
key: "是",
|
||||
val: 1,
|
||||
},
|
||||
{
|
||||
key: "否",
|
||||
val: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: FormType.radio,
|
||||
label: "专业队伍",
|
||||
name: "p_team",
|
||||
value: 1,
|
||||
radioData: [
|
||||
{
|
||||
key: "是",
|
||||
val: 1,
|
||||
},
|
||||
{
|
||||
key: "否",
|
||||
val: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
type: FormType.radio,
|
||||
label: "是否为社干力量",
|
||||
name: "c_member",
|
||||
value: 2,
|
||||
radioData: [
|
||||
{
|
||||
key: "是",
|
||||
val: 1,
|
||||
},
|
||||
{
|
||||
key: "否",
|
||||
val: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: FormType.radio,
|
||||
label: "三方力量",
|
||||
name: "o_member",
|
||||
value: 2,
|
||||
radioData: [
|
||||
{
|
||||
key: "是",
|
||||
val: 1,
|
||||
},
|
||||
{
|
||||
key: "否",
|
||||
val: 2,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
type: FormType.textarea,
|
||||
label: "描述",
|
||||
|
|
|
@ -19,7 +19,7 @@ class SysStore extends BaseStore<TagDataType> {
|
|||
bannerList: observable,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
async addBanner(param: any) {
|
||||
await baseHttp.post(SysConfig.ADDBanner, param)
|
||||
this.getbanner();
|
||||
|
@ -28,7 +28,18 @@ class SysStore extends BaseStore<TagDataType> {
|
|||
let res = await baseHttp.get(SysConfig.LISTBannler, {})
|
||||
this.bannerList = res.data.record
|
||||
}
|
||||
bannerList:Array<any> = []
|
||||
bannerList: Array<any> = []
|
||||
list: Array<any> = [
|
||||
{ id: 1, name: "婚姻" },
|
||||
{ id: 2, name: "政治面貌" },
|
||||
{ id: 3, name: "文化程度" },
|
||||
{ id: 4, name: "民族" },
|
||||
{ id: 5, name: "单位性质" },
|
||||
{ id: 6, name: "服役军兵种" },
|
||||
{ id: 7, name: "军衔" },
|
||||
{ id: 8, name: "技术职称" },
|
||||
{ id: 9, name: "职务级别" },
|
||||
];
|
||||
}
|
||||
export const sysStore = new SysStore()
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
class Config {
|
||||
// static baseUrl = "https://rw.quwanya.cn/";
|
||||
static baseUrl = "https://rw.quwanya.cn/";
|
||||
static uploadUrl = "https://rw.quwanya.cn/";
|
||||
// static ws = "wss://rw.quwanya.cn/wsadmin?id=admin";
|
||||
static ws = "ws://rw.quwanya.cn:12214/wsadmin?id=admin";
|
||||
static rtc = "wss://rw.quwanya.cn/ws";
|
||||
static ws = "ws://127.0.0.1:12214/ws?id=admin";
|
||||
static baseUrl = "http://127.0.0.1:12214/";
|
||||
// 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/";
|
||||
|
||||
}
|
||||
export default Config;
|
||||
|
||||
|
|
|
@ -1,145 +1,144 @@
|
|||
import Config from "./config"
|
||||
|
||||
export type AutoReconnectOptions = boolean | {
|
||||
maxRetries?: number
|
||||
retryInterval?: number
|
||||
onMaxRetriesReached?: Function
|
||||
maxRetries?: number
|
||||
retryInterval?: number
|
||||
onMaxRetriesReached?: Function
|
||||
}
|
||||
|
||||
export enum ConnectionStatus {
|
||||
Disconnected = 'DISCONNECTED',
|
||||
Connected = 'CONNECTED',
|
||||
Error = 'ERROR'
|
||||
}
|
||||
|
||||
class SocketService {
|
||||
private static instance: SocketService | null = null
|
||||
private adminws: WebSocket | null = null
|
||||
private listeners: Record<string, Function[]> = {}
|
||||
private autoReconnect: AutoReconnectOptions = true
|
||||
private times: any = null
|
||||
private retries: number = 0
|
||||
private connectionStatus: ConnectionStatus = ConnectionStatus.Disconnected
|
||||
|
||||
private constructor() {
|
||||
this.connect()
|
||||
}
|
||||
|
||||
export enum ConnectionStatus {
|
||||
Disconnected = 'DISCONNECTED',
|
||||
Connected = 'CONNECTED',
|
||||
Error = 'ERROR'
|
||||
|
||||
public static getInstance(): SocketService {
|
||||
if (!SocketService.instance) {
|
||||
SocketService.instance = new SocketService()
|
||||
}
|
||||
return SocketService.instance
|
||||
}
|
||||
|
||||
class SocketService {
|
||||
private static instance: SocketService | null = null
|
||||
private adminws: WebSocket | null = null
|
||||
private listeners: Record<string, Function[]> = {}
|
||||
private autoReconnect: AutoReconnectOptions = true
|
||||
private times: any = null
|
||||
private retries: number = 0
|
||||
private connectionStatus: ConnectionStatus = ConnectionStatus.Disconnected
|
||||
|
||||
private constructor() {
|
||||
this.connect()
|
||||
|
||||
public setAutoReconnectOptions(options: AutoReconnectOptions) {
|
||||
this.autoReconnect = options
|
||||
}
|
||||
|
||||
public connect() {
|
||||
this.adminws = new WebSocket(Config.ws)
|
||||
this.adminws.onopen = () => {
|
||||
this.connectionStatus = ConnectionStatus.Connected
|
||||
this.emit('connected', null)
|
||||
this.hert()
|
||||
}
|
||||
|
||||
public static getInstance(): SocketService {
|
||||
if (!SocketService.instance) {
|
||||
SocketService.instance = new SocketService()
|
||||
}
|
||||
return SocketService.instance
|
||||
this.adminws.onerror = () => {
|
||||
this.connectionStatus = ConnectionStatus.Error
|
||||
clearTimeout(this.times)
|
||||
this.emit('error', null)
|
||||
}
|
||||
|
||||
public setAutoReconnectOptions(options: AutoReconnectOptions) {
|
||||
this.autoReconnect = options
|
||||
this.adminws.onclose = () => {
|
||||
this.connectionStatus = ConnectionStatus.Disconnected
|
||||
clearTimeout(this.times)
|
||||
this.emit('disconnected', null)
|
||||
if (this.shouldReconnect()) {
|
||||
setTimeout(() => this.connect(), this.getRetryInterval())
|
||||
}
|
||||
}
|
||||
|
||||
public connect() {
|
||||
this.adminws = new WebSocket(Config.ws)
|
||||
this.adminws.onopen = () => {
|
||||
this.connectionStatus = ConnectionStatus.Connected
|
||||
this.emit('connected', null)
|
||||
this.hert()
|
||||
}
|
||||
this.adminws.onerror = () => {
|
||||
this.connectionStatus = ConnectionStatus.Error
|
||||
clearTimeout(this.times)
|
||||
this.emit('error', null)
|
||||
}
|
||||
this.adminws.onclose = () => {
|
||||
this.connectionStatus = ConnectionStatus.Disconnected
|
||||
clearTimeout(this.times)
|
||||
this.emit('disconnected', null)
|
||||
if (this.shouldReconnect()) {
|
||||
setTimeout(() => this.connect(), this.getRetryInterval())
|
||||
this.adminws.onmessage = (event) => {
|
||||
this.emit('message', event.data)
|
||||
}
|
||||
}
|
||||
public hert() {
|
||||
this.times = setInterval(() => this.send({ type: "heartbeat", data: {} }), 3000)
|
||||
}
|
||||
private shouldReconnect(): boolean {
|
||||
if (typeof this.autoReconnect === 'boolean') {
|
||||
return this.autoReconnect
|
||||
} else if (this.autoReconnect) {
|
||||
const { maxRetries } = this.autoReconnect
|
||||
|
||||
if (maxRetries !== undefined) {
|
||||
if (this.retries < maxRetries) {
|
||||
this.retries++
|
||||
return true
|
||||
} else if (this.retries >= maxRetries) {
|
||||
this.autoReconnect.onMaxRetriesReached && this.autoReconnect.onMaxRetriesReached()
|
||||
return false
|
||||
}
|
||||
}
|
||||
this.adminws.onmessage = (event) => {
|
||||
this.emit('message', event.data)
|
||||
}
|
||||
}
|
||||
public hert(){
|
||||
this.times = setInterval(() => this.send({"type":"heartbeat"}), 3000)
|
||||
}
|
||||
private shouldReconnect(): boolean {
|
||||
if (typeof this.autoReconnect === 'boolean') {
|
||||
return this.autoReconnect
|
||||
} else if (this.autoReconnect) {
|
||||
const { maxRetries } = this.autoReconnect
|
||||
|
||||
if (maxRetries !== undefined) {
|
||||
if (this.retries < maxRetries) {
|
||||
this.retries++
|
||||
return true
|
||||
} else if (this.retries >= maxRetries) {
|
||||
this.autoReconnect.onMaxRetriesReached && this.autoReconnect.onMaxRetriesReached()
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private getRetryInterval(): number {
|
||||
if (typeof this.autoReconnect === 'boolean') {
|
||||
return 1000
|
||||
} else if (this.autoReconnect && this.autoReconnect.retryInterval) {
|
||||
return this.autoReconnect.retryInterval
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private getRetryInterval(): number {
|
||||
if (typeof this.autoReconnect === 'boolean') {
|
||||
return 1000
|
||||
} else if (this.autoReconnect && this.autoReconnect.retryInterval) {
|
||||
return this.autoReconnect.retryInterval
|
||||
}
|
||||
|
||||
public send(data: any) {
|
||||
if (this.adminws && this.adminws.readyState === WebSocket.OPEN) {
|
||||
this.adminws.send(JSON.stringify(data))
|
||||
} else {
|
||||
console.error('WebSocket 连接未打开')
|
||||
}
|
||||
}
|
||||
|
||||
public close() {
|
||||
if (this.adminws) {
|
||||
this.adminws.close()
|
||||
SocketService.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
private emit(event: string, data: any) {
|
||||
if (!this.listeners[event]) {
|
||||
return
|
||||
}
|
||||
this.listeners[event].forEach((listener) => listener(data))
|
||||
}
|
||||
|
||||
public on(event: string, listener: Function) {
|
||||
if (!this.listeners[event]) {
|
||||
this.listeners[event] = []
|
||||
}
|
||||
this.listeners[event].push(listener)
|
||||
if (event === 'connected' && this.connectionStatus === ConnectionStatus.Connected) {
|
||||
listener()
|
||||
}
|
||||
}
|
||||
|
||||
public off(event: string, listener: Function) {
|
||||
if (!this.listeners[event]) {
|
||||
return
|
||||
}
|
||||
this.listeners[event] = this.listeners[event].filter((l) => l !== listener)
|
||||
}
|
||||
|
||||
public getConnectionStatus(): ConnectionStatus {
|
||||
return this.connectionStatus
|
||||
}
|
||||
|
||||
public watchConnectionStatus(callback: (status: ConnectionStatus) => void) {
|
||||
this.on('connected', () => callback(ConnectionStatus.Connected))
|
||||
this.on('disconnected', () => callback(ConnectionStatus.Disconnected))
|
||||
this.on('error', () => callback(ConnectionStatus.Error))
|
||||
return 1000
|
||||
}
|
||||
|
||||
public send(data: any) {
|
||||
if (this.adminws && this.adminws.readyState === WebSocket.OPEN) {
|
||||
this.adminws.send(JSON.stringify(data))
|
||||
} else {
|
||||
console.error('WebSocket 连接未打开')
|
||||
}
|
||||
}
|
||||
|
||||
export default SocketService
|
||||
|
||||
|
||||
public close() {
|
||||
if (this.adminws) {
|
||||
this.adminws.close()
|
||||
SocketService.instance = null
|
||||
}
|
||||
}
|
||||
|
||||
private emit(event: string, data: any) {
|
||||
if (!this.listeners[event]) {
|
||||
return
|
||||
}
|
||||
this.listeners[event].forEach((listener) => listener(data))
|
||||
}
|
||||
|
||||
public on(event: string, listener: Function) {
|
||||
if (!this.listeners[event]) {
|
||||
this.listeners[event] = []
|
||||
}
|
||||
this.listeners[event].push(listener)
|
||||
if (event === 'connected' && this.connectionStatus === ConnectionStatus.Connected) {
|
||||
listener()
|
||||
}
|
||||
}
|
||||
|
||||
public off(event: string, listener: Function) {
|
||||
if (!this.listeners[event]) {
|
||||
return
|
||||
}
|
||||
this.listeners[event] = this.listeners[event].filter((l) => l !== listener)
|
||||
}
|
||||
|
||||
public getConnectionStatus(): ConnectionStatus {
|
||||
return this.connectionStatus
|
||||
}
|
||||
|
||||
public watchConnectionStatus(callback: (status: ConnectionStatus) => void) {
|
||||
this.on('connected', () => callback(ConnectionStatus.Connected))
|
||||
this.on('disconnected', () => callback(ConnectionStatus.Disconnected))
|
||||
this.on('error', () => callback(ConnectionStatus.Error))
|
||||
}
|
||||
}
|
||||
|
||||
export default SocketService
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
import Config from "./config";
|
||||
import SocketService from "./socket";
|
||||
|
||||
class WebRtc {
|
||||
private mediaStream: MediaStream | Blob | null = null;
|
||||
|
@ -17,57 +18,52 @@ class WebRtc {
|
|||
}))
|
||||
}
|
||||
async init() {
|
||||
this.ws = new WebSocket(Config.rtc)
|
||||
this.ws.addEventListener('open', this.open);
|
||||
let that = this;
|
||||
this.createOffer()
|
||||
this.ws.onmessage = function (evt) {
|
||||
let msg = JSON.parse(evt.data)
|
||||
if (!msg) {
|
||||
return console.log('failed to parse msg')
|
||||
}
|
||||
switch (msg.type) {
|
||||
case 'offer':
|
||||
let offer = msg.data.description
|
||||
that.pee?.setRemoteDescription(offer)
|
||||
that.pee?.createAnswer().then(answer => {
|
||||
that.pee?.setLocalDescription(answer)
|
||||
that.ws?.send(JSON.stringify({
|
||||
type: 'answer', data: {
|
||||
'to': msg.data.from,
|
||||
'from': "31283192",
|
||||
'description': { 'sdp': answer.sdp, 'type': answer.type },
|
||||
'session_id': msg.data.from + "-31283192",
|
||||
}
|
||||
}))
|
||||
})
|
||||
return
|
||||
// this.ws.onmessage = function (evt) {
|
||||
// let msg = JSON.parse(evt.data)
|
||||
// if (!msg) {
|
||||
// return console.log('failed to parse msg')
|
||||
// }
|
||||
// switch (msg.type) {
|
||||
// case 'offer':
|
||||
// let offer = msg.data.description
|
||||
// that.pee?.setRemoteDescription(offer)
|
||||
// that.pee?.createAnswer().then(answer => {
|
||||
// that.pee?.setLocalDescription(answer)
|
||||
// that.ws?.send(JSON.stringify({
|
||||
// type: 'answer', data: {
|
||||
// 'to': msg.data.from,
|
||||
// 'from': "31283192",
|
||||
// 'description': { 'sdp': answer.sdp, 'type': answer.type },
|
||||
// 'session_id': msg.data.from + "-31283192",
|
||||
// }
|
||||
// }))
|
||||
// })
|
||||
// return
|
||||
|
||||
case 'candidate':
|
||||
let candidate = msg.data.candidate
|
||||
if (!candidate) {
|
||||
return console.log('failed to parse candidate')
|
||||
}
|
||||
that.pee?.addIceCandidate(candidate)
|
||||
break;
|
||||
case "answer":
|
||||
that.pee?.setRemoteDescription(msg.data.description)
|
||||
break;
|
||||
case "bye":
|
||||
that.pee?.close()
|
||||
that.close()
|
||||
break;
|
||||
}
|
||||
}
|
||||
// case 'candidate':
|
||||
// let candidate = msg.data.candidate
|
||||
// if (!candidate) {
|
||||
// return console.log('failed to parse candidate')
|
||||
// }
|
||||
// that.pee?.addIceCandidate(candidate)
|
||||
// break;
|
||||
// case "answer":
|
||||
// that.pee?.setRemoteDescription(msg.data.description)
|
||||
// break;
|
||||
// case "bye":
|
||||
// that.pee?.close()
|
||||
// that.close()
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
async createOffer() {
|
||||
|
||||
var url =
|
||||
'http://rw.quwanya.cn:12217/api/turn?service=turn&username=flutter-webrtc';
|
||||
'https://rw.quwanya.cn/api/turn?service=turn&username=flutter-webrtc';
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
|
||||
const configuration = {
|
||||
iceServers: [
|
||||
{
|
||||
|
@ -79,15 +75,18 @@ class WebRtc {
|
|||
}
|
||||
this.gets(configuration)
|
||||
})
|
||||
try {
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置远程offer
|
||||
setRemoteDes(answer) {
|
||||
this.pee?.setRemoteDescription(answer)
|
||||
}
|
||||
addCandidate(candidate) {
|
||||
if (!candidate) {
|
||||
return console.log('failed to parse candidate')
|
||||
}
|
||||
this.pee?.addIceCandidate(candidate)
|
||||
}
|
||||
async gets(configuration) {
|
||||
console.log(configuration);
|
||||
const peerConnection = new RTCPeerConnection(configuration);
|
||||
this.pee = peerConnection
|
||||
// 获取远方流添加到页面播放
|
||||
|
@ -97,7 +96,7 @@ class WebRtc {
|
|||
remoteVideo.controls = true
|
||||
remoteVideo.srcObject = event.streams[0];
|
||||
console.log(event);
|
||||
|
||||
|
||||
event.track.onmute = function () {
|
||||
remoteVideo.play()
|
||||
}
|
||||
|
@ -123,10 +122,10 @@ class WebRtc {
|
|||
that.ws?.send(JSON.stringify({
|
||||
type: "offer", "data": {
|
||||
"to": userId,
|
||||
"from": "31283192",
|
||||
"from": "admin",
|
||||
"description": offer,
|
||||
"media": "video",
|
||||
"session_id": userId + "-31283192",
|
||||
"session_id": userId + "-admin",
|
||||
}
|
||||
}))
|
||||
}).catch(function (error) {
|
||||
|
@ -150,20 +149,33 @@ class WebRtc {
|
|||
}
|
||||
}
|
||||
calls(userId) {
|
||||
this.sendOffer(userId)
|
||||
this.sendOffer("admin123")
|
||||
if (this.video) {
|
||||
this.video.srcObject = this.mediaStream;
|
||||
this.video.autoplay = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 发送本地offer
|
||||
setIceOffer(offer, toid) {
|
||||
this.pee?.setRemoteDescription(offer)
|
||||
this.pee?.createAnswer().then(answer => {
|
||||
this.pee?.setLocalDescription(answer)
|
||||
SocketService.getInstance().send({
|
||||
type: 'answer', data: {
|
||||
'to': toid,
|
||||
'from': "admin",
|
||||
'description': { 'sdp': answer.sdp, 'type': answer.type },
|
||||
'session_id': toid + "-admin",
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
close() {
|
||||
this.video?.pause();
|
||||
this.pee?.close();
|
||||
this.ws?.send(JSON.stringify({
|
||||
"type": "bye", "data": {
|
||||
"session_id": this.userToId + "31283192",
|
||||
"session_id": this.userToId + "admin",
|
||||
"to": this.userToId
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue