Example #1
0
OP_STATUS
OpScopeTranscoder::DoSetTranscoderFormat(OpScopeProxy::TranscodingFormat format)
{
	transcoding_format = format;
	if (host.GetSTPVersion() >= 1)
	{
		// Notify the host of the format change
		if (format != OpScopeProxy::Format_None)
		{
			OpAutoPtr<OpScopeTPMessage> msg;
			RETURN_IF_ERROR(OpScopeProtocolService::CreateConfigureMessage(msg, NULL, 0, ToMessageType(format)));
			RETURN_IF_ERROR(host.SendMessage(msg));
		}
		else
		{
			if (client_format != OpScopeTPHeader::None)
			{
				OpAutoPtr<OpScopeTPMessage> msg;
				RETURN_IF_ERROR(OpScopeProtocolService::CreateConfigureMessage(msg, NULL, 0, client_format));
				RETURN_IF_ERROR(host.SendMessage(msg));
			}
		}
	}
	return OpStatus::OK;
}
Example #2
0
OP_STATUS
OpScopeTranscoder::PreProcessMessageFromClient(OpScopeTPMessage &message, OpScopeClient *client, BOOL &skip)
{
	skip = FALSE;
	if (!IsEnabled())
		return FALSE;

	// If the client sends a connect signal we need to take action
	if (message.CommandID() == OpScopeProtocolService::Command_Connect && message.ServiceName().Compare(UNI_L("scope")) == 0)
	{
		skip = FALSE;

		// Record the wanted format, needed when turning off transcoding to reset the format
		OpScopeProtocolService::ClientInfo client_info;
		OpProtobufInstanceProxy proxy(OpScopeProtocolService::ClientInfo::GetMessageDescriptor(g_scope_manager->GetDescriptorSet().scope_), static_cast<void *>(&client_info));
		OpScopeTPError error;
		RETURN_IF_ERROR(client->Parse(message, proxy, error));
		RETURN_IF_ERROR(OpScopeProtocolService::ParseFormat(client_info.GetFormat(), client_format));
		if (transcoding_format != OpScopeProxy::Format_None)
		{
			// Transcoding is currently active, change the format to the transcoder format
			OpScopeTPHeader::MessageType message_format = ToMessageType(transcoding_format);
			OP_ASSERT(message_format != OpScopeTPHeader::None);
			const uni_char *format_name = NULL;
			RETURN_IF_ERROR(OpScopeProtocolService::GenerateFormat(message_format, format_name));
			RETURN_IF_ERROR(client_info.SetFormat(format_name));
			RETURN_IF_ERROR(client->Serialize(message, proxy, message.Type()));
			// TODO: Is this correct?
		}
	}
	return OpStatus::OK;
}
Example #3
0
/*static*/
OP_STATUS
OpScopeTranscoder::TranscodeFromClient( OpScopeClient *client, OpProtobufInstanceProxy &proxy, OpScopeTPMessage &to, const OpScopeTPMessage &from, OpScopeProxy::TranscodingFormat format )
{
	// Tell the client to convert from given format and into an instance
	OpScopeTPError error;
	RETURN_IF_ERROR(client->Parse(from, proxy, error));

	// Then convert from instance to actual format to send on the wire
	OpScopeTPHeader::MessageType type = ToMessageType(format);
	return OpScopeClient::SerializeDefault(to, proxy, type);
}
    MessageSharedPtr CreateMessageFromJSON(const QByteArray &json)
    {
        bool ok = false;
        QVariantMap in = TundraJson::Parse(json, &ok).toMap();
        if (!ok)
            MessageSharedPtr();
        
        // Read initial messageType information.
        QString channelTypeName = TundraJson::ValueForAnyKey(in, QStringList() << "channel" << "Channel", "").toString().trimmed();
        QVariantMap msgData = TundraJson::ValueForAnyKey(in, QStringList() << "message" << "Message", QVariantMap()).toMap();

        QString messageTypeName = TundraJson::ValueForAnyKey(msgData, QStringList() << "type" << "Type", "").toString().trimmed();
        QVariantMap data = TundraJson::ValueForAnyKey(msgData, QStringList() << "data" << "Data", QVariantMap()).toMap();
        MessageType messageType = ToMessageType(messageTypeName);           
        
        // Construct the correct message.
        MessageSharedPtr message;

        // Signaling
        if (messageType == Signaling::OfferMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Signaling::OfferMessage());
        else if (messageType == Signaling::AnswerMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Signaling::AnswerMessage());
        else if (messageType == Signaling::IceCandidatesMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Signaling::IceCandidatesMessage());
        // Room
        else if (messageType == Room::RoomAssignedMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Room::RoomAssignedMessage());
        else if (messageType == Room::RoomUserJoinedMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Room::RoomUserJoinedMessage());
        else if (messageType == Room::RoomUserLeftMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Room::RoomUserLeftMessage());
        // Application
        else if (messageType == Application::RoomCustomMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Application::RoomCustomMessage());
        else if (messageType == Application::PeerCustomMessage::MessageTypeStatic())
            message = MessageSharedPtr(new Application::PeerCustomMessage());

        if (message.get())
        {
            // If from data deserialization fails, return a null ptr.
            if (!message->FromData(data))
            {
                LogError(QString("CreateMessageFromJSON: Failed to serialize message with type name '%1' from data").arg(messageTypeName));
                message.reset();
            }
        }
        else
            LogError(QString("CreateMessageFromJSON: Unknown message with type name '%1'").arg(messageTypeName));

        return message;
    }
    bool IMessage::FromJSON(const QByteArray &json)
    {
        bool ok = false;
        QVariantMap in = TundraJson::Parse(json, &ok).toMap();
        if (ok)
        {
            // Parse preliminary information.
            QString channelTypeName = TundraJson::ValueForAnyKey(in, QStringList() << "channel" << "Channel", "").toString().trimmed();
            channelType = ToChannelType(channelTypeName);
            QVariantMap msgData = TundraJson::ValueForAnyKey(in, QStringList() << "message" << "Message", QVariantMap()).toMap();
            
            QString messageTypeName = TundraJson::ValueForAnyKey(msgData, QStringList() << "type" << "Type", "").toString().trimmed();
            messageType = ToMessageType(messageTypeName);
            data = TundraJson::ValueForAnyKey(msgData, QStringList() << "data" << "Data", QVariantMap()).toMap();

            // Request the implementation to parse its contents from data.
            if (IsValid())
                ok = Deserialize();
        }
        return ok;
    }