summaryrefslogtreecommitdiffstats
blob: befef4f1a08abdf98b26e225739bdb183fa4c84f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (c) 2012 Mateusz Piękos
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/Whiteboard/WhiteboardSession.h>

#include <iostream>
#include <memory>

#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/Elements/WhiteboardPayload.h>
#include <Swiften/Queries/IQRouter.h>

namespace Swift {
    WhiteboardSession::WhiteboardSession(const JID& jid, IQRouter* router) : toJID_(jid), router_(router) {
    }

    WhiteboardSession::~WhiteboardSession() {
    }

    void WhiteboardSession::handleIncomingAction(std::shared_ptr<WhiteboardPayload> payload) {
        switch (payload->getType()) {
            case WhiteboardPayload::Data:
                handleIncomingOperation(payload->getOperation());
                return;
            case WhiteboardPayload::SessionAccept:
                onRequestAccepted(toJID_);
                return;
            case WhiteboardPayload::SessionTerminate:
                onSessionTerminated(toJID_);
                return;

            //handled elsewhere
            case WhiteboardPayload::SessionRequest:

            case WhiteboardPayload::UnknownType:
                return;
        }
    }

    void WhiteboardSession::sendElement(const WhiteboardElement::ref element) {
        std::shared_ptr<WhiteboardPayload> payload = std::make_shared<WhiteboardPayload>();
        payload->setElement(element);
        std::shared_ptr<GenericRequest<WhiteboardPayload> > request = std::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
        request->send();
    }

    void WhiteboardSession::sendPayload(std::shared_ptr<WhiteboardPayload> payload) {
        std::shared_ptr<GenericRequest<WhiteboardPayload> > request = std::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
        request->send();
    }

    void WhiteboardSession::cancel() {
        if (router_->isAvailable()) {
            std::shared_ptr<WhiteboardPayload> payload = std::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionTerminate);
            std::shared_ptr<GenericRequest<WhiteboardPayload> > request = std::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
            request->send();
        }
        onSessionTerminated(toJID_);
    }

    const JID& WhiteboardSession::getTo() const {
        return toJID_;
    }
}