10 int lwsWrite(lws *lws, QByteArray d)
14 DebugOut(DebugOut::Error)<<__FUNCTION__<<": libwebsockets is not valid. Perhaps it has not been initialized?" << endl;
18 DebugOut() << "Writing to websocket: " << d.constData() << endl;
27 if(d.length() > framesize)
29 numframes = ceil((double)d.length() / double(framesize));
30 QVariantMap multiFrameMessage;
31 multiFrameMessage["type"] = "multiframe";
32 multiFrameMessage["frames"] = numframes;
34 lwsWriteVariant(lws, multiFrameMessage);
40 if(temp.length() > framesize)
42 else range = temp.length();
44 QByteArray toWrite = temp.mid(0,range);
45 const char* strToWrite = toWrite.data();
47 temp = temp.mid(range);
51 retval = lws_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_BINARY);
55 std::unique_ptr<char[]> buffer(new char[LWS_SEND_BUFFER_PRE_PADDING + toWrite.length() + LWS_SEND_BUFFER_POST_PADDING]);
56 char *buf = buffer.get() + LWS_SEND_BUFFER_PRE_PADDING;
57 memcpy(buf, strToWrite, toWrite.length());
59 retval = lws_write(lws, (unsigned char*)strToWrite, toWrite.length(), LWS_WRITE_TEXT);
65 int lwsWriteVariant(lws *lws, QVariant d)
69 replystr = QJsonDocument::fromVariant(d).toBinaryData();
72 replystr = QJsonDocument::fromVariant(d).toJson();
76 lwsWrite(lws, replystr);
79 void cleanJson(QByteArray &json)
81 json.replace(" ", "");
82 json.replace("\n", "");
83 json.replace("\t", "");