+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Note : Make sure the Reciever is waiting for your call before start Calling
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ng6-seed/src/app/video-chat/video-chat.component.scss b/ng6-seed/src/app/video-chat/video-chat.component.scss
new file mode 100644
index 000000000..b26518120
--- /dev/null
+++ b/ng6-seed/src/app/video-chat/video-chat.component.scss
@@ -0,0 +1,79 @@
+::ng-deep { .video-chat > mat-dialog-container {
+ background: #eee;
+ padding: 0;
+ }
+}
+
+
+@media(max-width:500px) {
+
+ video#myvideo {
+ max-width: 32%;
+ // min-width: 150px;
+ position: absolute;
+ border: 2px solid #9E9E9E;
+ top:0;
+ left: 0;
+ // /* top: 20px;
+}
+.body-container {
+ padding: 0px !important;
+}
+video#peervideo {
+ /* height: 498px; */
+ // position: relative;
+ // margin-top: 126px;
+ width: 100%;
+ margin-top: 5%;
+
+}
+
+// .peer_message{
+// font-size: 20px;
+// position: absolute;
+// top: 11%;
+// bottom: 10%;
+// float: right;
+// padding: 57px;
+// /* border: 2px solid lavender; */
+// left: 8%;
+// p{
+// text-align: center;
+// }
+// }
+ }
+ @media(min-width:500px) {
+ .peer_video{
+ max-height: 80vh;
+ }
+ video#myvideo {
+ max-width: 22%;
+ // min-width: 150px;
+ position: absolute;
+ border: 2px solid #9E9E9E;
+ top:0;
+ left: 0;
+ // max-width: 45%;
+ // text-align: center;
+ // margin-left:3%;
+ // margin-top:1%;
+ // min-width: 150px;
+ // position: absolute;
+ // border: 2px solid #9E9E9E;
+ // /* top: 20px;
+}
+
+video#peervideo {
+ /* height: 498px; */
+ max-width: 100%;
+ text-align: center;
+ margin-left:3%;
+ margin-top:1%;
+ // position: relative;
+ // margin-top: 126px;
+ // width: 100%;
+}
+}
+body{
+ margin:10px !important;
+}
diff --git a/ng6-seed/src/app/video-chat/video-chat.component.spec.ts b/ng6-seed/src/app/video-chat/video-chat.component.spec.ts
new file mode 100644
index 000000000..69efedd43
--- /dev/null
+++ b/ng6-seed/src/app/video-chat/video-chat.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { VideoChatComponent } from './video-chat.component';
+
+describe('VideoChatComponent', () => {
+ let component: VideoChatComponent;
+ let fixture: ComponentFixture
;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ VideoChatComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(VideoChatComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/ng6-seed/src/app/video-chat/video-chat.component.ts b/ng6-seed/src/app/video-chat/video-chat.component.ts
new file mode 100644
index 000000000..287159909
--- /dev/null
+++ b/ng6-seed/src/app/video-chat/video-chat.component.ts
@@ -0,0 +1,455 @@
+import { Component, OnInit, ChangeDetectorRef, ViewChild, Inject } from '@angular/core';
+import { Observable } from 'rxjs';
+import { PushNotifyService } from 'app/shared/push-notify.service';
+import { Socket } from 'ngx-socket-io';
+import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
+
+@Component({
+ selector: 'app-video-chat',
+ templateUrl: './video-chat.component.html',
+ styleUrls: ['./video-chat.component.scss']
+})
+export class VideoChatComponent implements OnInit {
+ MediaStream
+ title = 'simple-peer-video-chat';
+ peer:any;
+ targetpeer: string;
+ enableBtn: boolean;
+ @ViewChild('myvideo') myVideo: any;
+ @ViewChild('peervideo') peervideo: any;
+ @ViewChild('camera_switch') camereSwitchBtn: any;
+ // @ViewChild('textToCopy',{static:true}) textCopyElement: any;
+ n = navigator.mediaDevices;
+ // public textToCopy:any;
+ myVideoEnable: boolean = false;
+ peerVideoEnable: boolean = false;
+ shouldFaceUser: boolean = true;
+ userCallType: any;
+ is_video_enable:boolean = false;
+ mic_mute: boolean = true;
+ video_mute: boolean = true;
+ user_msg: string;
+ recorder: any;
+ constructor(private _notificationService:PushNotifyService,
+ private cdRef: ChangeDetectorRef,private socket: Socket,
+ private dialogRef: MatDialogRef,
+ @Inject(MAT_DIALOG_DATA) public chat_info:any) {
+ this._notificationService.requestPermission();
+ // this.notify('Approval','This is First Alert -- By Debasis Saha')
+ console.log("Version #8")
+ }
+ notify(title,approval) {
+ let data: Array < any >= [];
+ data.push({
+ 'title': title,
+ 'body': approval
+ });
+ this._notificationService.generateNotificationWithTitle(data);
+}
+ // ngOnInit() {
+ // setTimeout(()=>{
+ // console.log("ngOninti")
+ // this.peer = new SimplePeer({
+ // initiator: location.hash === '#init',
+ // trickle: false
+ // })
+ // console.log(this.peer)
+ // this.peer.on('signal', function(data) {
+ // console.log(JSON.stringify(data));
+
+ // this.targetpeer = data;
+ // })
+ // this.peer.on('error', err => console.log('error', err))
+ // this.peer.on('data', function(data) {
+ // console.log('Recieved message:' + data);
+ // this.notify('notify',data)
+ // })
+ // this.peer.on('connect', () => {
+ // console.log('CONNECT')
+ // this.peer.send('whatever' + Math.random())
+ // })
+ // setTimeout(()=>{
+ // console.log("updated")
+ // this.enableBtn=true
+ // this.notify('notify','enabled')
+ // },1000)
+ // },3000)
+ // }
+
+ ngOnInit() {
+ console.log(this.chat_info);
+ if(this.chat_info) {
+ if(this.chat_info.type == 'offer' && this.chat_info.hasOwnProperty('JSON_to_connect') && this.chat_info.JSON_to_connect) {
+ this.is_video_enable = true;
+ this.start_Calling('receive')
+ }
+ }
+ // this.start_Calling('receive')
+ }
+ start_Calling(option) {
+ this.user_msg ="Establishing Connection..."
+ this.userCallType = option
+ // let texk=this.textCopyElement.nativeElement
+ let video = this.myVideo.nativeElement;
+ let peerVideo = this.peervideo.nativeElement
+ let peerx: any;
+ let copyMessageText
+ this.n.getUserMedia = (this.n.getUserMedia || this.n.webkitGetUserMedia || this.n.mozGetUserMedia || this.n.msGetUserMedia);
+ if(this.n.getUserMedia == undefined || this.n.getUserMedia == null, this.n.getUserMedia == ''){
+ alert("unable to get the camera access. please close the browser and come back again")
+ }
+ console.log(this.n)
+ let defaultsOpts = { audio: true, video: {
+ facingMode: this.shouldFaceUser ? 'user' : 'environment'
+ }
+ }
+ this.n.getUserMedia(defaultsOpts).then(stream=> {
+ this.socket.emit('NewClient')
+ video.load();
+ video.muted = true;
+ this.fetchVideoAndPlay(stream,video);
+ this.myVideoEnable = true
+ this.MediaStream = stream
+ this.is_video_enable = true;
+ // let switchCameraBtn= this.camereSwitchBtn.nativeElement
+ let supports = navigator.mediaDevices.getSupportedConstraints();
+ console.log(supports)
+ if( supports['facingMode'] === true ) {
+ // switchCameraBtn.disabled = false;
+}
+ console.log("entered",stream);
+ peerx = new SimplePeer ({
+ initiator: option === 'init',
+ stream: stream,
+ reconnectTimer: 1000,
+ iceTransportPolicy: 'relay',
+ trickle: false,
+ config: {
+ iceServers: [
+ {
+ "urls": "stun:numb.viagenie.ca",
+ "username": 'fairoj@venbainfotech.com',
+ "credential": '0987123400'
+ },
+ {
+ "urls": "turn:numb.viagenie.ca",
+ "username": "fairoj@venbainfotech.com",
+ "credential": "0987123400"
+ }
+ ]
+ }
+ })
+
+ // function InitPeer(type) {
+ peerx.on('signal',(data)=> {
+
+ console.log(JSON.stringify(data));
+ if(data.hasOwnProperty('type') && data.type == 'offer'){
+ console.log("entered!!!!!!!!!!!!!!!!1");
+ this.user_msg = "Calling..."
+ let event_data = {JSON_to_connect:data,type:'offer',random_string:this.chat_info.random_string}
+ this.socket.emit('Offer', event_data)
+ }
+ else if(data.type == 'answer' ){
+ this.user_msg = "Waiting For Connection..."
+ let event_data = {JSON_to_connect:data,type:'answer',random_string:this.chat_info.random_string}
+ this.socket.emit('Answer', event_data)
+ }
+ // copyMessage(JSON.stringify(data))
+ copyMessageText = JSON.stringify(data);
+ // update()
+ // this.copyMessage(copyMessageText,data.type)
+ // this.targetpeer = data;
+ })
+ // }
+ peerx.on('data', function(data) {
+ console.log('Recieved message:' + data);
+ })
+ peerx.on('close', (data) => {
+ console.log("Peer Connection is closed ",data);
+ this.disconnect();
+ // alert("Peer Connection is closed " +JSON.stringify(data))
+ this.notify("Connection Closed",'Peer Connection Closed')
+ })
+ peerx.on('error', (err) => {
+ console.log("Fatal Error ",err);
+ this.disconnect();
+ alert("Fatal Error" +JSON.stringify(err))
+ })
+ peerx.on('stream', (stream)=> {
+ console.log("@##################33",stream)
+ if ('srcObject' in peerVideo) {
+ peerVideo.srcObject = stream
+ } else {
+ peerVideo.src = window.URL.createObjectURL(stream) // for older browsers
+ }
+ // video.play();
+
+ // console.log(this.peerVideoEnable);
+ peerVideo.load();
+ this. fetchVideoAndPlay(stream,peerVideo,true);
+ // setTimeout(()=>{
+ // // this.peerVideoEnable = true;
+ // // console.log(this.peerVideoEnable)
+ // },2000)
+ // CreateVideo(stream)
+ })
+ // fetchVideoAndPlay(stream,videotype) {
+ // fetch('')
+ // .then(response => response.blob())
+ // .then(blob => {
+ // videotype.srcObject = stream;
+ // return videotype.play();
+ // })
+ // .then(_ => {
+ // // Video playback started ;)
+ // })
+ // .catch(e => {
+ // // Video playback failed ;(
+ // })
+ // }
+
+ // function CreateVideo(stream) {
+ // // CreateDiv()
+
+ // let video = document.createElement('video')
+ // video.id = 'peerVideo'
+ // video.srcObject = stream
+ // video.setAttribute('class', 'embed-responsive-item')
+ // document.querySelector('#peervideo').appendChild(video)
+ // video.play()
+ // //wait for 1 sec
+ // }
+ function connectPeer(answer) {
+ console.log("$$$$$$$$$$$$$$44");
+ console.log(answer);
+ setTimeout(()=>{
+ peerx.signal(answer.JSON_to_connect);
+ },1000)
+ }
+ function getPeer(){
+ return JSON.stringify(copyMessageText)
+ }
+ // if(JSON.parse(copyMessageText).hasOwnProperty('type') && JSON.parse(copyMessageText).type == 'offer')
+ // {
+// setTimeout(()=>{
+// this.socket.on('BackOffer', getPeer)
+// },2000)
+ // }
+ if(this.chat_info.type == 'offer' && this.chat_info.JSON_to_connect && this.chat_info.JSON_to_connect != undefined) {
+ connectPeer(this.chat_info)
+ }
+ // let tt = this.socket.on('BackOffer', connectPeer)
+ // console.log(tt);
+ this.socket.on('BackAnswer', connectPeer)
+ }, err=>{
+ console.log('Failed to get stream', err);
+ alert('Failed to get stream '+err);
+ });
+ // function update(){
+ // console.log(copyMessageText)
+ // setTimeout(()=>{
+ // // texk.value = copyMessageText
+ // },2000)
+ // }
+ setTimeout(() => {
+ this.peer = peerx;
+
+ // this.copyMessage(JSON.stringify(this.targetpeer))
+ console.log(this.peer);
+ // console.log(copyMessageText)
+ // this.targetpeer = copyMessageText
+ // this.textToCopy = copyMessageText
+ // this.copyMessage(copyMessageText)
+ }, 5000);
+
+ // socket.on('SessionActive', SessionActive)
+ // socket.on('CreatePeer', MakePeer)
+ // socket.on('Disconnect', RemovePeer)
+ }
+ fetchVideoAndPlay(stream,videotype,enablePeerVideo?) {
+ console.log("12@@@@@@@@@2",enablePeerVideo)
+
+ fetch('')
+ .then(response => response.blob())
+ .then(blob => {
+ videotype.srcObject = stream;
+ return videotype.play();
+ })
+ .then(_ => {
+ // Video playback started ;)
+ if(enablePeerVideo) {
+ if(this.peervideo.nativeElement.videoHeight >= 500) {
+ this.peervideo.nativeElement.style.marginTop = '0px'
+ }
+ this.peerVideoEnable = enablePeerVideo
+ // this.camereSwitchBtn.nativeElement.disabled = true;
+ console.log("peervideo check",this.peerVideoEnable,this.peervideo.nativeElement.videoWidth,this.peervideo.nativeElement.videoHeight);
+ this.cdRef.detectChanges();
+ this.startRecording(stream)
+ }
+ })
+ .catch(e => {
+ // Video playback failed ;(
+ })
+ }
+ async startRecording(stream) {
+ this.recorder = []
+ this.recorder = new RecordRTCPromisesHandler(stream, {
+ type: 'video',
+ mimeType: 'video/webm', // or video/webm\;codecs=h264 or video/webm\;codecs=vp9
+ audioBitsPerSecond: 128000,
+ videoBitsPerSecond: 128000,
+ bitsPerSecond: 128000 // if this line is provided, skip above
+ });
+ this.recorder.startRecording();
+ // const sleep = m => new Promise(r => setTimeout(r, m));
+ // await sleep(3000);
+// setTimeout(()=>{
+
+// });
+// var file = new File([blob], 'video.mp4', {
+// type: 'video/mp4'
+// });
+// console.log(file)
+// const fileURL = window.URL.createObjectURL(file);
+// window.open(fileURL);
+// videotype.srcObject = null;
+// videotype.muted = false;
+// videotype.volume = 1;
+// videotype.srcObject = file;
+
+
+ // recorder.camera.stop();
+ // recorder.destroy();
+ // recorder = null;
+// let recorder = RecordRTC(stream, {
+// type: 'video'
+// });
+// recorder.startRecording();
+
+// const sleep = m => new Promise(r => setTimeout(r, m));
+// sleep(10000);
+
+// recorder.stopRecording(function() {
+// let blob = recorder.getBlob();
+// // invokeSaveAsDialog(blob);
+// console.log(blob);
+// });
+
+// blob.then(resul=>{
+// console.log(resul);
+// })
+// const fileURL = window.URL.createObjectURL(blob);
+// console.log(fileURL);
+// window.open(fileURL);
+// invokeSaveAsDialog(blob);
+ }
+ async stopRecording() {
+ await this.recorder.stopRecording();
+ console.log(this.recorder);
+ let blob = await this.recorder.getBlob();
+ setTimeout(()=>{
+ console.log(typeof(blob),blob);
+ var file = new File([blob], 'video.mp4', {
+ type: 'video/mp4'
+ });
+ console.log(file)
+ const fileURL = window.URL.createObjectURL(file);
+ alert("saved Recording will be opened in a new window");
+ window.open(fileURL);
+ },3000);
+ this.recorder.getDataURL().then(dataURL=>{
+ console.log("@@@@@",dataURL)
+ })
+}
+ connect() {
+ this.peer.signal(JSON.parse(this.targetpeer));
+ }
+ RemovePeer() {
+ document.getElementById("peerVideo").remove();
+ // document.getElementById("muteText").remove();
+ // if (client.peer) {
+ // client.peer.destroy()
+ // }
+}
+
+ message() {
+ this.peer.send('Hello world');
+ }
+ disconnect() {
+ console.log(this.peer)
+ this.peer.destroy();
+ this.peerVideoEnable = false
+ this.targetpeer = ''
+ this.peer = ''
+ // this.cdRef.detectChanges();
+ this.peervideo.nativeElement.pause();
+ this.stopRecording().then(res=>{
+
+ })
+ console.log(this.MediaStream.getTracks())
+ // this.MediaStream.stop()
+ // var track = this.MediaStream.getTracks()[0]; // if only one media track
+ // ...
+ // track.stop();
+ this.MediaStream.getTracks().forEach(function(track) {
+ track.stop();
+ });
+ console.log(this.peervideo);
+ // this.peervideo.nativeElement.videoWidth = 0
+ // this.peervideo.nativeElement.videoHeight = 0
+ this.myVideo.nativeElement.pause();
+ this.is_video_enable = false
+ this.cdRef.detectChanges();
+ console.log(this.peer)
+ }
+ copyMessage(val: string,message?){
+ const selBox = document.createElement('textarea');
+ selBox.style.position = 'fixed';
+ selBox.style.left = '0';
+ selBox.style.top = '0';
+ selBox.style.opacity = '0';
+ selBox.value = val;
+ document.body.appendChild(selBox);
+ selBox.focus();
+ selBox.select();
+ document.execCommand('copy');
+ document.body.removeChild(selBox);
+ // alert(message+ " JSON is copied to clipboard. Paste the JSON to another window")
+ this.notify("JSON copied to clipboard",message+ ' JSON');
+ }
+ switch_camera() {
+ this.shouldFaceUser = !this.shouldFaceUser;
+ console.log(this.userCallType);
+ this.peer.destroy();
+ this.start_Calling(this.userCallType)
+ }
+ close_all() {
+ if(this.peer) {
+ this.disconnect();
+ }
+ if(this.MediaStream && this.MediaStream.active) {
+ console.log(this.MediaStream.getTracks())
+ // this.MediaStream.stop()
+ // var track = this.MediaStream.getTracks()[0]; // if only one media track
+ // ...
+ // track.stop();
+ this.MediaStream.getTracks().forEach(function(track) {
+ track.stop();
+ });
+ }
+ this.dialogRef.close();
+ }
+ micMuteHandling(){
+ this.mic_mute = !this.mic_mute
+ this.cdRef.detectChanges();
+ this.MediaStream.getAudioTracks()[0].enabled = this.mic_mute;
+ }
+ videoHandling(){
+ this.video_mute = !this.video_mute
+ this.cdRef.detectChanges();
+ this.MediaStream.getVideoTracks()[0].enabled = this.video_mute;
+ }
+
+}
diff --git a/ng6-seed/src/assets/spinner/notfound.jpg b/ng6-seed/src/assets/spinner/notfound.jpg
new file mode 100644
index 000000000..900f35aeb
Binary files /dev/null and b/ng6-seed/src/assets/spinner/notfound.jpg differ
diff --git a/ng6-seed/src/assets/spinner/notfound2.jpg b/ng6-seed/src/assets/spinner/notfound2.jpg
new file mode 100644
index 000000000..25a1d3348
Binary files /dev/null and b/ng6-seed/src/assets/spinner/notfound2.jpg differ
diff --git a/ng6-seed/src/assets/spinner/notfound_blue.png b/ng6-seed/src/assets/spinner/notfound_blue.png
new file mode 100644
index 000000000..cf1f5a7f3
Binary files /dev/null and b/ng6-seed/src/assets/spinner/notfound_blue.png differ
diff --git a/ng6-seed/src/assets/spinner/notify.mp3 b/ng6-seed/src/assets/spinner/notify.mp3
new file mode 100644
index 000000000..9e859af35
Binary files /dev/null and b/ng6-seed/src/assets/spinner/notify.mp3 differ
diff --git a/ng6-seed/src/environments/environment.prod.ts b/ng6-seed/src/environments/environment.prod.ts
index 3a5f4c4e0..14cb1f21f 100755
--- a/ng6-seed/src/environments/environment.prod.ts
+++ b/ng6-seed/src/environments/environment.prod.ts
@@ -4,6 +4,7 @@ export const environment = {
environmentName: 'Production Environment',//Live Environment.
apiEndpoint: 'https://api.pdgenie.com/sparqprod/api/',
+ socketServerUrl:'https://morning-garden-90282.herokuapp.com',
authorization: 'TnAwuc64pVpcB9xf',
login_string: "cognito-idp.ap-south-1.amazonaws.com/ap-south-1_MlTee1O5V",
diff --git a/ng6-seed/src/environments/environment.stage.ts b/ng6-seed/src/environments/environment.stage.ts
index 0eaeb99d1..6e5b873da 100644
--- a/ng6-seed/src/environments/environment.stage.ts
+++ b/ng6-seed/src/environments/environment.stage.ts
@@ -4,6 +4,7 @@ export const environment = {
environmentName: 'Testing Environment',//Test Environment.
apiEndpoint: 'https://apitest.pdgenie.com/sparqtest/api/',
+ socketServerUrl:'https://morning-garden-90282.herokuapp.com',
authorization: 'sparqvenba2018',
login_string: "cognito-idp.ap-south-1.amazonaws.com/ap-south-1_qQ85yQZJO",
diff --git a/ng6-seed/src/environments/environment.ts b/ng6-seed/src/environments/environment.ts
index 3b8f9112f..55aaf3249 100755
--- a/ng6-seed/src/environments/environment.ts
+++ b/ng6-seed/src/environments/environment.ts
@@ -14,6 +14,7 @@ export const environment = {
// apiEndpoint: 'https://demo.pdgenie.com/sparqapi/api/',
apiEndpoint:'https://apitest.pdgenie.com/sparqtest/api/',
// apiEndpoint:'http://localhost/sineEdge/sparqapi/api/',
+ socketServerUrl:'https://morning-garden-90282.herokuapp.com',
authorization: 'sparqvenba2018',
diff --git a/ng6-seed/src/index.html b/ng6-seed/src/index.html
index 963d27c67..c97fe548d 100755
--- a/ng6-seed/src/index.html
+++ b/ng6-seed/src/index.html
@@ -9,6 +9,10 @@
+
+
+
+
PD Genie
diff --git a/ng6-seed/src/typings.d.ts b/ng6-seed/src/typings.d.ts
index a0786e36b..2c420c444 100755
--- a/ng6-seed/src/typings.d.ts
+++ b/ng6-seed/src/typings.d.ts
@@ -6,4 +6,7 @@ interface NodeModule {
declare module 'quill';
declare module 'leaflet';
declare module 'perfect-scrollbar';
-declare module 'screenfull';
\ No newline at end of file
+declare module 'screenfull';
+declare var SimplePeer: any;
+declare var RecordRTCPromisesHandler:any;
+declare var RecordRTC:any;
\ No newline at end of file