Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data channel private message #5202

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/io/antmedia/AntMediaApplicationAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.Queue;
import java.util.Set;

Expand Down Expand Up @@ -47,8 +46,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.errorprone.annotations.NoAllocation;

import io.antmedia.cluster.ClusterNode;
import io.antmedia.cluster.IClusterNotifier;
import io.antmedia.datastore.db.DataStore;
Expand All @@ -65,7 +62,6 @@
import io.antmedia.plugin.api.IFrameListener;
import io.antmedia.plugin.api.IPacketListener;
import io.antmedia.plugin.api.IStreamListener;
import io.antmedia.plugin.api.StreamParametersInfo;
import io.antmedia.rest.RestServiceBase;
import io.antmedia.rest.model.Result;
import io.antmedia.security.AcceptOnlyStreamsInDataStore;
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/io/antmedia/datastore/db/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,25 +446,31 @@ public Token getToken(Map<String, String> tokenMap, String tokenId,
}

/**
* Lists all subscribers of requested stream
* @param streamId
* @param offset
* @param size
* @return lists of subscribers
*/
public abstract List<Subscriber> listAllSubscribers(String streamId, int offset, int size);

public List<Subscriber> listAllSubscribers(Map<String, String> subscriberMap, String streamId, int offset, int size, Gson gson) {
* Lists all subscribers of requested stream
*
* @param streamId
* @param offset
lastpeony marked this conversation as resolved.
Show resolved Hide resolved
* @param size
* @param getAll
* @return lists of subscribers
*/
public abstract List<Subscriber> listAllSubscribers(String streamId, int offset, int size, boolean getAll);

public List<Subscriber> listAllSubscribers(Map<String, String> subscriberMap, String streamId, int offset, int size, Gson gson, boolean getAll) {
List<Subscriber> list = new ArrayList<>();
List<Subscriber> listSubscriber = new ArrayList<>();

synchronized (this) {
Collection<String> values = subscriberMap.values();
int t = 0;
int itemCount = 0;
if (size > MAX_ITEM_IN_ONE_LIST) {

if (getAll) {
size = Integer.MAX_VALUE; // Set size to maximum to return all elements
} else if (size > MAX_ITEM_IN_ONE_LIST) {
size = MAX_ITEM_IN_ONE_LIST;
}

if (offset < 0) {
offset = 0;
}
Expand All @@ -486,14 +492,12 @@ public List<Subscriber> listAllSubscribers(Map<String, String> subscriberMap, St
t++;
listIterator.next();
} else {

listSubscriber.add(listIterator.next());
itemCount++;

}
}

}

return listSubscriber;
}

Expand All @@ -505,7 +509,7 @@ public List<Subscriber> listAllSubscribers(Map<String, String> subscriberMap, St
* @return lists of subscriber statistics
*/
public List<SubscriberStats> listAllSubscriberStats(String streamId, int offset, int size) {
List<Subscriber> subscribers= listAllSubscribers(streamId, offset, size);
List<Subscriber> subscribers= listAllSubscribers(streamId, offset, size, false);
List<SubscriberStats> subscriberStats = new ArrayList<>();

for(Subscriber subscriber : subscribers) {
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/io/antmedia/datastore/db/InMemoryDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,37 +684,37 @@ public List<Token> listAllTokens(String streamId, int offset, int size) {
}

@Override
public List<Subscriber> listAllSubscribers(String streamId, int offset, int size) {
public List<Subscriber> listAllSubscribers(String streamId, int offset, int size, boolean getAll) {
List<Subscriber> list = new ArrayList<>();
List<Subscriber> returnList = new ArrayList<>();

Collection<Subscriber> values = subscriberMap.values();
int t = 0;
int itemCount = 0;
if (size > MAX_ITEM_IN_ONE_LIST) {

if (getAll) {
size = Integer.MAX_VALUE; // Set size to maximum to return all elements
} else if (size > MAX_ITEM_IN_ONE_LIST) {
size = MAX_ITEM_IN_ONE_LIST;
}

if (offset < 0) {
offset = 0;
}


for(Subscriber subscriber: values) {
for (Subscriber subscriber : values) {
if (subscriber.getStreamId().equals(streamId)) {
list.add(subscriber);
}
}


Iterator<Subscriber> iterator = list.iterator();

while(itemCount < size && iterator.hasNext()) {
while (itemCount < size && iterator.hasNext()) {
if (t < offset) {
t++;
iterator.next();
}
else {

} else {
returnList.add(iterator.next());
itemCount++;
}
Expand All @@ -723,6 +723,7 @@ public List<Subscriber> listAllSubscribers(String streamId, int offset, int size
return returnList;
}


@Override
public boolean addSubscriber(String streamId, Subscriber subscriber) {
boolean result = false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/antmedia/datastore/db/MapBasedDataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ public List<Token> listAllTokens(String streamId, int offset, int size) {
}

@Override
public List<Subscriber> listAllSubscribers(String streamId, int offset, int size) {
return super.listAllSubscribers(subscriberMap, streamId, offset, size, gson);
public List<Subscriber> listAllSubscribers(String streamId, int offset, int size, boolean getAll) {
return super.listAllSubscribers(subscriberMap, streamId, offset, size, gson, getAll);
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/antmedia/datastore/db/MongoStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,13 @@ public List<Token> listAllTokens(String streamId, int offset, int size) {
}

@Override
public List<Subscriber> listAllSubscribers(String streamId, int offset, int size) {
public List<Subscriber> listAllSubscribers(String streamId, int offset, int size, boolean getAll) {
synchronized(this) {
return subscriberDatastore.find(Subscriber.class).filter(Filters.eq(STREAM_ID, streamId)).iterator(new FindOptions().skip(offset).limit(size)).toList();
if(!getAll){
return subscriberDatastore.find(Subscriber.class).filter(Filters.eq(STREAM_ID, streamId)).iterator(new FindOptions().skip(offset).limit(size)).toList();
}else{
return subscriberDatastore.find(Subscriber.class).filter(Filters.eq(STREAM_ID, streamId)).iterator().toList();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/antmedia/rest/BroadcastRestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public List<Subscriber> listSubscriberV2(@ApiParam(value = "the id of the stream
@ApiParam(value = "size of the return list (max:50 )", required = true) @PathParam("size") int size) {
List<Subscriber> subscribers = null;
if(streamId != null) {
subscribers = getDataStore().listAllSubscribers(streamId, offset, size);
subscribers = getDataStore().listAllSubscribers(streamId, offset, size, false);
}
return subscribers;
}
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/io/antmedia/test/db/DBStoresUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1970,16 +1970,21 @@ public void testTimeBasedSubscriberOperations(DataStore store) {
assertTrue(store.addSubscriber(subscriberPub.getStreamId(), subscriberPub));

//get subscribers of stream
List <Subscriber> subscribers = store.listAllSubscribers(streamId, 0, 10);
List <Subscriber> subscribers = store.listAllSubscribers(streamId, 0, 10, false);
assertEquals(2, subscribers.size());
List <SubscriberStats> subscriberStats = store.listAllSubscriberStats(streamId, 0, 10);
assertEquals(2, subscriberStats.size());


//get all subscribers of stream
List <Subscriber> allSubscribers = store.listAllSubscribers(streamId, 0, 0, true);
assertEquals(2, allSubscribers.size());


//revoke subscribers
store.revokeSubscribers(subscriberPlay.getStreamId());

//get subscribers of stream
subscribers = store.listAllSubscribers(streamId, 0, 10);
subscribers = store.listAllSubscribers(streamId, 0, 10, false);
subscriberStats = store.listAllSubscriberStats(streamId, 0, 10);


Expand All @@ -2000,7 +2005,7 @@ public void testTimeBasedSubscriberOperations(DataStore store) {
//delete this subscriber
assertTrue(store.deleteSubscriber(streamId, written.getSubscriberId()));

subscribers = store.listAllSubscribers(streamId, 0, 10);
subscribers = store.listAllSubscribers(streamId, 0, 10, false);
subscriberStats = store.listAllSubscriberStats(streamId, 0, 10);

//it should be zero because subscriber is deleted
Expand Down