我想将下面的对象存储到我的本地存储中,并希望在整个应用程序中使用。为此,我使用了循环功能。但是,当我从字符串重新创建对象时,它不是同一对象。下面是我的对象。
e.exports {client: I}
client: I
browserDetails: {browser: "chrome", version: 80}
permOnClick: true
ringToneFlag: true
ringToneBackFlag: true
connectToneFlag: true
isLoggedIn: true
reconnectInterval: null
reconnectTryCount: 0
localStorage: Storage
length: 13
AsteriskIntegration:ServerIP: ""
auto_saved_sql: "INSERT INTO document_revisions (id,change_log,document_id,doc_id,doc_type,doc_url,date_entered,created_by,filename,file_ext,file_mime_type,revision,deleted,date_modified) VALUES ('e0a40e04-ceb6-dd54-a05d-5e5cc8f4461b','Document Created','390d0e08-1ba9-dcff-1eb8-5e5cc8b83741','','Sugar','','2020-03-02 08:47:40','1','Test.pdf','pdf','application/pdf','1',0,'2020-03-02 08:47:40')"
plivoBrowserSdkJSON: "{"client":{"browserDetails":{"browser":"chrome","version":80},"permOnClick":true,"ringToneFlag":true,"ringToneBackFlag":true,"connectToneFlag":true,"isLoggedIn":true,"reconnectInterval":null,"reconnectTryCount":0,"localStorage":{"AsteriskIntegration:ServerIP":"","endpointID":"001f922acfecfd9498ea0b2b84703ce8f14d2fa55dc96b857bfbfd1ffe9af40d","AsteriskIntegration:Extension":"","AsteriskIntegration:Context":"","AsteriskIntegration:ToggleStatus":"Minimized","AsteriskIntegration:ShowNotification":"0","favorite_tables":"undefined","debug":"","csio_auth_data":"\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWJtaXNzaW9uSW50ZXJ2YWwiOiI1MDAwIiwic2NvcGUiOlsicmVzdC1hcGktaDEiLCJyZXN0LWFwaSIsInN0b3JlLXNkcCIsImh0dHBzOi8vZXZlbnRzLWV1LXdlc3QtMS5jYWxsc3RhdHMuaW8vdjEvYXBwcyIsImh0dHBzOi8vc3RhdHMtZXUtd2VzdC0xLmNhbGxzdGF0cy5pby92MS9hcHBzIiwiaHR0cHM6Ly9hcHBzZXR0aW5ncy1ldS13ZXN0LTEuY2FsbHN0YXRzLmlvL3YxL2FwcHMiLCJodHRwczovL2Rhc2hib2FyZC1ldS13ZXN0LTEuY2FsbHN0YXRzLmlvL2FwcHMiXSwiY29sbGVjdFNEUCI6dHJ1ZSwiYWRhcHRpdmVJbnRlcnZhbCI6ZmFsc2UsImFkYXB0aXZlU3RhdHNFbmFibGVkIjpmYWxzZSwibXVsdGlTRFAiOmZhbHNlLCJ0YWFzRW5hYmxlZCI6ZmFsc2UsInJhd1VzZXJJRCI6ImRhdmlkNTcxOTg5ODM1ODMyOTU0OTIzMSIsInVzZXJJRCI6ImRhdmlkNTcxOTg5ODM1ODMyOTU0OTIzMSIsImp3dGlkQ2hhaW4iOlsiNDIiXSwiZW5kcG9pbnRUeXBlIjoiY2xpZW50IiwiYXBwSUQiOjM4MDA3NzA4NCwicmVzdEFwaVRyYW5zcG9ydCI6dHJ1ZSwicmVuZXdJbnRlcnZhbCI6MzQwMDAwMCwiZXhwaXJ5IjoiMjAyMC0wMi0xM1QwNzoxMDo1MS4zMDZaIiwib3JpZ2luIjpudWxsLCJpYXQiOjE1ODE1NzQ0NTEsImV4cCI6MTU4MTU3ODA1MSwianRpIjoiZWYxYmIxN2YtYzFkNy00MjJlLTg0MDktNTBmODQ4YjJhMmI4In0.FsF6rn82ss9JcAC9UxqUFeCiTe0xl9WDNNeQHBoFc4s\"","AsteriskIntegration:UserID":"1","AsteriskIntegration:SocketPort":""},"_events":{},"_eventsCount":0,"phone":{"_events":{},"_eventsCount":7,"_cache":{"credentials":{}},"_configuration":{"authorization_user":"david","password":null,"realm":"phone.plivo.com","ha1":"2291bb7891ceefc3ab2221cb1565fba6","display_name":null,"uri":{"_parameters":{},"_headers":{},"_scheme":"sip","_user":"david5719898358329549231","_host":"phone.plivo.com"},"contact_uri":{"_parameters":{"transport":"ws"},"_headers":{},"_scheme":"sip","_user":"r594n4dv","_host":"aeqf7b88emss.invalid","_port":null},"instance_id":"78fdf100-2c4d-4deb-a8ac-0cee371db730","use_preloaded_route":false,"session_timers":false,"session_timers_refresh_method":"UPDATE","no_answer_timeout":60000,"register":true,"register_expires":120,"registrar_server":{"_parameters":{},"_headers":{},"_scheme":"sip","_user":null,"_host":"phone.plivo.com"},"connection_recovery_max_interval":20,"connection_recovery_min_interval":2,"via_host":"aeqf7b88emss.invalid","user_agent":"plivo-browser-sdk 2.1.20","plivosip_id":"out4c","hostport_params":"phone.plivo.com"},"_dynConfiguration":{"register":true},"_dialogs":{},"_applicants":{},"_sessions":{},"_transport":{"status":0,"socket":{"_url":"wss://phone.plivo.com:5063","_sip_uri":"sip:phone.plivo.com:5063;transport=ws","_via_transport":"WSS","_ws":{}},"sockets":[{"weight":0,"status":0}],"recovery_options":{"max_interval":20,"min_interval":2},"recover_attempts":0,"recovery_timer":null,"close_requested":false},"_contact":{"pub_gruu":null,"temp_gruu":null},"_status":1,"_error":null,"_transactions":{"nist":{},"nict":{},"ist":{},"ict":{}},"_data":{},"_closeTimer":null,"_registrator":{"_expires":120,"_call_id":"vsa32oc37nnu7143rk274o","_cseq":2,"_registrationTimer":131,"_registering":false,"_registered":true,"_contact":"<sip:r594n4dv@aeqf7b88emss.invalid;transport=ws>;+sip.ice;reg-id=1;+sip.instance=\"<urn:uuid:78fdf100-2c4d-4deb-a8ac-0cee371db730>\"","_extraHeaders":[],"_extraContactParams":""}},"_currentSession":null,"callSession":null,"callUUID":null,"callDirection":null,"lastCallUUID":null,"_lastCallSession":null,"incomingInvites":{},"incomingCallsInitiationTime":{},"lastIncomingCall":null,"callStats":{},"sipAuthBy":null,"userName":"david5719898358329549231","options":{"codecs":["OPUS","PCMU"],"enableTracking":true,"debug":"DEBUG","permOnClick":true,"enableIPV6":false,"audioConstraints":{},"dscp":true,"appId":"380077084","appSecret":null,"registrationDomainSocket":null,"clientRegion":null,"preDetectOwa":false,"disableRtpTimeOut":false,"allowMultipleIncomingCalls":false},"callstatskey":null,"rtp_enabled":null,"statsioused":false,"audio":{"ringtoneDevices":{},"microphoneDevices":{},"speakerDevices":{}},"owaLastDetect":{"time":0,"isOneWay":true},"owaDetectTime":3600000,"outBoundConnectionStages":[],"_outboundExtraHeaders":{},"_outboundCallNumber":null,"statsSocket":null,"bucketApiUrl":"https://stats.plivo.com/v1/browser/bucketurl/","bucketApiBody":{"username":"david5719898358329549231","password":"lokesh","domain":"phone.plivo.com"},"remoteView":{"width":0,"height":0},"ringToneView":{},"ringBackToneView":{},"connectToneView":{},"audioDevDic":["{\"deviceId\":\"default\",\"kind\":\"audioinput\",\"label\":\"Default\",\"groupId\":\"4ce38a6beefca1618312cc984683f32afdd8a031f04697ce4606940d6456d61b\"}","{\"deviceId\":\"d07a50eedfb049ab16b39ddbb545865947600d3673194a608af977f9ce1cf21f\",\"kind\":\"audioinput\",\"label\":\"Built-in Audio Analog Stereo\",\"groupId\":\"e8c51c00b437c50e95499ec3af71c3ad64bd7f204ee5dc3723471a9e0b8a5291\"}","{\"deviceId\":\"default\",\"kind\":\"audiooutput\",\"label\":\"Default\",\"groupId\":\"default\"}","{\"deviceId\":\"aef20cba2448b4d804e2e968682a01c4b1940595ca9b65de3acc0e16ea987338\",\"kind\":\"audiooutput\",\"label\":\"Built-in Audio Analog Stereo\",\"groupId\":\"e8c51c00b437c50e95499ec3af71c3ad64bd7f204ee5dc3723471a9e0b8a5291\"}"]}}"
endpointID: "001f922acfecfd9498ea0b2b84703ce8f14d2fa55dc96b857bfbfd1ffe9af40d"
AsteriskIntegration:Extension: ""
AsteriskIntegration:Context: ""
AsteriskIntegration:ToggleStatus: "Minimized"
AsteriskIntegration:ShowNotification: "0"
favorite_tables: "undefined"
debug: ""
csio_auth_data: ""eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWJtaXNzaW9uSW50ZXJ2YWwiOiI1MDAwIiwic2NvcGUiOlsicmVzdC1hcGktaDEiLCJyZXN0LWFwaSIsInN0b3JlLXNkcCIsImh0dHBzOi8vZXZlbnRzLWV1LXdlc3QtMS5jYWxsc3RhdHMuaW8vdjEvYXBwcyIsImh0dHBzOi8vc3RhdHMtZXUtd2VzdC0xLmNhbGxzdGF0cy5pby92MS9hcHBzIiwiaHR0cHM6Ly9hcHBzZXR0aW5ncy1ldS13ZXN0LTEuY2FsbHN0YXRzLmlvL3YxL2FwcHMiLCJodHRwczovL2Rhc2hib2FyZC1ldS13ZXN0LTEuY2FsbHN0YXRzLmlvL2FwcHMiXSwiY29sbGVjdFNEUCI6dHJ1ZSwiYWRhcHRpdmVJbnRlcnZhbCI6ZmFsc2UsImFkYXB0aXZlU3RhdHNFbmFibGVkIjpmYWxzZSwibXVsdGlTRFAiOmZhbHNlLCJ0YWFzRW5hYmxlZCI6ZmFsc2UsInJhd1VzZXJJRCI6ImRhdmlkNTcxOTg5ODM1ODMyOTU0OTIzMSIsInVzZXJJRCI6ImRhdmlkNTcxOTg5ODM1ODMyOTU0OTIzMSIsImp3dGlkQ2hhaW4iOlsiNDIiXSwiZW5kcG9pbnRUeXBlIjoiY2xpZW50IiwiYXBwSUQiOjM4MDA3NzA4NCwicmVzdEFwaVRyYW5zcG9ydCI6dHJ1ZSwicmVuZXdJbnRlcnZhbCI6MzQwMDAwMCwiZXhwaXJ5IjoiMjAyMC0wMy0xN1QwNToxNTo0NS45MDZaIiwib3JpZ2luIjpudWxsLCJpYXQiOjE1ODQ0MTg3NDUsImV4cCI6MTU4NDQyMjM0NSwianRpIjoiNWQ2ODg4YjctN2E3MC00ZTFkLWJmYTMtODA4MWJiOGYyNjRhIn0.41caOjpo4BbY7qknU9HV-R7HIKhb_4ZiybW6njYcnqQ""
AsteriskIntegration:UserID: "1"
AsteriskIntegration:SocketPort: ""
__proto__: Storage
_events: {}
_eventsCount: 0
_maxListeners: undefined
phone: e.exports {_events: {…}, _eventsCount: 7, _maxListeners: undefined, _cache: {…}, _configuration: {…}, …}
_currentSession: null
callSession: null
callUUID: null
callDirection: null
lastCallUUID: null
_lastCallSession: null
incomingInvites: Map(0) {}
incomingCallsInitiationTime: Map(0) {}
lastIncomingCall: null
callStats: a {}
sipAuthBy: null
userName: "david5719898358329549231"
options: {codecs: Array(2), enableTracking: true, debug: "DEBUG", permOnClick: true, enableIPV6: false, …}
callstatskey: "73aec46c-4893-41ff-aab9-aa23ef9df7f0"
rtp_enabled: true
statsioused: false
audio: {ringtoneDevices: {…}, microphoneDevices: {…}, speakerDevices: {…}, availableDevices: ƒ, revealAudioDevices: ƒ}
audioConstraints: {}
owaLastDetect: {time: 0, isOneWay: true}
owaDetectTime: 3600000
outBoundConnectionStages: []
_outboundExtraHeaders: {}
_outboundCallNumber: null
statsSocket: s {url: "wss://insights.plivo.com/ws", ws: WebSocket, userName: "david5719898358329549231", callstatskey: "73aec46c-4893-41ff-aab9-aa23ef9df7f0"}
statsCallback: ƒ ()
calcConnStage: ƒ (e)
str: ƒ (e)
bucketApiUrl: URL {href: "https://stats.plivo.com/v1/browser/bucketurl/", origin: "https://stats.plivo.com", protocol: "https:", username: "", password: "", …}
bucketApiBody: {username: "david", password: "abc", domain: "phone.plivo.com"}
remoteView: audio#plivo_webrtc_remoteview
ringToneView: audio#plivo_ringtone
ringBackToneView: audio#plivo_ringbacktone
connectToneView: audio#plivo_connect_tone
audioDevDic: (4) ["{"deviceId":"default","kind":"audioinput","label":…2c403010b9047aa8545d46eda66540c5d9fcd4cec87eb17"}", "{"deviceId":"d07a50eedfb049ab16b39ddbb545865947600…9ef43f5d3efef4e5adabc15779e3ce654fd2ff0ae4c72e7"}", "{"deviceId":"default","kind":"audiooutput","label":"Default","groupId":"default"}", "{"deviceId":"aef20cba2448b4d804e2e968682a01c4b1940…9ef43f5d3efef4e5adabc15779e3ce654fd2ff0ae4c72e7"}"]
plivoSocket: e.exports {_url: "wss://phone.plivo.com:5063", _sip_uri: "sip:phone.plivo.com:5063;transport=ws", _via_transport: "WSS", _ws: WebSocket, onconnect: ƒ, …}
heartbeatTimer: 85
__proto__: o
__proto__: Object
下面是我将对象转换为字符串的代码。
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
var plivoBrowserSdkJSON = JSON.stringify(plivoBrowserSdk, getCircularReplacer());
我遵循以下答案。
答案 0 :(得分:0)
///使用构造函数创建一个类,仅使用数据重新初始化 您无法序列化功能。因为不是枚举属性
navigator.mediaDevices.getUserMedia
//归档一个
class SomeUtil {
constructor({ statsSocket, remoteView, ringToneView, ...rest }) {
this.statsSocket = statsSocket
this.remoteView = remoteView
this.ringToneView = ringToneView // some customization
Object.entries(rest).forEach(([key, value]) => {
this[key] = value
})
}
statsCallback() {
console.log(1)
}
}
const getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
//文件2
function test1() {
const util = new SomeUtil();
util.remoteView = "audio#plivo_webrtc_remoteview"
const onSave = () => {
localStorage.setItem("SomeUtil", JSON.stringify(util, getCircularReplacer()))
}
}
//