Wowza Server Module - timer / countdown in video chat

For our current project, we need a video chat application that tracks the duration of these video conferences.

Each conversation also has a limited time, after which the chat ends.

I have already created the base module, but I have problems with this timer. There are always 2 streams in the WOWZA 1-to-1 Video Chat application:

User1 publishes a stream that User2 plays (subscribes)
User2 publishes the stream that User1 plays (subscribes)

A limited amount of time is stored (until chat) in the database.

Now, what is the best way to reduce this amount?

I cannot do this in a StreamListener, because there are always two streams, and it will be halved.

Maybe some singleton?

Thanks!

+4
source share
1 answer

Instead of a single signal, if the time of your video chat does not change after the start of the chat, you can implement the module and attach the TimerTask on play or publish event. The following is an example to help you get started.

 import java.util.Timer; import java.util.TimerTask; import com.wowza.wms.amf.AMFDataList; import com.wowza.wms.client.IClient; import com.wowza.wms.logging.WMSLogger; import com.wowza.wms.module.*; import com.wowza.wms.request.RequestFunction; import com.wowza.wms.stream.IMediaStream; import com.wowza.wms.stream.IMediaStreamActionNotify; public class KillAfterNSeconds extends ModuleBase implements IMediaStreamActionNotify { private class StreamKiller extends TimerTask{ private IMediaStream stream; public StreamKiller(IMediaStream s){ this.stream = s; } @Override public void run() { try{ // Complete all your clean up, such as : if(stream != null){ WMSLogger.getLogger("").info("Killing stream: " + stream.getName()); stream.getClient().shutdownClient(); stream.shutdown(); stream.close(); } }catch(Exception e){} } } public void publish(IClient paramIClient, RequestFunction paramRequestFunction, AMFDataList paramAMFDataList) { WMSLogger.getLogger("").info("Start running publish.."); IMediaStream stream = getStream(paramIClient, paramRequestFunction); stream.addClientListener(this); Timer timer = new Timer(); TimerTask task = new StreamKiller(stream); // replace here with the actual time to kill stream timer.schedule(task, 10000); invokePrevious(paramIClient, paramRequestFunction, paramAMFDataList); WMSLogger.getLogger("").info("Finish running publish.."); return; } @Override public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) { WMSLogger.getLogger("").info("Start onUnPublish.."); double elapSeconds = stream.getElapsedTime().getTimeSeconds(); WMSLogger.getLogger("").info("Elapsed time " + elapSeconds); WMSLogger.getLogger("").info("Finish running onUnPublish.."); } @Override public void onPause(IMediaStream arg0, boolean arg1, double arg2) { } @Override public void onPlay(IMediaStream arg0, String arg1, double arg2, double arg3, int arg4) { } @Override public void onPublish(IMediaStream arg0, String arg1, boolean arg2, boolean arg3) { } @Override public void onSeek(IMediaStream arg0, double arg1) { } @Override public void onStop(IMediaStream arg0) { } } 
+1
source

All Articles