mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 19:42:38 +02:00
Adding socket support
-- When upload a video to a certain category, this video will be part of a user group automatically -- one category can add your video in more than one user group -- Allow user add some extra info in JSON format, for example bank info and other thing -- This is based on users_extra_info table -- add full text search https://github.com/WWBN/AVideo/issues/4343
This commit is contained in:
parent
939ad22ab1
commit
730f4893f2
659 changed files with 80151 additions and 1694 deletions
78
plugin/Socket/script.js
Normal file
78
plugin/Socket/script.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
var socketMyResourceId = 0;
|
||||
function socketConnect() {
|
||||
console.log('Trying to reconnect on ' + webSocketURL);
|
||||
conn = new WebSocket(webSocketURL);
|
||||
conn.onopen = function (e) {
|
||||
console.log("Socket onopen", e);
|
||||
socketMyResourceId = 0;
|
||||
sendSocketMessage("webSocketToken", "");
|
||||
return false;
|
||||
};
|
||||
conn.onmessage = function (e) {
|
||||
console.log("Socket onmessage", e);
|
||||
if (!socketMyResourceId) {
|
||||
socketMyResourceId = parseInt(e.data);
|
||||
var msg = "Socket socketMyResourceId " + socketMyResourceId;
|
||||
sendSocketMessage(msg, "");
|
||||
console.log(msg);
|
||||
} else {
|
||||
var json = JSON.parse(e.data);
|
||||
var myfunc;
|
||||
if (json.callback) {
|
||||
var code = "if(typeof " + json.callback + " == 'function'){myfunc = " + json.callback + ";}else{myfunc = defaultCallback;}";
|
||||
console.log(code);
|
||||
eval(code);
|
||||
} else {
|
||||
myfunc = defaultCallback;
|
||||
}
|
||||
myfunc(json);
|
||||
}
|
||||
|
||||
};
|
||||
conn.onclose = function (e) {
|
||||
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
|
||||
setTimeout(function () {
|
||||
socketConnect();
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
conn.onerror = function (err) {
|
||||
console.error('Socket encountered error: ', err.message, 'Closing socket');
|
||||
conn.close();
|
||||
};
|
||||
}
|
||||
|
||||
function sendSocketMessage(msg, callback) {
|
||||
if (conn.readyState === 1) {
|
||||
conn.send(JSON.stringify({msg: msg, webSocketToken: webSocketToken, callback: callback}));
|
||||
} else {
|
||||
console.log('Socket not ready send message in 1 second');
|
||||
setTimeout(function () {
|
||||
sendSocketMessage(msg, callback);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function sendSocketMessageToUser(msg, users_id, callback) {
|
||||
if (conn.readyState === 1) {
|
||||
conn.send(JSON.stringify({msg: msg, webSocketToken: webSocketToken, users_id: users_id, callback: callback}));
|
||||
} else {
|
||||
console.log('Socket not ready send message in 1 second');
|
||||
setTimeout(function () {
|
||||
sendSocketMessageToUser(msg, users_id, callback);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function isSocketActive(){
|
||||
return typeof conn != 'undefined' && conn.readyState === 1;
|
||||
}
|
||||
|
||||
function defaultCallback(json) {
|
||||
console.log('defaultCallback', json);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
socketConnect();
|
||||
sendSocketMessage("test", "");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue