This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add RpcConnection trait for Web Client connection - add config for rpc connection - add media track and peer - impl PeerStateMachine for Peer - impl signaling protocol - impl signaling and handle Command from Web Client - impl participant service for Room for store members with its rpc connection
- Loading branch information
Showing
23 changed files
with
2,095 additions
and
326 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ toml = "0.4" | |
[dev-dependencies] | ||
serial_test = "0.2" | ||
serial_test_derive = "0.2" | ||
tokio = "0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ Medea | |
Medea media server | ||
|
||
__DEVELOPMENT IN PROGRESS__ | ||
|
||
{"MakeSdpOffer":{"peer":0,"sdp_offer":"caller_offer"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Chat</title> | ||
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/> | ||
|
||
<script type="text/javascript"> | ||
|
||
var socket; | ||
var pcs = {}; | ||
|
||
function connectSocket(caller) { | ||
let role = caller ? "1/caller_credentials" : "2/responder_credentials"; | ||
socket = new WebSocket("ws://localhost:8080/ws/1/" + role); | ||
socket.onmessage = handleSocketMessage; | ||
|
||
window.setInterval(function () { | ||
socket.send("{\"ping\":1}"); | ||
}, 8000); | ||
}; | ||
|
||
function handleSocketMessage(message) { | ||
|
||
var msg = JSON.parse(message.data); | ||
|
||
switch (msg.event) { | ||
case 'PeerCreated': | ||
handlePeerCreated(msg.data); | ||
break; | ||
case 'SdpAnswerMade': | ||
handleSdpAnswerMade(msg.data); | ||
break; | ||
case 'IceCandidateDiscovered': | ||
handleIceCandidateDiscovered(msg.data); | ||
break; | ||
} | ||
} | ||
|
||
async function handlePeerCreated(msg) { | ||
var sendAudio = false; | ||
var sendVideo = false; | ||
var recvAudio = false; | ||
var recvVideo = false; | ||
|
||
msg.tracks.forEach((track) => { | ||
|
||
if (track.media_type.Audio != undefined) { | ||
if (track.direction.Send != undefined) { | ||
sendAudio = true; | ||
} | ||
|
||
if (track.direction.Recv != undefined) { | ||
recvAudio = true; | ||
} | ||
|
||
} | ||
if (track.media_type.Video != undefined) { | ||
if (track.direction.Send != undefined) { | ||
sendVideo = true; | ||
} | ||
|
||
if (track.direction.Recv != undefined) { | ||
recvVideo = true; | ||
} | ||
} | ||
}); | ||
|
||
pcs[msg.peer_id] = new RTCPeerConnection(); | ||
|
||
var pc = pcs[msg.peer_id]; | ||
pc.ontrack = function (e) { | ||
console.log("ontrack"); | ||
partnervid.srcObject = e.streams[0]; | ||
}; | ||
|
||
if (sendVideo || sendAudio) { | ||
const stream = await navigator.mediaDevices.getUserMedia({ | ||
audio: sendAudio, | ||
video: sendVideo | ||
}); | ||
|
||
yourvid.srcObject = stream; | ||
|
||
stream.getTracks().forEach((track) => { | ||
pc.addTrack(track, stream); | ||
}); | ||
} | ||
|
||
|
||
var mediaConstraints = { | ||
'mandatory': { | ||
'OfferToReceiveAudio': recvAudio, | ||
'OfferToReceiveVideo': recvVideo | ||
} | ||
}; | ||
|
||
if (msg.sdp_offer != undefined && msg.sdp_offer != null) { | ||
pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(msg.sdp_offer))); | ||
var answer = await pc.createAnswer(mediaConstraints); | ||
pc.setLocalDescription(answer); | ||
|
||
socket.send(JSON.stringify({ | ||
command: "MakeSdpAnswer", | ||
data: { | ||
peer_id: msg.peer_id, | ||
sdp_answer: JSON.stringify(answer) | ||
} | ||
})); | ||
} else { | ||
var offer = await pc.createOffer(mediaConstraints); | ||
pc.setLocalDescription(offer); | ||
socket.send(JSON.stringify({ | ||
command: "MakeSdpOffer", | ||
data: { | ||
peer_id: msg.peer_id, | ||
sdp_offer: JSON.stringify(offer) | ||
} | ||
})); | ||
} | ||
|
||
|
||
pc.onicecandidate = function (e) { | ||
|
||
if (e.candidate) { | ||
socket.send(JSON.stringify({ | ||
command: "SetIceCandidate", | ||
data: { | ||
peer_id: msg.peer_id, | ||
candidate: JSON.stringify(e.candidate) | ||
} | ||
})) | ||
} | ||
|
||
}; | ||
} | ||
|
||
async function handleSdpAnswerMade(msg) { | ||
var pc = pcs[msg.peer_id]; | ||
pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(msg.sdp_answer))) | ||
} | ||
|
||
async function handleIceCandidateDiscovered(msg) { | ||
var pc = pcs[msg.peer_id]; | ||
pc.addIceCandidate(JSON.parse(msg.candidate)); | ||
} | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<div> | ||
<div> | ||
<div> | ||
<video id="yourvid" muted autoplay width="100%" height="100%"></video> | ||
</div> | ||
<div> | ||
<video id="partnervid" autoplay width="100%" height="100%"></video> | ||
</div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
//! Implementation of Client API. | ||
pub mod room; | ||
pub mod server; | ||
pub mod session; | ||
mod session; | ||
|
||
pub use self::{room::*, server::*, session::*}; | ||
pub mod rpc_connection; | ||
pub mod server; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.