conectar-middleware
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -610,5 +610,5 @@ 'use strict'; | ||
try { | ||
_this9.websocketService.send(JSON.stringify(_extends({ | ||
_this9.websocketService.send(_extends({ | ||
action: action | ||
}, data))); | ||
}, data)); | ||
} catch (error) { | ||
@@ -894,5 +894,9 @@ console.error(error); | ||
_proto.send = function send(payload) { | ||
console.log(this.connection); | ||
var _this$connection; | ||
if (this.connection.readyState === this.connectionIsOpen) { | ||
console.log({ | ||
connection: this.connection | ||
}); | ||
if (((_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.readyState) === this.connectionIsOpen) { | ||
this.connection.send(JSON.stringify(payload)); | ||
@@ -1166,3 +1170,2 @@ return 'Sent to server'; | ||
this.diContainer.bind(TYPES.ConversationService).to(ConversationService); | ||
this.diContainer.bind(TYPES.WebsocketService).to(WebsocketService); | ||
this.diContainer.bind(TYPES.WhiteboardService).to(WhiteBoardService); | ||
@@ -1173,2 +1176,3 @@ this.diContainer.bind(TYPES.CallService).to(CallService); | ||
this.diContainer.bind(TYPES.ConfigService).to(ConfigService).inSingletonScope(); | ||
this.diContainer.bind(TYPES.WebsocketService).to(WebsocketService).inSingletonScope(); | ||
this.diContainer.bind(TYPES.PeerConnectionService).to(PeerConnectionService).inSingletonScope(); | ||
@@ -1175,0 +1179,0 @@ }; |
@@ -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.getConversationByUserId=function(e){try{var t=this.resolveParams(),r=t[1];return Promise.resolve(n.get(t[0]+"/users/"+e+"/conversations/",{headers:r&&{Authorization:"Bearer "+r}}))}catch(e){return Promise.reject(e)}},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 v=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{u(n,1,e(this.v))}catch(e){u(n,2,e)}return n}return this}return this.o=function(e){try{const i=e.v;1&e.s?u(n,1,t?t(i):i):r?u(n,1,r(i)):u(n,2,i)}catch(e){u(n,2,e)}},n},e}();function u(e,t,r){if(!e.s){if(r instanceof v){if(!r.s)return void(r.o=u.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(u.bind(null,e,t),u.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}function l(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 d=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,v,u,l,d=c[a],h=null===(s=t.peerConnections)||void 0===s||null===(v=s[r])||void 0===v?void 0:v[o+"_"+d];if(!h)return Promise.resolve();h.close(),(null===(u=t.peerConnections)||void 0===u||null===(l=u[r])||void 0===l?void 0:l[o+"_"+d])&&delete t.peerConnections[r][o+"_"+d]}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=l((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}();d=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])],d);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=r[1],i=r[0].split("//")[1];console.log(e.ConversationId),this.connection=new WebSocket("wss://"+i+"/ws?UserId="+e.UserId+"&ConversationType="+e.ConversationType+"&ConversationId="+e.ConversationId+"&RequestType="+e.RequestType+"&token="+n),this.connection.onopen=function(){console.log("CONNECTED")},this.connection.onmessage=function(e){console.log({WSEvent:e});var r=JSON.parse(e.data);t.eventService.publish(r.action,t.prepareTime(r)),console.log(r.action+"_payload")},this.connection.onerror=function(){console.error("WEBSOCKET_CONNECTION_ERROR")},this.connection.onclose=function(){console.error("WEBSOCKET_CONNECTION_CLOSED")}},t.send=function(e){if(console.log(this.connection),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(console.log({eventName:e}),!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=localStorage.getItem("token")}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(){return window.location.protocol+"//classroom-dev-api.herokuapp.com"},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 l=t[n][2];n++}while(l&&!l());return s}}const d=new v,h=u.bind(null,d,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 u(d,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 v=t[n][2];n++}while(v&&!v());u(d,1,s)}))).then(void 0,h),d;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)}u(d,1,e)}}(e.type,[[function(){return"offer"},function(){var i=new RTCSessionDescription({type:"offer",sdp:e.payload}),o=l((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(d),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 console.log(e),console.log(e.ConversationId),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)}},t.getConversationByUserId=function(e){try{return Promise.resolve(this.messageService.getConversationByUserId(e))}catch(e){return Promise.reject(e)}},t.sendMessage=function(e){try{return Promise.resolve(this.messageService.sendMessage(e))}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 y=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}();y=r.__decorate([t.injectable(),r.__param(0,t.inject(o.WhiteboardService)),r.__metadata("design:paramtypes",[Object])],y);var C=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}();C=r.__decorate([t.injectable(),r.__param(0,t.inject(o.CallService)),r.__metadata("design:paramtypes",[Object])],C);var _=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}();_=r.__decorate([t.injectable(),r.__param(0,t.inject(o.AttachmentService)),r.__metadata("design:paramtypes",[Object])],_);var j=new function(){this.bootstrap=new b("main"),this.Attachment=this.bootstrap.diContainer.resolve(_),this.Call=this.bootstrap.diContainer.resolve(C),this.Messaging=this.bootstrap.diContainer.resolve(g),this.Whiteboard=this.bootstrap.diContainer.resolve(y)},E=j.Call,P=j.Messaging,w=j.Whiteboard;exports.Attachment=j.Attachment,exports.Call=E,exports.Messaging=P,exports.Whiteboard=w,exports.default=j; | ||
"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.getConversationByUserId=function(e){try{var t=this.resolveParams(),r=t[1];return Promise.resolve(n.get(t[0]+"/users/"+e+"/conversations/",{headers:r&&{Authorization:"Bearer "+r}}))}catch(e){return Promise.reject(e)}},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 v=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{u(n,1,e(this.v))}catch(e){u(n,2,e)}return n}return this}return this.o=function(e){try{const i=e.v;1&e.s?u(n,1,t?t(i):i):r?u(n,1,r(i)):u(n,2,i)}catch(e){u(n,2,e)}},n},e}();function u(e,t,r){if(!e.s){if(r instanceof v){if(!r.s)return void(r.o=u.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(u.bind(null,e,t),u.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}function l(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 d=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,v,u,l,d=c[a],h=null===(s=t.peerConnections)||void 0===s||null===(v=s[r])||void 0===v?void 0:v[o+"_"+d];if(!h)return Promise.resolve();h.close(),(null===(u=t.peerConnections)||void 0===u||null===(l=u[r])||void 0===l?void 0:l[o+"_"+d])&&delete t.peerConnections[r][o+"_"+d]}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(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=l((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}();d=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])],d);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=r[1],i=r[0].split("//")[1];console.log(e.ConversationId),this.connection=new WebSocket("wss://"+i+"/ws?UserId="+e.UserId+"&ConversationType="+e.ConversationType+"&ConversationId="+e.ConversationId+"&RequestType="+e.RequestType+"&token="+n),this.connection.onopen=function(){console.log("CONNECTED")},this.connection.onmessage=function(e){console.log({WSEvent:e});var r=JSON.parse(e.data);t.eventService.publish(r.action,t.prepareTime(r)),console.log(r.action+"_payload")},this.connection.onerror=function(){console.error("WEBSOCKET_CONNECTION_ERROR")},this.connection.onclose=function(){console.error("WEBSOCKET_CONNECTION_CLOSED")}},t.send=function(e){var t;if(console.log({connection:this.connection}),(null===(t=this.connection)||void 0===t?void 0:t.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(console.log({eventName:e}),!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=localStorage.getItem("token")}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(){return window.location.protocol+"//classroom-dev-api.herokuapp.com"},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 l=t[n][2];n++}while(l&&!l());return s}}const d=new v,h=u.bind(null,d,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 u(d,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 v=t[n][2];n++}while(v&&!v());u(d,1,s)}))).then(void 0,h),d;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)}u(d,1,e)}}(e.type,[[function(){return"offer"},function(){var i=new RTCSessionDescription({type:"offer",sdp:e.payload}),o=l((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.WhiteboardService).to(c),this.diContainer.bind(o.CallService).to(d),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.WebsocketService).to(f).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 console.log(e),console.log(e.ConversationId),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)}},t.getConversationByUserId=function(e){try{return Promise.resolve(this.messageService.getConversationByUserId(e))}catch(e){return Promise.reject(e)}},t.sendMessage=function(e){try{return Promise.resolve(this.messageService.sendMessage(e))}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 C=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}();C=r.__decorate([t.injectable(),r.__param(0,t.inject(o.WhiteboardService)),r.__metadata("design:paramtypes",[Object])],C);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 _=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}();_=r.__decorate([t.injectable(),r.__param(0,t.inject(o.AttachmentService)),r.__metadata("design:paramtypes",[Object])],_);var j=new function(){this.bootstrap=new b("main"),this.Attachment=this.bootstrap.diContainer.resolve(_),this.Call=this.bootstrap.diContainer.resolve(y),this.Messaging=this.bootstrap.diContainer.resolve(g),this.Whiteboard=this.bootstrap.diContainer.resolve(C)},E=j.Call,P=j.Messaging,w=j.Whiteboard;exports.Attachment=j.Attachment,exports.Call=E,exports.Messaging=P,exports.Whiteboard=w,exports.default=j; | ||
//# sourceMappingURL=conectar-middleware.cjs.production.min.js.map |
@@ -604,5 +604,5 @@ import 'reflect-metadata'; | ||
try { | ||
_this9.websocketService.send(JSON.stringify(_extends({ | ||
_this9.websocketService.send(_extends({ | ||
action: action | ||
}, data))); | ||
}, data)); | ||
} catch (error) { | ||
@@ -888,5 +888,9 @@ console.error(error); | ||
_proto.send = function send(payload) { | ||
console.log(this.connection); | ||
var _this$connection; | ||
if (this.connection.readyState === this.connectionIsOpen) { | ||
console.log({ | ||
connection: this.connection | ||
}); | ||
if (((_this$connection = this.connection) === null || _this$connection === void 0 ? void 0 : _this$connection.readyState) === this.connectionIsOpen) { | ||
this.connection.send(JSON.stringify(payload)); | ||
@@ -1160,3 +1164,2 @@ return 'Sent to server'; | ||
this.diContainer.bind(TYPES.ConversationService).to(ConversationService); | ||
this.diContainer.bind(TYPES.WebsocketService).to(WebsocketService); | ||
this.diContainer.bind(TYPES.WhiteboardService).to(WhiteBoardService); | ||
@@ -1167,2 +1170,3 @@ this.diContainer.bind(TYPES.CallService).to(CallService); | ||
this.diContainer.bind(TYPES.ConfigService).to(ConfigService).inSingletonScope(); | ||
this.diContainer.bind(TYPES.WebsocketService).to(WebsocketService).inSingletonScope(); | ||
this.diContainer.bind(TYPES.PeerConnectionService).to(PeerConnectionService).inSingletonScope(); | ||
@@ -1169,0 +1173,0 @@ }; |
{ | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -31,3 +31,2 @@ import { Container } from 'inversify'; | ||
this.diContainer.bind<IConversationService>(TYPES.ConversationService).to(ConversationService); | ||
this.diContainer.bind<IWebsocketService>(TYPES.WebsocketService).to(WebsocketService); | ||
this.diContainer.bind<IWhiteBoardService>(TYPES.WhiteboardService).to(WhiteBoardService); | ||
@@ -45,2 +44,6 @@ this.diContainer.bind<ICallService>(TYPES.CallService).to(CallService); | ||
this.diContainer | ||
.bind<IWebsocketService>(TYPES.WebsocketService) | ||
.to(WebsocketService) | ||
.inSingletonScope(); | ||
this.diContainer | ||
.bind<IPeerConnectionService>(TYPES.PeerConnectionService) | ||
@@ -47,0 +50,0 @@ .to(PeerConnectionService) |
@@ -54,3 +54,3 @@ import 'reflect-metadata'; | ||
const configService: ConfigService = bootstrap.diContainer.resolve<ConfigService>(ConfigService); | ||
expect(configService.getBaseUrl()).toBe('http://localhost:8081'); | ||
expect(configService.getBaseUrl()).toBe('http://classroom-dev-api.herokuapp.com'); | ||
configService.setBaseUrl('http://localhost:8080'); | ||
@@ -57,0 +57,0 @@ expect(configService.getBaseUrl()).toBe('http://localhost:8080'); |
@@ -119,3 +119,3 @@ import { inject, injectable } from 'inversify'; | ||
try { | ||
this.websocketService.send(JSON.stringify({ action, ...data })); | ||
this.websocketService.send({ action, ...data }); | ||
} catch (error) { | ||
@@ -122,0 +122,0 @@ console.error(error); |
@@ -5,3 +5,2 @@ import { Subject } from 'rxjs'; | ||
export const EventMock = jest.fn<IEventService, []>(() => ({ | ||
@@ -8,0 +7,0 @@ send: jest.fn(), |
@@ -21,3 +21,3 @@ import { inject, injectable } from 'inversify'; | ||
console.log(conversationRequest); | ||
console.log(conversationRequest.ConversationId) | ||
console.log(conversationRequest.ConversationId); | ||
return this.messageService.createConnection(conversationRequest); | ||
@@ -24,0 +24,0 @@ } |
@@ -64,5 +64,5 @@ import { inject, injectable } from 'inversify'; | ||
send(payload: any): string { | ||
console.log(this.connection); | ||
if (this.connection!.readyState === this.connectionIsOpen) { | ||
this.connection!.send(JSON.stringify(payload)); | ||
console.log({ connection: this.connection }); | ||
if (this.connection?.readyState === this.connectionIsOpen) { | ||
this.connection.send(JSON.stringify(payload)); | ||
return 'Sent to server'; | ||
@@ -69,0 +69,0 @@ } else { |
@@ -75,9 +75,10 @@ import 'reflect-metadata'; | ||
messageService.sendMessage({ | ||
id: 'id', | ||
action: 'private_message', | ||
sender: 'sender', | ||
timestamp: 'now', | ||
recipient: 'recipient', | ||
messageType: 'text', | ||
text: 'message', | ||
Id: 'id', | ||
Text: 'message', | ||
Sender: 'sender', | ||
Timestamp: 'now', | ||
MessageType: 'text', | ||
ConversationId: 'id', | ||
Action: 'private_message', | ||
PrivateChatRecipient: 'recipient', | ||
}); | ||
@@ -84,0 +85,0 @@ expect(websocketMock.send).toHaveBeenCalled(); |
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
452391
4474