Skip to content

Commit

Permalink
New webhooks playStart, playStop, recordStart issue #4666
Browse files Browse the repository at this point in the history
  • Loading branch information
lastpeony committed Mar 8, 2023
1 parent 2746785 commit e859475
Showing 1 changed file with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.mockito.Mockito;
import org.red5.server.api.IContext;
import org.red5.server.api.scope.IScope;
import org.red5.server.api.stream.IPlayItem;
import org.red5.server.api.stream.ISubscriberStream;
import org.red5.server.stream.ClientBroadcastStream;
import org.springframework.context.ApplicationContext;

Expand Down Expand Up @@ -1831,4 +1833,69 @@ public void testRecordStartedHook() throws Exception {

}

@Test
public void testRtmpStreamPlayStop() throws Exception {
final AntMediaApplicationAdapter spyAdaptor = Mockito.spy(adapter);
AppSettings appSettings = new AppSettings();
spyAdaptor.setAppSettings(appSettings);

Broadcast broadcast = new Broadcast();
assertNull(spyAdaptor.getListenerHookURL(broadcast));
broadcast.setMp4Enabled(MuxAdaptor.RECORDING_ENABLED_FOR_STREAM);
String hookURL = "listener_hook_url";
appSettings.setListenerHookURL(hookURL);

assertEquals(hookURL, spyAdaptor.getListenerHookURL(broadcast));


appSettings = new AppSettings();
spyAdaptor.setServerSettings(new ServerSettings());
spyAdaptor.setAppSettings(appSettings);
DataStore dataStore = new InMemoryDataStore("test");
DataStoreFactory dsf = Mockito.mock(DataStoreFactory.class);
Mockito.when(dsf.getDataStore()).thenReturn(dataStore);
spyAdaptor.setDataStoreFactory(dsf);
spyAdaptor.setDataStore(dataStore);
broadcast.setStreamId("stream1");
broadcast.setName("name");
broadcast.setCategory("category");
broadcast.setListenerHookURL(hookURL);
dataStore.save(broadcast);
String streamId = broadcast.getStreamId();
IPlayItem item = mock(IPlayItem.class);
ISubscriberStream stream = mock(ISubscriberStream.class);
doReturn(streamId).when(item).getName();
doReturn(new StringBuilder()).when(spyAdaptor).sendPOST(anyString(),anyMap());
assertEquals(spyAdaptor.getDataStore().get(streamId).getRtmpViewerCount(), 0);

spyAdaptor.streamPlayItemPlay(stream, item, true);
verify(spyAdaptor, times(1)).sendStartPlayWebHook(anyString(), anyString(), anyString());
Awaitility.await().atMost(2, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(
()-> {
boolean called = false;
try{
assertEquals(spyAdaptor.getDataStore().get(streamId).getRtmpViewerCount(), 1);
called = true;
}catch (Exception e){
e.printStackTrace();
}
return called;
});

spyAdaptor.streamPlayItemStop(stream, item);
verify(spyAdaptor, times(1)).sendStopPlayWebHook(anyString(), anyString(), anyString());
Awaitility.await().atMost(2, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(
()-> {
boolean called = false;
try{
assertEquals(spyAdaptor.getDataStore().get(streamId).getRtmpViewerCount(), 0);
called = true;
}catch (Exception e){
e.printStackTrace();
}
return called;
});

}

}

0 comments on commit e859475

Please sign in to comment.