openvidu-browser Connection object creationTime real value. Stream objects creationTime property addded

pull/178/head
pabloFuente 2019-01-09 17:35:34 +01:00
parent b620cc0fa8
commit e001b2dbc9
9 changed files with 40 additions and 12 deletions

View File

@ -34,7 +34,7 @@ export class Connection {
connectionId: string;
/**
* Time when this connection was created (UTC milliseconds)
* Time when this connection was created in OpenVidu Server (UTC milliseconds)
*/
creationTime: number;
@ -77,6 +77,7 @@ export class Connection {
if (!!opts) {
// Connection is remote
this.connectionId = opts.id;
this.creationTime = opts.createdAt;
if (opts.metadata) {
this.data = opts.metadata;
}
@ -84,8 +85,6 @@ export class Connection {
this.initRemoteStreams(opts.streams);
}
}
this.creationTime = new Date().getTime();
}
@ -122,6 +121,7 @@ export class Connection {
options.forEach(opts => {
const streamOptions: InboundStreamOptions = {
id: opts.id,
createdAt: opts.createdAt,
connection: this,
hasAudio: opts.hasAudio,
hasVideo: opts.hasVideo,

View File

@ -1046,6 +1046,7 @@ export class Session implements EventDispatcher {
// Initialize local Connection object with values returned by openvidu-server
this.connection = new Connection(this);
this.connection.connectionId = response.id;
this.connection.creationTime = response.createdAt;
this.connection.data = response.metadata;
// Initialize remote Connections with value returned by openvidu-server

View File

@ -87,6 +87,13 @@ export class Stream implements EventDispatcher {
*/
streamId: string;
/**
* Time when this stream was created in OpenVidu Server (UTC milliseconds). Depending on the owner of this stream:
* - Subscriber object: property `creationTime` is always defined
* - Publisher object: property `creationTime` is only defined after successful execution of [[Session.publish]]
*/
creationTime: number;
/**
* `"CAMERA"`, `"SCREEN"` or `"CUSTOM"` (the latter when [[PublisherProperties.videoSource]] is a MediaStreamTrack when calling [[OpenVidu.initPublisher]]).
* If [[hasVideo]] is false, this property is undefined
@ -182,6 +189,7 @@ export class Stream implements EventDispatcher {
// InboundStreamOptions: stream belongs to a Subscriber
this.inboundStreamOpts = <InboundStreamOptions>options;
this.streamId = this.inboundStreamOpts.id;
this.creationTime = this.inboundStreamOpts.createdAt;
this.hasAudio = this.inboundStreamOpts.hasAudio;
this.hasVideo = this.inboundStreamOpts.hasVideo;
if (this.hasAudio) {
@ -709,6 +717,7 @@ export class Stream implements EventDispatcher {
this.webRtcPeer.processAnswer(response.sdpAnswer, false)
.then(() => {
this.streamId = response.id;
this.creationTime = response.createdAt;
this.isLocalStreamPublished = true;
this.publishedOnce = true;
if (this.displayMyRemote()) {

View File

@ -19,6 +19,7 @@ import { StreamOptionsServer } from './StreamOptionsServer';
export interface ConnectionOptions {
id: string;
createdAt: number;
metadata: string;
streams: StreamOptionsServer[];
}

View File

@ -20,6 +20,7 @@ import { Filter } from '../../../OpenVidu/Filter';
export interface InboundStreamOptions {
id: string;
createdAt: number;
connection: Connection;
hasAudio: boolean;
hasVideo: boolean;

View File

@ -19,6 +19,7 @@ import { Filter } from '../../../OpenVidu/Filter';
export interface StreamOptionsServer {
id: string;
createdAt: number;
hasAudio: boolean;
hasVideo: boolean;
audioActive: boolean;

View File

@ -41,6 +41,7 @@ public class ProtocolElements {
public static final String JOINROOM_RECORDER_PARAM = "recorder";
public static final String JOINROOM_PEERID_PARAM = "id";
public static final String JOINROOM_PEERCREATEDAT_PARAM = "createdAt";
public static final String JOINROOM_PEERSTREAMS_PARAM = "streams";
public static final String JOINROOM_PEERSTREAMID_PARAM = "id";
public static final String JOINROOM_PEERSTREAMHASAUDIO_PARAM = "hasAudio";
@ -57,6 +58,7 @@ public class ProtocolElements {
public static final String PUBLISHVIDEO_DOLOOPBACK_PARAM = "doLoopback";
public static final String PUBLISHVIDEO_SDPANSWER_PARAM = "sdpAnswer";
public static final String PUBLISHVIDEO_STREAMID_PARAM = "id";
public static final String PUBLISHVIDEO_CREATEDAT_PARAM = "createdAt";
public static final String PUBLISHVIDEO_HASAUDIO_PARAM = "hasAudio";
public static final String PUBLISHVIDEO_HASVIDEO_PARAM = "hasVideo";
public static final String PUBLISHVIDEO_AUDIOACTIVE_PARAM = "audioActive";
@ -108,7 +110,7 @@ public class ProtocolElements {
public static final String REMOVEFILTER_METHOD = "removeFilter";
public static final String ADDFILTEREVENTLISTENER_METHOD = "addFilterEventListener";
public static final String REMOVEFILTEREVENTLISTENER_METHOD = "removeFilterEventListener";
public static final String FILTEREVENTDISPATCHED_METHOD = "filterEventDispatched";
public static final String FILTEREVENTLISTENER_CONNECTIONID_PARAM = "connectionId";
public static final String FILTEREVENTLISTENER_STREAMID_PARAM = "streamId";
@ -120,6 +122,7 @@ public class ProtocolElements {
public static final String PARTICIPANTJOINED_METHOD = "participantJoined";
public static final String PARTICIPANTJOINED_USER_PARAM = "id";
public static final String PARTICIPANTJOINED_CREATEDAT_PARAM = "createdAt";
public static final String PARTICIPANTJOINED_METADATA_PARAM = "metadata";
public static final String PARTICIPANTLEFT_METHOD = "participantLeft";
@ -134,6 +137,7 @@ public class ProtocolElements {
public static final String PARTICIPANTPUBLISHED_USER_PARAM = "id";
public static final String PARTICIPANTPUBLISHED_STREAMS_PARAM = "streams";
public static final String PARTICIPANTPUBLISHED_STREAMID_PARAM = "id";
public static final String PARTICIPANTPUBLISHED_CREATEDAT_PARAM = "createdAt";
public static final String PARTICIPANTPUBLISHED_HASAUDIO_PARAM = "hasAudio";
public static final String PARTICIPANTPUBLISHED_HASVIDEO_PARAM = "hasVideo";
public static final String PARTICIPANTPUBLISHED_AUDIOACTIVE_PARAM = "audioActive";

View File

@ -86,6 +86,8 @@ public class SessionEventsHandler {
JsonObject participantJson = new JsonObject();
participantJson.addProperty(ProtocolElements.JOINROOM_PEERID_PARAM,
existingParticipant.getParticipantPublicId());
participantJson.addProperty(ProtocolElements.JOINROOM_PEERCREATEDAT_PARAM,
existingParticipant.getCreatedAt());
// Metadata associated to each existing participant
participantJson.addProperty(ProtocolElements.JOINROOM_METADATA_PARAM,
@ -98,6 +100,8 @@ public class SessionEventsHandler {
JsonObject stream = new JsonObject();
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM,
existingParticipant.getPublisherStreamId());
stream.addProperty(ProtocolElements.JOINROOM_PEERCREATEDAT_PARAM,
kParticipant.getPublisher().createdAt());
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMHASAUDIO_PARAM,
kParticipant.getPublisherMediaOptions().hasAudio);
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMHASVIDEO_PARAM,
@ -139,6 +143,8 @@ public class SessionEventsHandler {
// Metadata associated to new participant
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM,
participant.getParticipantPublicId());
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_CREATEDAT_PARAM,
participant.getCreatedAt());
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM,
participant.getFullMetadata());
@ -147,6 +153,7 @@ public class SessionEventsHandler {
}
}
result.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, participant.getParticipantPublicId());
result.addProperty(ProtocolElements.PARTICIPANTJOINED_CREATEDAT_PARAM, participant.getCreatedAt());
result.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, participant.getFullMetadata());
result.add("value", resultArray);
@ -181,8 +188,9 @@ public class SessionEventsHandler {
}
}
public void onPublishMedia(Participant participant, String streamId, String sessionId, MediaOptions mediaOptions,
String sdpAnswer, Set<Participant> participants, Integer transactionId, OpenViduException error) {
public void onPublishMedia(Participant participant, String streamId, Long createdAt, String sessionId,
MediaOptions mediaOptions, String sdpAnswer, Set<Participant> participants, Integer transactionId,
OpenViduException error) {
if (error != null) {
rpcNotificationService.sendErrorResponse(participant.getParticipantPrivateId(), transactionId, null, error);
return;
@ -190,6 +198,7 @@ public class SessionEventsHandler {
JsonObject result = new JsonObject();
result.addProperty(ProtocolElements.PUBLISHVIDEO_SDPANSWER_PARAM, sdpAnswer);
result.addProperty(ProtocolElements.PUBLISHVIDEO_STREAMID_PARAM, streamId);
result.addProperty(ProtocolElements.PUBLISHVIDEO_CREATEDAT_PARAM, createdAt);
rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId, result);
JsonObject params = new JsonObject();
@ -197,6 +206,7 @@ public class SessionEventsHandler {
JsonObject stream = new JsonObject();
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_STREAMID_PARAM, streamId);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_CREATEDAT_PARAM, createdAt);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_HASAUDIO_PARAM, mediaOptions.hasAudio);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_HASVIDEO_PARAM, mediaOptions.hasVideo);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_AUDIOACTIVE_PARAM, mediaOptions.audioActive);

View File

@ -256,8 +256,8 @@ public class KurentoSessionManager extends SessionManager {
+ kurentoOptions.getFilter().getType());
log.error("PARTICIPANT {}: Error applying filter. The token has no permissions to apply filter {}",
participant.getParticipantPublicId(), kurentoOptions.getFilter().getType(), e);
sessionEventsHandler.onPublishMedia(participant, null, session.getSessionId(), mediaOptions, sdpAnswer,
participants, transactionId, e);
sessionEventsHandler.onPublishMedia(participant, null, kParticipant.getPublisher().createdAt(),
session.getSessionId(), mediaOptions, sdpAnswer, participants, transactionId, e);
throw e;
}
}
@ -269,8 +269,8 @@ public class KurentoSessionManager extends SessionManager {
OpenViduException e = new OpenViduException(Code.MEDIA_SDP_ERROR_CODE,
"Error generating SDP response for publishing user " + participant.getParticipantPublicId());
log.error("PARTICIPANT {}: Error publishing media", participant.getParticipantPublicId(), e);
sessionEventsHandler.onPublishMedia(participant, null, session.getSessionId(), mediaOptions, sdpAnswer,
participants, transactionId, e);
sessionEventsHandler.onPublishMedia(participant, null, kParticipant.getPublisher().createdAt(),
session.getSessionId(), mediaOptions, sdpAnswer, participants, transactionId, e);
}
if (this.openviduConfig.isRecordingModuleEnabled()
@ -305,8 +305,9 @@ public class KurentoSessionManager extends SessionManager {
participants = kParticipant.getSession().getParticipants();
if (sdpAnswer != null) {
sessionEventsHandler.onPublishMedia(participant, participant.getPublisherStreamId(), session.getSessionId(),
mediaOptions, sdpAnswer, participants, transactionId, null);
sessionEventsHandler.onPublishMedia(participant, participant.getPublisherStreamId(),
kParticipant.getPublisher().createdAt(), session.getSessionId(), mediaOptions, sdpAnswer,
participants, transactionId, null);
}
}