conectar-ws
Advanced tools
Comparing version 0.0.7 to 0.0.9
@@ -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_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(", ")}`)})}}])}); | ||
!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})}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}×tamp=${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())}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),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){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 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(", ")}`)})}}])}); |
@@ -20,5 +20,10 @@ // Type definitions for Wire.js 0.0.1 | ||
): void; | ||
addWhiteboardMetadata( | ||
/** | ||
* Adds metadata such as active board, tool type, stroke color, stroke width | ||
* @param meta A stringified object of new whiteboard metadata to append | ||
*/ | ||
add_room_metadata(meta: string): void | ||
add_whiteboard_metadata( | ||
whiteboard_id: string, | ||
whiteboard_name: string | ||
whiteboard_meta: string | ||
): void; | ||
@@ -35,3 +40,3 @@ connect(url: string): Promise<void>; | ||
get_private_messages(roomId: string): Promise<any>; | ||
get_room_conversations(roomId: string): Promise<any>; | ||
get_room_conversations(roomId: string, limit?: string, timestamp?: string): Promise<any>; | ||
get_room_metadata(roomId: string): Promise<any>; | ||
@@ -52,5 +57,5 @@ get_room_participants(roomId: string): Promise<any>; | ||
): void; | ||
request(url:string, options: RequestInit): Promise<any>; | ||
request(url:string, options?: RequestInit): Promise<any>; | ||
run_listeners(): void; | ||
send_call_decline(): void; | ||
send_call_decline(recipient?: string): void; | ||
send_private_message(recipient: string, txt: string): void; | ||
@@ -62,6 +67,6 @@ send_stream( | ||
): void; | ||
send_video_call_accept(recipient: string): void; | ||
send_video_call_request(recipient: string): void; | ||
send_voice_call_accept(recipient: string): void; | ||
send_voice_call_request(recipient: string): void; | ||
send_video_call_accept(recipient?: string): void; | ||
send_video_call_request(recipient?: string): void; | ||
send_voice_call_accept(recipient?: string): void; | ||
send_voice_call_request(recipient?: string): void; | ||
send(action: string, data: object): void; | ||
@@ -74,4 +79,4 @@ share_screen(peer_id: string): void; | ||
toggle_video(): void; | ||
video_call(peer_id: string): void; | ||
voice_call(peer_id: string): void; | ||
video_call(peer_id?: string): void; | ||
voice_call(peer_id?: string): void; | ||
} | ||
@@ -78,0 +83,0 @@ const Wire: Wire; |
@@ -189,5 +189,5 @@ export default class Wire { | ||
addWhiteboardMetadata(whiteboard_id, whiteboard_meta) { | ||
this.send('rename_whiteboard', { | ||
action: 'rename_whiteboard', | ||
add_whiteboard_metadata(whiteboard_id, whiteboard_meta) { | ||
this.send('update_whiteboard', { | ||
action: 'update_whiteboard', | ||
whiteboard_id, | ||
@@ -198,2 +198,9 @@ whiteboard_meta, | ||
add_room_metadata(meta) { | ||
this.send('update_room_meta', { | ||
action: 'update_room_meta', | ||
meta, | ||
}); | ||
} | ||
removeWhiteboard(whiteboard_id) { | ||
@@ -245,8 +252,10 @@ this.send('remove_whiteboard', { | ||
get_room_conversations(roomId) { | ||
return window.fetch(`${this.protocols.http}//${this.host}/${roomId}/conversations/`, | ||
get_room_conversations(roomId, limit = 20, timestamp = +Date.now()) { | ||
return window.fetch( | ||
`${this.protocols.http}//${this.host}/${roomId}/conversations/?limit=${limit}×tamp=${timestamp}`, | ||
{ | ||
headers: this.options.httpHeaders, | ||
credentials: 'include', | ||
}).then(res => res.json()); | ||
}, | ||
).then(res => res.json()); | ||
} | ||
@@ -276,3 +285,3 @@ | ||
request(url, options) { | ||
request(url, options = {}) { | ||
return window.fetch(`${this.protocols.http}//${this.host}/${url}`, { | ||
@@ -279,0 +288,0 @@ ...options, |
{ | ||
"name": "conectar-ws", | ||
"version": "0.0.7", | ||
"version": "0.0.9", | ||
"description": "Conectar WS connections", | ||
@@ -5,0 +5,0 @@ "main": "dist/wire.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
285313
1
3
10
737