This repository has been archived by the owner on May 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfull.js
131 lines (113 loc) · 5.32 KB
/
full.js
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
let stream_id;
let hostname = "wss://sidekick.online:8443";
let localVideo;
function init() {
Flashphoner.init();
localVideo = document.getElementById("localVideo");
document.getElementById("localVideo").innerHTML = "";
//let timerId = setInterval(update_friends, 2000);
}
function start_stream() {
stream_id = document.getElementById("streamer_id").value;
Flashphoner.createSession({urlServer: hostname}).on(Flashphoner.constants.SESSION_STATUS.ESTABLISHED, function (session) {
//session connected, start streaming
startStreaming(session);
}).on(Flashphoner.constants.SESSION_STATUS.DISCONNECTED, function () {
setStatus("DISCONNECTED", "status_stream");
}).on(Flashphoner.constants.SESSION_STATUS.FAILED, function () {
setStatus("FAILED", "status_stream");
});
}
function startStreaming(session) {
session.createStream({
name: stream_id,
display: localVideo,
cacheLocalResources: true,
receiveVideo: false,
receiveAudio: false
}).on(Flashphoner.constants.STREAM_STATUS.PUBLISHING, function (publishStream) {
setStatus(Flashphoner.constants.STREAM_STATUS.PUBLISHING, "status_stream");
}).on(Flashphoner.constants.STREAM_STATUS.UNPUBLISHED, function () {
setStatus(Flashphoner.constants.STREAM_STATUS.UNPUBLISHED, "status_stream");
}).on(Flashphoner.constants.STREAM_STATUS.FAILED, function () {
setStatus(Flashphoner.constants.STREAM_STATUS.FAILED, "status_stream");
}).publish();
}
function setStatus(status, element_id) {
//document.getElementById(element_id).innerHTML = status;
}
let friends_id_list = new Set();
let video_id_to_update = [];
function update_friends() {
// for (let i = 1; i <= 10; i++) {
// document.getElementById("remoteVideo" + i).innerHTML = "";
// // document.getElementById("remoteVideo" + i).style.display = "none";
// }
video_id_to_update = [];
console.log("update friend", friends_id_list);
let i=0;
for (let friend_id of friends_id_list) {
//console.log(friend_id);
let local_i = i;
if (friend_id != user_name) {
Flashphoner.createSession({urlServer: hostname}).on(Flashphoner.constants.SESSION_STATUS.ESTABLISHED, function (session) {
startPlayback(session, friend_id, local_i+1, false);
}).on(Flashphoner.constants.SESSION_STATUS.DISCONNECTED, function () {
setStatus("DISCONNECTED", "status" + friend_id);
document.getElementById("remoteVideo" + (local_i+1)).innerHTML = "";
document.getElementById("remoteVideo" + (local_i+1)).style.display = "none";
}).on(Flashphoner.constants.SESSION_STATUS.FAILED, function () {
setStatus("FAILED", "status" + friend_id);
document.getElementById("remoteVideo" + (local_i+1)).innerHTML = "";
document.getElementById("remoteVideo" + (local_i+1)).style.display = "none";
});
}
i=i+1;
};
}
function startPlayback(session, friend_id, friend_video_id, is_real) {
let tag_friend_video_id = "remoteVideo" + friend_video_id;
let hidden_tag_friend_video_id = "hiddenremoteVideo" + friend_video_id;
let hidden_video = document.getElementById("hiddenremoteVideo" + friend_video_id);
let remoteVideo = document.getElementById(tag_friend_video_id);
let fake_video = document.getElementById("fakeVideo");
fake_video.innerHTML = "";
let working_video = fake_video;
console.log(tag_friend_video_id);
console.log(is_real);
if (is_real) {
console.log("remoteVideo");
working_video = remoteVideo;
} else {
console.log("fake_video");
}
let name_stream = friend_id;
session.createStream({
name: name_stream,
display: working_video,
cacheLocalResources: true,
receiveVideo: true,
receiveAudio: true
}).on(Flashphoner.constants.STREAM_STATUS.PLAYING, function (playStream) {
setStatus(Flashphoner.constants.STREAM_STATUS.PLAYING, "status" + friend_video_id);
//console.log("is?", (friend_video_id in video_id_to_update) && (remoteVideo.innerHTML == ""));
// if ((friend_video_id in video_id_to_update) && (remoteVideo.innerHTML == "")) {
// document.getElementById(tag_friend_video_id).style.display = "block";
// } else {
// video_id_to_update.push(friend_video_id);
// }
//document.getElementById(tag_friend_video_id).innerHTML = document.getElementById(hidden_tag_friend_video_id).innerHTML;
//document.getElementById(hidden_tag_friend_video_id).innerHTML = "";
console.log("succ", remoteVideo.style.display != "block");
if (!is_real && remoteVideo.style.display != "block") {
startPlayback(session, friend_id, friend_video_id, true);
}
document.getElementById(tag_friend_video_id).style.display = "block";
}).on(Flashphoner.constants.STREAM_STATUS.STOPPED, function () {
setStatus(Flashphoner.constants.STREAM_STATUS.STOPPED, "status" + friend_video_id);
}).on(Flashphoner.constants.STREAM_STATUS.FAILED, function () {
setStatus(Flashphoner.constants.STREAM_STATUS.FAILED, "status" + friend_video_id);
document.getElementById(tag_friend_video_id).innerHTML = "";
document.getElementById(tag_friend_video_id).style.display = "none";
}).play();
}