Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@conectar/conectar-ws

Package Overview
Dependencies
Maintainers
3
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@conectar/conectar-ws - npm Package Compare versions

Comparing version 0.0.27 to 0.0.28

2

dist/wire.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Wire=t():e.Wire=t()}(window,function(){return function(e){var t={};function s(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)s.d(i,n,function(t){return e[t]}.bind(null,n));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";s.r(t);class i{constructor(e){this.options=e,this.iceServers=[{urls:"stun:stun.l.google.com:19302"}],this.listeners={},this.wait_to_reconnect=1,this.peers={},this.peer_connections={},this.local_streams={},"localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname?this.host="localhost:8081":"staging.conectar.ru"===window.location.hostname?this.host="classroom-staging-api.conectar.ru":this.host="classroom-api.conectar.ru","http:"===window.location.protocol?this.protocols={ws:"ws:",http:"http:"}:this.protocols={ws:"wss:",http:"https:"}}run_listeners(e,...t){this.listeners[e]&&this.listeners[e].forEach(e=>{e(...t)})}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeEventListener(e){this.listeners[e]&&(this.listeners[e]=[])}connect(e){return new Promise((t,s)=>{this.connection?s():(this.connection=new WebSocket(`${this.protocols.ws}//${this.host}${e}`),this.connection.onopen=(()=>{this.wait_to_reconnect=1,this.run_listeners("connected"),t()}),this.connection.onclose=(()=>{console.error("WIRE: websocket connection closed, reconnecting..."),setTimeout(()=>{this.connect()},this.wait_to_reconnect*=2)}),this.connection.onmessage=(e=>{const t=JSON.parse(e.data);switch(t.action){case"join":this.peers[t.user_id]=t,this.peer_connections[t.user_id]={},Object.entries(this.local_streams).forEach(([e,s])=>{this.send_stream(t.user_id,e,s)}),this.run_listeners("joined",this.prepare_time(t));break;case"leave":delete this.peers[t.user_id],Object.entries(this.peer_connections[t.user_id]).forEach(([e,t])=>{t.close()}),delete this.peer_connections[t.user_id],this.run_listeners("left",this.prepare_time(t));break;case"message":case"private_message":this.run_listeners(t.action,this.prepare_time(t));break;case"private_event":this.run_listeners(t.payload,t.sender);break;case"webrtc":switch(t.type){case"offer":this.handle_remote_offer(t);break;case"answer":this.handle_remote_answer(t);break;case"candidate":this.handle_remote_candidate(t);break;default:console.error(`unknown wrtc type ${t.type}`)}break;default:this.run_listeners(t.action,t)}}))})}send(e,t){this.connection.send(JSON.stringify({action:e,...t}))}send_private_message(e,t){this.send("private_message",{recipient:e,text:t})}send_voice_call_request(e){this.send("private_event",{payload:"voice_call_request",recipient:e})}send_voice_call_accept(e){this.send("private_event",{payload:"voice_call_accept",recipient:e})}send_video_call_request(e){this.send("private_event",{payload:"video_call_request",recipient:e})}send_video_call_accept(e){this.send("private_event",{payload:"video_call_accept",recipient:e})}createWhiteboard(e,t){this.send("new_whiteboard",{action:"new_whiteboard",whiteboard_id:e,whiteboard_name:t})}renameWhiteboard(e,t){this.send("rename_whiteboard",{action:"rename_whiteboard",whiteboard_id:e,whiteboard_name:t})}add_whiteboard_metadata(e,t){this.send("update_whiteboard",{action:"update_whiteboard",whiteboard_id:e,whiteboard_meta:t})}add_room_metadata(e){this.send("update_room_meta",{action:"update_room_meta",meta:e})}removeWhiteboard(e){this.send("remove_whiteboard",{action:"remove_whiteboard",whiteboard_id:e})}addObject(e,t,s){this.send("add_whiteboard_object",{action:"add_whiteboard_object",whiteboard_id:e,object_id:t,object:s})}removeObject(e,t){this.send("remove_whiteboard_object",{action:"remove_whiteboard_object",whiteboard_id:e,object_id:t})}send_call_decline(e){const t={action:"private_event",payload:"call_decline",recipient:e};this.connection.send(JSON.stringify(t))}get_room_whiteboards(e){return window.fetch(`${this.protocols.http}//${this.host}/${e}/whiteboards/`,{headers:this.options.httpHeaders}).then(e=>e.json())}get_room_metadata(e){return window.fetch(`${this.protocols.http}//${this.host}/${e}/meta/`,{headers:this.options.httpHeaders,credentials:"include"}).then(e=>e.json())}get_room_conversations(e,t=20,s=+Date.now()){return window.fetch(`${this.protocols.http}//${this.host}/${e}/conversations/?limit=${t}&timestamp=${s}`,{headers:this.options.httpHeaders,credentials:"include"}).then(e=>e.json())}get_room_participants(e){return window.fetch(`${this.protocols.http}//${this.host}/${e}/participants/`,{headers:this.options.httpHeaders,credentials:"include"}).then(e=>e.json())}get_private_messages(e){return window.fetch(`${this.protocols.http}//${this.host}/conversations/${e}/messages/`,{credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json()||e)}get_list_of_conversations(){return window.fetch(`${this.protocols.http}//${this.host}/conversations/`,{credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json()||e)}request(e,t={}){return window.fetch(`${this.protocols.http}//${this.host}/${e}`,{...t,credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json()||e)}handle_remote_offer({sender:e,media:t,direction:s,payload:i}){const n=this.get_peerconnection(e,t,s),o=new RTCSessionDescription({type:"offer",sdp:i});n.setRemoteDescription(o).then(()=>n.createAnswer()).then(e=>n.setLocalDescription(e)).then(()=>{this.send("webrtc",{recipient:e,type:"answer",media:t,direction:s,payload:n.localDescription.sdp})})}handle_local_candidate(e,t,s,i){i.candidate&&this.send("webrtc",{recipient:e,type:"candidate",media:t,direction:s,payload:JSON.stringify(i.candidate.toJSON())})}handle_remote_candidate({sender:e,media:t,direction:s,payload:i}){const n=new RTCIceCandidate(JSON.parse(i));this.get_peerconnection(e,t,s).addIceCandidate(n).catch(console.error)}handle_negotiation_needed(e,t,s){const i=this.get_peerconnection(e,t,s);"stable"===i.signalingState&&i.createOffer().then(e=>i.setLocalDescription(e)).then(()=>{this.send("webrtc",{recipient:e,type:"offer",media:t,direction:s,payload:i.localDescription.sdp})})}handle_remote_answer({sender:e,media:t,direction:s,payload:i}){const n=this.get_peerconnection(e,t,s),o=new RTCSessionDescription({type:"answer",sdp:i});n.setRemoteDescription(o)}handle_remote_track(e,t,s){this.run_listeners("new_stream",e,t,s.streams[0])}handle_ice_connection_state_change(e,t,s,i){switch(this.get_peerconnection(e,t,s).iceConnectionState){case"connected":break;case"failed":console.error(`Peer connection ${e} ${t}_${s} failed`);break;case"disconnected":case"closed":this.run_listeners("closed",{user_id:e,media:t,direction:s})}}hande_remove_track(e,t,s){this.run_listeners("stream_removed",e,t)}get_peerconnection(e,t,s){if(this.peer_connections[e]&&this.peer_connections[e][`${t}_${s}`])return this.peer_connections[e][`${t}_${s}`];this.peer_connections[e]||(this.peer_connections[e]={});const i=new RTCPeerConnection({iceServers:this.iceServers});return this.peer_connections[e][`${t}_${s}`]=i,i.addEventListener("icecandidate",i=>{this.handle_local_candidate(e,t,s,i)}),i.addEventListener("track",s=>{this.handle_remote_track(e,t,s)}),i.addEventListener("negotiationneeded",()=>{this.handle_negotiation_needed(e,t,s)}),i.addEventListener("removetrack",s=>{this.handle_remove_track(e,t,s)}),i.addEventListener("iceconnectionstatechange",i=>{this.handle_ice_connection_state_change(e,t,s,i)}),i}send_stream(e,t,s){const i=this.get_peerconnection(e,t,"out");s.getTracks().forEach(e=>i.addTrack(e,s))}toggle_video(){if(!this.local_streams.camera)return;const e=this.local_streams.camera.getVideoTracks()[0];e&&(e.enabled=!e.enabled)}toggle_muted_mic(){if(!this.local_streams.mic)return;const e=this.local_streams.mic.getAudioTracks()[0];e&&(e.enabled=!e.enabled)}add_stream(e,t,s){this.local_streams[t]=e,s?this.send_stream(s,t,e):Object.entries(this.peers).forEach(([s,i])=>{i.user_id!==this.user_id&&this.send_stream(i.user_id,t,e)})}voice_call(e){this.local_streams.mic?this.add_stream(this.local_streams.mic,"mic",e):this.start_mic().then(t=>{this.add_stream(t,"mic",e)})}video_call(e){this.local_streams.mic?this.add_stream(this.local_streams.mic,"mic",e):this.start_mic().then(t=>{this.add_stream(t,"mic",e)}),this.local_streams.camera||this.start_camera().then(t=>{this.add_stream(t,"camera",e)}),this.add_stream(this.local_streams.camera,"camera",e)}start_camera(){return this.local_streams.camera?Promise.resolve(this.local_streams.camera):navigator.mediaDevices.getUserMedia({video:!0}).then(e=>(this.local_streams.camera=e,e))}start_mic(){return this.local_streams.mic?Promise.resolve(this.local_streams.mic):navigator.mediaDevices.getUserMedia({audio:!0}).then(e=>(this.local_streams.mic=e,e))}share_screen(e){return new Promise((t,s)=>{this.local_streams.screen||this.start_screensharing().then(t=>{this.add_stream(t,"screen",e)}).catch(s).then(()=>{this.local_streams.mic||this.start_mic().then(s=>{this.add_stream(s,"mic",e),t()}).catch(s)})})}end_camera(){this.local_streams.camera&&(this.local_streams.camera.getTracks().forEach(e=>e.stop()),delete this.local_streams.camera)}end_mic(){this.local_streams.mic&&(this.local_streams.mic.getTracks().forEach(e=>e.stop()),delete this.local_streams.mic)}end_screen(){this.local_streams.screen&&(this.local_streams.screen.getTracks().forEach(e=>e.stop()),delete this.local_streams.screen)}hang_up(e){this.send("private_event",{payload:"hang_up",recipient:e}),this.end_mic(),this.end_camera(),this.end_screen()}start_screensharing(){return new Promise((e,t)=>{if(window.chrome){const s="cnctrchrxt";let i=!1;const n=function(e){window.postMessage({extension_tag:s,direction:"p2e",...e},window.origin)};window.addEventListener("message",t=>{if(t.data.extension_tag===s&&"e2p"===t.data.direction)switch(t.data.type){case"helo":i=!0;break;case"streamId":navigator.mediaDevices.getUserMedia({audio:!1,video:{mandatory:{chromeMediaSource:"desktop",maxWidth:1920,maxHeight:1080,chromeMediaSourceId:t.data.streamId}}}).then(t=>{e(t)})}}),n({type:"ehlo"}),setTimeout(()=>{i?n({type:"chooseDesktopMedia"}):t(new Error("please install extension"))},1e3)}else navigator.mediaDevices.getUserMedia({video:{mediaSource:"screen"}}).then(t=>{e(t)})})}prepare_time({timestamp:e,...t}){return{timestamp:new Date(1e3*e),...t}}}s.d(t,"setConfig",function(){return o});const n={httpHeaders:{}};t.default=(e=>new i(e))(n);const o=(e={})=>{Object.keys(e).forEach(t=>{const s=n[t];s?typeof s==typeof e[t]?n[t]=e[t]:console.error(`WIRE: Expected ${t} to be of type ${typeof s} instead`+` found ${typeof e[t]}`):console.error(`WIRE: Unknown option ${t}. Available options are ${Object.keys(n).join(", ")}`)})}}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Wire=t():e.Wire=t()}(window,function(){return function(e){var t={};function s(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)s.d(i,n,function(t){return e[t]}.bind(null,n));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";s.r(t);class i{constructor(e){this.options=e,this.iceServers=[{urls:"turn:connectar.demo.forasoft.com",username:"conectar",credential:"ZVp1NaagEN7r"},{urls:"stun:stun.l.google.com:19302"}],this.listeners={},this.wait_to_reconnect=1,this.peers={},this.peer_connections={},this.local_streams={},"localhost"===window.location.hostname||"127.0.0.1"===window.location.hostname?this.host="localhost:8081":"staging.conectar.ru"===window.location.hostname?this.host="classroom-staging-api.conectar.ru":this.host="classroom-api.conectar.ru","http:"===window.location.protocol?this.protocols={ws:"ws:",http:"http:"}:this.protocols={ws:"wss:",http:"https:"}}run_listeners(e,...t){this.listeners[e]&&this.listeners[e].forEach(e=>{e(...t)})}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeEventListener(e){this.listeners[e]&&(this.listeners[e]=[])}connect(e){return new Promise((t,s)=>{this.connection?s():(this.connection=new WebSocket(`${this.protocols.ws}//${this.host}${e}`),this.connection.onopen=(()=>{this.wait_to_reconnect=1,this.run_listeners("connected"),t()}),this.connection.onclose=(()=>{console.error("WIRE: websocket connection closed, reconnecting..."),setTimeout(()=>{this.connect(e)},this.wait_to_reconnect*=2)}),this.connection.onmessage=(e=>{const t=JSON.parse(e.data);switch(t.action){case"join":this.peers[t.user_id]=t,this.peer_connections[t.user_id]={},Object.entries(this.local_streams).forEach(([e,s])=>{this.send_stream(t.user_id,e,s)}),this.run_listeners("joined",this.prepare_time(t));break;case"leave":delete this.peers[t.user_id],Object.entries(this.peer_connections[t.user_id]).forEach(([e,t])=>{t.close()}),delete this.peer_connections[t.user_id],this.run_listeners("left",this.prepare_time(t));break;case"message":case"private_message":this.run_listeners(t.action,this.prepare_time(t));break;case"private_event":this.run_listeners(t.payload,t.sender);break;case"webrtc":switch(t.type){case"offer":this.handle_remote_offer(t);break;case"answer":this.handle_remote_answer(t);break;case"candidate":this.handle_remote_candidate(t);break;default:console.error(`unknown wrtc type ${t.type}`)}break;default:this.run_listeners(t.action,t)}}))})}send(e,t){this.connection.send(JSON.stringify({action:e,...t}))}send_private_message(e,t){this.send("private_message",{recipient:e})}send_room_message(e){this.send("message",{text:e})}send_voice_call_request(e){this.send("private_event",{payload:"voice_call_request",recipient:e})}send_voice_call_accept(e){this.send("private_event",{payload:"voice_call_accept",recipient:e})}send_video_call_request(e){this.send("private_event",{payload:"video_call_request",recipient:e})}send_video_call_accept(e){this.send("private_event",{payload:"video_call_accept",recipient:e})}createWhiteboard(e,t){this.send("new_whiteboard",{action:"new_whiteboard",whiteboard_id:e,whiteboard_name:t})}renameWhiteboard(e,t){this.send("rename_whiteboard",{action:"rename_whiteboard",whiteboard_id:e,whiteboard_name:t})}add_whiteboard_metadata(e,t){this.send("update_whiteboard",{action:"update_whiteboard",whiteboard_id:e,whiteboard_meta:t})}add_room_metadata(e){this.send("update_room_meta",{action:"update_room_meta",meta:e})}removeWhiteboard(e){this.send("remove_whiteboard",{action:"remove_whiteboard",whiteboard_id:e})}addObject(e,t,s){this.send("add_whiteboard_object",{action:"add_whiteboard_object",whiteboard_id:e,object_id:t,object:s})}removeObject(e,t){this.send("remove_whiteboard_object",{action:"remove_whiteboard_object",whiteboard_id:e,object_id:t})}send_call_decline(e){const t={action:"private_event",payload:"call_decline",recipient:e};this.connection.send(JSON.stringify(t))}get_room_whiteboards(e){return window.fetch(`${this.protocols.http}//${this.host}/${e}/whiteboards/`,{headers:this.options.httpHeaders}).then(e=>e.json())}get_room_metadata(e){return window.fetch(`${this.protocols.http}//${this.host}/${e}/meta/`,{headers:this.options.httpHeaders,credentials:"include"}).then(e=>e.json())}get_room_conversations(e,t=20,s=+Date.now()){return window.fetch(`${this.protocols.http}//${this.host}/${e}/conversations/?limit=${t}&timestamp=${s}`,{headers:this.options.httpHeaders,credentials:"include"}).then(e=>e.json())}get_room_participants(e){return window.fetch(`${this.protocols.http}//${this.host}/${e}/participants/`,{headers:this.options.httpHeaders,credentials:"include"}).then(e=>e.json())}get_private_messages(e){return window.fetch(`${this.protocols.http}//${this.host}/conversations/${e}/messages/`,{credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json()||e)}get_list_of_conversations(){return window.fetch(`${this.protocols.http}//${this.host}/conversations/`,{credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json()||e)}request(e,t={}){return window.fetch(`${this.protocols.http}//${this.host}/${e}`,{...t,credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json()||e)}handle_remote_offer({sender:e,media:t,direction:s,payload:i}){const n=this.create_peerconnection(e,t,s),o=new RTCSessionDescription({type:"offer",sdp:i});let r=null;n.setRemoteDescription(o).then(()=>(n.answerResolve(),n.createAnswer())).then(e=>(r=e,n.setLocalDescription(r))).then(()=>{this.send("webrtc",{recipient:e,type:"answer",media:t,direction:s,payload:r.sdp})})}handle_local_candidate(e,t,s,i){i.candidate&&this.send("webrtc",{recipient:e,type:"candidate",media:t,direction:s,payload:JSON.stringify(i.candidate.toJSON())})}handle_remote_candidate({sender:e,media:t,direction:s,payload:i}){const n=new RTCIceCandidate(JSON.parse(i)),o=this.get_peerconnection(e,t,s);o.answerPromise.then(()=>{o.addIceCandidate(n).catch(e=>{console.error(e,n)})})}initiateOffer(e,t,s,i){e.createOffer().then(t=>e.setLocalDescription(t)).then(()=>{this.send("webrtc",{recipient:t,type:"offer",media:s,direction:i,payload:e.localDescription.sdp})})}handle_remote_answer({sender:e,media:t,direction:s,payload:i}){const n=this.get_peerconnection(e,t,s),o=new RTCSessionDescription({type:"answer",sdp:i});n.setRemoteDescription(o).then(()=>{n.answerResolve()})}handle_remote_track(e,t,s){this.run_listeners("new_stream",e,t,s.streams[0])}handle_ice_connection_state_change(e,t,s,i){switch(this.get_peerconnection(e,t,s).iceConnectionState){case"connected":break;case"failed":console.error(`Peer connection ${e} ${t}_${s} failed`);break;case"disconnected":case"closed":this.run_listeners("closed",{user_id:e,media:t,direction:s})}}hande_remove_track(e,t,s){this.run_listeners("stream_removed",e,t)}create_peerconnection(e,t,s){const i=new RTCPeerConnection({iceServers:this.iceServers});return i.addEventListener("icecandidate",i=>{this.handle_local_candidate(e,t,s,i)}),i.addEventListener("track",s=>{this.handle_remote_track(e,t,s)}),i.addEventListener("iceconnectionstatechange",i=>{this.handle_ice_connection_state_change(e,t,s,i)}),i.answerPromise=new Promise(e=>i.answerResolve=e),this.peer_connections[e]||(this.peer_connections[e]={}),this.peer_connections[e][`${t}_${s}`]=i,i}get_peerconnection(e,t,s){return this.peer_connections[e]&&this.peer_connections[e][`${t}_${s}`]?this.peer_connections[e][`${t}_${s}`]:null}remove_peerconnection(e,t,s){this.peer_connections[e]&&this.peer_connections[e][`${t}_${s}`]&&delete this.peer_connections[e][`${t}_${s}`]}send_stream(e,t,s){const i=this.create_peerconnection(e,t,"out");s.getTracks().forEach(e=>i.addTrack(e,s)),this.initiateOffer(i,e,t,"out")}toggle_video(){if(!this.local_streams.camera)return;const e=this.local_streams.camera.getVideoTracks()[0];e&&(e.enabled=!e.enabled)}toggle_muted_mic(){if(!this.local_streams.mic)return;const e=this.local_streams.mic.getAudioTracks()[0];e&&(e.enabled=!e.enabled)}add_stream(e,t,s){this.local_streams[t]=e,s?this.send_stream(s,t,e):Object.entries(this.peers).forEach(([s,i])=>{i.user_id!==this.user_id&&this.send_stream(i.user_id,t,e)})}voice_call(e){this.local_streams.mic?this.add_stream(this.local_streams.mic,"mic",e):this.start_mic().then(t=>{this.add_stream(t,"mic",e)})}video_call(e){this.local_streams.mic?this.add_stream(this.local_streams.mic,"mic",e):this.start_mic().then(t=>{this.add_stream(t,"mic",e)}),this.local_streams.camera||this.start_camera().then(t=>{this.add_stream(t,"camera",e)}),this.add_stream(this.local_streams.camera,"camera",e)}start_camera(){return this.local_streams.camera?Promise.resolve(this.local_streams.camera):navigator.mediaDevices.getUserMedia({video:!0}).then(e=>(this.local_streams.camera=e,e))}start_mic(){return this.local_streams.mic?Promise.resolve(this.local_streams.mic):navigator.mediaDevices.getUserMedia({audio:!0}).then(e=>(this.local_streams.mic=e,e))}share_screen(e){return new Promise((t,s)=>{this.local_streams.screen||this.start_screensharing().then(t=>{this.add_stream(t,"screen",e)}).catch(s).then(()=>{this.local_streams.mic||this.start_mic().then(s=>{this.add_stream(s,"mic",e),t()}).catch(s)})})}end_camera(){this.local_streams.camera&&(this.local_streams.camera.getTracks().forEach(e=>e.stop()),delete this.local_streams.camera)}end_mic(){this.local_streams.mic&&(this.local_streams.mic.getTracks().forEach(e=>e.stop()),delete this.local_streams.mic)}end_screen(){this.local_streams.screen&&(this.local_streams.screen.getTracks().forEach(e=>e.stop()),delete this.local_streams.screen)}hang_up(e){for(const e in this.peer_connections)for(const t of["camera","mic"])for(const s of["out","in"])this.destroyPeerConnection(e,t,s);this.send("private_event",{payload:"hang_up",recipient:e}),this.end_mic(),this.end_camera(),this.end_screen()}destroyPeerConnection(e,t,s){const i=this.get_peerconnection(e,t,s);i&&(i.close(),this.remove_peerconnection(e,t,s))}start_screensharing(){return new Promise((e,t)=>{if(window.chrome){const s="cnctrchrxt";let i=!1;const n=function(e){window.postMessage({extension_tag:s,direction:"p2e",...e},window.origin)};window.addEventListener("message",t=>{if(t.data.extension_tag===s&&"e2p"===t.data.direction)switch(t.data.type){case"helo":i=!0;break;case"streamId":navigator.mediaDevices.getUserMedia({audio:!1,video:{mandatory:{chromeMediaSource:"desktop",maxWidth:1920,maxHeight:1080,chromeMediaSourceId:t.data.streamId}}}).then(t=>{e(t)})}}),n({type:"ehlo"}),setTimeout(()=>{i?n({type:"chooseDesktopMedia"}):t(new Error("please install extension"))},1e3)}else navigator.mediaDevices.getUserMedia({video:{mediaSource:"screen"}}).then(t=>{e(t)})})}prepare_time({timestamp:e,...t}){return{timestamp:new Date(1e3*e),...t}}}s.d(t,"setConfig",function(){return o});const n={httpHeaders:{}};t.default=(e=>new i(e))(n);const o=(e={})=>{Object.keys(e).forEach(t=>{const s=n[t];s?typeof s==typeof e[t]?n[t]=e[t]:console.error(`WIRE: Expected ${t} to be of type ${typeof s} instead`+` found ${typeof e[t]}`):console.error(`WIRE: Unknown option ${t}. Available options are ${Object.keys(n).join(", ")}`)})}}])});
{
"name": "@conectar/conectar-ws",
"version": "0.0.27",
"version": "0.0.28",
"description": "Conectar WS connections",

@@ -5,0 +5,0 @@ "main": "dist/wire.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc