mirror of https://github.com/OpenVidu/openvidu.git
'signal' method
parent
1f74a554a4
commit
7f65f8ed5e
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "openvidu-browser",
|
"name": "openvidu-browser",
|
||||||
"version": "1.1.2",
|
"version": "1.1.3",
|
||||||
"description": "OpenVidu Browser",
|
"description": "OpenVidu Browser",
|
||||||
"author": "OpenVidu",
|
"author": "OpenVidu",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { SessionInternal, SessionOptions } from '../OpenViduInternal/SessionInternal';
|
import { SessionInternal, SessionOptions, SignalOptions } from '../OpenViduInternal/SessionInternal';
|
||||||
import { Stream } from '../OpenViduInternal/Stream';
|
import { Stream } from '../OpenViduInternal/Stream';
|
||||||
import { Connection } from "../OpenViduInternal/Connection";
|
import { Connection } from "../OpenViduInternal/Connection";
|
||||||
|
|
||||||
|
@ -128,4 +128,23 @@ export class Session {
|
||||||
subscriber.stream.removeVideo();
|
subscriber.stream.removeVideo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signal(signal: SignalOptions, completionHandler?: Function) {
|
||||||
|
var signalMessage = {};
|
||||||
|
|
||||||
|
if (signal.to && signal.to.length > 0) {
|
||||||
|
let connectionIds: string[] = [];
|
||||||
|
for (let i = 0; i < signal.to.length; i++) {
|
||||||
|
connectionIds.push(signal.to[i].connectionId);
|
||||||
|
}
|
||||||
|
signalMessage['to'] = connectionIds;
|
||||||
|
} else {
|
||||||
|
signalMessage['to'] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
signalMessage['data'] = signal.data ? signal.data : '';
|
||||||
|
signalMessage['type'] = signal.type ? signal.type : '';
|
||||||
|
|
||||||
|
this.openVidu.openVidu.sendMessage(this.sessionId, this.connection.connectionId, JSON.stringify(signalMessage));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,12 @@ export interface SessionOptions {
|
||||||
thresholdSpeaker?: number;
|
thresholdSpeaker?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SignalOptions {
|
||||||
|
type?: string;
|
||||||
|
to?: Connection[];
|
||||||
|
data?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class SessionInternal {
|
export class SessionInternal {
|
||||||
|
|
||||||
private id: string;
|
private id: string;
|
||||||
|
@ -364,20 +370,20 @@ export class SessionInternal {
|
||||||
|
|
||||||
onNewMessage(msg) {
|
onNewMessage(msg) {
|
||||||
|
|
||||||
console.info("New message: " + JSON.stringify(msg));
|
console.info("New signal: " + JSON.stringify(msg));
|
||||||
let room = msg.room;
|
|
||||||
let user = msg.user;
|
this.ee.emitEvent('signal', [{
|
||||||
let message = msg.message;
|
data: msg.data,
|
||||||
|
from: this.participants[msg.from],
|
||||||
|
type: msg.type
|
||||||
|
}]);
|
||||||
|
|
||||||
|
this.ee.emitEvent('signal:' + msg.type, [{
|
||||||
|
data: msg.data,
|
||||||
|
from: this.participants[msg.from],
|
||||||
|
type: msg.type
|
||||||
|
}]);
|
||||||
|
|
||||||
if (user !== undefined) {
|
|
||||||
this.ee.emitEvent('newMessage', [{
|
|
||||||
room: room,
|
|
||||||
user: user,
|
|
||||||
message: message
|
|
||||||
}]);
|
|
||||||
} else {
|
|
||||||
console.warn("User undefined in new message:", msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
recvIceCandidate(msg) {
|
recvIceCandidate(msg) {
|
||||||
|
|
|
@ -43,7 +43,10 @@ public class OpenViduException extends JsonRpcErrorException {
|
||||||
USER_UNAUTHORIZED_ERROR_CODE(401), ROLE_NOT_FOUND_ERROR_CODE(402),
|
USER_UNAUTHORIZED_ERROR_CODE(401), ROLE_NOT_FOUND_ERROR_CODE(402),
|
||||||
SESSIONID_CANNOT_BE_CREATED_ERROR_CODE(403), TOKEN_CANNOT_BE_CREATED_ERROR_CODE(404),
|
SESSIONID_CANNOT_BE_CREATED_ERROR_CODE(403), TOKEN_CANNOT_BE_CREATED_ERROR_CODE(404),
|
||||||
|
|
||||||
USER_METADATA_FORMAT_INVALID_ERROR_CODE(500);
|
USER_METADATA_FORMAT_INVALID_ERROR_CODE(500),
|
||||||
|
|
||||||
|
SIGNAL_FORMAT_INVALID_ERROR_CODE(600), SIGNAL_TO_INVALID_ERROR_CODE(601),
|
||||||
|
SIGNAL_MESSAGE_INVALID_ERROR_CODE(602);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
|
|
|
@ -109,13 +109,13 @@ public class ServerJsonRpcHandler extends DefaultJsonRpcHandler<JsonObject> {
|
||||||
|
|
||||||
private Notification participantSendMessage(Transaction transaction,
|
private Notification participantSendMessage(Transaction transaction,
|
||||||
Request<JsonObject> request) {
|
Request<JsonObject> request) {
|
||||||
String room = JsonRoomUtils.getRequestParam(request,
|
String data = JsonRoomUtils.getRequestParam(request,
|
||||||
ProtocolElements.PARTICIPANTSENDMESSAGE_ROOM_PARAM, String.class);
|
ProtocolElements.PARTICIPANTSENDMESSAGE_DATA_PARAM, String.class);
|
||||||
String user = JsonRoomUtils.getRequestParam(request,
|
String from = JsonRoomUtils.getRequestParam(request,
|
||||||
ProtocolElements.PARTICIPANTSENDMESSAGE_USER_PARAM, String.class);
|
ProtocolElements.PARTICIPANTSENDMESSAGE_FROM_PARAM, String.class);
|
||||||
String message = JsonRoomUtils.getRequestParam(request,
|
String type = JsonRoomUtils.getRequestParam(request,
|
||||||
ProtocolElements.PARTICIPANTSENDMESSAGE_MESSAGE_PARAM, String.class);
|
ProtocolElements.PARTICIPANTSENDMESSAGE_TYPE_PARAM, String.class);
|
||||||
SendMessageInfo eventInfo = new SendMessageInfo(room, user, message);
|
SendMessageInfo eventInfo = new SendMessageInfo(data, from, type);
|
||||||
log.debug("Recvd send message event {}", eventInfo);
|
log.debug("Recvd send message event {}", eventInfo);
|
||||||
return eventInfo;
|
return eventInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,9 +93,9 @@ public class ProtocolElements {
|
||||||
public static final String PARTICIPANTUNPUBLISHED_NAME_PARAM = "name";
|
public static final String PARTICIPANTUNPUBLISHED_NAME_PARAM = "name";
|
||||||
|
|
||||||
public static final String PARTICIPANTSENDMESSAGE_METHOD = "sendMessage";
|
public static final String PARTICIPANTSENDMESSAGE_METHOD = "sendMessage";
|
||||||
public static final String PARTICIPANTSENDMESSAGE_USER_PARAM = "user";
|
public static final String PARTICIPANTSENDMESSAGE_DATA_PARAM = "data";
|
||||||
public static final String PARTICIPANTSENDMESSAGE_ROOM_PARAM = "room";
|
public static final String PARTICIPANTSENDMESSAGE_FROM_PARAM = "from";
|
||||||
public static final String PARTICIPANTSENDMESSAGE_MESSAGE_PARAM = "message";
|
public static final String PARTICIPANTSENDMESSAGE_TYPE_PARAM = "type";
|
||||||
|
|
||||||
public static final String ROOMCLOSED_METHOD = "roomClosed";
|
public static final String ROOMCLOSED_METHOD = "roomClosed";
|
||||||
public static final String ROOMCLOSED_ROOM_PARAM = "room";
|
public static final String ROOMCLOSED_ROOM_PARAM = "room";
|
||||||
|
|
|
@ -27,6 +27,10 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
|
||||||
import io.openvidu.client.OpenViduException;
|
import io.openvidu.client.OpenViduException;
|
||||||
import io.openvidu.client.OpenViduException.Code;
|
import io.openvidu.client.OpenViduException.Code;
|
||||||
import io.openvidu.server.core.RoomManager.JoinRoomReturnValue;
|
import io.openvidu.server.core.RoomManager.JoinRoomReturnValue;
|
||||||
|
@ -265,10 +269,17 @@ public class NotificationRoomManager {
|
||||||
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE,
|
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE,
|
||||||
"Provided room name '" + roomName + "' differs from the participant's room");
|
"Provided room name '" + roomName + "' differs from the participant's room");
|
||||||
}
|
}
|
||||||
notificationRoomHandler.onSendMessage(request, message, userName, roomName,
|
try {
|
||||||
internalManager.getParticipants(roomName), null);
|
JsonObject messageJSON = new JsonParser().parse(message).getAsJsonObject();
|
||||||
|
|
||||||
|
notificationRoomHandler.onSendMessage(request, messageJSON, userName, roomName, internalManager.getParticipants(roomName), null);
|
||||||
|
|
||||||
|
} catch (JsonSyntaxException | IllegalStateException e) {
|
||||||
|
throw new OpenViduException(Code.SIGNAL_FORMAT_INVALID_ERROR_CODE,
|
||||||
|
"Provided signal object '" + message + "' has not a valid JSON format");
|
||||||
|
}
|
||||||
} catch (OpenViduException e) {
|
} catch (OpenViduException e) {
|
||||||
log.warn("PARTICIPANT {}: Error sending message", userName, e);
|
log.warn("PARTICIPANT {}: Error sending signal", userName, e);
|
||||||
notificationRoomHandler.onSendMessage(request, null, null, null, null, e);
|
notificationRoomHandler.onSendMessage(request, null, null, null, null, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.kurento.client.MediaElement;
|
import org.kurento.client.MediaElement;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import io.openvidu.client.OpenViduException;
|
import io.openvidu.client.OpenViduException;
|
||||||
import io.openvidu.server.core.NotificationRoomManager;
|
import io.openvidu.server.core.NotificationRoomManager;
|
||||||
import io.openvidu.server.core.api.pojo.ParticipantRequest;
|
import io.openvidu.server.core.api.pojo.ParticipantRequest;
|
||||||
|
@ -190,7 +192,7 @@ public interface NotificationRoomHandler extends RoomHandler {
|
||||||
* null, then the operation was unsuccessful and the user should be responded
|
* null, then the operation was unsuccessful and the user should be responded
|
||||||
* accordingly.
|
* accordingly.
|
||||||
*/
|
*/
|
||||||
void onSendMessage(ParticipantRequest request, String message, String userName, String roomName,
|
void onSendMessage(ParticipantRequest request, JsonObject message, String userName, String roomName,
|
||||||
Set<UserParticipant> participants, OpenViduException error);
|
Set<UserParticipant> participants, OpenViduException error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,15 +16,20 @@
|
||||||
|
|
||||||
package io.openvidu.server.core.internal;
|
package io.openvidu.server.core.internal;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.kurento.client.IceCandidate;
|
import org.kurento.client.IceCandidate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import io.openvidu.client.OpenViduException;
|
import io.openvidu.client.OpenViduException;
|
||||||
|
import io.openvidu.client.OpenViduException.Code;
|
||||||
import io.openvidu.client.internal.ProtocolElements;
|
import io.openvidu.client.internal.ProtocolElements;
|
||||||
import io.openvidu.server.InfoHandler;
|
import io.openvidu.server.InfoHandler;
|
||||||
import io.openvidu.server.core.api.NotificationRoomHandler;
|
import io.openvidu.server.core.api.NotificationRoomHandler;
|
||||||
|
@ -200,23 +205,54 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSendMessage(ParticipantRequest request, String message, String userName,
|
public void onSendMessage(ParticipantRequest request, JsonObject message, String userName,
|
||||||
String roomName, Set<UserParticipant> participants, OpenViduException error) {
|
String roomName, Set<UserParticipant> participants, OpenViduException error) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
notifService.sendErrorResponse(request, null, error);
|
notifService.sendErrorResponse(request, null, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
notifService.sendResponse(request, new JsonObject());
|
|
||||||
|
|
||||||
JsonObject params = new JsonObject();
|
JsonObject params = new JsonObject();
|
||||||
params.addProperty(ProtocolElements.PARTICIPANTSENDMESSAGE_ROOM_PARAM, roomName);
|
params.addProperty(ProtocolElements.PARTICIPANTSENDMESSAGE_DATA_PARAM, message.get("data").getAsString());
|
||||||
params.addProperty(ProtocolElements.PARTICIPANTSENDMESSAGE_USER_PARAM, userName);
|
params.addProperty(ProtocolElements.PARTICIPANTSENDMESSAGE_FROM_PARAM, userName);
|
||||||
params.addProperty(ProtocolElements.PARTICIPANTSENDMESSAGE_MESSAGE_PARAM, message);
|
params.addProperty(ProtocolElements.PARTICIPANTSENDMESSAGE_TYPE_PARAM, message.get("type").getAsString());
|
||||||
|
|
||||||
for (UserParticipant participant : participants) {
|
Set<String> toSet = new HashSet<String>();
|
||||||
notifService.sendNotification(participant.getParticipantId(),
|
|
||||||
ProtocolElements.PARTICIPANTSENDMESSAGE_METHOD, params);
|
if (message.has("to")) {
|
||||||
|
JsonArray toJson = message.get("to").getAsJsonArray();
|
||||||
|
for (int i=0; i < toJson.size(); i++) {
|
||||||
|
JsonElement el = toJson.get(i);
|
||||||
|
if (el.isJsonNull()) {
|
||||||
|
throw new OpenViduException(Code.SIGNAL_TO_INVALID_ERROR_CODE, "Signal \"to\" field invalid format: null");
|
||||||
|
}
|
||||||
|
toSet.add(el.getAsString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (toSet.isEmpty()) {
|
||||||
|
for (UserParticipant participant : participants) {
|
||||||
|
notifService.sendNotification(participant.getParticipantId(),
|
||||||
|
ProtocolElements.PARTICIPANTSENDMESSAGE_METHOD, params);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Set<String> participantNames = participants.stream()
|
||||||
|
.map(UserParticipant::getUserName)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
for (String to : toSet) {
|
||||||
|
if (participantNames.contains(to)) {
|
||||||
|
Optional<UserParticipant> p = participants.stream()
|
||||||
|
.filter(x -> to.equals(x.getUserName()))
|
||||||
|
.findFirst();
|
||||||
|
notifService.sendNotification(p.get().getParticipantId(),
|
||||||
|
ProtocolElements.PARTICIPANTSENDMESSAGE_METHOD, params);
|
||||||
|
} else {
|
||||||
|
throw new OpenViduException(Code.SIGNAL_TO_INVALID_ERROR_CODE, "Signal \"to\" field invalid format: Connection [" + to + "] does not exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifService.sendResponse(request, new JsonObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue