小编Mao*_*ion的帖子

实时流媒体:node-media-server + Dash.js 配置为实时低延迟

我们正在开发一款应用程序,可以实时监控您的后院。每个客户端都有一个连接到互联网的摄像头,流式传输到我们的公共 node.js 服务器。

我正在尝试使用 node-media-server 发布一个 MPEG-DASH(或 HLS)流,以便我们的应用程序客户端在世界各地的不同网络、带宽和分辨率上可用。

我们的目标是尽可能接近“实时”生活,以便您可以立即监控后院发生的事情。

已经完成的技术流程是:

  1. 我们服务器上的 ffmpeg 进程处理传入的相机流(每个相机的单独子进程)并通过本地机器上的 RTSP 发布流以供节点媒体服务器用作“输入”(我们还保存分段文件,生成缩略图等)。负责的 ffmpeg 命令是:

    -c:v libx264 -preset ultrafast -tune zerolatency -b:v 900k -f flv rtmp://127.0.0.1:1935/live/office

  2. node-media-server 正在使用我发现的“实时流媒体”的默认配置运行

    private NMS_CONFIG = {
    server: {
      secret: 'thisisnotmyrealsecret',
    },
    rtmp_server: {
      rtmp: {
        port: 1935,
        chunk_size: 60000,
        gop_cache: false,
        ping: 60,
        ping_timeout: 30,
      },
      http: {
        port: 8888,
        mediaroot: './server/media',
        allow_origin: '*',
      },
      trans: {
        ffmpeg: '/usr/bin/ffmpeg',
        tasks: [
          {
            app: 'live',
            hls: true,
            hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
            dash: true, …
    Run Code Online (Sandbox Code Playgroud)

ffmpeg live-streaming node.js mpeg-dash dash.js

9
推荐指数
1
解决办法
1万
查看次数

使用 class-validator 验证每个 Map<string, number> 值

我正在尝试对由我的 DTO 之一建模的 JSON 输入执行简单的验证。对象属性之一的类型是Map<string, number>。输入示例:

{
  "type": "CUSTOM",
  "is_active": true,
  "current_plan_day": 1,
  "custom_warmup_plan": {
    "1": 123,
    "2": 456
}
Run Code Online (Sandbox Code Playgroud)

在我的控制器上,我使用 DTO 来指定主体类型。该类与类验证器装饰器一起是这样的:

    export class CreateWarmupPlanRequestDto {
      @IsEnum(WarmupPlanType)
      type: string;
    
      @IsOptional()
      @IsNumber({ allowInfinity: false, allowNaN: false, maxDecimalPlaces: 0 })
      @IsPositive()
      hard_cap: number | null;
    
      @IsBoolean()
      is_active: boolean;
    
      @IsNumber({ allowInfinity: false, allowNaN: false, maxDecimalPlaces: 0 })
      @IsPositive()
      current_plan_day: number;
    
      @IsOptional()
      @IsNumber({ allowInfinity: false, allowNaN: false, maxDecimalPlaces: 0 })
      @IsPositive()
      previous_plan_day: number | null;
    
      @IsOptional()
      @IsNumber({ allowInfinity: false, allowNaN: false, …
Run Code Online (Sandbox Code Playgroud)

validation class-validator nestjs

7
推荐指数
1
解决办法
4337
查看次数

类验证器:根据另一个属性的值在验证时删除一个属性

与 NestJS 一起使用class-validator,我的工作如下:

export class MatchDeclineReason {
  @IsString()
  @IsEnum(MatchDeclineReasonType)
  @ApiProperty()
  type: MatchDeclineReasonType;

  @ValidateIf(reason => reason.type === MatchDeclineReasonType.Other)
  @IsString()
  @ApiProperty()
  freeText: string;
}
Run Code Online (Sandbox Code Playgroud)

所以如果delinceReason.type === Other,我希望得到一个freeText字符串值。


但是,如果 与declineReason.type有任何不同Other,我希望该freeText财产被剥夺。

有没有什么方法可以在不编写 的情况下实现这种行为CustomValidator

我的ValidationPipe配置:

  app.useGlobalPipes(
    new ValidationPipe({
      disableErrorMessages: false,
      whitelist: true,
      transform: true,
    }),
  );
Run Code Online (Sandbox Code Playgroud)

validation typescript class-validator nestjs

3
推荐指数
1
解决办法
5616
查看次数

角度:HttpErrorResponse:“解析...期间Http失败...”-从服务器成功返回的字符串

Spring-boot RESTful服务器端;一个将返回字符串的测试方法:

@RequestMapping(value = "test", method = RequestMethod.GET)
    public ResponseEntity<String> test(HttpServletRequest req, HttpServletResponse resp) {
        try {
            return new ResponseEntity<String>("Test has worked, biatch!", HttpStatus.OK);
        } catch (Exception e) {
            System.err.println("## EXCEPTION: " + e.getMessage());
            return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
        }
    }
Run Code Online (Sandbox Code Playgroud)

从邮递员那里-一切正常,我得到了从JSON正确解析返回的字符串。

但是,当从Angular客户端尝试相同操作时,我不断获取HttpErrorResponse对象。

  public url: string = "http://localhost:8080/theater/admin/test";
  constructor(private as: AdminService, private http: HttpClient) { }

  ngOnInit() {
  }

  getTest() {
    this.as.getTest()
      .subscribe(data => console.log(data), // this should happen on success
        error => console.log(error));  // this should happen on error
  } …
Run Code Online (Sandbox Code Playgroud)

string parsing json string-parsing angular

2
推荐指数
2
解决办法
7819
查看次数

Angular:在一个组件中调用一个函数,在另一个组件上调用事件

使用 Angular6,假设我有 2 个子组件 A、B,它们都是父组件 P 的一部分。我想在组件 A 上使用表单输入-因此一旦单击,字符串值将传递并触发组件 B 上的函数. 可能是这样的:

functionOnB(valueFromA: string) { //some code here; } 
Run Code Online (Sandbox Code Playgroud)

这甚至可能吗?

我已经使用 angular 的 EventEmitter 在组件之间成功传输了数据,但是是否可以使用这些数据调用函数,而不仅仅是传递原始信息?

eventemitter angular angular-event-emitter

2
推荐指数
1
解决办法
1万
查看次数

Flutter:基于 intl 在 RTL 应用程序中强制小部件的 LTR 方向

我正在使用带有内置 redux 支持的样板 flutter 应用程序模板,以及使用flutter_localizationsintl包的希伯来语 RTL 方向。

整个应用程序以及我创建的每个新小部件都正确地具有本机 RTL 方向性。

我有一个文本输入字段来获取用户电话号码。我希望这个输入字段及其所有样式和内部功能都以 LTR 方式运行。对于我可能有的其他输入字段也是如此,例如电子邮件(始终为英文)。

似乎由 app intl配置确定的整体方向性与我试图“强制”文本字段以专门交换其行为的新方向性小部件之间存在冲突:

                child: SizedBox(
                  width: 250,
                  child: Directionality(
                    textDirection: TextDirection.LTR,
                    child: TextField(
                      controller: phoneController,
                      keyboardType: TextInputType.phone,
                      inputFormatters: [FilteringTextInputFormatter.digitsOnly],
                    ),
                  ),
                ),
Run Code Online (Sandbox Code Playgroud)

运行此代码会导致以下错误:

lib/modules/login/login_page.dart:54:54: Error: The argument type 'TextDirection/*1*/' can't be assigned to the parameter type 'TextDirection/*2*/'.
 - 'TextDirection/*1*/' is from 'package:intl/src/intl/text_direction.dart' ('../../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/intl-0.17.0-nullsafety.2/lib/src/intl/text_direction.dart').
 - 'TextDirection/*2*/' is from 'dart:ui'.
                        textDirection: TextDirection.LTR,
                                                     ^
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么?我怎样才能完成所需的行为?

localization arabic dart flutter flutter-layout

1
推荐指数
2
解决办法
4581
查看次数

Promise.allSettled() - 多个异步调用的重试策略

TL;DR:我正在寻找一种策略或示例来处理未知数量的承诺拒绝,并X在用于多个异步调用时重试它们一段时间Promise.allSettled()

读完这篇文章后:https://www.coreycleary.me/better-handling-of-rejections-using-promise-allsettled 我对这句话感到非常兴奋:

这很棒,因为我们仍然可以加载用户帐户信息,并稍后重试获取用户活动。(重试超出了本文的范围,并且有多种策略)

然而,在网上研究时,我发现完全没有具体的例子,甚至没有直接处理这个问题的帖子。

这是一些示例代码:

  public async test() {
    try {
      console.log('trying..');
      const multiAsync = [this.somethingA(), this.somethingB(), this.somethingC()];
      const [a, b, c] = await Promise.allSettled(multiAsync);
    } catch (e) {
      console.log('catch');
      console.log(e);
    }
  }
Run Code Online (Sandbox Code Playgroud)

现在假设对于上面的代码,A 和 C 都失败了,我想重试它们,比如说——再试一次。即使我有a, b, c,我也只知道哪些是fullfilled:true,哪些不是。但我不知道如何链接asomethingA()和仅csomethingC()试这两个函数,而且我绝对不想调用somethingB()两次。

有任何想法吗?

javascript node.js promise typescript es6-promise

1
推荐指数
1
解决办法
2260
查看次数

NestJS:全局异常过滤器无法捕获基于 Kafka 的微服务应用程序抛出的任何内容

我们使用 NestJS 作为基于微服务的架构的 Typescript 框架。我们的一些部署被称为“Kafka 工作线程”,这些 pod 运行的代码实际上并不公开任何 REST 端点,而只是监听 kafka 主题并处理传入事件。

问题是,配置为希望捕获任何抛出异常的全局异常过滤器没有捕获任何内容(我们最终点头UnhandledPromiseRejection

异常过滤器的基本配置如下(遵循 NestJS 文档指南):

@Catch()
export class KafkaWorkerExceptionFilter implements ExceptionFilter {
  private logger: AppLogger = new AppLogger(KafkaWorkerExceptionFilter.name);

  catch(error: Error, host: ArgumentsHost): void {
    this.logger.error('Uncaught exception', error);
  }
}
Run Code Online (Sandbox Code Playgroud)

我们针对此类工作人员的控制器配置如下:

@Controller()
export class KafkaWorkerController {
  private readonly logger = new AppLogger(KafkaWorkerController.name);

  constructor(
  ) {
    this.logger.log('Init');
  }

  @EventPattern(KafkaTopic.PiiRemoval)
  async removePiiForTalent(data: IncomingKafkaMessage): Promise<void> {
    await asyncDoSomething();
    throw new Error('Business logic failed');
  }
}
Run Code Online (Sandbox Code Playgroud)

现在,我们期望全局异常过滤器捕获从控制器处理函数内部抛出的错误(以及从嵌套在其中进行同步/异步操作的实际函数抛出的实际错误)。这不会发生。


同样,按照 NestJS 文档实现此类过滤器,我尝试了多种方法以及“注册”该过滤器的方法组合,但没有成功:

  • 在顶级模块定义中列为提供者{ …

exception nestjs kafkajs nestjs-config nestjs-exception-filters

1
推荐指数
1
解决办法
2779
查看次数