fritz-callmonitor
Advanced tools
Comparing version 4.1.0 to 5.0.0
@@ -1,6 +0,4 @@ | ||
import { EventEmitter } from "events"; | ||
import { EventEmitter } from "node:events"; | ||
export declare class CallMonitor extends EventEmitter { | ||
private readonly host; | ||
private readonly port; | ||
private readonly socket; | ||
#private; | ||
constructor(host: string, port?: number); | ||
@@ -15,3 +13,3 @@ connect(): void; | ||
on(event: "hangup", listener: (data: HangUpEvent) => void): this; | ||
on(event: string, listener: (...args: any[]) => void): this; | ||
on(event: string, listener: (...args: unknown[]) => void): this; | ||
private createEvent; | ||
@@ -28,3 +26,3 @@ private parseLine; | ||
export interface RingEvent extends PhoneEventBase { | ||
kind: EventKind.Ring; | ||
kind: "ring"; | ||
caller: string; | ||
@@ -34,3 +32,3 @@ callee: string; | ||
export interface CallEvent extends PhoneEventBase { | ||
kind: EventKind.Call; | ||
kind: "call"; | ||
extension: string; | ||
@@ -41,3 +39,3 @@ caller: string; | ||
export interface PickUpEvent extends PhoneEventBase { | ||
kind: EventKind.PickUp; | ||
kind: "pickUp"; | ||
extension: string; | ||
@@ -47,10 +45,5 @@ phoneNumber: string; | ||
export interface HangUpEvent extends PhoneEventBase { | ||
kind: EventKind.HangUp; | ||
kind: "hangUp"; | ||
callDuration: number; | ||
} | ||
export declare enum EventKind { | ||
Call = 0, | ||
Ring = 1, | ||
PickUp = 2, | ||
HangUp = 4 | ||
} | ||
export type EventKind = "call" | "ring" | "pickUp" | "hangUp"; |
@@ -1,20 +0,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EventKind = exports.CallMonitor = void 0; | ||
const net_1 = require("net"); | ||
const events_1 = require("events"); | ||
const readline_1 = require("readline"); | ||
import { Socket } from "node:net"; | ||
import { EventEmitter } from "node:events"; | ||
import { createInterface } from "node:readline"; | ||
const datePattern = /(\d{2})\.(\d{2})\.(\d{2})\s+?(\d{2}):(\d{2}):(\d{2})/gi; | ||
class CallMonitor extends events_1.EventEmitter { | ||
export class CallMonitor extends EventEmitter { | ||
#socket; | ||
#host; | ||
#port; | ||
constructor(host, port = 1012) { | ||
super(); | ||
this.host = host; | ||
this.port = port; | ||
this.socket = new net_1.Socket(); | ||
this.#host = host; | ||
this.#port = port; | ||
this.#socket = new Socket(); | ||
} | ||
connect() { | ||
const s = this.socket; | ||
const s = this.#socket; | ||
s.on("connect", () => { | ||
const reader = (0, readline_1.createInterface)({ | ||
input: this.socket, | ||
const reader = createInterface({ | ||
input: this.#socket, | ||
}); | ||
@@ -29,6 +29,6 @@ reader.on("line", l => this.processLine(l)); | ||
s.on("close", had_error => this.emit("close", had_error)); | ||
s.connect(this.port, this.host); | ||
s.connect(this.#port, this.#host); | ||
} | ||
end() { | ||
this.socket.end(); | ||
this.#socket.end(); | ||
} | ||
@@ -41,6 +41,6 @@ processLine(line) { | ||
switch (data.kind) { | ||
case EventKind.Ring: return this.emit("ring", data); | ||
case EventKind.Call: return this.emit("call", data); | ||
case EventKind.PickUp: return this.emit("pickup", data); | ||
case EventKind.HangUp: return this.emit("hangup", data); | ||
case "ring": return this.emit("ring", data); | ||
case "call": return this.emit("call", data); | ||
case "pickUp": return this.emit("pickup", data); | ||
case "hangUp": return this.emit("hangup", data); | ||
default: return false; | ||
@@ -59,10 +59,30 @@ } | ||
switch (eventKind) { | ||
case EventKind.HangUp: | ||
return Object.assign(Object.assign({}, res), { kind: eventKind, callDuration: parseInt(splitLines[3]) }); | ||
case EventKind.Call: | ||
return Object.assign(Object.assign({}, res), { kind: eventKind, extension: splitLines[3], caller: splitLines[4], callee: splitLines[5] }); | ||
case EventKind.PickUp: | ||
return Object.assign(Object.assign({}, res), { kind: eventKind, extension: splitLines[3], phoneNumber: splitLines[4] }); | ||
case EventKind.Ring: | ||
return Object.assign(Object.assign({}, res), { kind: eventKind, caller: splitLines[3], callee: splitLines[4] }); | ||
case "hangUp": | ||
return { | ||
...res, | ||
kind: eventKind, | ||
callDuration: Number.parseInt(splitLines[3]), | ||
}; | ||
case "call": | ||
return { | ||
...res, | ||
kind: eventKind, | ||
extension: splitLines[3], | ||
caller: splitLines[4], | ||
callee: splitLines[5] | ||
}; | ||
case "pickUp": | ||
return { | ||
...res, | ||
kind: eventKind, | ||
extension: splitLines[3], | ||
phoneNumber: splitLines[4] | ||
}; | ||
case "ring": | ||
return { | ||
...res, | ||
kind: eventKind, | ||
caller: splitLines[3], | ||
callee: splitLines[4] | ||
}; | ||
} | ||
@@ -88,3 +108,3 @@ } | ||
return null; | ||
const connId = parseInt(sp[2]); | ||
const connId = Number.parseInt(sp[2]); | ||
return this.createEvent(evt, date, connId, line, sp); | ||
@@ -94,6 +114,6 @@ } | ||
switch (ev.toUpperCase()) { | ||
case "RING": return EventKind.Ring; | ||
case "CALL": return EventKind.Call; | ||
case "CONNECT": return EventKind.PickUp; | ||
case "DISCONNECT": return EventKind.HangUp; | ||
case "RING": return "ring"; | ||
case "CALL": return "call"; | ||
case "CONNECT": return "pickUp"; | ||
case "DISCONNECT": return "hangUp"; | ||
default: return undefined; | ||
@@ -103,9 +123,1 @@ } | ||
} | ||
exports.CallMonitor = CallMonitor; | ||
var EventKind; | ||
(function (EventKind) { | ||
EventKind[EventKind["Call"] = 0] = "Call"; | ||
EventKind[EventKind["Ring"] = 1] = "Ring"; | ||
EventKind[EventKind["PickUp"] = 2] = "PickUp"; | ||
EventKind[EventKind["HangUp"] = 4] = "HangUp"; | ||
})(EventKind || (exports.EventKind = EventKind = {})); |
@@ -1,1 +0,1 @@ | ||
export * from "./fritz-callmonitor"; | ||
export * from "./fritz-callmonitor.js"; |
@@ -1,17 +0,1 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./fritz-callmonitor"), exports); | ||
export * from "./fritz-callmonitor.js"; |
{ | ||
"name": "fritz-callmonitor", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"description": "Provides a TypeScript Node.js wrapper for the call monitor api of the AVM Fritz!Box.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
0
15288
7
163