You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Add JSDoc; Add createNewMatrixCall to globals.
This commit is contained in:
@@ -140,7 +140,7 @@ module.exports.MatrixHttpApi.prototype = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload content to the Home Server
|
* Upload content to the Home Server
|
||||||
* @param {File object} file A File object (in a browser) or in Node,
|
* @param {File} file A File object (in a browser) or in Node,
|
||||||
an object with properties:
|
an object with properties:
|
||||||
name: The file's name
|
name: The file's name
|
||||||
stream: A read stream
|
stream: A read stream
|
||||||
|
|||||||
@@ -24,6 +24,15 @@ module.exports.RoomState = require("./models/room-state");
|
|||||||
module.exports.User = require("./models/user");
|
module.exports.User = require("./models/user");
|
||||||
/** The {@link module:scheduler~MatrixScheduler|MatrixScheduler} class. */
|
/** The {@link module:scheduler~MatrixScheduler|MatrixScheduler} class. */
|
||||||
module.exports.MatrixScheduler = require("./scheduler");
|
module.exports.MatrixScheduler = require("./scheduler");
|
||||||
|
/**
|
||||||
|
* Create a new Matrix Call.
|
||||||
|
* @function
|
||||||
|
* @param {module:client.MatrixClient} client The MatrixClient instance to use.
|
||||||
|
* @param {string} roomId The room the call is in.
|
||||||
|
* @return {module:webrtc/call~MatrixCall} The Matrix call or null if the browser
|
||||||
|
* does not support WebRTC.
|
||||||
|
*/
|
||||||
|
module.exports.createNewMatrixCall = require("./webrtc/call").createNewMatrixCall;
|
||||||
|
|
||||||
// expose the underlying request object so different environments can use
|
// expose the underlying request object so different environments can use
|
||||||
// different request libs (e.g. request or browser-request)
|
// different request libs (e.g. request or browser-request)
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
/**
|
||||||
|
* This is an internal module. See {@link createNewMatrixCall} for the public API.
|
||||||
|
* @module webrtc/call
|
||||||
|
*/
|
||||||
var utils = require("../utils");
|
var utils = require("../utils");
|
||||||
var EventEmitter = require("events").EventEmitter;
|
var EventEmitter = require("events").EventEmitter;
|
||||||
|
|
||||||
@@ -186,34 +190,13 @@ MatrixCall.prototype.replacedBy = function(newCall) {
|
|||||||
*/
|
*/
|
||||||
MatrixCall.prototype.hangup = function(reason, suppressEvent) {
|
MatrixCall.prototype.hangup = function(reason, suppressEvent) {
|
||||||
console.log("Ending call " + this.callId);
|
console.log("Ending call " + this.callId);
|
||||||
|
terminate(this, "local", reason, !suppressEvent);
|
||||||
// pausing now keeps the last frame (ish) of the video call in the video element
|
|
||||||
// rather than it just turning black straight away
|
|
||||||
if (this.getRemoteVideoElement() && this.getRemoteVideoElement().pause) {
|
|
||||||
this.getRemoteVideoElement().pause();
|
|
||||||
}
|
|
||||||
if (this.getLocalVideoElement() && this.getLocalVideoElement().pause) {
|
|
||||||
this.getLocalVideoElement().pause();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.stopAllMedia();
|
|
||||||
if (this.peerConn) {
|
|
||||||
this.peerConn.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.hangupParty = 'local';
|
|
||||||
this.hangupReason = reason;
|
|
||||||
|
|
||||||
var content = {
|
var content = {
|
||||||
version: 0,
|
version: 0,
|
||||||
call_id: this.callId,
|
call_id: this.callId,
|
||||||
reason: reason
|
reason: reason
|
||||||
};
|
};
|
||||||
this.sendEvent('m.call.hangup', content);
|
this.sendEvent('m.call.hangup', content);
|
||||||
this.state = 'ended';
|
|
||||||
if (!suppressEvent) {
|
|
||||||
this.emit("onHangup", this);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -357,14 +340,15 @@ MatrixCall.prototype.receivedAnswer = function(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.peerConn.ngsetRemoteDescription(
|
this.peerConn.setRemoteDescription(
|
||||||
new this.webRtc.RtcSessionDescription(msg.answer)
|
new this.webRtc.RtcSessionDescription(msg.answer),
|
||||||
).then(function(s) {
|
function(s) {
|
||||||
self.onSetRemoteDescriptionSuccess(s);
|
self.onSetRemoteDescriptionSuccess(s);
|
||||||
},
|
},
|
||||||
function(e) {
|
function(e) {
|
||||||
self.onSetRemoteDescriptionError(e);
|
self.onSetRemoteDescriptionError(e);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
this.state = 'connecting';
|
this.state = 'connecting';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -382,7 +366,7 @@ MatrixCall.prototype.gotLocalOffer = function(description) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.peerConn.ngsetLocalDescription(description).then(function() {
|
self.peerConn.setLocalDescription(description, function() {
|
||||||
var content = {
|
var content = {
|
||||||
version: 0,
|
version: 0,
|
||||||
call_id: self.callId,
|
call_id: self.callId,
|
||||||
@@ -411,8 +395,7 @@ MatrixCall.prototype.gotLocalOffer = function(description) {
|
|||||||
self.state = 'invite_sent';
|
self.state = 'invite_sent';
|
||||||
}, function() {
|
}, function() {
|
||||||
console.log("Error setting local description!");
|
console.log("Error setting local description!");
|
||||||
}
|
});
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -572,20 +555,7 @@ MatrixCall.prototype.onRemoteStreamTrackStarted = function(event) {
|
|||||||
*/
|
*/
|
||||||
MatrixCall.prototype.onHangupReceived = function(msg) {
|
MatrixCall.prototype.onHangupReceived = function(msg) {
|
||||||
console.log("Hangup received");
|
console.log("Hangup received");
|
||||||
if (this.getRemoteVideoElement() && this.getRemoteVideoElement().pause) {
|
terminate(this, "remote", msg.reason, true);
|
||||||
this.getRemoteVideoElement().pause();
|
|
||||||
}
|
|
||||||
if (this.getLocalVideoElement() && this.getLocalVideoElement().pause) {
|
|
||||||
this.getLocalVideoElement().pause();
|
|
||||||
}
|
|
||||||
this.state = 'ended';
|
|
||||||
this.hangupParty = 'remote';
|
|
||||||
this.hangupReason = msg.reason;
|
|
||||||
stopAllMedia(this);
|
|
||||||
if (this.peerConn && this.peerConn.signalingState != 'closed') {
|
|
||||||
this.peerConn.close();
|
|
||||||
}
|
|
||||||
this.emit("onHangup", this);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -594,20 +564,7 @@ MatrixCall.prototype.onHangupReceived = function(msg) {
|
|||||||
*/
|
*/
|
||||||
MatrixCall.prototype.onAnsweredElsewhere = function(msg) {
|
MatrixCall.prototype.onAnsweredElsewhere = function(msg) {
|
||||||
console.log("Answered elsewhere");
|
console.log("Answered elsewhere");
|
||||||
if (this.getRemoteVideoElement() && this.getRemoteVideoElement().pause) {
|
terminate(this, "remote", "answered_elsewhere", true);
|
||||||
this.getRemoteVideoElement().pause();
|
|
||||||
}
|
|
||||||
if (this.getLocalVideoElement() && this.getLocalVideoElement().pause) {
|
|
||||||
this.getLocalVideoElement().pause();
|
|
||||||
}
|
|
||||||
this.state = 'ended';
|
|
||||||
this.hangupParty = 'remote';
|
|
||||||
this.hangupReason = "answered_elsewhere";
|
|
||||||
stopAllMedia(this);
|
|
||||||
if (this.peerConn && this.peerConn.signalingState != 'closed') {
|
|
||||||
this.peerConn.close();
|
|
||||||
}
|
|
||||||
this.emit("onHangup", this);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -636,6 +593,26 @@ MatrixCall.prototype.sendCandidate = function(content) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var terminate = function(self, hangupParty, hangupReason, shouldEmit) {
|
||||||
|
if (self.getRemoteVideoElement() && self.getRemoteVideoElement().pause) {
|
||||||
|
self.getRemoteVideoElement().pause();
|
||||||
|
}
|
||||||
|
if (self.getLocalVideoElement() && self.getLocalVideoElement().pause) {
|
||||||
|
self.getLocalVideoElement().pause();
|
||||||
|
}
|
||||||
|
self.state = 'ended';
|
||||||
|
self.hangupParty = hangupParty;
|
||||||
|
self.hangupReason = hangupReason;
|
||||||
|
stopAllMedia(self);
|
||||||
|
if (self.peerConn &&
|
||||||
|
(hangupParty === "local" || self.peerConn.signalingState != 'closed')) {
|
||||||
|
self.peerConn.close();
|
||||||
|
}
|
||||||
|
if (shouldEmit) {
|
||||||
|
self.emit("onHangup", self);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var stopAllMedia = function(self) {
|
var stopAllMedia = function(self) {
|
||||||
if (self.localAVStream) {
|
if (self.localAVStream) {
|
||||||
forAllTracksOnStream(self.localAVStream, function(t) {
|
forAllTracksOnStream(self.localAVStream, function(t) {
|
||||||
@@ -780,9 +757,19 @@ module.exports.MatrixCall = MatrixCall;
|
|||||||
*/
|
*/
|
||||||
module.exports.createNewMatrixCall = function(client, roomId) {
|
module.exports.createNewMatrixCall = function(client, roomId) {
|
||||||
var w = global.window;
|
var w = global.window;
|
||||||
|
var doc = global.document;
|
||||||
var webRtc = {};
|
var webRtc = {};
|
||||||
webRtc.isOpenWebRTC = function() {
|
webRtc.isOpenWebRTC = function() {
|
||||||
// TODO
|
var scripts = doc.getElementById("script");
|
||||||
|
if (!scripts || !scripts.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < scripts.length; i++) {
|
||||||
|
if (scripts[i].src.indexOf("owr.js") > -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
var getUserMedia = (
|
var getUserMedia = (
|
||||||
w.navigator.getUserMedia || w.navigator.webkitGetUserMedia ||
|
w.navigator.getUserMedia || w.navigator.webkitGetUserMedia ||
|
||||||
|
|||||||
Reference in New Issue
Block a user