Bug 1087528 - Call IDs in about:webrtc. r=standard8, r=pkerr

This commit is contained in:
Romain Gauthier 2014-11-14 16:50:17 +01:00
Родитель 4fc60a106f
Коммит fc3dc7434e
11 изменённых файлов: 125 добавлений и 13 удалений

Просмотреть файл

@ -707,6 +707,24 @@ function injectLoopAPI(targetWindow) {
request.send();
}
},
/**
* Associates a session-id and a call-id with a window for debugging.
*
* @param {string} windowId The window id.
* @param {string} sessionId OT session id.
* @param {string} callId The callId on the server.
*/
addConversationContext: {
enumerable: true,
writable: true,
value: function(windowId, sessionId, callid) {
MozLoopService.addConversationContext(windowId, {
sessionId: sessionId,
callId: callid
});
}
}
};

Просмотреть файл

@ -120,6 +120,8 @@ let gConversationWindowData = new Map();
* and register with the Loop server.
*/
let MozLoopServiceInternal = {
conversationContexts: new Map(),
mocks: {
pushHandler: undefined,
webSocket: undefined,
@ -817,6 +819,22 @@ let MozLoopServiceInternal = {
if (winID != ourID) {
return;
}
// Chat Window Id, this is different that the internal winId
let windowId = window.location.hash.slice(1);
var context = this.conversationContexts.get(windowId);
var exists = pc.id.match(/session=(\S+)/);
if (context && !exists) {
// Not ideal but insert our data amidst existing data like this:
// - 000 (id=00 url=http)
// + 000 (session=000 call=000 id=00 url=http)
var pair = pc.id.split("("); //)
if (pair.length == 2) {
pc.id = pair[0] + "(session=" + context.sessionId +
(context.callId? " call=" + context.callId : "") + " " + pair[1]; //)
}
}
if (type == "iceconnectionstatechange") {
switch(pc.iceConnectionState) {
case "failed":
@ -1485,5 +1503,13 @@ this.MozLoopService = {
log.error("Window data was already fetched before. Possible race condition!");
return null;
},
getConversationContext: function(winId) {
return MozLoopServiceInternal.conversationContexts.get(winId);
},
addConversationContext: function(windowId, context) {
MozLoopServiceInternal.conversationContexts.set(windowId, context);
}
};

Просмотреть файл

@ -675,10 +675,10 @@ loop.conversation = (function(mozL10n) {
// XXX Old class creation for the incoming conversation view, whilst
// we transition across (bug 1072323).
var conversation = new sharedModels.ConversationModel(
{}, // Model attributes
{sdk: window.OT} // Model dependencies
);
var conversation = new sharedModels.ConversationModel({}, {
sdk: window.OT,
mozLoop: navigator.mozLoop
});
// Obtain the windowId and pass it through
var helper = new loop.shared.utils.Helper();

Просмотреть файл

@ -675,10 +675,10 @@ loop.conversation = (function(mozL10n) {
// XXX Old class creation for the incoming conversation view, whilst
// we transition across (bug 1072323).
var conversation = new sharedModels.ConversationModel(
{}, // Model attributes
{sdk: window.OT} // Model dependencies
);
var conversation = new sharedModels.ConversationModel({}, {
sdk: window.OT,
mozLoop: navigator.mozLoop
});
// Obtain the windowId and pass it through
var helper = new loop.shared.utils.Helper();

Просмотреть файл

@ -161,7 +161,8 @@ loop.store.ActiveRoomStore = (function() {
this._registerPostSetupActions();
this.setStoreState({
roomState: ROOM_STATES.GATHER
roomState: ROOM_STATES.GATHER,
windowId: actionData.windowId
});
// Get the window data from the mozLoop api.
@ -307,6 +308,9 @@ loop.store.ActiveRoomStore = (function() {
this._setRefreshTimeout(actionData.expires);
this._sdkDriver.connectSession(actionData);
this._mozLoop.addConversationContext(this._storeState.windowId,
actionData.sessionId, "");
// If we haven't got a room name yet, go and get one. We typically
// need to do this in the case of the standalone window.
// XXX When bug 1103331 lands this can be moved to earlier.

Просмотреть файл

@ -170,6 +170,9 @@ loop.store.ConversationStore = (function() {
sessionId: this.get("sessionId"),
sessionToken: this.get("sessionToken")
});
navigator.mozLoop.addConversationContext(this.get("windowId"),
this.get("sessionId"),
this.get("callId"));
this.set({callState: CALL_STATES.ONGOING});
break;
}

Просмотреть файл

@ -57,6 +57,7 @@ loop.shared.models = (function(l10n) {
* Constructor.
*
* Options:
* - {OT} mozLoop: browser mozLoop service object.
*
* Required:
* - {OT} sdk: OT SDK object.
@ -66,6 +67,7 @@ loop.shared.models = (function(l10n) {
*/
initialize: function(attributes, options) {
options = options || {};
this.mozLoop = options.mozLoop;
if (!options.sdk) {
throw new Error("missing required sdk");
}
@ -186,6 +188,13 @@ loop.shared.models = (function(l10n) {
this._sessionDisconnected);
this.session.connect(this.get("apiKey"), this.get("sessionToken"),
this._onConnectCompletion.bind(this));
// We store the call credentials for debugging purposes.
if (this.mozLoop) {
this.mozLoop.addConversationContext(this.get("windowId"),
this.get("sessionId"),
this.get("callId"));
}
},
/**

Просмотреть файл

@ -263,7 +263,11 @@ loop.StandaloneMozLoop = (function(mozL10n) {
*/
getLoopPref: function(prefName) {
return localStorage.getItem(prefName);
}
},
// Dummy function to reflect those in the desktop mozLoop that we
// don't currently use.
addConversationContext: function() {}
};
return StandaloneMozLoop;

Просмотреть файл

@ -21,6 +21,7 @@ describe("loop.store.ActiveRoomStore", function () {
fakeMozLoop = {
setLoopPref: sandbox.stub(),
addConversationContext: sandbox.stub(),
rooms: {
get: sinon.stub(),
join: sinon.stub(),
@ -398,6 +399,7 @@ describe("loop.store.ActiveRoomStore", function () {
apiKey: "9876543210",
sessionToken: "12563478",
sessionId: "15263748",
windowId: "42",
expires: 20
};
@ -431,6 +433,21 @@ describe("loop.store.ActiveRoomStore", function () {
actionData);
});
it("should call mozLoop.addConversationContext", function() {
var actionData = new sharedActions.JoinedRoom(fakeJoinedData);
store.setupWindowData(new sharedActions.SetupWindowData({
windowId: "42",
type: "room",
}));
store.joinedRoom(actionData);
sinon.assert.calledOnce(fakeMozLoop.addConversationContext);
sinon.assert.calledWithExactly(fakeMozLoop.addConversationContext,
"42", "15263748", "");
});
it("should call mozLoop.rooms.get to get the room data if the roomName" +
"is not known", function() {
store.setStoreState({roomName: undefined});

Просмотреть файл

@ -38,6 +38,7 @@ describe("loop.store.ConversationStore", function () {
navigator.mozLoop = {
getLoopPref: sandbox.stub(),
addConversationContext: sandbox.stub(),
calls: {
setCallInProgress: sandbox.stub(),
clearCallInProgress: sandbox.stub()
@ -75,6 +76,7 @@ describe("loop.store.ConversationStore", function () {
sessionId: "321456",
sessionToken: "341256",
websocketToken: "543216",
windowId: "28",
progressURL: "fakeURL"
};
@ -222,6 +224,17 @@ describe("loop.store.ConversationStore", function () {
sessionToken: "341256"
});
});
it("should call mozLoop.addConversationContext", function() {
store.set(fakeSessionData);
store.connectionProgress(
new sharedActions.ConnectionProgress({wsState: WS_STATES.CONNECTING}));
sinon.assert.calledOnce(navigator.mozLoop.addConversationContext);
sinon.assert.calledWithExactly(navigator.mozLoop.addConversationContext,
"28", "321456", "142536");
});
});
});

Просмотреть файл

@ -9,8 +9,8 @@ var expect = chai.expect;
describe("loop.shared.models", function() {
"use strict";
var sharedModels = loop.shared.models,
sandbox, fakeXHR, requests = [], fakeSDK, fakeSession, fakeSessionData;
var sharedModels = loop.shared.models, sandbox, fakeXHR,
requests = [], fakeSDK, fakeMozLoop, fakeSession, fakeSessionData;
beforeEach(function() {
sandbox = sinon.sandbox.create();
@ -42,6 +42,7 @@ describe("loop.shared.models", function() {
initPublisher: sandbox.spy(),
initSession: sandbox.stub().returns(fakeSession)
};
fakeMozLoop = {};
});
afterEach(function() {
@ -63,6 +64,7 @@ describe("loop.shared.models", function() {
beforeEach(function() {
conversation = new sharedModels.ConversationModel({}, {
sdk: fakeSDK
mozLoop: fakeMozLoop
});
conversation.set("loopToken", "fakeToken");
});
@ -159,7 +161,8 @@ describe("loop.shared.models", function() {
beforeEach(function() {
model = new sharedModels.ConversationModel(fakeSessionData, {
sdk: fakeSDK
sdk: fakeSDK,
mozLoop: fakeMozLoop
});
model.set({
publishedStream: true,
@ -177,6 +180,21 @@ describe("loop.shared.models", function() {
expect(model.get("subscribedStream")).eql(false);
});
it("should call addConversationContext", function() {
fakeMozLoop.addConversationContext = sandbox.stub();
model.set({
windowId: "28",
sessionId: "321456",
callId: "142536",
});
model.startSession();
sinon.assert.calledOnce(fakeMozLoop.addConversationContext);
sinon.assert.calledWithExactly(fakeMozLoop.addConversationContext,
"28", "321456", "142536");
});
it("should call connect", function() {
fakeSession.connect = sandbox.stub();