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

conectar-ws

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conectar-ws - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

102

dist/index.d.ts

@@ -5,53 +5,53 @@ // Type definitions for Wire.js 0.0.1

declare module Wire {
export function setConfig(a: string): string;
declare class Wire {
constructor(greeting: string);
addEventListener(): void;
run_listeners(): void;
addEventListener(): void;
removeEventListener(): void;
connect(): void;
send(): void;
send_private_message(): void;
send_voice_call_request(): void;
send_voice_call_accept(): void;
send_video_call_request(): void;
send_video_call_accept(): void;
createWhiteboard(): void;
renameWhiteboard(): void;
removeWhiteboard(): void;
addObject(): void;
removeObject(): void;
send_call_decline(): void;
get_room_whiteboards(): void;
get_private_messages(): void;
get_list_of_conversations(): void;
handle_remote_offer(): void;
handle_local_candidate(): void;
handle_remote_candidate(): void;
handle_negotiation_needed(): void;
handle_remote_answer(): void;
handle_remote_track(): void;
handle_ice_connection_state_change(): void;
hande_remove_track(): void;
get_peerconnection(): void;
send_stream(): void;
toggle_video(): void;
toggle_muted_mic(): void;
add_stream(): void;
voice_call(): void;
video_call(): void;
start_camera(): void;
start_mic(): void;
share_screen(): void;
end_camera(): void;
end_mic(): void;
end_screen(): void;
hang_up(): void;
start_screensharing(): void;
prepare_time(): void;
}
export function setConfig(a: any): string;
declare interface Wire {
add_stream(): void;
addEventListener(): void;
addEventListener(): void;
addObject(): void;
connect(): Promise<void>;
createWhiteboard(): void;
end_camera(): void;
end_mic(): void;
end_screen(): void;
get_list_of_conversations(): Promise<any>;
get_peerconnection(): void;
get_private_messages(): Promise<any>;
get_room_conversations(): Promise<any>;
get_room_metadata(): Promise<any>;
get_room_participants(): Promise<any>;
get_room_whiteboards(): Promise<void>;
// hande_remove_track(): void;
// handle_ice_connection_state_change(): void;
// handle_local_candidate(): void;
// handle_negotiation_needed(): void;
// handle_remote_answer(): void;
// handle_remote_candidate(): void;
// handle_remote_offer(): void;
// handle_remote_track(): void;
hang_up(): void;
prepare_time(): void;
removeEventListener(): void;
removeObject(): void;
removeWhiteboard(): void;
renameWhiteboard(): void;
request(): Promise<any>;
run_listeners(): void;
send_call_decline(): void;
send_private_message(): void;
send_stream(): void;
send_video_call_accept(): void;
send_video_call_request(): void;
send_voice_call_accept(): void;
send_voice_call_request(): void;
send(): void;
share_screen(): void;
start_camera(): Promise<void>;
start_mic(): Promise<void>;
start_screensharing(): void;
toggle_muted_mic(): void;
toggle_video(): void;
video_call(): void;
voice_call(): void;
}

@@ -58,0 +58,0 @@

@@ -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":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})}addWhiteboardMetadata(e,t){this.send("rename_whiteboard",{action:"rename_whiteboard",whiteboard_id:e,whiteboard_meta:t})}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_private_messages(e){return window.fetch(`${this.protocols.http}//${this.host}/conversations/${e}/messages/`,{credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json())}get_list_of_conversations(){return window.fetch(`${this.protocols.http}//${this.host}/conversations/`,{credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json())}handle_remote_offer({sender:e,media:t,direction:s,payload:i}){const n=this.get_peerconnection(e,t,s),r=new RTCSessionDescription({type:"offer",sdp:i});n.setRemoteDescription(r).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),r=new RTCSessionDescription({type:"answer",sdp:i});n.setRemoteDescription(r)}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){this.local_streams.screen||this.start_screensharing().then(t=>{this.add_stream(t,"screen",e)}),this.local_streams.mic||this.start_mic().then(t=>{this.add_stream(t,"mic",e)})}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 r});const n={httpHeaders:{}};t.default=(e=>new i(e))(n);const r=(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:"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":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})}addWhiteboardMetadata(e,t){this.send("rename_whiteboard",{action:"rename_whiteboard",whiteboard_id:e,whiteboard_meta:t})}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){return window.fetch(`${this.protocols.http}//${this.host}/${e}/conversations/`,{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())}get_list_of_conversations(){return window.fetch(`${this.protocols.http}//${this.host}/conversations/`,{credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json())}request(e,t){return window.fetch(`${this.protocols.http}//${this.host}/${e}`,{...t,credentials:"include",headers:this.options.httpHeaders}).then(e=>e.json())}handle_remote_offer({sender:e,media:t,direction:s,payload:i}){const n=this.get_peerconnection(e,t,s),r=new RTCSessionDescription({type:"offer",sdp:i});n.setRemoteDescription(r).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),r=new RTCSessionDescription({type:"answer",sdp:i});n.setRemoteDescription(r)}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){this.local_streams.screen||this.start_screensharing().then(t=>{this.add_stream(t,"screen",e)}),this.local_streams.mic||this.start_mic().then(t=>{this.add_stream(t,"mic",e)})}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 r});const n={httpHeaders:{}};t.default=(e=>new i(e))(n);const r=(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(", ")}`)})}}])});

@@ -235,2 +235,26 @@ export default class Wire {

get_room_metadata(roomId) {
return window.fetch(`${this.protocols.http}//${this.host}/${roomId}/meta/`,
{
headers: this.options.httpHeaders,
credentials: 'include',
}).then(res => res.json());
}
get_room_conversations(roomId) {
return window.fetch(`${this.protocols.http}//${this.host}/${roomId}/conversations/`,
{
headers: this.options.httpHeaders,
credentials: 'include',
}).then(res => res.json());
}
get_room_participants(roomId) {
return window.fetch(`${this.protocols.http}//${this.host}/${roomId}/participants/`,
{
headers: this.options.httpHeaders,
credentials: 'include',
}).then(res => res.json());
}
get_private_messages(user_id) {

@@ -250,2 +274,10 @@ return window.fetch(`${this.protocols.http}//${this.host}/conversations/${user_id}/messages/`, {

request(url, options) {
return window.fetch(`${this.protocols.http}//${this.host}/${url}`, {
...options,
credentials: 'include',
headers: this.options.httpHeaders,
}).then(response => response.json());
}
handle_remote_offer({

@@ -252,0 +284,0 @@ sender,

{
"name": "conectar-ws",
"version": "0.0.3",
"version": "0.0.4",
"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