-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,125 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
// ); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]"> | ||
|
Oops, something went wrong.