Reputation: 1064
For our current project we need a video chat application which keeps track of the duration of those video conversations.
Every conversation also has a limited time after which the chat terminates.
I've build already the basic module, but i've got problems implementing that timer. In a WOWZA 1-to-1 Video Chat Application are always 2 Streams:
User1 publishes a stream, which User2 plays (subscribes to)
User2 publishes a stream, which User1 plays (subscribes to)
The limited time amount is saved (before the chat) in a database.
Now what's the best way to decrease this amount?
I can't do that in a StreamListener, because there are always two stream and it would decrease twice.
Maybe some sort of Singleton?
Thanks!
Upvotes: 4
Views: 1460
Reputation: 338
Instead of a singleton, if your video-chat time does not change once the chat starts, you can implement a module and attach a TimerTask
on play
or publish
event. Below is an example for you 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) {
}
}
Upvotes: 1