Notifications over AMCP

@dimitry_ishenko
by the way, what do you mean by dynamically adding clients?

For working with standard OSC protocol:
If you mean that you have several casparCG servers, then the approximate solution is that you need to have a list of current servers (and keep it up to date): this.connectionService.servers

Then, with each new message received on the OSC port, you check whether the sender’s address is your target CasparCG server and send a stop event to the media layer if it is completed…

Simplified example:

      const OSC_STATE_REGEX = /^\/channel\/1\/stage\/layer\/(\d+)\/foreground\/file\/time$/;
      
      const oscConnection = new OSC({
        plugin: new OSC.DatagramPlugin(),
      });
      oscConnection.on(
        '/channel/1/stage/layer/*/foreground/file/time',
        async (message: any, { address }) => {
          const server = this.connectionService.servers.find(
            (server) => server.playoutHost === address,
          );
          if (!server) return;

          try {
            const match = message.address.match(OSC_STATE_REGEX);
            if (!match) return;
            const layer = match[1];

            const currentTime = Math.floor(message.args[0]);
            const duration = Math.floor(message.args[1]);
            
            if (
              currentTime > duration ||
                (currentTime === duration && currentTime !== 0)
            ) {
              this.eventEmitter.emit(EVENT_SERVER.MEDIA.STOP, {
                serverId: server._id.toString(),
                layer,
              });
            }
          } catch (error) {
            this.loggingService.logError(error, {
              module: moduleName,
              function: 'oscListener',
            });
          }
        },
      );
      oscConnection.on('error', (error: any) => {
        this.loggingService.logError(error, {
          module: moduleName,
          function: 'oscListener',
        });
      });

      oscConnection.open({
        host: '0.0.0.0',
        port: +process.env.CASPAR_SETTINGS_OSC_PORT,
      });         

I hope this helps