Skip to content

Commit

Permalink
This is the first version that has internationalization.
Browse files Browse the repository at this point in the history
  • Loading branch information
EricDavies committed Feb 8, 2014
1 parent ca68a91 commit 6039865
Show file tree
Hide file tree
Showing 4 changed files with 4,229 additions and 31 deletions.
1 change: 1 addition & 0 deletions api/buildEnglishVersions.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type easyrtc_int.js easyrtc_lang_en.js > easyrtc.js
94 changes: 63 additions & 31 deletions api/easyrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@

var easyrtc = {};

//
// for supporting internationalization
//
easyrtc.format = function() {
var formatted = arguments[0];
for (var i = 1; i < arguments.length; i++) {
var regexp = new RegExp('\\{' + (i - 1) + '\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};

/** @private
* @param {Object} destObject
* @param {Object} allowedEventsArray
Expand Down Expand Up @@ -257,7 +269,7 @@ easyrtc.joinRoom = function(roomName, roomParameters, successCB, failureCB) {
failureCB(errorCode, errorText, roomName);
}
else {
easyrtc.showError(errorCode, "Unable to enter room " + roomName + " because " + errorText);
easyrtc.showError(errorCode, easyrtc.format(easyrtc.constantStrings.unableToEnterRoom, roomName, errorText));
}
};

Expand Down Expand Up @@ -342,6 +354,7 @@ easyrtc.setScreenCapture = function() {
optional: []
};
};

/** Set the application name. Applications can only communicate with other applications
* that share the same API Key and application name. There is no predefined set of application
* names. Maximum length is
Expand All @@ -352,6 +365,8 @@ easyrtc.setScreenCapture = function() {
easyrtc.setApplicationName = function(name) {
easyrtc.applicationName = name;
};


/** Enable or disable logging to the console.
* Note: if you want to control the printing of debug messages, override the
* easyrtc.debugPrinter variable with a function that takes a message string as it's argument.
Expand Down Expand Up @@ -379,10 +394,15 @@ easyrtc.enableDebug = function(enable) {
easyrtc.debugPrinter = null;
}
};

//
// this is a temporary version used until we connect to the server.
//
easyrtc.updatePresence = function(state, statusText) {
easyrtc.presenceShow = state;
easyrtc.presenceStatus = statusText;
};

/**
* Determines if the local browser supports WebRTC GetUserMedia (access to camera and microphone).
* @returns {Boolean} True getUserMedia is supported.
Expand Down Expand Up @@ -1265,8 +1285,9 @@ easyrtc.initMediaSource = function(successCallback, errorCallback) {
(easyrtc.nativeVideoHeight !== easyrtc.videoFeatures.mandatory.minHeight ||
easyrtc.nativeVideoWidth !== easyrtc.videoFeatures.mandatory.minWidth)) {
easyrtc.showError(easyrtc.errCodes.MEDIA_WARNING,
"requested video size of " + easyrtc.videoFeatures.mandatory.minWidth + "x" + easyrtc.videoFeatures.mandatory.minHeight +
" but got size of " + easyrtc.nativeVideoWidth + "x" + easyrtc.nativeVideoHeight);
easyrtc.format(easyrtc.constantStrings.resolutionWarning,
easyrtc.videoFeatures.mandatory.minWidth, easyrtc.videoFeatures.mandatory.minHeight,
easyrtc.nativeVideoWidth, easyrtc.nativeVideoHeight));
}
easyrtc.setVideoObjectSrc(videoObj, "");
if (videoObj.removeNode) {
Expand Down Expand Up @@ -1326,24 +1347,24 @@ easyrtc.initMediaSource = function(successCallback, errorCallback) {
audio: easyrtc.audioEnabled,
video: easyrtc.videoEnabled
};

function getCurrentTime() {
return (new Date()).getTime();
}

var firstCallTime;
if (easyrtc.videoEnabled || easyrtc.audioEnabled) {
//
// getUserMedia sopm fails the first time I call it. I suspect it's a page loading
// issue. So I'm going to try adding a 3 second delay to allow things to settle down first.
// In addition, I'm going to try again after 3 seconds.
//

function tryAgain(error) {
var currentTime = getCurrentTime();
if( currentTime < firstCallTime + 1000) {
if (currentTime < firstCallTime + 1000) {
console.log("Trying getUserMedia a second time");
setTimeout(function(){
setTimeout(function() {
getUserMedia(mode, onUserMediaSuccess, onUserMediaError);
}, 3000);
}
Expand Down Expand Up @@ -1599,7 +1620,7 @@ easyrtc.setUsername = function(username) {
return true;
}
else {
easyrtc.showError(easyrtc.errCodes.BAD_NAME, "Illegal username " + username);
easyrtc.showError(easyrtc.errCodes.BAD_NAME, easyrtc.format(easyrtc.constantStrings.badUserName, username));
return false;
}
};
Expand Down Expand Up @@ -1786,8 +1807,8 @@ easyrtc.supportsStatistics = function() {
* @param {String} applicationName is a string that identifies the application so that different applications can have different
* lists of users. Note that the server configuration specifies a regular expression that is used to check application names
* for validity. The default pattern is that of an identifier, spaces are not allowed.
* @param {Function} successCallback (easyrtcid, roomOwner) - is called on successful connect. easyrtcid is the
* unique name that the client is known to the server by. A client usually only needs it's own easyrtcid for debugging purposes.
* @param {Function} successCallback (easyrtcId, roomOwner) - is called on successful connect. easyrtcId is the
* unique name that the client is known to the server by. A client usually only needs it's own easyrtcId for debugging purposes.
* roomOwner is true if the user is the owner of a room. It's value is random if the user is in multiple rooms.
* @param {Function} errorCallback (errorCode, errorText) - is called on unsuccessful connect. if null, an alert is called instead.
* The errorCode takes it's value from easyrtc.errCodes.
Expand Down Expand Up @@ -1989,7 +2010,7 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {
};
/** Sends data to another user using websockets. The easyrtc.sendServerMessage or easyrtc.sendPeerMessage methods
* are wrappers for this method; application code should use them instead.
* @param {String} destination - either a string containing the easyrtcid of the other user, or an object containing some subset of the following fields: targetEasyrtcid, targetGroup, targetRoom.
* @param {String} destination - either a string containing the easyrtcId of the other user, or an object containing some subset of the following fields: targetEasyrtcid, targetGroup, targetRoom.
* Specifying multiple fields restricts the scope of the destination (operates as a logical AND, not a logical OR).
* @param {String} msgType -the type of message being sent (application specific).
* @param {Object} msgData - an object which can be JSON'ed.
Expand Down Expand Up @@ -2050,7 +2071,7 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {
}
};
/** Sends data to another user. This method uses datachannels if one has been set up, or websockets otherwise.
* @param {String} destUser - a string containing the easyrtcid of the other user.
* @param {String} destUser - a string containing the easyrtcId of the other user.
* Specifying multiple fields restricts the scope of the destination (operates as a logical AND, not a logical OR).
* @param {String} msgType -the type of message being sent (application specific).
* @param {Object} msgData - an object which can be JSON'ed.
Expand All @@ -2071,7 +2092,7 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {
};
/**
* Sends a message to another peer on the easyrtcMsg channel.
* @param {String} destination - either a string containing the easyrtcid of the other user, or an object containing some subset of the following fields: targetEasyrtcid, targetGroup, targetRoom.
* @param {String} destination - either a string containing the easyrtcId of the other user, or an object containing some subset of the following fields: targetEasyrtcid, targetGroup, targetRoom.
* Specifying multiple fields restricts the scope of the destination (operates as a logical AND, not a logical OR).
* @param {String} msgType - the type of message being sent (application specific).
* @param {Object} msgData - a JSONable object with the message contents.
Expand Down Expand Up @@ -2759,7 +2780,7 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {
doAnswer(caller, msgData);
},
function(err) {
easyrtc.showError(easyrtc.errCodes.MEDIA_ERR, "Error getting local media stream: " + err);
easyrtc.showError(easyrtc.errCodes.MEDIA_ERR, easyrtc.format(easyrtc.constantStrings.localMediaError, err));
});
return;
}
Expand Down Expand Up @@ -3191,15 +3212,15 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {
function handleErrorEvent() {
if (easyrtc.myEasyrtcid) {
if (easyrtc.webSocket.socket.connected) {
easyrtc.showError(easyrtc.errCodes.SIGNAL_ERROR, "Miscellaneous error from signalling server. It may be ignorable.");
easyrtc.showError(easyrtc.errCodes.SIGNAL_ERROR, easyrtc.constantStrings.miscSignalError);
}
else {
/* socket server went down. this will generate a 'disconnect' event as well, so skip this event */
console.warn("The connection to the EasyRTC socket server went down. It may come back by itself.");
}
}
else {
errorCallback(easyrtc.errCodes.CONNECT_ERR, "Unable to reach the EasyRTC signalling server.");
errorCallback(easyrtc.errCodes.CONNECT_ERR,easyrtc.constantStrings.noServer);
}
}

