conectar-middleware
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -18,3 +18,2 @@ 'use strict'; | ||
ConversationService: /*#__PURE__*/Symbol["for"]('IConversationService'), | ||
MessageComponent: /*#__PURE__*/Symbol["for"]('MessageComponent'), | ||
WhiteboardService: /*#__PURE__*/Symbol["for"]('IWhiteboardService'), | ||
@@ -21,0 +20,0 @@ WebsocketService: /*#__PURE__*/Symbol["for"]('IWebsocketService'), |
@@ -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"),MessageComponent:Symbol.for("MessageComponent"),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(){switch(window.location.host){case"localhost":return"localhost:8081";default:return"conectar.ru"}},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(){switch(window.location.host){case"localhost":return"localhost:8081";default:return"conectar.ru"}},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 |
@@ -12,3 +12,2 @@ import 'reflect-metadata'; | ||
ConversationService: /*#__PURE__*/Symbol["for"]('IConversationService'), | ||
MessageComponent: /*#__PURE__*/Symbol["for"]('MessageComponent'), | ||
WhiteboardService: /*#__PURE__*/Symbol["for"]('IWhiteboardService'), | ||
@@ -15,0 +14,0 @@ WebsocketService: /*#__PURE__*/Symbol["for"]('IWebsocketService'), |
{ | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -6,3 +6,2 @@ export const TYPES = { | ||
ConversationService: Symbol.for('IConversationService'), | ||
MessageComponent: Symbol.for('MessageComponent'), | ||
WhiteboardService: Symbol.for('IWhiteboardService'), | ||
@@ -9,0 +8,0 @@ WebsocketService: Symbol.for('IWebsocketService'), |
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
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
442557
73
4361