openvidu-browser
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -6,1 +6,2 @@ export * from './OpenVidu'; | ||
export * from '../OpenViduInternal/Stream'; | ||
export * from '../OpenViduInternal/Connection'; |
@@ -11,2 +11,3 @@ "use strict"; | ||
__export(require("../OpenViduInternal/Stream")); | ||
__export(require("../OpenViduInternal/Connection")); | ||
//# sourceMappingURL=index.js.map |
@@ -10,2 +10,3 @@ import { OpenViduInternal } from '../OpenViduInternal/OpenViduInternal'; | ||
initSession(sessionId: string): Session; | ||
initPublisher(parentId: string): Publisher; | ||
initPublisher(parentId: string, cameraOptions: any): Publisher; | ||
@@ -12,0 +13,0 @@ initPublisher(parentId: string, cameraOptions: any, callback: any): Publisher; |
@@ -46,8 +46,16 @@ "use strict"; | ||
if (this.checkSystemRequirements()) { | ||
if (!("audio" in cameraOptions && "data" in cameraOptions && "mediaConstraints" in cameraOptions && | ||
"video" in cameraOptions && (Object.keys(cameraOptions).length === 4))) { | ||
cameraOptions = { | ||
if (cameraOptions != null) { | ||
var cameraOptionsAux = { | ||
audio: cameraOptions.audio != null ? cameraOptions.audio : true, | ||
video: cameraOptions.video != null ? cameraOptions.video : true, | ||
data: true, | ||
mediaConstraints: this.openVidu.generateMediaConstraints(cameraOptions.quality) | ||
}; | ||
cameraOptions = cameraOptionsAux; | ||
} | ||
else { | ||
cameraOptions = { | ||
audio: true, | ||
video: true, | ||
data: true, | ||
mediaConstraints: { | ||
@@ -54,0 +62,0 @@ audio: true, |
@@ -22,2 +22,3 @@ "use strict"; | ||
} | ||
this.ee.emitEvent('streamCreated', [{ stream: stream }]); | ||
} | ||
@@ -57,2 +58,13 @@ Publisher.prototype.publishAudio = function (value) { | ||
} | ||
if (eventName == 'streamCreated') { | ||
if (this.stream.isReady) { | ||
this.ee.emitEvent('streamCreated', [{ stream: this.stream }]); | ||
} | ||
else { | ||
this.stream.addEventListener('stream-created-by-publisher', function () { | ||
console.warn("Publisher emitting streamCreated"); | ||
_this.ee.emitEvent('streamCreated', [{ stream: _this.stream }]); | ||
}); | ||
} | ||
} | ||
}; | ||
@@ -59,0 +71,0 @@ return Publisher; |
import { SessionInternal } from '../OpenViduInternal/SessionInternal'; | ||
import { Stream } from '../OpenViduInternal/Stream'; | ||
import { Connection } from "../OpenViduInternal/Connection"; | ||
import { OpenVidu } from './OpenVidu'; | ||
@@ -10,4 +11,7 @@ import { Publisher } from './Publisher'; | ||
sessionId: String; | ||
connection: Connection; | ||
private ee; | ||
constructor(session: SessionInternal, openVidu: OpenVidu); | ||
connect(token: any, callback: any): void; | ||
connect(token: string, callback: any): any; | ||
connect(token: string, metadata: string, callback: any): any; | ||
disconnect(): void; | ||
@@ -14,0 +18,0 @@ publish(publisher: Publisher): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Subscriber_1 = require("./Subscriber"); | ||
var EventEmitter = require("wolfy87-eventemitter"); | ||
var Session = (function () { | ||
function Session(session, openVidu) { | ||
var _this = this; | ||
this.session = session; | ||
this.openVidu = openVidu; | ||
this.ee = new EventEmitter(); | ||
this.sessionId = session.getSessionId(); | ||
// Listens to the deactivation of the default behaviour upon the deletion of a Stream object | ||
this.session.addEventListener('stream-removed-default', function (event) { | ||
event.stream.removeVideo(); | ||
}); | ||
// Listens to the deactivation of the default behaviour upon the disconnection of a Session | ||
this.session.addEventListener('session-disconnected-default', function () { | ||
var s; | ||
for (var _i = 0, _a = _this.openVidu.openVidu.getRemoteStreams(); _i < _a.length; _i++) { | ||
s = _a[_i]; | ||
s.removeVideo(); | ||
} | ||
for (var streamId in _this.connection.getStreams()) { | ||
_this.connection.getStreams()[streamId].removeVideo(); | ||
} | ||
}); | ||
// Sets or updates the value of 'connection' property. Triggered by SessionInternal when succesful connection | ||
this.session.addEventListener('update-connection-object', function (event) { | ||
_this.connection = event.connection; | ||
}); | ||
} | ||
Session.prototype.connect = function (token, callback) { | ||
Session.prototype.connect = function (param1, param2, param3) { | ||
// Early configuration to deactivate automatic subscription to streams | ||
this.session.configure({ | ||
sessionId: this.session.getSessionId(), | ||
participantId: token, | ||
subscribeToStreams: false | ||
}); | ||
this.session.connect(token, callback); | ||
if (typeof param2 == "string") { | ||
this.session.configure({ | ||
sessionId: this.session.getSessionId(), | ||
participantId: param1, | ||
metadata: param2, | ||
subscribeToStreams: false | ||
}); | ||
this.session.connect(param1, param3); | ||
} | ||
else { | ||
this.session.configure({ | ||
sessionId: this.session.getSessionId(), | ||
participantId: param1, | ||
metadata: '', | ||
subscribeToStreams: false | ||
}); | ||
this.session.connect(param1, param2); | ||
} | ||
}; | ||
Session.prototype.disconnect = function () { | ||
var _this = this; | ||
this.openVidu.openVidu.close(false); | ||
this.session.emitEvent('sessionDisconnected', [{ | ||
preventDefault: function () { _this.session.removeEvent('session-disconnected-default'); } | ||
}]); | ||
this.session.emitEvent('session-disconnected-default', [{}]); | ||
}; | ||
@@ -115,3 +151,3 @@ Session.prototype.publish = function (publisher) { | ||
this.session.addEventListener("participant-joined", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -121,3 +157,3 @@ }; | ||
this.session.addEventListener("participant-left", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -127,3 +163,3 @@ }; | ||
this.session.addEventListener("participant-published", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -133,3 +169,3 @@ }; | ||
this.session.addEventListener("participant-evicted", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -136,0 +172,0 @@ }; |
export * from './OpenViduInternal'; | ||
export * from './ParticipantInternal'; | ||
export * from './Connection'; | ||
export * from './SessionInternal'; | ||
export * from './Stream'; |
@@ -7,5 +7,5 @@ "use strict"; | ||
__export(require("./OpenViduInternal")); | ||
__export(require("./ParticipantInternal")); | ||
__export(require("./Connection")); | ||
__export(require("./SessionInternal")); | ||
__export(require("./Stream")); | ||
//# sourceMappingURL=index.js.map |
@@ -47,2 +47,6 @@ import { SessionInternal } from './SessionInternal'; | ||
unpublishLocalVideoAudio(): void; | ||
generateMediaConstraints(quality: string): { | ||
audio: boolean; | ||
video: {}; | ||
}; | ||
} |
@@ -250,3 +250,3 @@ "use strict"; | ||
}; | ||
options.participant = this.session.getLocalParticipant(); | ||
options.connection = this.session.getLocalParticipant(); | ||
this.camera = new Stream_1.Stream(this, true, this.session, options); | ||
@@ -299,2 +299,30 @@ return this.camera; | ||
}; | ||
OpenViduInternal.prototype.generateMediaConstraints = function (quality) { | ||
var mediaConstraints = { | ||
audio: true, | ||
video: {} | ||
}; | ||
var w, h; | ||
switch (quality) { | ||
case 'LOW': | ||
w = 320; | ||
h = 240; | ||
break; | ||
case 'MEDIUM': | ||
w = 640; | ||
h = 480; | ||
break; | ||
case 'HIGH': | ||
w = 1280; | ||
h = 720; | ||
break; | ||
default: | ||
w = 640; | ||
h = 480; | ||
} | ||
mediaConstraints.video['width'] = { exact: w }; | ||
mediaConstraints.video['height'] = { exact: h }; | ||
//mediaConstraints.video['frameRate'] = { ideal: Number((<HTMLInputElement>document.getElementById('frameRate')).value) }; | ||
return mediaConstraints; | ||
}; | ||
return OpenViduInternal; | ||
@@ -301,0 +329,0 @@ }()); |
import { Stream } from './Stream'; | ||
import { OpenViduInternal } from './OpenViduInternal'; | ||
import { ParticipantInternal } from './ParticipantInternal'; | ||
import { Connection } from './Connection'; | ||
export interface SessionOptions { | ||
sessionId: string; | ||
participantId: string; | ||
metadata: string; | ||
subscribeToStreams?: boolean; | ||
@@ -20,3 +21,3 @@ updateSpeakerInterval?: number; | ||
private connected; | ||
private localParticipant; | ||
localParticipant: Connection; | ||
private subscribeToStreams; | ||
@@ -29,11 +30,2 @@ private updateSpeakerInterval; | ||
publish(): void; | ||
onStreamAddedOV(callback: any): void; | ||
onStreamRemovedOV(callback: any): void; | ||
onParticipantJoinedOV(callback: any): void; | ||
onParticipantLeftOV(callback: any): void; | ||
onParticipantPublishedOV(callback: any): void; | ||
onParticipantEvictedOV(callback: any): void; | ||
onRoomClosedOV(callback: any): void; | ||
onLostConnectionOV(callback: any): void; | ||
onMediaErrorOV(callback: any): void; | ||
configure(options: SessionOptions): void; | ||
@@ -43,6 +35,7 @@ getId(): string; | ||
private activateUpdateMainSpeaker(); | ||
getLocalParticipant(): ParticipantInternal; | ||
getLocalParticipant(): Connection; | ||
addEventListener(eventName: any, listener: any): void; | ||
addOnceEventListener(eventName: any, listener: any): void; | ||
removeListener(eventName: any, listener: any): void; | ||
removeEvent(eventName: any): void; | ||
emitEvent(eventName: any, eventsArray: any): void; | ||
@@ -49,0 +42,0 @@ subscribe(stream: Stream): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ParticipantInternal_1 = require("./ParticipantInternal"); | ||
var Connection_1 = require("./Connection"); | ||
var EventEmitter = require("wolfy87-eventemitter"); | ||
@@ -14,3 +14,3 @@ var SessionInternal = (function () { | ||
this.connected = false; | ||
this.localParticipant = new ParticipantInternal_1.ParticipantInternal(this.openVidu, true, this); | ||
this.localParticipant = new Connection_1.Connection(this.openVidu, true, this); | ||
} | ||
@@ -25,10 +25,6 @@ /* NEW METHODS */ | ||
else { | ||
_this.configure({ | ||
sessionId: _this.sessionId, | ||
participantId: token, | ||
subscribeToStreams: _this.subscribeToStreams | ||
}); | ||
var joinParams = { | ||
user: token, | ||
room: _this.sessionId, | ||
token: token, | ||
session: _this.sessionId, | ||
metadata: _this.options.metadata, | ||
dataChannels: false | ||
@@ -56,6 +52,7 @@ }; | ||
for (var i = 0; i < length_1; i++) { | ||
var participant = new ParticipantInternal_1.ParticipantInternal(_this.openVidu, false, _this, exParticipants[i]); | ||
_this.participants[participant.getId()] = participant; | ||
roomEvent.participants.push(participant); | ||
var streams = participant.getStreams(); | ||
var connection = new Connection_1.Connection(_this.openVidu, false, _this, exParticipants[i]); | ||
connection.creationTime = new Date().getTime(); | ||
_this.participants[connection.getId()] = connection; | ||
roomEvent.participants.push(connection); | ||
var streams = connection.getStreams(); | ||
for (var key in streams) { | ||
@@ -68,5 +65,17 @@ roomEvent.streams.push(streams[key]); | ||
} | ||
// Update local Connection object properties with values returned by server | ||
_this.localParticipant.data = response.metadata; | ||
_this.localParticipant.creationTime = new Date().getTime(); | ||
// Updates the value of property 'connection' in Session object | ||
_this.ee.emitEvent('update-connection-object', [{ connection: _this.localParticipant }]); | ||
// Own connection created event | ||
_this.ee.emitEvent('connectionCreated', [{ connection: _this.localParticipant }]); | ||
// One connection created event for each existing connection in the session | ||
for (var _i = 0, _a = roomEvent.participants; _i < _a.length; _i++) { | ||
var part = _a[_i]; | ||
_this.ee.emitEvent('connectionCreated', [{ connection: part }]); | ||
} | ||
//if (this.subscribeToStreams) { | ||
for (var _i = 0, _a = roomEvent.streams; _i < _a.length; _i++) { | ||
var stream = _a[_i]; | ||
for (var _b = 0, _c = roomEvent.streams; _b < _c.length; _b++) { | ||
var stream = _c[_b]; | ||
_this.ee.emitEvent('stream-added', [{ stream: stream }]); | ||
@@ -86,47 +95,2 @@ // Adding the remote stream to the OpenVidu object | ||
}; | ||
SessionInternal.prototype.onStreamAddedOV = function (callback) { | ||
this.addEventListener("stream-added", function (streamEvent) { | ||
callback(streamEvent.stream); | ||
}); | ||
}; | ||
SessionInternal.prototype.onStreamRemovedOV = function (callback) { | ||
this.addEventListener("stream-removed", function (streamEvent) { | ||
callback(streamEvent.stream); | ||
}); | ||
}; | ||
SessionInternal.prototype.onParticipantJoinedOV = function (callback) { | ||
this.addEventListener("participant-joined", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
}); | ||
}; | ||
SessionInternal.prototype.onParticipantLeftOV = function (callback) { | ||
this.addEventListener("participant-left", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
}); | ||
}; | ||
SessionInternal.prototype.onParticipantPublishedOV = function (callback) { | ||
this.addEventListener("participant-published", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
}); | ||
}; | ||
SessionInternal.prototype.onParticipantEvictedOV = function (callback) { | ||
this.addEventListener("participant-evicted", function (participantEvent) { | ||
callback(participantEvent.participant); | ||
}); | ||
}; | ||
SessionInternal.prototype.onRoomClosedOV = function (callback) { | ||
this.addEventListener("room-closed", function (roomEvent) { | ||
callback(roomEvent.room); | ||
}); | ||
}; | ||
SessionInternal.prototype.onLostConnectionOV = function (callback) { | ||
this.addEventListener("lost-connection", function (roomEvent) { | ||
callback(roomEvent.room); | ||
}); | ||
}; | ||
SessionInternal.prototype.onMediaErrorOV = function (callback) { | ||
this.addEventListener("error-media", function (errorEvent) { | ||
callback(errorEvent.error); | ||
}); | ||
}; | ||
/* NEW METHODS */ | ||
@@ -171,2 +135,5 @@ SessionInternal.prototype.configure = function (options) { | ||
}; | ||
SessionInternal.prototype.removeEvent = function (eventName) { | ||
this.ee.removeEvent(eventName); | ||
}; | ||
SessionInternal.prototype.emitEvent = function (eventName, eventsArray) { | ||
@@ -192,4 +159,5 @@ this.ee.emitEvent(eventName, eventsArray); | ||
SessionInternal.prototype.onParticipantPublished = function (options) { | ||
var participant = new ParticipantInternal_1.ParticipantInternal(this.openVidu, false, this, options); | ||
var pid = participant.getId(); | ||
options.metadata = this.participants[options.id].data; | ||
var connection = new Connection_1.Connection(this.openVidu, false, this, options); | ||
var pid = connection.getId(); | ||
if (!(pid in this.participants)) { | ||
@@ -201,6 +169,7 @@ console.info("Publisher not found in participants list by its id", pid); | ||
} | ||
//replacing old participant (this one has streams) | ||
this.participants[pid] = participant; | ||
this.ee.emitEvent('participant-published', [{ participant: participant }]); | ||
var streams = participant.getStreams(); | ||
//replacing old connection (this one has streams) | ||
connection.creationTime = this.participants[pid].creationTime; | ||
this.participants[pid] = connection; | ||
this.ee.emitEvent('participant-published', [{ connection: connection }]); | ||
var streams = connection.getStreams(); | ||
for (var key in streams) { | ||
@@ -217,7 +186,8 @@ var stream = streams[key]; | ||
SessionInternal.prototype.onParticipantJoined = function (msg) { | ||
var participant = new ParticipantInternal_1.ParticipantInternal(this.openVidu, false, this, msg); | ||
var pid = participant.getId(); | ||
var connection = new Connection_1.Connection(this.openVidu, false, this, msg); | ||
connection.creationTime = new Date().getTime(); | ||
var pid = connection.getId(); | ||
if (!(pid in this.participants)) { | ||
console.log("New participant to participants list with id", pid); | ||
this.participants[pid] = participant; | ||
this.participants[pid] = connection; | ||
} | ||
@@ -227,18 +197,21 @@ else { | ||
console.info("Participant already exists in participants list with " + | ||
"the same id, old:", this.participants[pid], ", joined now:", participant); | ||
participant = this.participants[pid]; | ||
"the same id, old:", this.participants[pid], ", joined now:", connection); | ||
connection = this.participants[pid]; | ||
} | ||
this.ee.emitEvent('participant-joined', [{ | ||
participant: participant | ||
connection: connection | ||
}]); | ||
this.ee.emitEvent('connectionCreated', [{ | ||
connection: connection | ||
}]); | ||
}; | ||
SessionInternal.prototype.onParticipantLeft = function (msg) { | ||
var _this = this; | ||
var participant = this.participants[msg.name]; | ||
if (participant !== undefined) { | ||
var connection = this.participants[msg.name]; | ||
if (connection !== undefined) { | ||
delete this.participants[msg.name]; | ||
this.ee.emitEvent('participant-left', [{ | ||
participant: participant | ||
connection: connection | ||
}]); | ||
var streams = participant.getStreams(); | ||
var streams = connection.getStreams(); | ||
for (var key in streams) { | ||
@@ -256,3 +229,6 @@ this.ee.emitEvent('stream-removed', [{ | ||
} | ||
participant.dispose(); | ||
connection.dispose(); | ||
this.ee.emitEvent('connectionDestroyed', [{ | ||
connection: connection | ||
}]); | ||
} | ||
@@ -294,4 +270,4 @@ else { | ||
}; | ||
var participant = this.participants[msg.endpointName]; | ||
if (!participant) { | ||
var connection = this.participants[msg.endpointName]; | ||
if (!connection) { | ||
console.error("Participant not found for endpoint " + | ||
@@ -301,3 +277,3 @@ msg.endpointName + ". Ice candidate will be ignored.", candidate); | ||
} | ||
var streams = participant.getStreams(); | ||
var streams = connection.getStreams(); | ||
var _loop_1 = function (key) { | ||
@@ -381,11 +357,11 @@ var stream = streams[key]; | ||
SessionInternal.prototype.disconnect = function (stream) { | ||
var participant = stream.getParticipant(); | ||
if (!participant) { | ||
var connection = stream.getParticipant(); | ||
if (!connection) { | ||
console.error("Stream to disconnect has no participant", stream); | ||
return; | ||
} | ||
delete this.participants[participant.getId()]; | ||
participant.dispose(); | ||
if (participant === this.localParticipant) { | ||
console.log("Unpublishing my media (I'm " + participant.getId() + ")"); | ||
delete this.participants[connection.getId()]; | ||
connection.dispose(); | ||
if (connection === this.localParticipant) { | ||
console.log("Unpublishing my media (I'm " + connection.getId() + ")"); | ||
delete this.localParticipant; | ||
@@ -406,11 +382,11 @@ this.openVidu.sendRequest('unpublishVideo', function (error, response) { | ||
SessionInternal.prototype.unpublish = function (stream) { | ||
var participant = stream.getParticipant(); | ||
if (!participant) { | ||
var connection = stream.getParticipant(); | ||
if (!connection) { | ||
console.error("Stream to disconnect has no participant", stream); | ||
return; | ||
} | ||
if (participant === this.localParticipant) { | ||
delete this.participants[participant.getId()]; | ||
participant.dispose(); | ||
console.log("Unpublishing my media (I'm " + participant.getId() + ")"); | ||
if (connection === this.localParticipant) { | ||
delete this.participants[connection.getId()]; | ||
connection.dispose(); | ||
console.log("Unpublishing my media (I'm " + connection.getId() + ")"); | ||
delete this.localParticipant; | ||
@@ -417,0 +393,0 @@ this.openVidu.sendRequest('unpublishVideo', function (error, response) { |
@@ -1,2 +0,2 @@ | ||
import { ParticipantInternal } from './ParticipantInternal'; | ||
import { Connection } from './Connection'; | ||
import { SessionInternal } from './SessionInternal'; | ||
@@ -6,3 +6,3 @@ import { OpenViduInternal, Callback } from './OpenViduInternal'; | ||
id: string; | ||
participant: ParticipantInternal; | ||
connection: Connection; | ||
recvVideo: any; | ||
@@ -23,2 +23,3 @@ recvAudio: any; | ||
private room; | ||
connection: Connection; | ||
private ee; | ||
@@ -31,3 +32,2 @@ private wrStream; | ||
private elements; | ||
private participant; | ||
private speechEvent; | ||
@@ -78,3 +78,3 @@ private recvVideo; | ||
getIdInParticipant(): string; | ||
getParticipant(): ParticipantInternal; | ||
getParticipant(): Connection; | ||
getId(): string; | ||
@@ -81,0 +81,0 @@ getRTCPeerConnection(): any; |
@@ -38,3 +38,3 @@ "use strict"; | ||
} | ||
this.participant = options.participant; | ||
this.connection = options.connection; | ||
this.recvVideo = options.recvVideo; | ||
@@ -191,2 +191,3 @@ this.recvAudio = options.recvAudio; | ||
}]); | ||
this.ee.emitEvent('stream-created-by-publisher'); | ||
this.isReady = true; | ||
@@ -221,7 +222,7 @@ return this.video; | ||
Stream.prototype.getParticipant = function () { | ||
return this.participant; | ||
return this.connection; | ||
}; | ||
Stream.prototype.getId = function () { | ||
if (this.participant) { | ||
return this.participant.getId() + "_" + this.id; | ||
if (this.connection) { | ||
return this.connection.getId() + "_" + this.id; | ||
} | ||
@@ -237,3 +238,3 @@ else { | ||
var _this = this; | ||
this.participant.addStream(this); | ||
this.connection.addStream(this); | ||
var constraints = this.mediaConstraints; | ||
@@ -323,3 +324,3 @@ var constraints2 = { | ||
mediaConstraints: userMediaConstraints, | ||
onicecandidate: this.participant.sendIceCandidate.bind(this.participant), | ||
onicecandidate: this.connection.sendIceCandidate.bind(this.connection), | ||
}; | ||
@@ -360,3 +361,3 @@ if (this.dataChannel) { | ||
var options = { | ||
onicecandidate: this.participant.sendIceCandidate.bind(this.participant), | ||
onicecandidate: this.connection.sendIceCandidate.bind(this.connection), | ||
connectionConstraints: offerConstraints | ||
@@ -363,0 +364,0 @@ }; |
{ | ||
"name": "openvidu-browser", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "OpenVidu Browser", | ||
@@ -9,2 +9,3 @@ "main": "lib/OpenVidu/index.js", | ||
"browserify": "cd ts/OpenVidu && browserify Main.ts -p [ tsify ] --exclude kurento-browser-extensions --debug -o ../../static/js/OpenVidu.js -v", | ||
"updatetsc": "cd ts/OpenViduInternal && tsc && cd ../OpenVidu && tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
@@ -21,3 +22,3 @@ "prepublish": "cd ts && tsc", | ||
"webrtc-adapter": "3.3.2", | ||
"kurento-utils": "6.6.1", | ||
"kurento-utils": "6.6.2", | ||
"uuid": "~2.0.1", | ||
@@ -24,0 +25,0 @@ "sdp-translator": "^0.1.15" |
@@ -6,1 +6,2 @@ export * from './OpenVidu'; | ||
export * from '../OpenViduInternal/Stream'; | ||
export * from '../OpenViduInternal/Connection'; |
@@ -51,13 +51,21 @@ /* | ||
initPublisher(parentId: string): Publisher; | ||
initPublisher(parentId: string, cameraOptions: any): Publisher; | ||
initPublisher(parentId: string, cameraOptions: any, callback: any): Publisher; | ||
initPublisher(parentId: string, cameraOptions: any, callback?): any { | ||
if (this.checkSystemRequirements()){ | ||
if (!("audio" in cameraOptions && "data" in cameraOptions && "mediaConstraints" in cameraOptions && | ||
"video" in cameraOptions && (Object.keys(cameraOptions).length === 4))) { | ||
cameraOptions = { | ||
initPublisher(parentId: string, cameraOptions?: any, callback?: Function): any { | ||
if (this.checkSystemRequirements()) { | ||
if (cameraOptions != null){ | ||
let cameraOptionsAux = { | ||
audio: cameraOptions.audio != null ? cameraOptions.audio : true, | ||
video: cameraOptions.video != null ? cameraOptions.video : true, | ||
data: true, | ||
mediaConstraints: this.openVidu.generateMediaConstraints(cameraOptions.quality) | ||
}; | ||
cameraOptions = cameraOptionsAux; | ||
} else { | ||
cameraOptions = { | ||
audio: true, | ||
video: true, | ||
data: true, | ||
mediaConstraints: { | ||
@@ -69,3 +77,5 @@ audio: true, | ||
} | ||
return new Publisher(this.openVidu.initPublisherTagged(parentId, cameraOptions, callback), parentId); | ||
} else { | ||
@@ -99,2 +109,3 @@ alert("Browser not supported"); | ||
} | ||
} |
@@ -65,3 +65,3 @@ /* | ||
} else { | ||
this.stream.addEventListener('video-element-created-by-stream', element => { | ||
this.stream.addEventListener('video-element-created-by-stream', (element) => { | ||
console.warn("Publisher emitting videoElementCreated"); | ||
@@ -75,3 +75,33 @@ this.id = element.id; | ||
} | ||
if (eventName == 'streamCreated') { | ||
if (this.stream.isReady) { | ||
this.ee.emitEvent('streamCreated', [{ stream: this.stream }]); | ||
} else { | ||
this.stream.addEventListener('stream-created-by-publisher', () => { | ||
console.warn("Publisher emitting streamCreated"); | ||
this.ee.emitEvent('streamCreated', [{ stream: this.stream }]); | ||
}); | ||
} | ||
} | ||
/*if (eventName == 'accessAllowed') { | ||
if (this.stream.isReady) { | ||
this.ee.emitEvent('accessAllowed'); | ||
} else { | ||
this.stream.addEventListener('access-allowed-by-publisher', () => { | ||
console.warn("Publisher emitting accessAllowed"); | ||
this.ee.emitEvent('accessAllowed'); | ||
}); | ||
} | ||
} | ||
if (eventName == 'accessDenied') { | ||
if (this.stream.isReady) { | ||
this.ee.emitEvent('accessDenied'); | ||
} else { | ||
this.stream.addEventListener('access-denied-by-publisher', () => { | ||
console.warn("Publisher emitting accessDenied"); | ||
this.ee.emitEvent('accessDenied'); | ||
}); | ||
} | ||
}*/ | ||
} | ||
} |
import { SessionInternal, SessionOptions } from '../OpenViduInternal/SessionInternal'; | ||
import { Stream } from '../OpenViduInternal/Stream'; | ||
import { Connection } from "../OpenViduInternal/Connection"; | ||
import { OpenVidu } from './OpenVidu'; | ||
import { Publisher} from './Publisher'; | ||
import { Publisher } from './Publisher'; | ||
import { Subscriber } from './Subscriber'; | ||
import EventEmitter = require('wolfy87-eventemitter'); | ||
export class Session { | ||
sessionId: String; | ||
//capabilities: Capabilities | ||
//connection: Connection | ||
sessionId: String; | ||
connection: Connection; | ||
private ee = new EventEmitter(); | ||
constructor(private session: SessionInternal, private openVidu: OpenVidu) { | ||
this.sessionId = session.getSessionId(); | ||
// Listens to the deactivation of the default behaviour upon the deletion of a Stream object | ||
this.session.addEventListener('stream-removed-default', event => { | ||
event.stream.removeVideo(); | ||
}); | ||
// Listens to the deactivation of the default behaviour upon the disconnection of a Session | ||
this.session.addEventListener('session-disconnected-default', () => { | ||
let s: Stream; | ||
for (s of this.openVidu.openVidu.getRemoteStreams()) { | ||
s.removeVideo(); | ||
} | ||
for (let streamId in this.connection.getStreams()) { | ||
this.connection.getStreams()[streamId].removeVideo(); | ||
} | ||
}); | ||
// Sets or updates the value of 'connection' property. Triggered by SessionInternal when succesful connection | ||
this.session.addEventListener('update-connection-object', event => { | ||
this.connection = event.connection; | ||
}); | ||
} | ||
connect(token, callback) { | ||
connect(token: string, callback: any); | ||
connect(token: string, metadata: string, callback: any); | ||
connect(param1, param2, param3?) { | ||
// Early configuration to deactivate automatic subscription to streams | ||
this.session.configure({ | ||
sessionId: this.session.getSessionId(), | ||
participantId: token, | ||
subscribeToStreams: false | ||
}); | ||
this.session.connect(token, callback); | ||
if (typeof param2 == "string") { | ||
this.session.configure({ | ||
sessionId: this.session.getSessionId(), | ||
participantId: param1, | ||
metadata: param2, | ||
subscribeToStreams: false | ||
}); | ||
this.session.connect(param1, param3); | ||
} else { | ||
this.session.configure({ | ||
sessionId: this.session.getSessionId(), | ||
participantId: param1, | ||
metadata: '', | ||
subscribeToStreams: false | ||
}); | ||
this.session.connect(param1, param2); | ||
} | ||
} | ||
@@ -33,2 +70,6 @@ | ||
this.openVidu.openVidu.close(false); | ||
this.session.emitEvent('sessionDisconnected', [{ | ||
preventDefault: () => { this.session.removeEvent('session-disconnected-default'); } | ||
}]); | ||
this.session.emitEvent('session-disconnected-default', [{}]); | ||
} | ||
@@ -106,3 +147,3 @@ | ||
subscribe(stream: Stream, htmlId: string): Subscriber; | ||
subscribe(param1, param2, param3?): Subscriber { | ||
@@ -140,3 +181,3 @@ // Subscription | ||
this.session.addEventListener("participant-joined", participantEvent => { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -147,3 +188,3 @@ } | ||
this.session.addEventListener("participant-left", participantEvent => { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -154,3 +195,3 @@ } | ||
this.session.addEventListener("participant-published", participantEvent => { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -161,3 +202,3 @@ } | ||
this.session.addEventListener("participant-evicted", participantEvent => { | ||
callback(participantEvent.participant); | ||
callback(participantEvent.connection); | ||
}); | ||
@@ -164,0 +205,0 @@ } |
export * from './OpenViduInternal'; | ||
export * from './ParticipantInternal'; | ||
export * from './Connection'; | ||
export * from './SessionInternal'; | ||
export * from './Stream'; |
@@ -301,3 +301,3 @@ /* | ||
options.participant = this.session.getLocalParticipant(); | ||
options.connection = this.session.getLocalParticipant(); | ||
this.camera = new Stream(this, true, this.session, options); | ||
@@ -358,2 +358,32 @@ return this.camera; | ||
generateMediaConstraints(quality: string) { | ||
let mediaConstraints = { | ||
audio: true, | ||
video: {} | ||
} | ||
let w, h; | ||
switch (quality) { | ||
case 'LOW': | ||
w = 320; | ||
h = 240; | ||
break; | ||
case 'MEDIUM': | ||
w = 640; | ||
h = 480; | ||
break; | ||
case 'HIGH': | ||
w = 1280; | ||
h = 720; | ||
break; | ||
default: | ||
w = 640; | ||
h = 480; | ||
} | ||
mediaConstraints.video['width'] = { exact: w }; | ||
mediaConstraints.video['height'] = { exact: h }; | ||
//mediaConstraints.video['frameRate'] = { ideal: Number((<HTMLInputElement>document.getElementById('frameRate')).value) }; | ||
return mediaConstraints; | ||
} | ||
} |
import { Stream } from './Stream'; | ||
import { OpenViduInternal } from './OpenViduInternal'; | ||
import { ParticipantInternal, ParticipantOptions } from './ParticipantInternal'; | ||
import { Connection, ConnectionOptions } from './Connection'; | ||
import EventEmitter = require('wolfy87-eventemitter'); | ||
@@ -9,2 +9,3 @@ | ||
participantId: string; | ||
metadata: string; | ||
subscribeToStreams?: boolean; | ||
@@ -21,5 +22,5 @@ updateSpeakerInterval?: number; | ||
private participants = {}; | ||
private participantsSpeaking: ParticipantInternal[] = []; | ||
private participantsSpeaking: Connection[] = []; | ||
private connected = false; | ||
private localParticipant: ParticipantInternal; | ||
public localParticipant: Connection; | ||
private subscribeToStreams: boolean; | ||
@@ -31,3 +32,3 @@ private updateSpeakerInterval: number; | ||
constructor(private openVidu: OpenViduInternal, private sessionId: string) { | ||
this.localParticipant = new ParticipantInternal(this.openVidu, true, this); | ||
this.localParticipant = new Connection(this.openVidu, true, this); | ||
} | ||
@@ -45,11 +46,7 @@ | ||
else { | ||
this.configure({ | ||
sessionId: this.sessionId, | ||
participantId: token, | ||
subscribeToStreams: this.subscribeToStreams | ||
}); | ||
let joinParams = { | ||
user: token, | ||
room: this.sessionId, | ||
token: token, | ||
session: this.sessionId, | ||
metadata: this.options.metadata, | ||
dataChannels: false | ||
@@ -76,3 +73,3 @@ } | ||
let roomEvent = { | ||
participants: new Array<ParticipantInternal>(), | ||
participants: new Array<Connection>(), | ||
streams: new Array<Stream>() | ||
@@ -84,10 +81,11 @@ } | ||
let participant = new ParticipantInternal(this.openVidu, false, this, | ||
let connection = new Connection(this.openVidu, false, this, | ||
exParticipants[i]); | ||
connection.creationTime = new Date().getTime(); | ||
this.participants[participant.getId()] = participant; | ||
this.participants[connection.getId()] = connection; | ||
roomEvent.participants.push(participant); | ||
roomEvent.participants.push(connection); | ||
let streams = participant.getStreams(); | ||
let streams = connection.getStreams(); | ||
for (let key in streams) { | ||
@@ -101,2 +99,16 @@ roomEvent.streams.push(streams[key]); | ||
// Update local Connection object properties with values returned by server | ||
this.localParticipant.data = response.metadata; | ||
this.localParticipant.creationTime = new Date().getTime(); | ||
// Updates the value of property 'connection' in Session object | ||
this.ee.emitEvent('update-connection-object', [{ connection: this.localParticipant }]); | ||
// Own connection created event | ||
this.ee.emitEvent('connectionCreated', [{ connection: this.localParticipant }]); | ||
// One connection created event for each existing connection in the session | ||
for (let part of roomEvent.participants) { | ||
this.ee.emitEvent('connectionCreated', [{ connection: part }]); | ||
} | ||
//if (this.subscribeToStreams) { | ||
@@ -121,56 +133,2 @@ for (let stream of roomEvent.streams) { | ||
} | ||
onStreamAddedOV(callback) { | ||
this.addEventListener("stream-added", streamEvent => { | ||
callback(streamEvent.stream); | ||
}); | ||
} | ||
onStreamRemovedOV(callback) { | ||
this.addEventListener("stream-removed", streamEvent => { | ||
callback(streamEvent.stream); | ||
}); | ||
} | ||
onParticipantJoinedOV(callback) { | ||
this.addEventListener("participant-joined", participantEvent => { | ||
callback(participantEvent.participant); | ||
}); | ||
} | ||
onParticipantLeftOV(callback) { | ||
this.addEventListener("participant-left", participantEvent => { | ||
callback(participantEvent.participant); | ||
}); | ||
} | ||
onParticipantPublishedOV(callback) { | ||
this.addEventListener("participant-published", participantEvent => { | ||
callback(participantEvent.participant); | ||
}); | ||
} | ||
onParticipantEvictedOV(callback) { | ||
this.addEventListener("participant-evicted", participantEvent => { | ||
callback(participantEvent.participant); | ||
}); | ||
} | ||
onRoomClosedOV(callback) { | ||
this.addEventListener("room-closed", roomEvent => { | ||
callback(roomEvent.room); | ||
}); | ||
} | ||
onLostConnectionOV(callback) { | ||
this.addEventListener("lost-connection", roomEvent => { | ||
callback(roomEvent.room); | ||
}); | ||
} | ||
onMediaErrorOV(callback) { | ||
this.addEventListener("error-media", errorEvent => { | ||
callback(errorEvent.error) | ||
}); | ||
} | ||
/* NEW METHODS */ | ||
@@ -230,2 +188,6 @@ | ||
removeEvent(eventName){ | ||
this.ee.removeEvent(eventName); | ||
} | ||
emitEvent(eventName, eventsArray) { | ||
@@ -256,5 +218,7 @@ this.ee.emitEvent(eventName, eventsArray); | ||
let participant = new ParticipantInternal(this.openVidu, false, this, options); | ||
options.metadata = this.participants[options.id].data; | ||
let pid = participant.getId(); | ||
let connection = new Connection(this.openVidu, false, this, options); | ||
let pid = connection.getId(); | ||
if (!(pid in this.participants)) { | ||
@@ -265,8 +229,9 @@ console.info("Publisher not found in participants list by its id", pid); | ||
} | ||
//replacing old participant (this one has streams) | ||
this.participants[pid] = participant; | ||
//replacing old connection (this one has streams) | ||
connection.creationTime = this.participants[pid].creationTime; | ||
this.participants[pid] = connection; | ||
this.ee.emitEvent('participant-published', [{ participant }]); | ||
this.ee.emitEvent('participant-published', [{ connection }]); | ||
let streams = participant.getStreams(); | ||
let streams = connection.getStreams(); | ||
for (let key in streams) { | ||
@@ -286,18 +251,24 @@ let stream = streams[key]; | ||
let participant = new ParticipantInternal(this.openVidu, false, this, msg); | ||
let connection = new Connection(this.openVidu, false, this, msg); | ||
connection.creationTime = new Date().getTime(); | ||
let pid = participant.getId(); | ||
let pid = connection.getId(); | ||
if (!(pid in this.participants)) { | ||
console.log("New participant to participants list with id", pid); | ||
this.participants[pid] = participant; | ||
this.participants[pid] = connection; | ||
} else { | ||
//use existing so that we don't lose streams info | ||
console.info("Participant already exists in participants list with " + | ||
"the same id, old:", this.participants[pid], ", joined now:", participant); | ||
participant = this.participants[pid]; | ||
"the same id, old:", this.participants[pid], ", joined now:", connection); | ||
connection = this.participants[pid]; | ||
} | ||
this.ee.emitEvent('participant-joined', [{ | ||
participant: participant | ||
connection: connection | ||
}]); | ||
this.ee.emitEvent('connectionCreated', [{ | ||
connection: connection | ||
}]); | ||
} | ||
@@ -307,12 +278,12 @@ | ||
let participant = this.participants[msg.name]; | ||
let connection = this.participants[msg.name]; | ||
if (participant !== undefined) { | ||
if (connection !== undefined) { | ||
delete this.participants[msg.name]; | ||
this.ee.emitEvent('participant-left', [{ | ||
participant: participant | ||
connection: connection | ||
}]); | ||
let streams = participant.getStreams(); | ||
let streams = connection.getStreams(); | ||
for (let key in streams) { | ||
@@ -332,4 +303,8 @@ this.ee.emitEvent('stream-removed', [{ | ||
participant.dispose(); | ||
connection.dispose(); | ||
this.ee.emitEvent('connectionDestroyed', [{ | ||
connection: connection | ||
}]); | ||
} else { | ||
@@ -374,4 +349,4 @@ console.warn("Participant " + msg.name | ||
let participant = this.participants[msg.endpointName]; | ||
if (!participant) { | ||
let connection = this.participants[msg.endpointName]; | ||
if (!connection) { | ||
console.error("Participant not found for endpoint " + | ||
@@ -383,3 +358,3 @@ msg.endpointName + ". Ice candidate will be ignored.", | ||
let streams = participant.getStreams(); | ||
let streams = connection.getStreams(); | ||
for (let key in streams) { | ||
@@ -469,4 +444,4 @@ let stream = streams[key]; | ||
let participant = stream.getParticipant(); | ||
if (!participant) { | ||
let connection = stream.getParticipant(); | ||
if (!connection) { | ||
console.error("Stream to disconnect has no participant", stream); | ||
@@ -476,8 +451,8 @@ return; | ||
delete this.participants[participant.getId()]; | ||
participant.dispose(); | ||
delete this.participants[connection.getId()]; | ||
connection.dispose(); | ||
if (participant === this.localParticipant) { | ||
if (connection === this.localParticipant) { | ||
console.log("Unpublishing my media (I'm " + participant.getId() + ")"); | ||
console.log("Unpublishing my media (I'm " + connection.getId() + ")"); | ||
delete this.localParticipant; | ||
@@ -499,4 +474,4 @@ this.openVidu.sendRequest('unpublishVideo', function (error, response) { | ||
let participant = stream.getParticipant(); | ||
if (!participant) { | ||
let connection = stream.getParticipant(); | ||
if (!connection) { | ||
console.error("Stream to disconnect has no participant", stream); | ||
@@ -506,8 +481,8 @@ return; | ||
if (participant === this.localParticipant) { | ||
if (connection === this.localParticipant) { | ||
delete this.participants[participant.getId()]; | ||
participant.dispose(); | ||
delete this.participants[connection.getId()]; | ||
connection.dispose(); | ||
console.log("Unpublishing my media (I'm " + participant.getId() + ")"); | ||
console.log("Unpublishing my media (I'm " + connection.getId() + ")"); | ||
delete this.localParticipant; | ||
@@ -514,0 +489,0 @@ this.openVidu.sendRequest('unpublishVideo', function (error, response) { |
@@ -8,3 +8,3 @@ /* | ||
*/ | ||
import { ParticipantInternal } from './ParticipantInternal'; | ||
import { Connection } from './Connection'; | ||
import { SessionInternal } from './SessionInternal'; | ||
@@ -37,3 +37,3 @@ import { OpenViduInternal, Callback } from './OpenViduInternal'; | ||
id: string; | ||
participant: ParticipantInternal; | ||
connection: Connection; | ||
recvVideo: any; | ||
@@ -54,2 +54,4 @@ recvAudio: any; | ||
public connection: Connection; | ||
private ee = new EventEmitter(); | ||
@@ -62,3 +64,2 @@ private wrStream: any; | ||
private elements: HTMLDivElement[] = []; | ||
private participant: ParticipantInternal; | ||
private speechEvent: any; | ||
@@ -88,3 +89,3 @@ private recvVideo: any; | ||
this.participant = options.participant; | ||
this.connection = options.connection; | ||
this.recvVideo = options.recvVideo; | ||
@@ -283,2 +284,4 @@ this.recvAudio = options.recvAudio; | ||
this.ee.emitEvent('stream-created-by-publisher'); | ||
this.isReady = true; | ||
@@ -322,8 +325,8 @@ | ||
getParticipant() { | ||
return this.participant; | ||
return this.connection; | ||
} | ||
getId() { | ||
if (this.participant) { | ||
return this.participant.getId() + "_" + this.id; | ||
if (this.connection) { | ||
return this.connection.getId() + "_" + this.id; | ||
} else { | ||
@@ -340,3 +343,3 @@ return this.id + "_webcam"; | ||
this.participant.addStream(this); | ||
this.connection.addStream(this); | ||
@@ -435,3 +438,3 @@ let constraints = this.mediaConstraints; | ||
mediaConstraints: userMediaConstraints, | ||
onicecandidate: this.participant.sendIceCandidate.bind(this.participant), | ||
onicecandidate: this.connection.sendIceCandidate.bind(this.connection), | ||
} | ||
@@ -473,3 +476,3 @@ | ||
let options = { | ||
onicecandidate: this.participant.sendIceCandidate.bind(this.participant), | ||
onicecandidate: this.connection.sendIceCandidate.bind(this.connection), | ||
connectionConstraints: offerConstraints | ||
@@ -476,0 +479,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3122988
40001
+ Addedkurento-utils@6.6.2(transitive)
- Removedkurento-utils@6.6.1(transitive)
Updatedkurento-utils@6.6.2