first commit

This commit is contained in:
Ivan Antunes 2025-03-27 12:02:51 -03:00
parent 08e3e54f50
commit fa596d1822
25 changed files with 15115 additions and 0 deletions

17
.editorconfig Executable file
View File

@ -0,0 +1,17 @@
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.ts]
quote_type = single
ij_typescript_use_double_quotes = false
[*.md]
max_line_length = off
trim_trailing_whitespace = false

42
.gitignore vendored Executable file
View File

@ -0,0 +1,42 @@
# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files.
# Compiled output
/dist
/tmp
/out-tsc
/bazel-out
# Node
/node_modules
npm-debug.log
yarn-error.log
# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*
# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings
# System files
.DS_Store
Thumbs.db

4
.vscode/extensions.json vendored Executable file
View File

@ -0,0 +1,4 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": ["angular.ng-template"]
}

20
.vscode/launch.json vendored Executable file
View File

@ -0,0 +1,20 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ng serve",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
},
{
"name": "ng test",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: test",
"url": "http://localhost:9876/debug.html"
}
]
}

42
.vscode/tasks.json vendored Executable file
View File

@ -0,0 +1,42 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
},
{
"type": "npm",
"script": "test",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
}
]
}

104
angular.json Executable file
View File

@ -0,0 +1,104 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-sip": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:application",
"options": {
"outputPath": "dist/angular-sip",
"index": "src/index.html",
"browser": "src/main.ts",
"polyfills": [
"zone.js"
],
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"@angular/material/prebuilt-themes/azure-blue.css",
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kB",
"maximumError": "1MB"
},
{
"type": "anyComponentStyle",
"maximumWarning": "4kB",
"maximumError": "8kB"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "angular-sip:build:production"
},
"development": {
"buildTarget": "angular-sip:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n"
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
"inlineStyleLanguage": "scss",
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
"styles": [
"@angular/material/prebuilt-themes/azure-blue.css",
"src/styles.scss"
],
"scripts": []
}
}
}
}
}
}

14505
package-lock.json generated Executable file

File diff suppressed because it is too large Load Diff

41
package.json Executable file
View File

@ -0,0 +1,41 @@
{
"name": "angular-sip",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --disable-host-check",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
"private": true,
"dependencies": {
"@angular/animations": "^19.1.0",
"@angular/cdk": "^19.2.7",
"@angular/common": "^19.1.0",
"@angular/compiler": "^19.1.0",
"@angular/core": "^19.1.0",
"@angular/forms": "^19.1.0",
"@angular/material": "^19.2.7",
"@angular/platform-browser": "^19.1.0",
"@angular/platform-browser-dynamic": "^19.1.0",
"@angular/router": "^19.1.0",
"jssip": "^3.10.1",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.15.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "^19.1.5",
"@angular/cli": "^19.1.5",
"@angular/compiler-cli": "^19.1.0",
"@types/jasmine": "~5.1.0",
"jasmine-core": "~5.5.0",
"karma": "~6.4.0",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.0",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"typescript": "~5.7.2"
}
}

BIN
public/favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

28
src/app/app.component.html Executable file
View File

@ -0,0 +1,28 @@
<mat-toolbar color="primary" style="background-color: green;">
<span style="color: white;">FRE ACCESS</span>
<span style="flex: 1 1"></span>
<span style="color: white;">{{ isRegistred ? 'Online' : 'Offline' }}</span>
</mat-toolbar>
<mat-card style="margin: 20px;">
<mat-card-header>
<mat-card-title>Apartamentos</mat-card-title>
<mat-card-subtitle style="color: gray; font-size: 12px;">Clique no telefone para chamar o apartamento desejado.</mat-card-subtitle>
</mat-card-header>
<mat-card-content style="display: flex; row-gap: 10px; column-gap: 10px; flex-wrap: wrap; margin-top: 10px; justify-content: center; align-items: center;">
@for (apartment of apartments; track $index) {
<mat-card style="background-color: white;">
<mat-card-content style="display: flex; flex-direction: row; align-items: center; column-gap: 10px;">
<mat-icon>apartment</mat-icon>
<span>{{apartment}}</span>
<button mat-icon-button color="primary" style="color: green;" (click)="makeCall(apartment)">
<mat-icon>phone</mat-icon>
</button>
</mat-card-content>
</mat-card>
}
</mat-card-content>
</mat-card>

0
src/app/app.component.scss Executable file
View File

29
src/app/app.component.spec.ts Executable file
View File

