Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Qt can speak :)

  • Loading branch information...
commit 0495c817a5060fde5a5ba5713bdf73c9cea8d0e2 1 parent 926ba98
@alaingilbert authored
View
10 extension/backend.js
@@ -26,6 +26,11 @@ function onRequest(request, sender, callback) {
case 'initWebsocket': initWebsocket(); break;
case 'stopWebsocket': stopWebsocket(); break;
case 'checkSocket': callback(checkSocket()); break;
+ case 'setTurntableTab':
+ turntableTab = sender.tab.id;
+ break;
+ case 'speak':
+ break
}
}
@@ -43,7 +48,10 @@ function initWebsocket() {
state = false;
};
websocket.onmessage = function (evt) {
- console.log( evt.data );
+ var msg = evt.data || '';
+ chrome.tabs.sendRequest(turntableTab, { action: 'speak', msg: msg }, function (err, res) {
+ console.log(err, res);
+ });
};
websocket.onerror = function (evt) {
console.log('ERROR: ' + evt.data);
View
6 extension/injectScript.js
@@ -26,9 +26,9 @@ chrome.extension.sendRequest({ action: 'setTurntableTab' });
chrome.extension.onRequest.addListener(function (request, sender, callback) {
switch (request.action) {
- case 'setPlaylist':
- var playlist = request.playlist;
- data_receiver.innerText = JSON.stringify(playlist);
+ case 'speak':
+ var msg = request.msg;
+ data_receiver.innerText = JSON.stringify(msg);
data_receiver.dispatchEvent(receiverEvent);
break;
}
View
43 extension/turntable.js
@@ -4,39 +4,26 @@ customEvent.initEvent('myCustomEvent', true, true)
var data_gatherer = document.getElementById('data_gatherer');
var data_receiver = document.getElementById('data_receiver');
+
data_receiver.addEventListener('myReceiverEvent', function () {
var eventData = document.getElementById('data_receiver').innerText;
- var data = JSON.parse(eventData).songs;
-
- // Remove the current playlist
- var files = turntable.playlist.files;
- var arr = [];
- for (var i=0, len=files.length; i<len; i++) {
- arr.push(files[i].fileId);
- }
- function remRec(arr) {
- var fileId = arr.splice(0, 1)[0];
- turntable.playlist.removeFile(fileId);
- if (arr.length > 0) {
- setTimeout(remRec(arr), 300);
- } else {
- addSongsRec(data);
+ var data = JSON.parse(eventData);
+
+ // Find the right object.
+ var request_re = / Preparing message /i, x = null, rq = null;
+ for (x in turntable) {
+ if (typeof turntable[x] === "function") {
+ turntable[x].toString = Function.prototype.toString;
+ if (request_re.test(turntable[x].toString())) {
+ rq = turntable[x];
+ break;
+ }
}
}
+ // Get the roomid.
+ for (var i in turntable) { if (turntable[i].roomId) { var rid = turntable[i].roomId; break; } }
- if (arr.length > 0) {
- remRec(arr);
- } else {
- addSongsRec(data);
- }
-
- function addSongsRec(songs) {
- var song = songs.splice(0, 1)[0];
- turntable.playlist.addSong({ fileId: song.songid, metadata: song });
- if (songs.length > 0) {
- setTimeout(addSongsRec(songs), 300);
- }
- }
+ rq({"api":"room.speak","roomid":rid,"text":data});
});
View
13 qt/Server.cpp
@@ -36,10 +36,17 @@ void ServerExample::onDataReceived(QString data) {
this->txtChat->append(data);
- QWsSocket * client;
+ //QWsSocket * client;
+ // foreach ( client, clients ) {
+ // client->write( data );
+ //}
+}
+
+void ServerExample::send(QString msg) {
+ QWsSocket * client;
foreach ( client, clients ) {
- client->write( data );
- }
+ client->write(msg);
+ }
}
void ServerExample::onPong(quint64 elapsedTime) {
View
5 qt/Server.h
@@ -13,9 +13,10 @@ class ServerExample : public QObject
Q_OBJECT
public:
- ServerExample(QTextEdit *txtChat);
- ~ServerExample();
+ ServerExample(QTextEdit *txtChat);
+ ~ServerExample();
QTextEdit *txtChat;
+ void send(QString msg);
public slots:
void onClientConnection();
View
1  qt/mainwindow.cpp
@@ -20,6 +20,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
}
void MainWindow::returnPressed() {
+ myServer->send(txtMsg->text());
txtMsg->clear();
}
Please sign in to comment.
Something went wrong with that request. Please try again.