Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as angular from "angular";
- import * as SimpleWebRTC from "simplewebrtc";
- import { CONSTANTS, ServerConfig } from "../constants";
- import { IActiveCall, ICall } from "../models/call";
- import { ICallInformation } from "../models/callInformation";
- import { CallStatus } from "../models/callStatus";
- import { ICallSummaryModel } from "../models/callSummary";
- import { IEmptyResponse } from "../models/emptyResponse";
- import { ProviderStatus } from "../models/provider";
- import { IProviderDetails } from "../models/providerDetails";
- import { IUserProfile } from "../models/user";
- import { FCMService } from "../services/fcm";
- import { CurrentUserService } from "./currentUser";
- import { ITrackService } from "./gaService";
- import { IHistoryService } from "./historyService";
- import { ILocalStorageService } from "./localStorageService";
- import { IMenuService } from "./menuService";
- import { ProvidersService } from "./providers";
- import { SnackbarService } from "./snackbar";
- declare var NODE_ENV: string;
- declare var AudioToggle: AudioToggle;
- export enum EventType {
- VideoPaused,
- videoResumed
- }
- export enum InternetConnectionState {
- OK,
- noConnection,
- }
- export class CallingService {
- public get webrtc(): SimpleWebRTC {
- return this.rtc;
- }
- private rtc: SimpleWebRTC;
- private videoPausedEvents: Array<() => void> = [];
- private videoResumedEvents: Array<() => void> = [];
- private videoAdded: boolean = false;
- private internetConnectionstate: InternetConnectionState;
- private previousICEState: any;
- private retryInProgress: boolean = false;
- private connectionTimeOutStarted: boolean = false;
- private timeoutPromise: any;
- private retryPromise: any;
- private connectionChecker: any;
- private previousStats: any;
- private previousSent: any;
- private peerConnection: any;
- private senderMsg: any;
- private receiverMsg: any;
- private retryInterval: any;
- private retryCounter: number = 0;
- constructor(
- private $q: ng.IQService,
- private $http: ng.IHttpService,
- private $translate: ng.translate.ITranslateService,
- private $window: ng.IWindowService,
- private $timeout: ng.ITimeoutService,
- private $interval: ng.IIntervalService,
- private fcmService: FCMService,
- private localStorageService: ILocalStorageService,
- private snackbarService: SnackbarService,
- private currentUser: CurrentUserService,
- private historyService: IHistoryService,
- private providerService: ProvidersService,
- private menuService: IMenuService,
- private $log: ng.ILogService,
- private trackService: ITrackService,
- private $rootScope: angular.IRootScopeService,
- ) {
- fcmService.setCallingService(this);
- fcmService.onAcceptAdd(() => {
- const callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- this.trackService.trackRoomEvent("Call", "accept call", "The call was accepted", 1, callInfo.roomId);
- });
- }
- public initializeCallToProvider(provider: IProviderDetails) {
- if (this.localStorageService.ReadObjectSafely<boolean>(CONSTANTS.LocalStorage.isActiveCall)) {
- return;
- }
- this.providerService.getStatus(provider.id)
- .then((result: ng.IHttpPromiseCallbackArg<number>) => {
- let online = result.data;
- if (online === ProviderStatus.Online) {
- let currentUser = this.localStorageService.ReadObjectSafely<IUserProfile>(CONSTANTS.LocalStorage.userProfile);
- let roomId = this.createRoomId();
- let callInfo: ICall = {
- roomId: roomId,
- callerInfo: {
- id: currentUser.id,
- userId: currentUser.userId,
- hasImage: currentUser.hasImage,
- name: `${currentUser.firstName} ${currentUser.lastName}`
- },
- calleeInfo: {
- id: provider.id,
- userId: provider.userId,
- hasImage: provider.hasImage,
- name: provider.name
- },
- isCaller: true,
- isCreated: false,
- duration: 0
- };
- this.localStorageService.WriteObject<ICall>(CONSTANTS.LocalStorage.callInfo, callInfo);
- this.localStorageService.WriteObject<boolean>(CONSTANTS.LocalStorage.isActiveCall, true);
- this.trackService.trackRoomEvent("Call", "calling", "Calling provider", 1, callInfo.roomId);
- this.historyService.go("waiting");
- } else {
- this.snackbarService.show({ message: this.$translate.instant("COACH_IS_BUSY") });
- }
- });
- }
- callAccepted(): void {
- let callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- this.fcmService.sendCallAcceptedNotification(callInfo.callerInfo.userId, callInfo.roomId)
- .then(() => {
- this.$log.debug("Call accepted");
- this.historyService.goReplace("conversation");
- })
- .then(() => this.readyToCall(callInfo.roomId))
- .catch((result: any) => {
- this.$log.error("call accepted error: " + JSON.stringify(result));
- this.snackbarService.show({ message: this.$translate.instant("CONNECTION_FAILED") });
- this.closeConnection();
- this.goBack();
- });
- }
- callDeclined(): ng.IPromise<{}> {
- let deferred = this.$q.defer();
- let isActiveCall = this.localStorageService.ReadObjectSafely<Boolean>(CONSTANTS.LocalStorage.isActiveCall);
- if (!isActiveCall) {
- deferred.reject();
- return deferred.promise;
- }
- this.localStorageService.WriteObject(CONSTANTS.LocalStorage.isActiveCall, false);
- let callInfo: ICall = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- if (!callInfo.callerInfo) {
- this.closeConnection();
- deferred.reject();
- return deferred.promise;
- }
- this.fcmService.sendCallDeclinedNotification(callInfo.callerInfo.userId, callInfo.roomId, null)
- .then(() => {
- this.closeConnection();
- deferred.resolve();
- })
- .catch((result: any) => {
- this.$log.error("call declined error: " + JSON.stringify(result));
- this.snackbarService.show({ message: this.$translate.instant("CONNECTION_FAILED") });
- deferred.reject();
- });
- return deferred.promise;
- }
- endCall(): void {
- let isActiveCall = this.localStorageService.ReadObjectSafely<boolean>(CONSTANTS.LocalStorage.isActiveCall);
- if (!isActiveCall) {
- this.$log.debug("endCall: !isActiveCall");
- return;
- }
- let callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- if (callInfo === null) {
- this.$log.debug("endCall: callInfo === null");
- return;
- }
- let userId: string = callInfo.isCaller ? callInfo.calleeInfo.userId : callInfo.callerInfo.userId;
- this.fcmService.sendCallEndNotification(userId, callInfo.roomId)
- .then(() => this.endedCall())
- .catch((result: any) => {
- this.historyService.goBack();
- this.$log.warn("Error end call: " + JSON.stringify(result));
- })
- .finally(() => this.closeConnection());
- }
- endedCall(): void {
- let isActiveCall = this.localStorageService.ReadObjectSafely<boolean>(CONSTANTS.LocalStorage.isActiveCall);
- if (!isActiveCall) { return; }
- if (!this.videoAdded) {
- const callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- this.trackService.trackRoomEvent("Call", "add video", `The ${this.menuService.isStudentMode ? "student's" : "coach's"} video wasn't added`, 0, callInfo.roomId);
- }
- this.changeUserStatus("online");
- this.closeConnection();
- this.historyService.goReplace("summary");
- }
- public createRoom(roomId: string): ng.IPromise<string> {
- this.rtc = new SimpleWebRTC({
- socketio: { forceNew: true },
- url: ServerConfig.simpleWebRtcUrl,
- localVideoEl: "localVideo",
- remoteVideosEl: "remoteVideos",
- autoRequestMedia: false,
- peerVolumeWhenSpeaking: 1,
- debug: NODE_ENV === "dev"
- });
- this.initWebRtcEvents();
- let deferred = this.$q.defer();
- this.rtc.createRoom(roomId, (error: any, roomId: string) => {
- if (error) {
- this.$log.error("Error: ", + JSON.stringify(error));
- }
- deferred.resolve(roomId);
- });
- return deferred.promise as ng.IPromise<string>;
- }
- joinRoom(roomId: string, newConnection: boolean): ng.IPromise<{}> {
- this.rtc = new SimpleWebRTC({
- socketio: { forceNew: newConnection },
- url: ServerConfig.simpleWebRtcUrl,
- localVideoEl: "localVideo",
- remoteVideosEl: "remoteVideos",
- autoRequestMedia: false,
- autoRemoveVideos: true,
- peerVolumeWhenSpeaking: 1,
- debug: NODE_ENV === "dev"
- });
- this.initWebRtcEvents();
- let deferred = this.$q.defer();
- this.rtc.joinRoom(roomId, () => {
- deferred.resolve();
- });
- return deferred.promise;
- }
- private readyToCall(roomId: string): ng.IPromise<void> {
- this.$log.info("on readyToCall");
- return this.joinRoom(roomId, true)
- .then(() => this.changeUserStatus("busy"));
- }
- closeConnection(): void {
- this.localStorageService.WriteObject(CONSTANTS.LocalStorage.isActiveCall, false);
- this.videoPausedEvents = [];
- this.videoResumedEvents = [];
- if (!this.rtc) { return; }
- this.rtc.stopLocalVideo();
- this.rtc.leaveRoom();
- this.rtc.disconnect();
- this.rtc = null;
- }
- private createRoomId(): string {
- let roomId = "";
- let abc = CONSTANTS.AvailableCharacters;
- for (let i = 0; i < CONSTANTS.RoomIdLength; i++) {
- let randPoz = Math.floor(Math.random() * abc.length);
- roomId += abc.substring(randPoz, randPoz + 1);
- }
- return roomId;
- }
- createCall(calleeId: number, roomId: string): angular.IHttpPromise<ICall> {
- let data = {
- CaleeId: calleeId,
- RoomId: roomId
- };
- return this.$http.post(`${ServerConfig.serverBaseUrl}api/call/create`, data)
- .then((result: angular.IHttpPromiseCallbackArg<ICall>) => {
- return result.data;
- });
- }
- setCallDuration(roomId: string, duration: number): angular.IHttpPromise<IEmptyResponse> {
- let data = {
- RoomId: roomId,
- Duration: duration
- };
- return this.$http.post(`${ServerConfig.serverBaseUrl}api/call/setduration`, data);
- }
- getCurrentCallInformation(): angular.IHttpPromise<ICallInformation> {
- let callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- return this.getCallInformation((callInfo === null) ? "" : callInfo.roomId);
- }
- // Get information about finished call
- getCallInformation(roomId: string): angular.IHttpPromise<ICallInformation> {
- let deferred = this.$q.defer();
- this.$http.get(ServerConfig.serverBaseUrl + "api/call/callinformation", { params: { roomId: roomId } })
- .then((result: any) => {
- let callInformation: ICallInformation = this.renderCallInformation(result);
- deferred.resolve(callInformation);
- })
- .catch((result: any) => {
- this.$log.error("Error has occured: " + result);
- deferred.resolve([]);
- // todo: handle this exception
- });
- return deferred.promise;
- }
- // Get information about active call
- public getActiveCallInformation(roomId: string): angular.IPromise<IActiveCall> {
- let deferred = this.$q.defer();
- this.$http.get(ServerConfig.serverBaseUrl + "api/call/activecallinformation", { params: { roomId: roomId } })
- .then((result: angular.IHttpPromiseCallbackArg<IActiveCall>) => {
- deferred.resolve(result.data);
- })
- .catch((reason) => {
- deferred.reject(reason);
- });
- return deferred.promise as angular.IPromise<IActiveCall>;
- }
- public getCallStatus(roomId: string): angular.IPromise<CallStatus> {
- let deferred = this.$q.defer();
- this.$http.get(ServerConfig.serverBaseUrl + "api/call/getcallstatus", { params: { roomId: roomId } })
- .then((result) => {
- deferred.resolve(result.data as CallStatus);
- })
- .catch((reason) => {
- deferred.reject(reason);
- });
- return deferred.promise as angular.IPromise<CallStatus>;
- }
- public sendCallSummary(data: ICallSummaryModel): angular.IHttpPromise<IEmptyResponse> {
- let callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- data.callerId = callInfo.callerInfo.id;
- data.calleeId = callInfo.calleeInfo.id;
- data.isCaller = callInfo.isCaller;
- return this.$http.post(ServerConfig.serverBaseUrl + "api/call/setcallsummary", data);
- }
- public muteAudio(): void {
- this.rtc.mute();
- }
- public unmuteAudio(): void {
- this.rtc.unmute();
- }
- public pauseVideo(): void {
- this.rtc.pauseVideo();
- }
- public resumeVideo(): void {
- this.rtc.resumeVideo();
- }
- public registerVideoEventCallback(eventType: EventType, cb: () => void) {
- switch (eventType) {
- case EventType.VideoPaused: this.videoPausedEvents.push(cb); break;
- case EventType.videoResumed: this.videoResumedEvents.push(cb); break;
- default: this.$log.debug("Error EventType"); break;
- }
- }
- public unregisterVideoEventCallback(eventType: EventType, cb: () => void) {
- switch (eventType) {
- case EventType.VideoPaused: {
- let index = this.videoPausedEvents.indexOf(cb);
- if (index > -1) {
- this.videoPausedEvents.splice(index, 1);
- }
- break;
- }
- case EventType.videoResumed: {
- let index = this.videoResumedEvents.indexOf(cb);
- if (index > -1) {
- this.videoResumedEvents.splice(index, 1);
- }
- break;
- }
- default: this.$log.debug("Error EventType"); break;
- }
- }
- private renderCallInformation(result: any): ICallInformation {
- let data: any = result.data;
- let callInformation: ICallInformation = {
- rateExperience: data.rateExperience,
- commentExperience: data.commentExperience,
- rateCallQuality: data.rateCallQuality,
- commentCallQuality: data.commentCallQuality,
- callerName: data.callerName,
- callerId: data.callerId,
- calleeName: data.calleeName,
- calleeId: data.calleeId,
- callDurationMin: data.callDurationMin,
- minutesCharges: data.minutesCharges,
- freeMinutes: data.freeMinutes,
- totalCharge: data.totalCharge,
- roomId: data.roomId,
- calleeHasImage: data.calleeHasImage,
- callerHasImage: data.callerHasImage
- };
- return callInformation;
- }
- private changeUserStatus(toStateName: string): ng.IPromise<void> {
- let state = CONSTANTS.UserStatusList.find((s) => s.state === toStateName);
- return this.currentUser.setUserStatus(state.value)
- .then(() => {
- let userProfile = this.localStorageService.ReadObjectSafely<IUserProfile>(CONSTANTS.LocalStorage.userProfile);
- this.currentUser.setUserStatus(state.value);
- userProfile.status = {
- id: state.value,
- name: state.name
- };
- this.menuService.userProfile = userProfile;
- })
- .catch(() => {
- this.$log.error("Change coach status failed");
- });
- }
- public startLocalVideo(): void {
- this.rtc.startLocalVideo();
- }
- public refreshVideos() {
- if (device.platform === "iOS") {
- this.$window.requestAnimationFrame(this.$window.cordova.plugins.iosrtc.refreshVideos);
- }
- }
- private goBack() {
- if (!this.historyService.isHistoryEmpty()) {
- this.historyService.goBack();
- }
- else {
- this.historyService.goReplace(this.menuService.isStudentMode ? "providerlist" : "coach");
- }
- }
- private initWebRtcEvents(): void {
- let self = this;
- this.rtc.on("connectivityError", (peer) => {
- const callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- this.trackService.trackRoomEvent("Call", "connectivity", `Connectivity error to peer`, 1, callInfo.roomId);
- });
- this.rtc.on("iceFailed", (peer) => {
- const callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- this.trackService.trackRoomEvent("Call", "connectivity",
- `Local ICE/p2p server failed:
- 1. ICE server down
- 2. P2P connections blocked by Firewall
- 3. Symmetric NAT which does not reuse session address binding. This results some NAT Traversal techniques failing in traverse packets through NAT devices
- `, 1, callInfo.roomId);
- });
- this.rtc.on("localMediaError", () => {
- const callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- this.trackService.trackRoomEvent("Call", "media",
- `The access to the camera wasn't obtained for ${this.currentUser.userProfile.firstName} ${this.currentUser.userProfile.lastName}`, 1, callInfo.roomId);
- });
- this.rtc.on("videoAdded", (video: HTMLVideoElement, peer: SimpleWebRTCPeer) => {
- if (device.platform !== "iOS") {
- self.changeAudioOutput(AudioToggle.SPEAKER);
- }
- if (!self.videoAdded) {
- self.videoAdded = true;
- const callInfo = self.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- self.trackService.trackRoomEvent("Call", "add video", `The ${self.menuService.isStudentMode ? "student's" : "coach's"} video was added`, 2, callInfo.roomId);
- }
- if (peer && peer.pc) {
- peer.pc.on("iceConnectionStateChange", (event: any) => {
- this.handleIceStateChange(peer.pc, event);
- });
- let pc = peer.pc as any;
- let rtcpc = pc.pc.peerconnection;
- this.$log.info(rtcpc);
- }
- });
- this.rtc.on("mute", (data: any) => {
- this.rtc.getPeers(data.id).forEach((peer: any) => {
- if (data.name === "video") {
- this.$log.debug("CallingService: Peer video paused");
- for (let cb of this.videoPausedEvents) {
- cb();
- }
- }
- });
- });
- this.rtc.on("unmute", (data: any) => {
- this.rtc.getPeers(data.id).forEach((peer: any) => {
- if (data.name === "video") {
- this.$log.debug("CallingService: peer video resumed");
- for (let cb of this.videoResumedEvents) {
- cb();
- }
- }
- });
- });
- }
- private handleIceStateChange(pc: any, event: any) {
- let rtcpc: RTCPeerConnection = pc.pc.peerconnection;
- this.$log.info("ICE Connection state:" + pc.iceConnectionState);
- switch (pc.iceConnectionState) {
- case "checking":
- break;
- case "connected":
- case "completed":
- if (this.connectionTimeOutStarted) {
- this.$timeout.cancel(this.timeoutPromise);
- this.$rootScope.$broadcast("timer-resume");
- this.connectionTimeOutStarted = false;
- }
- if (!this.connectionChecker) {
- this.connectionChecker = this.$interval(() => { this.checkStats(pc); }, CONSTANTS.statInterval);
- }
- break;
- case "disconnected":
- case "failed":
- if (!this.connectionTimeOutStarted) {
- this.$rootScope.$broadcast("timer-stop");
- this.timeoutPromise = this.$timeout(() => {
- if (this.internetConnectionstate === InternetConnectionState.noConnection) {
- this.endCallBasedOnConnection();
- }
- this.connectionTimeOutStarted = false;
- }, CONSTANTS.waitingConnectionTimeout);
- this.connectionTimeOutStarted = true;
- }
- if (this.connectionChecker) {
- this.$interval.cancel(this.connectionChecker);
- this.connectionChecker = null;
- }
- this.$interval.cancel(this.retryInterval);
- break;
- case "closed":
- if (!this.retryInProgress || this.connectionTimeOutStarted) {
- this.endCallBasedOnConnection();
- }
- this.$interval.cancel(this.retryInterval);
- break;
- default: break;
- }
- }
- private checkStats(pc: any): void {
- this.$log.info("Checking data flow...");
- this.peerConnection = pc;
- let rtcpc: RTCPeerConnection = pc.pc.peerconnection;
- this.$log.info("IceSingaling state: " + rtcpc.signalingState);
- if (rtcpc) {
- if (pc.getLocalStreams()[0]) {
- let remoteSelector: MediaStreamTrack = pc.getRemoteStreams()[0].getVideoTracks()[0];
- let localSelector: MediaStreamTrack = pc.getLocalStreams()[0].getVideoTracks()[0];
- rtcpc.getStats(localSelector, (data: any) => {
- for (let tmp in data) {
- if (tmp.startsWith("ssrc")) {
- let actualSent = data.get(tmp);
- if (this.previousSent) {
- if (this.previousSent.bytesSent === actualSent.bytesSent && navigator.onLine) {
- this.$log.info("Cannot send data.");
- this.senderMsg = this.snackbarService.show({ message: "Waiting for the other peer..." });
- } else {
- if (this.senderMsg) {
- this.senderMsg.hide();
- }
- this.snackbarService.hide();
- }
- }
- this.previousSent = actualSent;
- }
- }
- });
- rtcpc.getStats(remoteSelector, (data: any) => {
- for (let tmp in data) {
- if (tmp.startsWith("ssrc")) {
- let actualStats = data.get(tmp);
- if (this.previousStats) {
- if (this.previousStats.bytesReceived === actualStats.bytesReceived) {
- this.$interval.cancel(this.connectionChecker);
- this.connectionChecker = null;
- if (navigator.onLine && !this.retryInProgress) {
- this.$log.info("NO INCOMING DATA!");
- this.retryCounter = 0;
- this.retryInterval = this.$interval(() => { this.retryChecker(pc, rtcpc, remoteSelector, this.previousStats); }, 1000);
- }
- } else {
- if (this.receiverMsg) {
- this.receiverMsg.hide();
- }
- this.retryInProgress = false;
- }
- }
- this.previousStats = actualStats;
- }
- }
- });
- } else {
- /*
- this.$interval.cancel(this.connectionChecker);
- this.connectionChecker = null;
- if (this.localStorageService.ReadObjectSafely<boolean>(CONSTANTS.LocalStorage.isActiveCall)) {
- this.$timeout(() => {
- this.connectionChecker = this.$interval(() => { this.checkStats(pc); }, CONSTANTS.statInterval);
- }, CONSTANTS.retryTimeout);
- this.retryAttempt();
- } */
- this.$log.info("No local streams.. :(");
- this.$log.info(pc.getLocalStreams());
- }
- }
- }
- private retryChecker(pc: any, rtcpc: any, remoteSelector: any, previousStats: any): void {
- if (this.retryCounter > CONSTANTS.retryTotal) {
- this.snackbarService.show({ message: "Could not reconnect." });
- this.$interval.cancel(this.retryInterval);
- this.endCallBasedOnConnection();
- } else {
- this.snackbarService.show({ message: "Retry..." + ((this.retryCounter++ % CONSTANTS.retryCount) + 1) + "/" + CONSTANTS.retryCount });
- rtcpc.getStats(remoteSelector, (data: any) => {
- for (let tmp in data) {
- if (tmp.startsWith("ssrc")) {
- let actualStats = data.get(tmp);
- if (previousStats.bytesReceived === actualStats.bytesReceived && navigator.onLine) {
- if (!this.retryInProgress) {
- this.retryAttempt();
- }
- } else if (previousStats.bytesReceived !== actualStats.bytesReceived && navigator.onLine) {
- this.retryInProgress = false;
- this.$interval.cancel(this.retryInterval);
- this.connectionChecker = this.$interval(() => { this.checkStats(pc); }, CONSTANTS.statInterval);
- }
- }
- }
- });
- }
- }
- private retryAttempt(): void {
- this.$log.info("Retry triggered, retrying...");
- this.retryInProgress = true;
- let rtcpc: RTCPeerConnection = this.peerConnection.pc.peerconnection;
- this.$timeout(() => { this.retryInProgress = false; }, CONSTANTS.retryTimeout);
- if (navigator.onLine) {
- let callInfo = this.localStorageService.ReadObjectSafely<ICall>(CONSTANTS.LocalStorage.callInfo);
- if (callInfo) {
- if (this.peerConnection) {
- let offerOptions = {
- offerToReceiveAudio: 1,
- offerToReceiveVideo: 1,
- iceRestart:true
- };
- this.peerConnection.offer(offerOptions, (desc: string, answer: any) => {
- this.$log.info("Getting answer...");
- this.$log.info(answer);
- });
- }
- }
- }
- }
- private endCallBasedOnConnection() {
- this.$interval.cancel(this.connectionChecker);
- this.$interval.cancel(this.retryInterval);
- this.$timeout.cancel(this.timeoutPromise);
- this.connectionChecker = null;
- this.retryInProgress = false;
- if (this.localStorageService.ReadObjectSafely<boolean>(CONSTANTS.LocalStorage.isActiveCall) && navigator.onLine) {
- this.endCall();
- }
- else {
- this.closeConnection();
- this.historyService.goReplace(this.menuService.isStudentMode ? "providerlist" : "coach");
- }
- }
- public changeAudioOutput(type: string) {
- if (AudioToggle) {
- AudioToggle.setAudioMode(type);
- this.$log.debug("CallingService: audio output device changed to " + type);
- }
- // add when it needs the browser support
- /* navigator.mediaDevices
- .enumerateDevices()
- .then((deviceInfos: any[]) => {
- let speaker: any;
- deviceInfos.forEach((deviceInfo) => {
- if ((deviceInfo.label.search(/speaker/i)) > -1) {
- speaker = deviceInfo;
- }
- });
- if (speaker) {
- let videoElement = peer.videoEl;
- if (typeof videoElement.sinkId !== "undefined") {
- videoElement.setSinkId(speaker.deviceId)
- .then(() => {
- this.$log.debug("Success, audio output device attached: " + speaker.deviceId);
- });
- }
- }
- });*/
- }
- }
- CallingService.$inject = [
- "$q",
- "$http",
- "$translate",
- "$window",
- "$timeout",
- "$interval",
- "FCMService",
- "LocalStorageService",
- "SnackbarService",
- "CurrentUserService",
- "HistoryService",
- "ProvidersService",
- "MenuService",
- "$log",
- "GAService",
- "$rootScope"
- ];
- export default angular.module("app.services.calling", [])
- .service("CallingService", CallingService)
- .name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement