+
diff --git a/ng6-seed/src/app/video-chat/video-chat.component.ts b/ng6-seed/src/app/video-chat/video-chat.component.ts
index 287159909..e5f8b1062 100644
--- a/ng6-seed/src/app/video-chat/video-chat.component.ts
+++ b/ng6-seed/src/app/video-chat/video-chat.component.ts
@@ -1,4 +1,4 @@
-import { Component, OnInit, ChangeDetectorRef, ViewChild, Inject } from '@angular/core';
+import { Component, OnInit, ChangeDetectorRef, ViewChild, Inject, HostListener } from '@angular/core';
import { Observable } from 'rxjs';
import { PushNotifyService } from 'app/shared/push-notify.service';
import { Socket } from 'ngx-socket-io';
@@ -30,6 +30,8 @@ export class VideoChatComponent implements OnInit {
video_mute: boolean = true;
user_msg: string;
recorder: any;
+ start_btn_enable:boolean = true
+ displayMsg:string = "Note : Make sure the Reciever is waiting for your call before start Calling"
constructor(private _notificationService:PushNotifyService,
private cdRef: ChangeDetectorRef,private socket: Socket,
private dialogRef: MatDialogRef
,
@@ -147,12 +149,12 @@ export class VideoChatComponent implements OnInit {
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}
+ let event_data = {JSON_to_connect:data,type:'offer',random_string:this.chat_info.random_string,user_type:"officer"}
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}
+ let event_data = {JSON_to_connect:data,type:'answer',random_string:this.chat_info.random_string,user_type:"officer"}
this.socket.emit('Answer', event_data)
}
// copyMessage(JSON.stringify(data))
@@ -227,9 +229,9 @@ export class VideoChatComponent implements OnInit {
peerx.signal(answer.JSON_to_connect);
},1000)
}
- function getPeer(){
- return JSON.stringify(copyMessageText)
- }
+ // function getPeer(){
+ // return JSON.stringify(copyMessageText)
+ // }
// if(JSON.parse(copyMessageText).hasOwnProperty('type') && JSON.parse(copyMessageText).type == 'offer')
// {
// setTimeout(()=>{
@@ -246,6 +248,12 @@ export class VideoChatComponent implements OnInit {
console.log('Failed to get stream', err);
alert('Failed to get stream '+err);
});
+ this.socket.on('callStatusMessage',this.updateTheMsg)
+ this.socket.fromEvent('callStatusMessage').subscribe(res=>{
+ if(res) {
+ this.updateTheMsg(res)
+ }
+ })
// function update(){
// console.log(copyMessageText)
// setTimeout(()=>{
@@ -267,6 +275,17 @@ export class VideoChatComponent implements OnInit {
// socket.on('CreatePeer', MakePeer)
// socket.on('Disconnect', RemovePeer)
}
+ updateTheMsg(msg_obj) {
+ console.log("CallstatusMsg",msg_obj)
+ if(msg_obj && msg_obj.status_code == 2){
+ console.log("entered");
+ this.start_btn_enable = false
+ this.displayMsg = msg_obj.msg
+ // this.cdRef.detectChanges();
+ this.disconnect();
+
+ }
+ }
fetchVideoAndPlay(stream,videotype,enablePeerVideo?) {
console.log("12@@@@@@@@@2",enablePeerVideo)
@@ -283,6 +302,7 @@ export class VideoChatComponent implements OnInit {
this.peervideo.nativeElement.style.marginTop = '0px'
}
this.peerVideoEnable = enablePeerVideo
+ this.socket.emit('callStatus',{random_string:this.chat_info.random_string,status:'connected',status_code:1})
// this.camereSwitchBtn.nativeElement.disabled = true;
console.log("peervideo check",this.peerVideoEnable,this.peervideo.nativeElement.videoWidth,this.peervideo.nativeElement.videoHeight);
this.cdRef.detectChanges();
@@ -379,15 +399,18 @@ export class VideoChatComponent implements OnInit {
}
disconnect() {
console.log(this.peer)
+ if(this.peer) {
this.peer.destroy();
this.peerVideoEnable = false
this.targetpeer = ''
this.peer = ''
// this.cdRef.detectChanges();
+ this.socket.emit('callStatus',{random_string:this.chat_info.random_string,status:'disconnected',status_code:0})
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
@@ -451,5 +474,20 @@ export class VideoChatComponent implements OnInit {
this.cdRef.detectChanges();
this.MediaStream.getVideoTracks()[0].enabled = this.video_mute;
}
+ clearRandomString() {
+ if(this.peer) {
+ this.disconnect() }
+ else{
+ this.socket.emit('callStatus',{random_string:this.chat_info.random_string,status:'disconnected',status_code:0})
+ }
+ }
+
+ @HostListener('window:beforeunload', ['$event'])
+ unloadHandler(event) {
+ console.log("unload caled",event);
+ if(this.peerVideoEnable) {
+ this.disconnect();
+ }
+ }
}