@ -0,0 +1,29 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have the 'angular-sip' title`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('angular-sip');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, angular-sip');
});
});

78
src/app/app.component.ts Executable file
View File

@ -0,0 +1,78 @@
import { Component } from '@angular/core';
import { WebSocketInterface, UA } from 'jssip';
import { RTCSession } from 'jssip/lib/RTCSession';
import { MatToolbarModule } from '@angular/material/toolbar'
import { MatIconModule } from '@angular/material/icon'
import { MatCardModule } from '@angular/material/card'
import { MatButtonModule } from '@angular/material/button'
import { CommonModule } from '@angular/common';
import { MatDialog } from '@angular/material/dialog';
import { DialogCallComponent } from './dialog-call/dialog-call.component';
@Component({
selector: 'app-root',
imports: [
CommonModule,
MatToolbarModule,
MatIconModule,
MatCardModule,
MatButtonModule
],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
export class AppComponent {
private readonly server = '192.168.2.169';
private readonly wss = `wss://${this.server}:8089/ws`;
private readonly sip = `sip:1003@${this.server}`;
private readonly password = '32687548';
private socket: WebSocketInterface;
private ua: UA;
protected isRegistred = false;
protected readonly apartments = ['1001', '1002', '1004'];
constructor(
private dialog: MatDialog
) {
this.socket = new WebSocketInterface(this.wss);
this.ua = new UA({
sockets: [this.socket],
uri: this.sip,
password: this.password
});
this.ua.start();
this.ua.on('registered', () => this.isRegistred = true);
this.ua.on('unregistered', () => this.isRegistred = false);
this.ua.on('registrationFailed', () => this.isRegistred = false);
this.ua.on('newRTCSession', (data: any) => {
var session = data.session as RTCSession;
if (session.direction === "incoming") {
session.answer(this.callOptions);
}
this.dialog.open(
DialogCallComponent,
{
disableClose: true,
data: { ramal: session.remote_identity.uri.user, session }
}
);
});
}
private get callOptions() {
return { mediaConstraints: { audio: true, video: false } }
}
public makeCall(ramal: string): void {
this.ua.call(`sip:${ramal}@${this.server}`, this.callOptions);
}
}

8
src/app/app.config.ts Executable file
View File

@ -0,0 +1,8 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes)]
};

3
src/app/app.routes.ts Executable file
View File

@ -0,0 +1,3 @@
import { Routes } from '@angular/router';
export const routes: Routes = [];

View File

@ -0,0 +1,21 @@
<div style="padding: 20px;">
<div style="display: flex; flex-direction: column; row-gap: 10px; text-align: center; align-items: center; justify-content: center;">
<div style="width: 80px; height: 80px; border-radius: 50%; background-color: gray; color: white; align-items: center; justify-content: center; display: flex;" >
<mat-icon style="transform: scale(2)">apartment</mat-icon>
</div>
<span>{{ value.ramal }}</span>
</div>
<span>{{eventMessage}}</span>
<div style="display: flex; flex-direction: row; justify-content: center; align-items: center; column-gap: 10px; margin-top: 10px;">
<button mat-icon-button color="warn" (click)="hangup()" style="color: red;">
<mat-icon>call_end</mat-icon>
</button>
<button mat-icon-button (click)="microphone()">
<mat-icon>{{ isMicrophone ? 'mic' : 'mic_off' }}</mat-icon>
</button>
</div>
</div>

View File

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DialogCallComponent } from './dialog-call.component';
describe('DialogCallComponent', () => {
let component: DialogCallComponent;
let fixture: ComponentFixture<DialogCallComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DialogCallComponent]
})
.compileComponents();
fixture = TestBed.createComponent(DialogCallComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,68 @@
import { CommonModule } from '@angular/common';
import { Component, Inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { RTCSession } from 'jssip/lib/RTCSession';
@Component({
selector: 'app-dialog-call',
imports: [
CommonModule,
MatIconModule,
MatButtonModule
],
templateUrl: './dialog-call.component.html',
styleUrl: './dialog-call.component.scss'
})
export class DialogCallComponent {
protected eventMessage = '';
protected isMicrophone = true;
constructor(
private dialogRef: MatDialogRef<DialogCallComponent>,
@Inject(MAT_DIALOG_DATA) public value: { ramal: string, session: RTCSession }
) {
const session = value.session;
session.on('connecting', () => this.eventMessage = 'Conectando...');
session.on('progress', () => this.eventMessage = 'Chamada em progresso...');
session.on('failed', () => {
this.eventMessage = 'Chamada falhou...';
setTimeout(() => this.dialogRef.close(), 1500);
});
session.on('ended', () => {
this.eventMessage = 'Chamada encerrada...';
setTimeout(() => this.dialogRef.close(), 1500);
});
session.on('accepted', (event: any) => {
console.log('Chamada aceita...', event);
this.eventMessage = 'Chamada aceita!';
});
session.connection.addEventListener('track', (event: RTCTrackEvent) => {
const remoteStream = new MediaStream();
remoteStream.addTrack(event.track);
const remoteAudio = document.createElement('audio');
remoteAudio.srcObject = remoteStream;
remoteAudio.autoplay = true;
document.body.appendChild(remoteAudio);
});
}
protected hangup() {
this.value.session.terminate();
}
protected microphone() {
if (this.isMicrophone) {
this.value.session.mute();
this.isMicrophone = false;
} else {
this.value.session.unmute();
this.isMicrophone = true;
}
}
}

15
src/index.html Executable file
View File

@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>FRE ACCESS SIP</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body class="mat-typography">
<app-root></app-root>
</body>
</html>

6
src/main.ts Executable file
View File

@ -0,0 +1,6 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, appConfig)
.catch((err) => console.error(err));

4
src/styles.scss Executable file
View File

@ -0,0 +1,4 @@
/* You can add global styles to this file, and also import other style files */
html, body { height: 100%; }
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }

15
tsconfig.app.json Executable file
View File

@ -0,0 +1,15 @@
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"src/main.ts"
],
"include": [
"src/**/*.d.ts"
]
}

27
tsconfig.json Executable file
View File

@ -0,0 +1,27 @@
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"isolatedModules": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"moduleResolution": "bundler",
"importHelpers": true,
"target": "ES2022",
"module": "ES2022"
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}

15
tsconfig.spec.json Executable file
View File

@ -0,0 +1,15 @@
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/spec",
"types": [
"jasmine"
]
},
"include": [
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}