Expand All @@ -3209,7 +3230,7 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {

easyrtc.webSocketConnected = true;
if (!easyrtc.webSocket || !easyrtc.webSocket.socket || !easyrtc.webSocket.socket.sessionid) {
easyrtc.showError(easyrtc.errCodes.CONNECT_ERR, "Socket.io connect event fired with bad websocket.");
easyrtc.showError(easyrtc.errCodes.CONNECT_ERR, easyrtc.constantStrings.badsocket);
}

if (easyrtc.debugPrinter) {
Expand All @@ -3219,7 +3240,7 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {
sendAuthenticate(successCallback, errorCallback);
}
else {
errorCallback(easyrtc.errCodes.SIGNAL_ERROR, "Internal communications failure.");
errorCallback(easyrtc.errCodes.SIGNAL_ERROR, easyrtc.constantStrings.icf);
}
}
);
Expand Down Expand Up @@ -3476,7 +3497,7 @@ easyrtc.connect = function(applicationName, successCallback, errorCallback) {
if (item.username) {
fixedItem = createIceServer(item.url, item.username, item.credential);
}
else {
else {
easyrtc.showError("badparam", "Iceserver entry doesn't have a username: " + JSON.stringify(item));
}
ipaddress = item.url.split(/[@:&]/g)[1];
Expand Down Expand Up @@ -3704,7 +3725,7 @@ easyrtc.easyAppBody = function(monitorVideoId, videoIds) {
return (obj.caller === "" || obj.caller === null || obj.caller === undefined);
}

if( !easyrtc._validateVideoIds(monitorVideoId, videoIds)) {
if (!easyrtc._validateVideoIds(monitorVideoId, videoIds)) {
throw "bad video element id";
}

Expand Down Expand Up @@ -3889,8 +3910,8 @@ easyrtc.easyAppBody = function(monitorVideoId, videoIds) {
monitorVideo.muted = "muted";
monitorVideo.defaultMuted = true;
}


};

/**
Expand All @@ -3903,26 +3924,26 @@ easyrtc.easyAppBody = function(monitorVideoId, videoIds) {
* @param {String} applicationName - name of the application.
* @param {String} monitorVideoId - the id of the video object used for monitoring the local stream.
* @param {Array} videoIds - an array of video object ids (strings)
* @param {Function} onReady - a callback function used on success. It is called with the easyrtcid this peer is knopwn to the server as.
* @param {Function} onReady - a callback function used on success. It is called with the easyrtcId this peer is knopwn to the server as.
* @param {Function} onFailure - a callbackfunction used on failure (failed to get local media or a connection of the signaling server).
* @example
* easyrtc.easyApp('multiChat', 'selfVideo', ['remote1', 'remote2', 'remote3'],
* function(easyrtcid){
* console.log("successfully connected, I am " + easyrtcid);
* function(easyrtcId){
* console.log("successfully connected, I am " + easyrtcId);
* },
* function(errorCode, errorText){
* console.log(errorText);
* );
*/
easyrtc.easyApp = function(applicationName, monitorVideoId, videoIds, onReady, onFailure) {
gotMediaCallback = null, gotConnectionCallback = null;
gotMediaCallback = null, gotConnectionCallback = null;

if( !easyrtc._validateVideoIds(monitorVideoId, videoIds)) {
if (!easyrtc._validateVideoIds(monitorVideoId, videoIds)) {
throw "bad video id";
}

easyrtc.easyAppBody(monitorVideoId, videoIds);

easyrtc.setGotMedia = function(gotMediaCB) {
gotMediaCallback = gotMediaCB;
};
Expand All @@ -3942,8 +3963,8 @@ easyrtc.easyApp = function(applicationName, monitorVideoId, videoIds, onReady, o
easyrtc.setGotConnection = function(gotConnectionCB) {
gotConnectionCallback = gotConnectionCB;
};




var nextInitializationStep;
Expand Down Expand Up @@ -4131,3 +4152,14 @@ if (navigator.mozGetUserMedia) {

/** @private */
easyrtc.isMozilla = (webrtcDetectedBrowser === "firefox");

easyrtc.constantStrings = {
"unableToEnterRoom":"Unable to enter room {0} because {1}" ,
"resolutionWarning": "Requested video size of {0}x{1} but got size of {2}x{3}",
"badUserName": "Illegal username {0}",
"localMediaError": "Error getting local media stream: {0}",
"miscSignalError": "Miscellaneous error from signalling server. It may be ignorable.",
"noServer": "Unable to reach the EasyRTC signalling server.",
"badsocket": "Socket.io connect event fired with bad websocket.",
"icf": "Internal communications failure"
}
Loading

0 comments on commit 6039865

Please sign in to comment.