Skip to content

Commit

Permalink
all added lost files
Browse files Browse the repository at this point in the history
  • Loading branch information
mateen777 committed Mar 2, 2024
1 parent e581a2c commit b511daf
Show file tree
Hide file tree
Showing 19 changed files with 1,125 additions and 116 deletions.
43 changes: 43 additions & 0 deletions src/app/core/services/call.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Injectable, inject } from '@angular/core';
// import { RestService } from './rest.service';
import { TokenModel } from 'openvidu-angular';
import { Observable } from 'rxjs';
import { HttpService } from './http.service';
import { ApiMethod } from '../constants/apiRestRequest';

@Injectable({
providedIn: 'root'
})
export class CallService {
private privateAccess: boolean = true;
private initialized: boolean = false;
tokens!: TokenModel

//services
http = inject(HttpService);

constructor() {}

async initialize(): Promise<void> {
if (this.initialized) {
return;
}
// const config = await this.restService.getConfig();
// this.privateAccess = config.isPrivate;
// this.initialized = true;
}

isPrivateAccess(): boolean {
return this.privateAccess;
}

getSessionId(): Observable<any> {
return this.http.requestCall('/sessions', ApiMethod.POST);
}

getTokens(sessionId:any,nickname:any):any {
return this.http.requestCall(`/:${sessionId}/connections`, ApiMethod.POST,{sessionId,nickname});
}


}
10 changes: 5 additions & 5 deletions src/app/core/services/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ export class HttpService {

constructor(private http:HttpClient) { }

requestCall(api:any,method:ApiMethod,data?:any){
requestCall(apiEndpoint:any,method:ApiMethod,data?:any){
let response:any;

switch (method) {
case ApiMethod.GET:
response = this.http.get<any>(`${environment.url}${api}`).pipe(
response = this.http.get<any>(`${environment.url}${apiEndpoint}`).pipe(
catchError((err)=> this.handleError(err)))
break;

case ApiMethod.POST:
response = this.http.post<any>(`${environment.url}${api}`,data).pipe(
response = this.http.post<any>(`${environment.url}${apiEndpoint}`,data).pipe(
catchError((err)=> this.handleError(err)))
break;

case ApiMethod.PUT:
response = this.http.put<any>(`${environment.url}${api}`,data).pipe(
response = this.http.put<any>(`${environment.url}${apiEndpoint}`,data).pipe(
catchError((err)=> this.handleError(err)))
break;

case ApiMethod.DELETE:
response = this.http.delete<any>(`${environment.url}${api}`).pipe(
response = this.http.delete<any>(`${environment.url}${apiEndpoint}`).pipe(
catchError((err)=> this.handleError(err)))
break;
default:
Expand Down
16 changes: 16 additions & 0 deletions src/app/core/services/navigator.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* tslint:disable:no-unused-variable */

import { TestBed, async, inject } from '@angular/core/testing';
import { NavigatorService } from './navigator.service';

describe('Service: Navigator', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [NavigatorService]
});
});

it('should ...', inject([NavigatorService], (service: NavigatorService) => {
expect(service).toBeTruthy();
}));
});
45 changes: 45 additions & 0 deletions src/app/core/services/navigator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Injectable } from '@angular/core';
import { Observable, from } from 'rxjs';
import { filter, map } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class NavigatorService {

getVideoDevices(): Observable<MediaDeviceInfo[]> {
const allVideoDevices = this.getDevices('videoinput');
return allVideoDevices;

}

getAudioDevices(): Observable<MediaDeviceInfo[]> {
const allAudioDevices = this.getDevices('audioinput');
return allAudioDevices;
}

getSpeakers(): Observable<MediaDeviceInfo[]> {
const allSpeakerDevices = this.getDevices('audiooutput');
return allSpeakerDevices;
}

private getDevices(kind: MediaDeviceKind): Observable<MediaDeviceInfo[]> {
return from(navigator.mediaDevices.enumerateDevices()).pipe(
map((devices:any) => {
return devices.filter((device:any) =>
device.kind === kind &&
device.deviceId !== 'default' &&
!device.label.toLowerCase().includes('communications'));
})
);
}

// private filterDevices(devices: MediaDeviceInfo[]): MediaDeviceInfo[] {
// // Filter out default and communications audio devices
// return devices.filter(
// (device) =>
// device.deviceId !== 'default' &&
// !device.label.toLowerCase().includes('communications')
// );
// }
}
141 changes: 141 additions & 0 deletions src/app/core/services/peerjs.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { Injectable, OnInit, inject } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { HttpService } from './http.service';
import { ApiMethod, Webrtc } from '../constants/apiRestRequest';
import { Peer } from "peerjs";
import { Router } from '@angular/router';

@Injectable({
providedIn: 'root'
})
export class PeerjsService implements OnInit{

http = inject(HttpService);
router = inject(Router);
public message$: BehaviorSubject<string> = new BehaviorSubject('');
public userJoined$: BehaviorSubject<string> = new BehaviorSubject('');
peer:any;
peerId: any;
conn: any;
remoteCall: any;

constructor() {}

ngOnInit(): void {

}

initPeer(){
this.peer = new Peer('',{
host: "localhost",
port: 9000,
path: "/myapp",
});
let lastPeerId:any;
this.peer.on('open', (id: any) => {
this.peerId = id;
console.log('My peer ID is: ' + id);

if (this.peer.id === null) {
console.log('Received null id from peer open');
this.peer.id = lastPeerId;
} else {
lastPeerId = this.peer.id;
}
});

this.peer.on('connection',(c:any)=> {
// Allow only a single connection
// if (this.conn && this.conn.open) {
// c.on('open', function () {
// c.send("Already connected to another client");
// setTimeout(function () { c.close(); }, 500);
// });
// return;
// }

this.conn = c;
console.log("Connected to: " + this.conn.peer);

this.conn.send('Hello');
// Handle incoming data (messages only since this is the signal sender)
this.conn.on('data', function (data: any) {
console.log(data);
});
this.conn.on('close', function () {
console.log("Connection closed");
});
});

this.peer.on('call',(call:any)=>{
this.remoteCall = call;
this.router.navigate(['join/consumer']);
})

this.peer.on('disconnected', ()=> {
console.log('Connection lost. Please reconnect');

// Workaround for peer.reconnect deleting previous id
this.peer.id = lastPeerId;
this.peer._lastServerId = lastPeerId;
this.peer.reconnect();
});

this.peer.on('close',()=> {
this.conn = null;
console.log('Connection destroyed');
});
this.peer.on('error',(err:any)=> {
console.log(err);
alert('' + err);
});
}

getpeer(){
return this.peer;
}

join(othersPeerId:any) {
// Close old connection
if (this.conn) {
this.conn.close();
}

// Create connection to destination peer specified in the input field
this.conn = this.peer.connect(othersPeerId, {
reliable: true
});

this.conn.on('open', () => {
console.log("Connected to: " + this.conn.peer);

// Check URL params for comamnds that should be sent immediately
// var command = getUrlParam("command");
// if (command)
// conn.send(command);
this.conn.send('Hello');
this.router.navigate(['join'])
});
// Handle incoming data (messages only since this is the signal sender)
this.conn.on('data', function (data: any) {
console.log(data);
});
this.conn.on('close', function () {
console.log("Connection closed");
});
};

async getMedia() {
try {
const stream = await navigator.mediaDevices.getUserMedia({video: true, audio: true});

console.log(stream,'stream')
// this.vid = stream;
return stream;
} catch (error) {
console.log(error);
return null;
}
}

}
66 changes: 61 additions & 5 deletions src/app/core/services/socket.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, OnInit, inject } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { io } from 'socket.io-client';
// import { io } from 'socket.io-client';
import { Socket } from 'ngx-socket-io';
import { HttpService } from './http.service';
import { ApiMethod, Webrtc } from '../constants/apiRestRequest';

Expand All @@ -13,14 +14,69 @@ export class SocketService implements OnInit{
public message$: BehaviorSubject<string> = new BehaviorSubject('');
public userJoined$: BehaviorSubject<string> = new BehaviorSubject('');

constructor() {}
private socket!:Socket;
constructor() {
this.socket = new Socket({
url: "http://localhost:8000",
options: {},
});
// this.initSocketConnection();
}

// private socket:any;

ngOnInit(): void {

console.log('initSocket started');
// this.initSocketConnection();
}

initSocketConnection(){
// this.socket = io('http://localhost:8000');
this.socket.on("connect", () => {
console.log('abcdefgh');
// console.log(this.socket.id,'connected');
});
this.socket.on("disconnect", () => {
// console.log(this.socket.id,'disconnected');
});

this.socket.on("connect_error", () => {
console.log('connect_error');
});
this.socket.on("from", (res:any) => {
console.log(res,'pp[p');
});
}

get getSocket(){
return this.socket;
}

// this method is used to start connection/handhshake of socket with server
connectSocket(message:any) {
this.socket.emit('connect', message);
}

// this method is used to get response from server
connectEvent() {
return this.socket.fromEvent('connect');
}
disconnectEvent() {
return this.socket.fromEvent('disconnect');
}


// this method is used to end web socket connection
disconnectSocket() {
this.socket.disconnect();
}


sendMessage(){
this.socket.emit('check','dwadaw')
}

// socket = io('http://localhost:8000');
socket!:any;
// socket!:any;

public joinRoom(payload:any) {
this.socket.emit('room:join', payload);
Expand Down
17 changes: 17 additions & 0 deletions src/app/core/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function generateUUID4() {
return (
(1e7.toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c:any) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16),
)
);
}

function isValidUUID(uuid: string): boolean {
const uuidRegex = /^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/;
return uuidRegex.test(uuid);
}

export { generateUUID4, isValidUUID };
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1 class="font-bold text-[32px] text-center mb-8">Sign Up</h1>
*this field is required
</span>
<span class="text-[#ff6347] text-xs" *ngIf="(registerForm.get('email')?.hasError('email') || registerForm.get('email')?.hasError('pattern')) && registerForm.get('email')?.dirty">
*Enter correct email ([email protected]).
*Enter correct email.
</span>
</div>
<div class="mb-2 min-h-[74px]">
Expand Down
Loading

0 comments on commit b511daf

Please sign in to comment.