New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

conectar-middleware

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conectar-middleware - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

15

dist/conectar-middleware.cjs.development.js

@@ -615,3 +615,3 @@ 'use strict';

} catch (e) {
console.log('create connection failed due to' + e);
console.log('create connection failed due to ' + e);
}

@@ -658,3 +658,2 @@

if (peerId) {
//this.sendStream(peerId, media, stream);
var peerConnection = this.createPeerConnection(peerId, media, 'out');

@@ -667,3 +666,2 @@ stream.getTracks().forEach(function (track) {

Object.values(this.peers).forEach(function (peer) {
// this.sendStream(peer.userId, media, stream);
var peerConnection = _this12.createPeerConnection(peer.userId, media, 'out');

@@ -715,7 +713,2 @@

this.peerConnectionService.processEventFromPeerConnection(peerConnection, userId, media, direction);
/*
The line below seems to be used to resolve promises in the wire.js file in previous branches.
I haven't found a use for it.
*/
// peerConnection.answerPromise = new Promise(resolve => (peerConnection.answerResolve = resolve));

@@ -728,7 +721,3 @@ if (!this.peerConnections[userId]) {

return peerConnection;
}
/* private handleRemoveTrack(userId: string, media: StreamKeys): void {
this.runListeners('stream_removed', userId, media);
}*/
;
};

@@ -735,0 +724,0 @@ _proto.handleWebRTCEvent = function handleWebRTCEvent(event) {

2

dist/conectar-middleware.cjs.production.min.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("reflect-metadata");var e,t=require("inversify"),r=require("tslib"),n=(e=require("axios"))&&"object"==typeof e&&"default"in e?e.default:e,i=require("rxjs"),o={CallService:Symbol.for("ICallService"),AttachmentService:Symbol.for("IAttachmentService"),EventService:Symbol.for("IEventService"),ConversationService:Symbol.for("IConversationService"),WhiteboardService:Symbol.for("IWhiteboardService"),WebsocketService:Symbol.for("IWebsocketService"),ConfigService:Symbol.for("IConfigService"),PeerConnectionService:Symbol.for("IPeerConnectionService")},a=function(){function e(e,t,r){this.configService=e,this.websocketService=t,this.eventService=r}var t=e.prototype;return t.createConnection=function(e){return this.websocketService.createObservableSocket(e)},t.setConfig=function(e,t){this.configService.setBaseUrl(e),this.configService.setApiToken(t)},t.getUserConversations=function(){try{var e=this.resolveParams(),t=e[1];return Promise.resolve(n.get(e[0]+"/conversations",{headers:t&&{Authorization:"Bearer "+t}}))}catch(e){return Promise.reject(e)}},t.getMessages=function(e,t){try{var r=this.configService,i=[r.getBaseUrl(),r.getApiToken()],o=i[1];return Promise.resolve(n.get(i[0]+"/"+e+"/messages",{headers:o&&{Authorization:"Bearer "+o},data:{conversationId:e,page:t}}))}catch(e){return Promise.reject(e)}},t.getRoomConversation=function(e){try{var t=this.resolveParams(),r=t[1];return Promise.resolve(n.get(t[0]+"/"+e+"/room",{headers:r&&{Authorization:"Bearer "+r}}))}catch(e){return Promise.reject(e)}},t.resolveParams=function(){var e=this.configService,t=[e.getBaseUrl(),e.getApiToken()];return[t[0],t[1]]},t.sendMessage=function(e){this.websocketService.send(e)},t.addEventListener=function(e,t){this.eventService.addEventListener(e,t)},e}();a=r.__decorate([t.injectable(),r.__param(0,t.inject(o.ConfigService)),r.__param(1,t.inject(o.WebsocketService)),r.__param(2,t.inject(o.EventService)),r.__metadata("design:paramtypes",[Object,Object,Object])],a);var c=function(){function e(e){this.websocketService=e}var t=e.prototype;return t.addWhiteboardMetadata=function(e,t){this.sendEvent("update_whiteboard",{id:e,name:"",meta:t,objects:[]})},t.addWhiteboardObject=function(e,t,r){this.sendEvent("add_whiteboard_object",{id:e,name:"",meta:"",objects:[{id:t,object:r}]})},t.createWhiteboard=function(e,t){this.sendEvent("new_whiteboard",{id:e,name:t,meta:"",objects:[]})},t.removeWhiteboard=function(e){this.sendEvent("remove_whiteboard",{id:e,name:"",meta:"",objects:[]})},t.removeWhiteBoardObject=function(e,t,r){this.sendEvent("remove_whiteboard_object",{id:e,name:"",meta:"",objects:[{id:t,object:r}]})},t.renameWhiteboard=function(e,t){this.sendEvent("rename_whiteboard",{id:e,name:t,meta:"",objects:[]})},t.sendEvent=function(e,t){this.websocketService.send({action:e,data:t})},e}();function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}c=r.__decorate([t.injectable(),r.__param(0,t.inject(o.WebsocketService)),r.__metadata("design:paramtypes",[Object])],c);const u=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,i=this.s;if(i){const e=1&i?t:r;if(e){try{v(n,1,e(this.v))}catch(e){v(n,2,e)}return n}return this}return this.o=function(e){try{const i=e.v;1&e.s?v(n,1,t?t(i):i):r?v(n,1,r(i)):v(n,2,i)}catch(e){v(n,2,e)}},n},e}();function v(e,t,r){if(!e.s){if(r instanceof u){if(!r.s)return void(r.o=v.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(v.bind(null,e,t),v.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}function d(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var l=function(){function e(e,t,r){var n=this;this.eventService=e,this.websocketService=t,this.peerConnectionService=r,this.eventService.getObservableForEvent("webrtc").subscribe({next:function(e){return n.handleWebRTCEvent(e)}}),this.peers={},this.localStreams={},this.remoteStreams={},this.peerConnections={},this.iceServers=[{urls:"turn:conectar.demo.forasoft.com?transport=tcp",username:"conectar",credential:"ZVp1NaagEN7r"},{urls:"stun:stun.l.google.com:19302"}]}var t=e.prototype;return t.startDevice=function(e){try{return Promise.resolve(this.startStream(e)).then((function(){}))}catch(e){return Promise.reject(e)}},t.endCamera=function(){var e=this.localStreams.camera;null==e||e.getTracks().forEach((function(e){return e.stop()})),delete this.localStreams.camera},t.hangUp=function(e){try{var t=this;for(var r in t.peerConnections)for(var n=0,i=["mic","camera"];n<i.length;n++)for(var o=i[n],a=0,c=["out","in"];a<c.length;a++){var s,u,v,d,l=c[a],h=null===(s=t.peerConnections)||void 0===s||null===(u=s[r])||void 0===u?void 0:u[o+"_"+l];if(!h)return Promise.resolve();h.close(),(null===(v=t.peerConnections)||void 0===v||null===(d=v[r])||void 0===d?void 0:d[o+"_"+l])&&delete t.peerConnections[r][o+"_"+l]}var f=t.stringify("private_event",{payload:"hang_up",recipient:e});return t.websocketService.send(f),t.send("private_event",{payload:"hang_up",recipient:e}),["mic","camera","screen"].forEach((function(e){var r=t.localStreams[e];null==r||r.getTracks().forEach((function(e){return e.stop()})),delete t.localStreams[e]})),Promise.resolve()}catch(e){return Promise.reject(e)}},t.makeCall=function(e,t){try{var r,n=function(r){if(!r)throw new Error("Cannot find audio stream");return i.addStream(r,"mic",e),function(){if("video"===t){var r,n=function(t){if(!t)throw new Error("Cannot find video stream");i.addStream(t,"mic",e)},o=null===(r=i.localStreams)||void 0===r?void 0:r.camera;return o?Promise.resolve(i.startStream("camera")).then(n):n(o)}}()},i=this,o=null===(r=i.localStreams)||void 0===r?void 0:r.mic;return Promise.resolve(o?Promise.resolve(i.startStream("mic")).then(n):n(o))}catch(e){return Promise.reject(e)}},t.stringify=function(e,t){return JSON.stringify(s({action:e},t))},t.send=function(e,t){try{try{this.websocketService.send(JSON.stringify(s({action:e},t)))}catch(e){console.error(e)}return Promise.resolve()}catch(e){return Promise.reject(e)}},t.shareScreen=function(e){try{var t=this;return Promise.resolve(t.startStream("screen")).then((function(r){return function(){if(r){var n;try{t.addStream(r,"screen",e)}catch(e){console.log("create connection failed due to"+e)}return null===(n=t.eventService.getObservableForEvent("new_stream"))||void 0===n||n.next([e,"screen",r]),function(){if(!t.localStreams.mic)return Promise.resolve(t.startStream("mic")).then((function(r){if(!r)throw new Error("Cannot find mic stream");t.addStream(r,"mic",e)}))}()}throw new Error("Cannot find screen stream.")}()}))}catch(e){return Promise.reject(e)}},t.toggleMedia=function(e){var t,r;if(this.localStreams[e]){var n="mic"===e?"getAudioTracks":"camera"===e?"getVideoTracks":null;if(n){var i=null===(t=this.localStreams)||void 0===t||null===(r=t[e])||void 0===r?void 0:r[n]()[0];i&&(i.enabled=!i.enabled)}}},t.addStream=function(e,t,r){var n=this;if(this.localStreams[t]=e,r){var i=this.createPeerConnection(r,t,"out");e.getTracks().forEach((function(e){return i.addTrack(e)})),this.initiateOffer(i,r,t,"out")}else Object.values(this.peers).forEach((function(r){var i=n.createPeerConnection(r.userId,t,"out");e.getTracks().forEach((function(e){return i.addTrack(e)})),n.initiateOffer(i,r.userId,t,"out")}))},t.initiateOffer=function(e,t,r,n){try{var i=this,o=d((function(){return Promise.resolve(e.createOffer()).then((function(o){return Promise.resolve(e.setLocalDescription(o)).then((function(){var e=i.stringify("webrtc",{media:r,direction:n,type:"offer",recipient:t,payload:o.sdp});i.websocketService.send(e)}))}))}),(function(e){console.error(e)}));return Promise.resolve(o&&o.then?o.then((function(){})):void 0)}catch(e){return Promise.reject(e)}},t.createPeerConnection=function(e,t,r){var n;return n=new RTCPeerConnection({iceServers:this.iceServers}),console.log("create connection"),this.peerConnectionService.processEventFromPeerConnection(n,e,t,r),this.peerConnections[e]||(this.peerConnections[e]={}),this.peerConnections[e][t+"_"+r]=n,n},t.handleWebRTCEvent=function(e){try{var t,r,n;return t="offer"===e.type?this.createPeerConnection(e.sender,e.media,e.direction):null===(r=this.peerConnections)||void 0===r||null===(n=r[e.sender])||void 0===n?void 0:n[e.media+"_"+e.direction],Promise.resolve(this.peerConnectionService.processWebRTCEventFromWebsocket(e,t)).then((function(){}))}catch(e){return Promise.reject(e)}},t.startStream=function(e){try{var t=function(t){return r?t:Promise.resolve(n.localStreams[e])},r=!1,n=this,i=function(){if(!n.localStreams[e])return Promise.resolve(n.peerConnectionService.getUserMedia(e)).then((function(t){return n.localStreams[e]=t,r=!0,t}))}();return Promise.resolve(i&&i.then?i.then(t):t(i))}catch(e){return Promise.reject(e)}},e}();l=r.__decorate([t.injectable(),r.__param(0,t.inject(o.EventService)),r.__param(1,t.inject(o.WebsocketService)),r.__param(2,t.inject(o.PeerConnectionService)),r.__metadata("design:paramtypes",[Object,Object,Object])],l);var h=function(){function e(e){this.configService=e}var t=e.prototype;return t.uploadAttachment=function(e,t){try{return Promise.resolve(n.post(this.configService.getBaseUrl()+"/"+e.userId+"/attachment/"+e.roomId+"/upload",t,{headers:this.configService.getApiToken()&&{"Content-type":"multipart/form-data",Authorization:"Bearer "+this.configService.getApiToken()}}))}catch(e){return Promise.reject(e)}},t.getRoomFiles=function(e){try{return Promise.resolve(n.get(this.configService.getBaseUrl()+"/"+e+"/attachments",{headers:this.configService.getApiToken()&&{Authorization:"Bearer "+this.configService.getApiToken()}}))}catch(e){return Promise.reject(e)}},e}();h=r.__decorate([t.injectable(),r.__param(0,t.inject(o.ConfigService)),r.__metadata("design:paramtypes",[Object])],h);var f=function(){function e(e,t){this.eventService=e,this.config=t,this.connectionIsOpen=1}var t=e.prototype;return t.prepareTime=function(e){var t=e.timestamp;return s(s({},function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(i[r]=e[r]);return i}(e,["timestamp"])),{},{timestamp:new Date(1e3*t)})},t.createObservableSocket=function(e){var t=this,r=[this.config.getBaseUrl(),this.config.getApiToken()],n="ws";"http:"!==window.location.protocol&&(n+="s"),this.connection=new WebSocket(n+"://"+r[0]+"/ws?user_id="+e.userId+"&conversation_type="+e.conversationType+"&conversation_id="+e.conversationId+"&request_type="+e.requestType+"&token="+r[1]),this.connection.onopen=function(){console.log("CONNECTED")},this.connection.onmessage=function(e){var r=JSON.parse(e.data);t.eventService.publish(r.action,t.prepareTime(r)),console.log(r.action+"payload")},this.connection.onerror=function(){throw new Error("CONNECTION_ERROR")}},t.send=function(e){if(this.connection.readyState===this.connectionIsOpen)return this.connection.send(JSON.stringify(e)),"Sent to server";throw new Error("NO_CONNECTION")},e}();f=r.__decorate([t.injectable(),r.__param(0,t.inject(o.EventService)),r.__param(1,t.inject(o.ConfigService)),r.__metadata("design:paramtypes",[Object,Object])],f);var m=function(){function e(){this.allEvents=new Map}var t=e.prototype;return t.publish=function(e,t){var r;if(!this.allEvents.has(e))throw new Error("EVENT_NOT_REGISTERED");null===(r=this.allEvents.get(e))||void 0===r||r.next(t)},t.getObservableForEvent=function(e){return console.log("got here"),this.allEvents.has(e)||this.allEvents.set(e,new i.Subject),this.allEvents.get(e)},t.addEventListener=function(e,t){var r;this.allEvents.has(e)||this.allEvents.set(e,new i.Subject),null===(r=this.allEvents.get(e))||void 0===r||r.subscribe(t)},e}();m=r.__decorate([t.injectable()],m);var p=function(){function e(){this.CLASSROOM_BASE_URL=this.resolveBaseURL(),this.API_TOKEN=null}var t=e.prototype;return t.setApiToken=function(e){this.API_TOKEN=e},t.setBaseUrl=function(e){this.CLASSROOM_BASE_URL=e},t.getApiToken=function(){return this.API_TOKEN},t.getBaseUrl=function(){return this.CLASSROOM_BASE_URL},t.resolveBaseURL=function(){var e;switch(window.location.hostname){case"localhost":e="localhost:8081";break;case"staging.conectar.ru":e="classroom-staging-api.conectar.ru";break;default:e="conectar.ru"}return window.location.protocol+"//"+e},e}();p=r.__decorate([t.injectable(),r.__metadata("design:paramtypes",[])],p);var S=function(){function e(e,t){this.eventService=e,this.websocketService=t}var t=e.prototype;return t.processEventFromPeerConnection=function(e,t,r,n){var i=this;e.ontrack=function(e){i.runListeners("new_stream",t,r,e.streams[0])},e.onicecandidate=function(e){if(e.candidate){var o=i.stringify("webrtc",{media:r,direction:n,type:"candidate",recipient:t,payload:JSON.stringify(e.candidate.toJSON())});i.websocketService.send(o)}},e.oniceconnectionstatechange=function(){switch(null==e?void 0:e.iceConnectionState){case"connected":break;case"failed":console.error("Peer connection "+t+" "+r+"_"+n+" failed");break;case"closed":case"disconnected":i.runListeners("closed",{media:r,userId:t,direction:n})}}},t.processWebRTCEventFromWebsocket=function(e,t){try{var r=function(){},n=this,i=function(e,t){var r,n=-1;e:{for(var i=0;i<t.length;i++){var o=t[i][0];if(o){var a=o();if(a&&a.then)break e;if(a===e){n=i;break}}else n=i}if(-1!==n){do{for(var c=t[n][1];!c;)n++,c=t[n][1];var s=c();if(s&&s.then){r=!0;break e}var d=t[n][2];n++}while(d&&!d());return s}}const l=new u,h=v.bind(null,l,2);return(r?s.then(f):a.then((function r(a){for(;;){if(a===e){n=i;break}if(++i===t.length){if(-1!==n)break;return void v(l,1,s)}if(o=t[i][0]){if((a=o())&&a.then)return void a.then(r).then(void 0,h)}else n=i}do{for(var c=t[n][1];!c;)n++,c=t[n][1];var s=c();if(s&&s.then)return void s.then(f).then(void 0,h);var u=t[n][2];n++}while(u&&!u());v(l,1,s)}))).then(void 0,h),l;function f(e){for(;;){var r=t[n][2];if(!r||r())break;n++;for(var i=t[n][1];!i;)n++,i=t[n][1];if((e=i())&&e.then)return void e.then(f).then(void 0,h)}v(l,1,e)}}(e.type,[[function(){return"offer"},function(){var i=new RTCSessionDescription({type:"offer",sdp:e.payload}),o=d((function(){return Promise.resolve(t.setRemoteDescription(i)).then((function(){return Promise.resolve(t.createAnswer()).then((function(r){return Promise.resolve(t.setLocalDescription(r)).then((function(){var t=n.stringify("webrtc",{media:e.media,direction:e.direction,type:"answer",recipient:e.sender,payload:r.sdp});n.websocketService.send(t)}))}))}))}),(function(e){console.error(e)}));return o&&o.then?o.then(r):void 0}],[function(){return"answer"},function(){var r=new RTCSessionDescription({type:"answer",sdp:e.payload});null==t||t.setRemoteDescription(r)}],[function(){return"candidate"},function(){var r=new RTCIceCandidate(JSON.parse(e.payload));try{null==t||t.addIceCandidate(r)}catch(e){console.error(e,r)}}]]);return Promise.resolve(i&&i.then?i.then((function(){})):void 0)}catch(e){return Promise.reject(e)}},t.getUserMedia=function(e){try{var t;return Promise.resolve(navigator.mediaDevices.getUserMedia(((t={})["mic"===e?"audio":"video"]="screen"!==e||{frameRate:15},t)))}catch(e){return Promise.reject(e)}},t.runListeners=function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];null===(t=this.eventService.getObservableForEvent(e))||void 0===t||t.next.apply(t,n)},t.stringify=function(e,t){return JSON.stringify(s({action:e},t))},e}();S=r.__decorate([t.injectable(),r.__param(0,t.inject(o.EventService)),r.__param(1,t.inject(o.WebsocketService)),r.__metadata("design:paramtypes",[Object,Object])],S);var b=function(){function e(e){this.diContainer=new t.Container,"mocks"!==e&&this.configureServices()}return e.prototype.configureServices=function(){this.diContainer.bind(o.ConversationService).to(a),this.diContainer.bind(o.WebsocketService).to(f),this.diContainer.bind(o.WhiteboardService).to(c),this.diContainer.bind(o.CallService).to(l),this.diContainer.bind(o.AttachmentService).to(h),this.diContainer.bind(o.EventService).to(m).inSingletonScope(),this.diContainer.bind(o.ConfigService).to(p).inSingletonScope(),this.diContainer.bind(o.PeerConnectionService).to(S).inSingletonScope()},e}(),g=function(){function e(e){this.messageService=e}var t=e.prototype;return t.setConfig=function(e,t){this.messageService.setConfig(e,t)},t.createConnection=function(e){return this.messageService.createConnection(e)},t.addEventListener=function(e,t){this.messageService.addEventListener(e,t)},t.getMessages=function(e,t){try{return Promise.resolve(this.messageService.getMessages(e,t))}catch(e){return Promise.reject(e)}},t.getConversations=function(){try{return Promise.resolve(this.messageService.getUserConversations())}catch(e){return Promise.reject(e)}},e}();g=r.__decorate([t.injectable(),r.__param(0,t.inject(o.ConversationService)),r.__metadata("design:paramtypes",[Object])],g);var _=function(){function e(e){this.whiteBoardService=e}var t=e.prototype;return t.createWhiteboard=function(e,t){return this.whiteBoardService.createWhiteboard(e,t)},t.renameWhiteboard=function(e,t){return this.whiteBoardService.renameWhiteboard(e,t)},t.addWhiteboardMetadata=function(e,t){return this.whiteBoardService.addWhiteboardMetadata(e,t)},t.removeWhiteboard=function(e){return this.whiteBoardService.removeWhiteboard(e)},t.addWhiteboardObject=function(e,t,r){return this.whiteBoardService.addWhiteboardObject(e,t,r)},t.removeWhiteBoardObject=function(e,t,r){return this.whiteBoardService.removeWhiteBoardObject(e,t,r)},e}();_=r.__decorate([t.injectable(),r.__param(0,t.inject(o.WhiteboardService)),r.__metadata("design:paramtypes",[Object])],_);var y=function(){function e(e){this.callService=e}var t=e.prototype;return t.endCamera=function(){return this.callService.endCamera()},t.hangUp=function(e){return this.callService.hangUp(e)},t.makeVideoCall=function(e){return this.callService.makeCall(e,"video")},t.makeVoiceCall=function(e){return this.callService.makeCall(e,"voice")},t.send=function(e,t){return this.callService.send(e,t)},t.sendCallDecline=function(e){return this.send("private_event",{payload:"call_decline",recipient:e})},t.sendCallEvent=function(e,t,r){this.send("private_event",{recipient:e,payload:t+"_call_"+r})},t.sendVideoCallAccept=function(e){return this.sendCallEvent(e,"video","accept")},t.sendVideoCallRequest=function(e){return this.sendCallEvent(e,"video","request")},t.sendVoiceCallAccept=function(e){return this.sendCallEvent(e,"audio","accept")},t.sendVoiceCallRequest=function(e){return this.sendCallEvent(e,"audio","request")},t.shareScreen=function(e){return this.callService.shareScreen(e)},t.startCamera=function(){return this.callService.startDevice("camera")},t.startMic=function(){return this.callService.startDevice("screen")},t.toggleMic=function(){return this.callService.toggleMedia("mic")},t.toggleVideo=function(){return this.callService.toggleMedia("camera")},e}();y=r.__decorate([t.injectable(),r.__param(0,t.inject(o.CallService)),r.__metadata("design:paramtypes",[Object])],y);var C=function(){function e(e){this.attachmentService=e}var t=e.prototype;return t.uploadAttachment=function(e,t){try{return Promise.resolve(this.attachmentService.uploadAttachment(e,t))}catch(e){return Promise.reject(e)}},t.getRoomFiles=function(e){try{return Promise.resolve(this.attachmentService.getRoomFiles(e))}catch(e){return Promise.reject(e)}},e}();C=r.__decorate([t.injectable(),r.__param(0,t.inject(o.AttachmentService)),r.__metadata("design:paramtypes",[Object])],C),exports.default=new function(){this.bootstrap=new b("main"),this.Attachment=this.bootstrap.diContainer.resolve(C),this.CallComponent=this.bootstrap.diContainer.resolve(y),this.Messaging=this.bootstrap.diContainer.resolve(g),this.Whiteboard=this.bootstrap.diContainer.resolve(_)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("reflect-metadata");var e,t=require("inversify"),r=require("tslib"),n=(e=require("axios"))&&"object"==typeof e&&"default"in e?e.default:e,i=require("rxjs"),o={CallService:Symbol.for("ICallService"),AttachmentService:Symbol.for("IAttachmentService"),EventService:Symbol.for("IEventService"),ConversationService:Symbol.for("IConversationService"),WhiteboardService:Symbol.for("IWhiteboardService"),WebsocketService:Symbol.for("IWebsocketService"),ConfigService:Symbol.for("IConfigService"),PeerConnectionService:Symbol.for("IPeerConnectionService")},a=function(){function e(e,t,r){this.configService=e,this.websocketService=t,this.eventService=r}var t=e.prototype;return t.createConnection=function(e){return this.websocketService.createObservableSocket(e)},t.setConfig=function(e,t){this.configService.setBaseUrl(e),this.configService.setApiToken(t)},t.getUserConversations=function(){try{var e=this.resolveParams(),t=e[1];return Promise.resolve(n.get(e[0]+"/conversations",{headers:t&&{Authorization:"Bearer "+t}}))}catch(e){return Promise.reject(e)}},t.getMessages=function(e,t){try{var r=this.configService,i=[r.getBaseUrl(),r.getApiToken()],o=i[1];return Promise.resolve(n.get(i[0]+"/"+e+"/messages",{headers:o&&{Authorization:"Bearer "+o},data:{conversationId:e,page:t}}))}catch(e){return Promise.reject(e)}},t.getRoomConversation=function(e){try{var t=this.resolveParams(),r=t[1];return Promise.resolve(n.get(t[0]+"/"+e+"/room",{headers:r&&{Authorization:"Bearer "+r}}))}catch(e){return Promise.reject(e)}},t.resolveParams=function(){var e=this.configService,t=[e.getBaseUrl(),e.getApiToken()];return[t[0],t[1]]},t.sendMessage=function(e){this.websocketService.send(e)},t.addEventListener=function(e,t){this.eventService.addEventListener(e,t)},e}();a=r.__decorate([t.injectable(),r.__param(0,t.inject(o.ConfigService)),r.__param(1,t.inject(o.WebsocketService)),r.__param(2,t.inject(o.EventService)),r.__metadata("design:paramtypes",[Object,Object,Object])],a);var c=function(){function e(e){this.websocketService=e}var t=e.prototype;return t.addWhiteboardMetadata=function(e,t){this.sendEvent("update_whiteboard",{id:e,name:"",meta:t,objects:[]})},t.addWhiteboardObject=function(e,t,r){this.sendEvent("add_whiteboard_object",{id:e,name:"",meta:"",objects:[{id:t,object:r}]})},t.createWhiteboard=function(e,t){this.sendEvent("new_whiteboard",{id:e,name:t,meta:"",objects:[]})},t.removeWhiteboard=function(e){this.sendEvent("remove_whiteboard",{id:e,name:"",meta:"",objects:[]})},t.removeWhiteBoardObject=function(e,t,r){this.sendEvent("remove_whiteboard_object",{id:e,name:"",meta:"",objects:[{id:t,object:r}]})},t.renameWhiteboard=function(e,t){this.sendEvent("rename_whiteboard",{id:e,name:t,meta:"",objects:[]})},t.sendEvent=function(e,t){this.websocketService.send({action:e,data:t})},e}();function s(){return(s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}c=r.__decorate([t.injectable(),r.__param(0,t.inject(o.WebsocketService)),r.__metadata("design:paramtypes",[Object])],c);const u=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,i=this.s;if(i){const e=1&i?t:r;if(e){try{v(n,1,e(this.v))}catch(e){v(n,2,e)}return n}return this}return this.o=function(e){try{const i=e.v;1&e.s?v(n,1,t?t(i):i):r?v(n,1,r(i)):v(n,2,i)}catch(e){v(n,2,e)}},n},e}();function v(e,t,r){if(!e.s){if(r instanceof u){if(!r.s)return void(r.o=v.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(v.bind(null,e,t),v.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}function d(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var l=function(){function e(e,t,r){var n=this;this.eventService=e,this.websocketService=t,this.peerConnectionService=r,this.eventService.getObservableForEvent("webrtc").subscribe({next:function(e){return n.handleWebRTCEvent(e)}}),this.peers={},this.localStreams={},this.remoteStreams={},this.peerConnections={},this.iceServers=[{urls:"turn:conectar.demo.forasoft.com?transport=tcp",username:"conectar",credential:"ZVp1NaagEN7r"},{urls:"stun:stun.l.google.com:19302"}]}var t=e.prototype;return t.startDevice=function(e){try{return Promise.resolve(this.startStream(e)).then((function(){}))}catch(e){return Promise.reject(e)}},t.endCamera=function(){var e=this.localStreams.camera;null==e||e.getTracks().forEach((function(e){return e.stop()})),delete this.localStreams.camera},t.hangUp=function(e){try{var t=this;for(var r in t.peerConnections)for(var n=0,i=["mic","camera"];n<i.length;n++)for(var o=i[n],a=0,c=["out","in"];a<c.length;a++){var s,u,v,d,l=c[a],h=null===(s=t.peerConnections)||void 0===s||null===(u=s[r])||void 0===u?void 0:u[o+"_"+l];if(!h)return Promise.resolve();h.close(),(null===(v=t.peerConnections)||void 0===v||null===(d=v[r])||void 0===d?void 0:d[o+"_"+l])&&delete t.peerConnections[r][o+"_"+l]}var f=t.stringify("private_event",{payload:"hang_up",recipient:e});return t.websocketService.send(f),t.send("private_event",{payload:"hang_up",recipient:e}),["mic","camera","screen"].forEach((function(e){var r=t.localStreams[e];null==r||r.getTracks().forEach((function(e){return e.stop()})),delete t.localStreams[e]})),Promise.resolve()}catch(e){return Promise.reject(e)}},t.makeCall=function(e,t){try{var r,n=function(r){if(!r)throw new Error("Cannot find audio stream");return i.addStream(r,"mic",e),function(){if("video"===t){var r,n=function(t){if(!t)throw new Error("Cannot find video stream");i.addStream(t,"mic",e)},o=null===(r=i.localStreams)||void 0===r?void 0:r.camera;return o?Promise.resolve(i.startStream("camera")).then(n):n(o)}}()},i=this,o=null===(r=i.localStreams)||void 0===r?void 0:r.mic;return Promise.resolve(o?Promise.resolve(i.startStream("mic")).then(n):n(o))}catch(e){return Promise.reject(e)}},t.stringify=function(e,t){return JSON.stringify(s({action:e},t))},t.send=function(e,t){try{try{this.websocketService.send(JSON.stringify(s({action:e},t)))}catch(e){console.error(e)}return Promise.resolve()}catch(e){return Promise.reject(e)}},t.shareScreen=function(e){try{var t=this;return Promise.resolve(t.startStream("screen")).then((function(r){return function(){if(r){var n;try{t.addStream(r,"screen",e)}catch(e){console.log("create connection failed due to "+e)}return null===(n=t.eventService.getObservableForEvent("new_stream"))||void 0===n||n.next([e,"screen",r]),function(){if(!t.localStreams.mic)return Promise.resolve(t.startStream("mic")).then((function(r){if(!r)throw new Error("Cannot find mic stream");t.addStream(r,"mic",e)}))}()}throw new Error("Cannot find screen stream.")}()}))}catch(e){return Promise.reject(e)}},t.toggleMedia=function(e){var t,r;if(this.localStreams[e]){var n="mic"===e?"getAudioTracks":"camera"===e?"getVideoTracks":null;if(n){var i=null===(t=this.localStreams)||void 0===t||null===(r=t[e])||void 0===r?void 0:r[n]()[0];i&&(i.enabled=!i.enabled)}}},t.addStream=function(e,t,r){var n=this;if(this.localStreams[t]=e,r){var i=this.createPeerConnection(r,t,"out");e.getTracks().forEach((function(e){return i.addTrack(e)})),this.initiateOffer(i,r,t,"out")}else Object.values(this.peers).forEach((function(r){var i=n.createPeerConnection(r.userId,t,"out");e.getTracks().forEach((function(e){return i.addTrack(e)})),n.initiateOffer(i,r.userId,t,"out")}))},t.initiateOffer=function(e,t,r,n){try{var i=this,o=d((function(){return Promise.resolve(e.createOffer()).then((function(o){return Promise.resolve(e.setLocalDescription(o)).then((function(){var e=i.stringify("webrtc",{media:r,direction:n,type:"offer",recipient:t,payload:o.sdp});i.websocketService.send(e)}))}))}),(function(e){console.error(e)}));return Promise.resolve(o&&o.then?o.then((function(){})):void 0)}catch(e){return Promise.reject(e)}},t.createPeerConnection=function(e,t,r){var n;return n=new RTCPeerConnection({iceServers:this.iceServers}),console.log("create connection"),this.peerConnectionService.processEventFromPeerConnection(n,e,t,r),this.peerConnections[e]||(this.peerConnections[e]={}),this.peerConnections[e][t+"_"+r]=n,n},t.handleWebRTCEvent=function(e){try{var t,r,n;return t="offer"===e.type?this.createPeerConnection(e.sender,e.media,e.direction):null===(r=this.peerConnections)||void 0===r||null===(n=r[e.sender])||void 0===n?void 0:n[e.media+"_"+e.direction],Promise.resolve(this.peerConnectionService.processWebRTCEventFromWebsocket(e,t)).then((function(){}))}catch(e){return Promise.reject(e)}},t.startStream=function(e){try{var t=function(t){return r?t:Promise.resolve(n.localStreams[e])},r=!1,n=this,i=function(){if(!n.localStreams[e])return Promise.resolve(n.peerConnectionService.getUserMedia(e)).then((function(t){return n.localStreams[e]=t,r=!0,t}))}();return Promise.resolve(i&&i.then?i.then(t):t(i))}catch(e){return Promise.reject(e)}},e}();l=r.__decorate([t.injectable(),r.__param(0,t.inject(o.EventService)),r.__param(1,t.inject(o.WebsocketService)),r.__param(2,t.inject(o.PeerConnectionService)),r.__metadata("design:paramtypes",[Object,Object,Object])],l);var h=function(){function e(e){this.configService=e}var t=e.prototype;return t.uploadAttachment=function(e,t){try{return Promise.resolve(n.post(this.configService.getBaseUrl()+"/"+e.userId+"/attachment/"+e.roomId+"/upload",t,{headers:this.configService.getApiToken()&&{"Content-type":"multipart/form-data",Authorization:"Bearer "+this.configService.getApiToken()}}))}catch(e){return Promise.reject(e)}},t.getRoomFiles=function(e){try{return Promise.resolve(n.get(this.configService.getBaseUrl()+"/"+e+"/attachments",{headers:this.configService.getApiToken()&&{Authorization:"Bearer "+this.configService.getApiToken()}}))}catch(e){return Promise.reject(e)}},e}();h=r.__decorate([t.injectable(),r.__param(0,t.inject(o.ConfigService)),r.__metadata("design:paramtypes",[Object])],h);var f=function(){function e(e,t){this.eventService=e,this.config=t,this.connectionIsOpen=1}var t=e.prototype;return t.prepareTime=function(e){var t=e.timestamp;return s(s({},function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(i[r]=e[r]);return i}(e,["timestamp"])),{},{timestamp:new Date(1e3*t)})},t.createObservableSocket=function(e){var t=this,r=[this.config.getBaseUrl(),this.config.getApiToken()],n="ws";"http:"!==window.location.protocol&&(n+="s"),this.connection=new WebSocket(n+"://"+r[0]+"/ws?user_id="+e.userId+"&conversation_type="+e.conversationType+"&conversation_id="+e.conversationId+"&request_type="+e.requestType+"&token="+r[1]),this.connection.onopen=function(){console.log("CONNECTED")},this.connection.onmessage=function(e){var r=JSON.parse(e.data);t.eventService.publish(r.action,t.prepareTime(r)),console.log(r.action+"payload")},this.connection.onerror=function(){throw new Error("CONNECTION_ERROR")}},t.send=function(e){if(this.connection.readyState===this.connectionIsOpen)return this.connection.send(JSON.stringify(e)),"Sent to server";throw new Error("NO_CONNECTION")},e}();f=r.__decorate([t.injectable(),r.__param(0,t.inject(o.EventService)),r.__param(1,t.inject(o.ConfigService)),r.__metadata("design:paramtypes",[Object,Object])],f);var m=function(){function e(){this.allEvents=new Map}var t=e.prototype;return t.publish=function(e,t){var r;if(!this.allEvents.has(e))throw new Error("EVENT_NOT_REGISTERED");null===(r=this.allEvents.get(e))||void 0===r||r.next(t)},t.getObservableForEvent=function(e){return console.log("got here"),this.allEvents.has(e)||this.allEvents.set(e,new i.Subject),this.allEvents.get(e)},t.addEventListener=function(e,t){var r;this.allEvents.has(e)||this.allEvents.set(e,new i.Subject),null===(r=this.allEvents.get(e))||void 0===r||r.subscribe(t)},e}();m=r.__decorate([t.injectable()],m);var p=function(){function e(){this.CLASSROOM_BASE_URL=this.resolveBaseURL(),this.API_TOKEN=null}var t=e.prototype;return t.setApiToken=function(e){this.API_TOKEN=e},t.setBaseUrl=function(e){this.CLASSROOM_BASE_URL=e},t.getApiToken=function(){return this.API_TOKEN},t.getBaseUrl=function(){return this.CLASSROOM_BASE_URL},t.resolveBaseURL=function(){var e;switch(window.location.hostname){case"localhost":e="localhost:8081";break;case"staging.conectar.ru":e="classroom-staging-api.conectar.ru";break;default:e="conectar.ru"}return window.location.protocol+"//"+e},e}();p=r.__decorate([t.injectable(),r.__metadata("design:paramtypes",[])],p);var S=function(){function e(e,t){this.eventService=e,this.websocketService=t}var t=e.prototype;return t.processEventFromPeerConnection=function(e,t,r,n){var i=this;e.ontrack=function(e){i.runListeners("new_stream",t,r,e.streams[0])},e.onicecandidate=function(e){if(e.candidate){var o=i.stringify("webrtc",{media:r,direction:n,type:"candidate",recipient:t,payload:JSON.stringify(e.candidate.toJSON())});i.websocketService.send(o)}},e.oniceconnectionstatechange=function(){switch(null==e?void 0:e.iceConnectionState){case"connected":break;case"failed":console.error("Peer connection "+t+" "+r+"_"+n+" failed");break;case"closed":case"disconnected":i.runListeners("closed",{media:r,userId:t,direction:n})}}},t.processWebRTCEventFromWebsocket=function(e,t){try{var r=function(){},n=this,i=function(e,t){var r,n=-1;e:{for(var i=0;i<t.length;i++){var o=t[i][0];if(o){var a=o();if(a&&a.then)break e;if(a===e){n=i;break}}else n=i}if(-1!==n){do{for(var c=t[n][1];!c;)n++,c=t[n][1];var s=c();if(s&&s.then){r=!0;break e}var d=t[n][2];n++}while(d&&!d());return s}}const l=new u,h=v.bind(null,l,2);return(r?s.then(f):a.then((function r(a){for(;;){if(a===e){n=i;break}if(++i===t.length){if(-1!==n)break;return void v(l,1,s)}if(o=t[i][0]){if((a=o())&&a.then)return void a.then(r).then(void 0,h)}else n=i}do{for(var c=t[n][1];!c;)n++,c=t[n][1];var s=c();if(s&&s.then)return void s.then(f).then(void 0,h);var u=t[n][2];n++}while(u&&!u());v(l,1,s)}))).then(void 0,h),l;function f(e){for(;;){var r=t[n][2];if(!r||r())break;n++;for(var i=t[n][1];!i;)n++,i=t[n][1];if((e=i())&&e.then)return void e.then(f).then(void 0,h)}v(l,1,e)}}(e.type,[[function(){return"offer"},function(){var i=new RTCSessionDescription({type:"offer",sdp:e.payload}),o=d((function(){return Promise.resolve(t.setRemoteDescription(i)).then((function(){return Promise.resolve(t.createAnswer()).then((function(r){return Promise.resolve(t.setLocalDescription(r)).then((function(){var t=n.stringify("webrtc",{media:e.media,direction:e.direction,type:"answer",recipient:e.sender,payload:r.sdp});n.websocketService.send(t)}))}))}))}),(function(e){console.error(e)}));return o&&o.then?o.then(r):void 0}],[function(){return"answer"},function(){var r=new RTCSessionDescription({type:"answer",sdp:e.payload});null==t||t.setRemoteDescription(r)}],[function(){return"candidate"},function(){var r=new RTCIceCandidate(JSON.parse(e.payload));try{null==t||t.addIceCandidate(r)}catch(e){console.error(e,r)}}]]);return Promise.resolve(i&&i.then?i.then((function(){})):void 0)}catch(e){return Promise.reject(e)}},t.getUserMedia=function(e){try{var t;return Promise.resolve(navigator.mediaDevices.getUserMedia(((t={})["mic"===e?"audio":"video"]="screen"!==e||{frameRate:15},t)))}catch(e){return Promise.reject(e)}},t.runListeners=function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];null===(t=this.eventService.getObservableForEvent(e))||void 0===t||t.next.apply(t,n)},t.stringify=function(e,t){return JSON.stringify(s({action:e},t))},e}();S=r.__decorate([t.injectable(),r.__param(0,t.inject(o.EventService)),r.__param(1,t.inject(o.WebsocketService)),r.__metadata("design:paramtypes",[Object,Object])],S);var b=function(){function e(e){this.diContainer=new t.Container,"mocks"!==e&&this.configureServices()}return e.prototype.configureServices=function(){this.diContainer.bind(o.ConversationService).to(a),this.diContainer.bind(o.WebsocketService).to(f),this.diContainer.bind(o.WhiteboardService).to(c),this.diContainer.bind(o.CallService).to(l),this.diContainer.bind(o.AttachmentService).to(h),this.diContainer.bind(o.EventService).to(m).inSingletonScope(),this.diContainer.bind(o.ConfigService).to(p).inSingletonScope(),this.diContainer.bind(o.PeerConnectionService).to(S).inSingletonScope()},e}(),g=function(){function e(e){this.messageService=e}var t=e.prototype;return t.setConfig=function(e,t){this.messageService.setConfig(e,t)},t.createConnection=function(e){return this.messageService.createConnection(e)},t.addEventListener=function(e,t){this.messageService.addEventListener(e,t)},t.getMessages=function(e,t){try{return Promise.resolve(this.messageService.getMessages(e,t))}catch(e){return Promise.reject(e)}},t.getConversations=function(){try{return Promise.resolve(this.messageService.getUserConversations())}catch(e){return Promise.reject(e)}},e}();g=r.__decorate([t.injectable(),r.__param(0,t.inject(o.ConversationService)),r.__metadata("design:paramtypes",[Object])],g);var _=function(){function e(e){this.whiteBoardService=e}var t=e.prototype;return t.createWhiteboard=function(e,t){return this.whiteBoardService.createWhiteboard(e,t)},t.renameWhiteboard=function(e,t){return this.whiteBoardService.renameWhiteboard(e,t)},t.addWhiteboardMetadata=function(e,t){return this.whiteBoardService.addWhiteboardMetadata(e,t)},t.removeWhiteboard=function(e){return this.whiteBoardService.removeWhiteboard(e)},t.addWhiteboardObject=function(e,t,r){return this.whiteBoardService.addWhiteboardObject(e,t,r)},t.removeWhiteBoardObject=function(e,t,r){return this.whiteBoardService.removeWhiteBoardObject(e,t,r)},e}();_=r.__decorate([t.injectable(),r.__param(0,t.inject(o.WhiteboardService)),r.__metadata("design:paramtypes",[Object])],_);var y=function(){function e(e){this.callService=e}var t=e.prototype;return t.endCamera=function(){return this.callService.endCamera()},t.hangUp=function(e){return this.callService.hangUp(e)},t.makeVideoCall=function(e){return this.callService.makeCall(e,"video")},t.makeVoiceCall=function(e){return this.callService.makeCall(e,"voice")},t.send=function(e,t){return this.callService.send(e,t)},t.sendCallDecline=function(e){return this.send("private_event",{payload:"call_decline",recipient:e})},t.sendCallEvent=function(e,t,r){this.send("private_event",{recipient:e,payload:t+"_call_"+r})},t.sendVideoCallAccept=function(e){return this.sendCallEvent(e,"video","accept")},t.sendVideoCallRequest=function(e){return this.sendCallEvent(e,"video","request")},t.sendVoiceCallAccept=function(e){return this.sendCallEvent(e,"audio","accept")},t.sendVoiceCallRequest=function(e){return this.sendCallEvent(e,"audio","request")},t.shareScreen=function(e){return this.callService.shareScreen(e)},t.startCamera=function(){return this.callService.startDevice("camera")},t.startMic=function(){return this.callService.startDevice("screen")},t.toggleMic=function(){return this.callService.toggleMedia("mic")},t.toggleVideo=function(){return this.callService.toggleMedia("camera")},e}();y=r.__decorate([t.injectable(),r.__param(0,t.inject(o.CallService)),r.__metadata("design:paramtypes",[Object])],y);var C=function(){function e(e){this.attachmentService=e}var t=e.prototype;return t.uploadAttachment=function(e,t){try{return Promise.resolve(this.attachmentService.uploadAttachment(e,t))}catch(e){return Promise.reject(e)}},t.getRoomFiles=function(e){try{return Promise.resolve(this.attachmentService.getRoomFiles(e))}catch(e){return Promise.reject(e)}},e}();C=r.__decorate([t.injectable(),r.__param(0,t.inject(o.AttachmentService)),r.__metadata("design:paramtypes",[Object])],C),exports.default=new function(){this.bootstrap=new b("main"),this.Attachment=this.bootstrap.diContainer.resolve(C),this.CallComponent=this.bootstrap.diContainer.resolve(y),this.Messaging=this.bootstrap.diContainer.resolve(g),this.Whiteboard=this.bootstrap.diContainer.resolve(_)};
//# sourceMappingURL=conectar-middleware.cjs.production.min.js.map

@@ -609,3 +609,3 @@ import 'reflect-metadata';

} catch (e) {
console.log('create connection failed due to' + e);
console.log('create connection failed due to ' + e);
}

@@ -652,3 +652,2 @@

if (peerId) {
//this.sendStream(peerId, media, stream);
var peerConnection = this.createPeerConnection(peerId, media, 'out');

@@ -661,3 +660,2 @@ stream.getTracks().forEach(function (track) {

Object.values(this.peers).forEach(function (peer) {
// this.sendStream(peer.userId, media, stream);
var peerConnection = _this12.createPeerConnection(peer.userId, media, 'out');

@@ -709,7 +707,2 @@

this.peerConnectionService.processEventFromPeerConnection(peerConnection, userId, media, direction);
/*
The line below seems to be used to resolve promises in the wire.js file in previous branches.
I haven't found a use for it.
*/
// peerConnection.answerPromise = new Promise(resolve => (peerConnection.answerResolve = resolve));

@@ -722,7 +715,3 @@ if (!this.peerConnections[userId]) {

return peerConnection;
}
/* private handleRemoveTrack(userId: string, media: StreamKeys): void {
this.runListeners('stream_removed', userId, media);
}*/
;
};

@@ -729,0 +718,0 @@ _proto.handleWebRTCEvent = function handleWebRTCEvent(event) {

@@ -11,1 +11,2 @@ /// <reference types="jest" />

export declare const PeerConnectionServiceMock: jest.Mock<IPeerConnectionService, []>;
export declare const setupWebRTCMocks: () => void;
{
"version": "0.1.4",
"version": "0.1.5",
"license": "MIT",

@@ -45,2 +45,3 @@ "main": "dist/index.js",

"dependencies": {
"@types/webrtc": "^0.0.26",
"axios": "^0.19.2",

@@ -47,0 +48,0 @@ "inversify": "^5.0.1",

@@ -54,5 +54,5 @@ import 'reflect-metadata';

const configService: ConfigService = bootstrap.diContainer.resolve<ConfigService>(ConfigService);
expect(configService.getBaseUrl()).toBe('localhost:8081');
configService.setBaseUrl('localhost:8080');
expect(configService.getBaseUrl()).toBe('localhost:8080');
expect(configService.getBaseUrl()).toBe('http://localhost:8081');
configService.setBaseUrl('http://localhost:8080');
expect(configService.getBaseUrl()).toBe('http://localhost:8080');
});

@@ -59,0 +59,0 @@

@@ -19,3 +19,3 @@ import { IPeerConnectionService, ICallService } from 'webrtc_module/interfaces';

console.log('using mock getUserMedia');
return { video: { frameRate: 15 } };
return { video: { frameRate: 15 }, getTracks: () => [] };
}),

@@ -29,4 +29,19 @@ };

console.log('using mock getUserMedia');
return { audio: true, video: true };
return { audio: true, video: true, getTracks: () => [] };
}),
}));
export const setupWebRTCMocks = () => {
class RTCPeerConnection {
close = () => jest.fn();
addTrack = () => jest.fn();
createOffer = () => jest.fn();
setLocalDescription = () => jest.fn();
}
Object.defineProperty(window, 'RTCPeerConnection', {
writable: true,
configurable: true,
value: RTCPeerConnection,
});
};
import 'reflect-metadata';
import { EventMock, WebsocketMock } from '../websocket_module/__mocks__/services';
import { CallService } from './services/call_service';
import { MediaDevicesMock, PeerConnectionServiceMock } from './__mocks__/service';
import { MediaDevicesMock, PeerConnectionServiceMock, setupWebRTCMocks } from './__mocks__/service';

@@ -17,7 +17,2 @@ declare var global: any;

// const mediaDevices = {
// getUserMedia() {
// return jest.fn().mockImplementation(() => Promise.resolve(new MediaStream()));
// },
// };
windowSpy.mockImplementation(() => ({

@@ -31,6 +26,6 @@ location: {

}));
// expect(window.navigator.mediaDevices.getUserMedia).toHaveBeenCalled();
});
setupWebRTCMocks();
it('should end camera', async () => {

@@ -67,3 +62,3 @@ await callService.endCamera();

console.log('using mock getUserMedia for screen sharing');
return { video: { frameRate: 15 } };
return { video: { frameRate: 15 }, getTracks: () => [] };
});

@@ -76,2 +71,3 @@

});
/* it ("should toggle media", ()=>{

@@ -78,0 +74,0 @@ callService.toggleMedia("mic" as StreamKeys)

@@ -101,2 +101,3 @@ import { inject, injectable } from 'inversify';

}
if (callType === 'video') {

@@ -132,3 +133,3 @@ const videoStream = this.localStreams?.camera ?? (await this.startStream('camera'));

} catch (e) {
console.log('create connection failed due to' + e);
console.log('create connection failed due to ' + e);
}

@@ -167,4 +168,2 @@

if (peerId) {
//this.sendStream(peerId, media, stream);
const peerConnection = this.createPeerConnection(peerId, media, 'out');

@@ -176,4 +175,4 @@

Object.values(this.peers).forEach(peer => {
// this.sendStream(peer.userId, media, stream);
const peerConnection = this.createPeerConnection(peer.userId, media, 'out');
stream.getTracks().forEach(track => peerConnection.addTrack(track));

@@ -216,8 +215,2 @@ this.initiateOffer(peerConnection, peer.userId, media, 'out');

/*
The line below seems to be used to resolve promises in the wire.js file in previous branches.
I haven't found a use for it.
*/
// peerConnection.answerPromise = new Promise(resolve => (peerConnection.answerResolve = resolve));
if (!this.peerConnections[userId]) {

@@ -232,6 +225,2 @@ this.peerConnections[userId] = {};

/* private handleRemoveTrack(userId: string, media: StreamKeys): void {
this.runListeners('stream_removed', userId, media);
}*/
private async handleWebRTCEvent(event: RemoteData) {

@@ -238,0 +227,0 @@ let peerConnection;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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