Make call establishment with pub/note/info work.

This commit is contained in:
aforge
2022-02-15 18:24:33 -08:00
parent 5370b39fb6
commit 6cea3e97db
2 changed files with 61 additions and 43 deletions
+36 -21
View File
@@ -152,7 +152,7 @@ class TinodeWeb extends React.Component {
this.handleHideForwardDialog = this.handleHideForwardDialog.bind(this); this.handleHideForwardDialog = this.handleHideForwardDialog.bind(this);
this.handleStartVideoCall = this.handleStartVideoCall.bind(this); this.handleStartVideoCall = this.handleStartVideoCall.bind(this);
this.handleTeleMessage = this.handleTeleMessage.bind(this); this.handleInfoMessage = this.handleInfoMessage.bind(this);
this.handleCallClose = this.handleCallClose.bind(this); this.handleCallClose = this.handleCallClose.bind(this);
this.handleTeleInvite = this.handleTeleInvite.bind(this); this.handleTeleInvite = this.handleTeleInvite.bind(this);
@@ -278,7 +278,7 @@ class TinodeWeb extends React.Component {
this.tinode.onConnect = this.handleConnected; this.tinode.onConnect = this.handleConnected;
this.tinode.onDisconnect = this.handleDisconnect; this.tinode.onDisconnect = this.handleDisconnect;
this.tinode.onAutoreconnectIteration = this.handleAutoreconnectIteration; this.tinode.onAutoreconnectIteration = this.handleAutoreconnectIteration;
this.tinode.onTeleMessage = this.handleTeleMessage; this.tinode.onInfoMessage = this.handleInfoMessage;
}).then(() => { }).then(() => {
// Initialize desktop alerts. // Initialize desktop alerts.
if (this.state.desktopAlertsEnabled) { if (this.state.desktopAlertsEnabled) {
@@ -968,7 +968,7 @@ class TinodeWeb extends React.Component {
// - head - head dictionary to be attached to the message // - head - head dictionary to be attached to the message
handleSendMessage(msg, promise, uploader, head) { handleSendMessage(msg, promise, uploader, head) {
const topic = this.tinode.getTopic(this.state.topicSelected); const topic = this.tinode.getTopic(this.state.topicSelected);
this.sendMessageToTopic(topic, msg, promise, uploader, head); return this.sendMessageToTopic(topic, msg, promise, uploader, head);
} }
sendMessageToTopic(topic, msg, promise, uploader, head) { sendMessageToTopic(topic, msg, promise, uploader, head) {
@@ -1003,11 +1003,12 @@ class TinodeWeb extends React.Component {
}); });
} }
topic.publishDraft(msg, promise) return topic.publishDraft(msg, promise)
.then((ctrl) => { .then((ctrl) => {
if (topic.isArchived()) { if (topic.isArchived()) {
return topic.archive(false); return topic.archive(false);
} }
return ctrl;
}) })
.catch((err) => { .catch((err) => {
this.handleError(err.message, 'err'); this.handleError(err.message, 'err');
@@ -1401,7 +1402,7 @@ class TinodeWeb extends React.Component {
this.tinode.onConnect = this.handleConnected; this.tinode.onConnect = this.handleConnected;
this.tinode.onDisconnect = this.handleDisconnect; this.tinode.onDisconnect = this.handleDisconnect;
this.tinode.onAutoreconnectIteration = this.handleAutoreconnectIteration; this.tinode.onAutoreconnectIteration = this.handleAutoreconnectIteration;
this.tinode.onTeleMessage = this.handleTeleMessage; this.tinode.onInfoMessage = this.handleInfoMessage;
HashNavigation.navigateTo(''); HashNavigation.navigateTo('');
} }
@@ -1755,18 +1756,29 @@ class TinodeWeb extends React.Component {
} }
handleTeleInvite(callTopic, callSeq, callState) { handleTeleInvite(callTopic, callSeq, callState) {
const topic = this.tinode.getTopic(this.state.topicSelected);
if (!topic) {
return;
}
if (callState == 1) { if (callState == 1) {
let head = {mime: 'application/tinode-video-call'};
this.handleSendMessage('started', undefined, undefined, head)
.then((ctrl) => {
//this.handleTeleLeaseReply(ctrl, 0);
if (ctrl.code < 200 || ctrl.code >= 300 || typeof ctrl.params == 'undefined' || typeof ctrl.params['seq'] == 'undefined') {
this.handleCallClose();
return;
}
this.setState({callSeq: ctrl.params['seq']});
});
/*
topic.call('invite').then((ctrl) => { topic.call('invite').then((ctrl) => {
if (ctrl.params && ctrl.params['sip-code'] == 100) { if (ctrl.params && ctrl.params['sip-code'] == 100) {
this.handleTeleLeaseReply(ctrl, 0); this.handleTeleLeaseReply(ctrl, 0);
} }
}); });
*/
} else if (callState == 3) { } else if (callState == 3) {
const topic = this.tinode.getTopic(callTopic);
if (!topic) {
return;
}
topic.call('accept', callSeq).then((ctrl) => { topic.call('accept', callSeq).then((ctrl) => {
this.handleTeleLeaseReply(ctrl, 2000); this.handleTeleLeaseReply(ctrl, 2000);
}); });
@@ -1837,33 +1849,36 @@ class TinodeWeb extends React.Component {
}); });
} }
handleTeleMessage(tele) { handleInfoMessage(info) {
// //
switch (tele.what) { if (info.what != 'call') {
return;
}
switch (info.event) {
case 'invite': case 'invite':
console.log('invite: ', tele); console.log('invite: ', info);
if (tele.from != this.state.myUserId) { if (info.from != this.state.myUserId) {
// incoming call. // incoming call.
this.setState({ this.setState({
callTopic: tele.src, callTopic: info.src,
callState: 2, callState: 2,
callSeq: tele.seq, callSeq: info.seq
sdp: tele.sdp //sdp: info.sdp
}); });
} }
break; break;
case 'accept': case 'accept':
console.log('TinodeWeb: received accept msg ', tele); console.log('TinodeWeb: received accept msg ', info);
// If another my session has accepted the call. // If another my session has accepted the call.
if (tele.topic == 'me' && tele.from == this.state.myUserId) { if (info.topic == 'me' && info.from == this.state.myUserId) {
this.setState({ this.setState({
callTopic: null,//tele.src, callTopic: null,//tele.src,
callState: 0, callState: 0,
callSeq: null,//tele.seq, callSeq: null//tele.seq,
//sdp: tele.sdp //sdp: tele.sdp
}); });
} }
if (tele.topic == this.state.callTopic) { if (info.topic == this.state.callTopic) {
// Update state. // Update state.
this.setState({callState: 3}); this.setState({callState: 3});
if (this.state.callTimeout) { if (this.state.callTimeout) {
+25 -22
View File
@@ -12,7 +12,7 @@ export default class RtcPanel extends React.PureComponent {
pc: undefined, pc: undefined,
remoteStream: undefined, remoteStream: undefined,
previousOnTele: undefined previousOnInfo: undefined
}; };
this.localStreamConstraints = { this.localStreamConstraints = {
@@ -40,7 +40,7 @@ export default class RtcPanel extends React.PureComponent {
this.localRef = React.createRef(); this.localRef = React.createRef();
this.remoteRef = React.createRef(); this.remoteRef = React.createRef();
this.onTele = this.onTele.bind(this); this.onInfo = this.onInfo.bind(this);
this.launchStream = this.launchStream.bind(this); this.launchStream = this.launchStream.bind(this);
this.createPeerConnection = this.createPeerConnection.bind(this); this.createPeerConnection = this.createPeerConnection.bind(this);
@@ -72,41 +72,44 @@ export default class RtcPanel extends React.PureComponent {
this.handleVideoCallAccepted = this.handleVideoCallAccepted.bind(this); this.handleVideoCallAccepted = this.handleVideoCallAccepted.bind(this);
} }
handleVideoCallAccepted(tele) { handleVideoCallAccepted(info) {
const pc = this.createPeerConnection(); const pc = this.createPeerConnection();
const stream = this.state.localStream; const stream = this.state.localStream;
stream.getTracks().forEach(track => pc.addTrack(track, stream)); stream.getTracks().forEach(track => pc.addTrack(track, stream));
console.log('RtcPanel: tele msg', tele); console.log('RtcPanel: info msg', info);
} }
onTele(tele) { onInfo(info) {
console.log('tele --> ', tele); console.log('info --> ', info);
switch (tele.what) { if (info.what != 'call') {
return;
}
switch (info.event) {
//case 'invite' //case 'invite'
case 'accept': case 'accept':
// Call accepted. // Call accepted.
this.handleVideoCallAccepted(tele); this.handleVideoCallAccepted(info);
break; break;
case 'offer': case 'offer':
this.handleVideoOfferMsg(tele); this.handleVideoOfferMsg(info);
break; break;
case 'answer': case 'answer':
this.handleVideoAnswerMsg(tele); this.handleVideoAnswerMsg(info);
break; break;
case 'ice-candidate': case 'ice-candidate':
this.handleNewICECandidateMsg(tele); this.handleNewICECandidateMsg(info);
break; break;
case 'hang-up': case 'hang-up':
this.handleRemoteHangup(tele); this.handleRemoteHangup(info);
break; break;
} }
} }
componentDidUpdate(props) { componentDidUpdate(props) {
const topic = this.props.topic; const topic = this.props.topic;
if (this.onTele != topic.onTele) { if (this.onInfo != topic.onInfo) {
this.previousOnTele = topic.onTele; this.previousOnInfo = topic.onInfo;
topic.onTele = this.onTele; topic.onInfo = this.onInfo;
} }
} }
@@ -117,7 +120,7 @@ export default class RtcPanel extends React.PureComponent {
} }
componentWillUnmount() { componentWillUnmount() {
this.props.topic.onTele = this.previousOnTele; this.props.topic.onInfo = this.previousOnInfo;
} }
launchStream() { launchStream() {
@@ -151,13 +154,13 @@ export default class RtcPanel extends React.PureComponent {
return pc; return pc;
} }
handleVideoAnswerMsg(tele) { handleVideoAnswerMsg(info) {
console.log("*** Call recipient has accepted our call"); console.log("*** Call recipient has accepted our call");
// Configure the remote description, which is the SDP payload // Configure the remote description, which is the SDP payload
// in our "video-answer" message. // in our "video-answer" message.
var desc = new RTCSessionDescription(tele.payload); var desc = new RTCSessionDescription(info.payload);
this.state.pc.setRemoteDescription(desc).catch(this.reportError); this.state.pc.setRemoteDescription(desc).catch(this.reportError);
} }
@@ -181,8 +184,8 @@ export default class RtcPanel extends React.PureComponent {
} }
} }
handleNewICECandidateMsg(tele) { handleNewICECandidateMsg(info) {
var candidate = new RTCIceCandidate(tele.payload); var candidate = new RTCIceCandidate(info.payload);
this.state.pc.addIceCandidate(candidate) this.state.pc.addIceCandidate(candidate)
.catch(reportError); .catch(reportError);
@@ -236,12 +239,12 @@ export default class RtcPanel extends React.PureComponent {
} }
handleVideoOfferMsg(tele) { handleVideoOfferMsg(info) {
var localStream = null; var localStream = null;
const pc = this.createPeerConnection(); const pc = this.createPeerConnection();
var desc = new RTCSessionDescription(tele.payload); var desc = new RTCSessionDescription(info.payload);
pc.setRemoteDescription(desc).then(() => { pc.setRemoteDescription(desc).then(() => {
return navigator.mediaDevices.getUserMedia(this.localStreamConstraints); return navigator.mediaDevices.getUserMedia(this.localStreamConstraints);