Skip to content

Commit 1ddf779

Browse files
committed
Merge pull request #44 from brianjmiller/master
Couple of quick enhancements
2 parents 3f0ba07 + 457d3c0 commit 1ddf779

File tree

7 files changed

+418
-20
lines changed

7 files changed

+418
-20
lines changed

build/tincan-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/tincan.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,11 +1552,18 @@ TinCan client library
15521552
schemeMatches,
15531553
locationPort,
15541554
isXD,
1555-
env = TinCan.environment()
1555+
env = TinCan.environment(),
1556+
versions = TinCan.versions(),
1557+
versionMatch = false,
1558+
i
15561559
;
15571560

15581561
cfg = cfg || {};
15591562

1563+
if (cfg.hasOwnProperty("alertOnRequestFailure")) {
1564+
this.alertOnRequestFailure = cfg.alertOnRequestFailure;
1565+
}
1566+
15601567
if (! cfg.hasOwnProperty("endpoint")) {
15611568
if (env.isBrowser && this.alertOnRequestFailure) {
15621569
alert("[error] LRS invalid: no endpoint");
@@ -1568,6 +1575,10 @@ TinCan client library
15681575
}
15691576

15701577
this.endpoint = cfg.endpoint;
1578+
if (this.endpoint.slice(-1) !== "/") {
1579+
this.log("adding trailing slash to endpoint");
1580+
this.endpoint += "/";
1581+
}
15711582

15721583
if (cfg.hasOwnProperty("allowFail")) {
15731584
this.allowFail = cfg.allowFail;
@@ -1584,9 +1595,18 @@ TinCan client library
15841595
this.extended = cfg.extended;
15851596
}
15861597

1587-
urlParts = cfg.endpoint.toLowerCase().match(/([A-Za-z]+:)\/\/([^:\/]+):?(\d+)?(\/.*)?$/);
1588-
15891598
if (env.isBrowser) {
1599+
urlParts = this.endpoint.toLowerCase().match(/([A-Za-z]+:)\/\/([^:\/]+):?(\d+)?(\/.*)?$/);
1600+
if (urlParts === null) {
1601+
if (this.alertOnRequestFailure) {
1602+
alert("[error] LRS invalid: failed to divide URL parts");
1603+
}
1604+
throw {
1605+
code: 4,
1606+
mesg: "LRS invalid: failed to divide URL parts"
1607+
};
1608+
}
1609+
15901610
//
15911611
// determine whether this is a cross domain request,
15921612
// whether our browser has CORS support at all, and then
@@ -1650,7 +1670,7 @@ TinCan client library
16501670
alert("[error] LRS invalid: cross domain requests not supported in this browser");
16511671
}
16521672
throw {
1653-
code: 2,
1673+
code: 1,
16541674
mesg: "LRS invalid: cross domain requests not supported in this browser"
16551675
};
16561676
}
@@ -1663,14 +1683,29 @@ TinCan client library
16631683

16641684
if (typeof cfg.version !== "undefined") {
16651685
this.log("version: " + cfg.version);
1686+
for (i = 0; i < versions.length; i += 1) {
1687+
if (versions[i] === cfg.version) {
1688+
versionMatch = true;
1689+
break;
1690+
}
1691+
}
1692+
if (! versionMatch) {
1693+
if (env.isBrowser && this.alertOnRequestFailure) {
1694+
alert("[error] LRS invalid: version not supported (" + cfg.version + ")");
1695+
}
1696+
throw {
1697+
code: 5,
1698+
mesg: "LRS invalid: version not supported (" + cfg.version + ")"
1699+
};
1700+
}
16661701
this.version = cfg.version;
16671702
}
16681703
else {
16691704
//
16701705
// assume max supported when not specified,
16711706
// TODO: add detection of LRS from call to endpoint
16721707
//
1673-
this.version = TinCan.versions()[0];
1708+
this.version = versions[0];
16741709
}
16751710
},
16761711

@@ -4160,6 +4195,12 @@ TinCan client library
41604195
*/
41614196
this.type = null;
41624197

4198+
/**
4199+
@property moreInfo
4200+
@type String
4201+
*/
4202+
this.moreInfo = null;
4203+
41634204
/**
41644205
@property extensions
41654206
@type Object
@@ -4214,7 +4255,7 @@ TinCan client library
42144255
/**
42154256
@property LOG_SRC
42164257
*/
4217-
LOG_SRC: 'ActivityDefinition',
4258+
LOG_SRC: "ActivityDefinition",
42184259

42194260
/**
42204261
@method log
@@ -4234,6 +4275,7 @@ TinCan client library
42344275
directProps = [
42354276
"name",
42364277
"description",
4278+
"moreInfo",
42374279
"extensions",
42384280
"correctResponsesPattern"
42394281
],
@@ -4371,6 +4413,12 @@ TinCan client library
43714413
}
43724414
}
43734415

4416+
if (version.indexOf("0.9") !== 0) {
4417+
if (this.moreInfo !== null) {
4418+
result.moreInfo = this.moreInfo;
4419+
}
4420+
}
4421+
43744422
return result;
43754423
},
43764424

src/ActivityDefinition.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ TinCan client library
7373
*/
7474
this.type = null;
7575

76+
/**
77+
@property moreInfo
78+
@type String
79+
*/
80+
this.moreInfo = null;
81+
7682
/**
7783
@property extensions
7884
@type Object
@@ -127,7 +133,7 @@ TinCan client library
127133
/**
128134
@property LOG_SRC
129135
*/
130-
LOG_SRC: 'ActivityDefinition',
136+
LOG_SRC: "ActivityDefinition",
131137

132138
/**
133139
@method log
@@ -147,6 +153,7 @@ TinCan client library
147153
directProps = [
148154
"name",
149155
"description",
156+
"moreInfo",
150157
"extensions",
151158
"correctResponsesPattern"
152159
],
@@ -284,6 +291,12 @@ TinCan client library
284291
}
285292
}
286293

294+
if (version.indexOf("0.9") !== 0) {
295+
if (this.moreInfo !== null) {
296+
result.moreInfo = this.moreInfo;
297+
}
298+
}
299+
287300
return result;
288301
},
289302

src/LRS.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,18 @@ TinCan client library
102102
schemeMatches,
103103
locationPort,
104104
isXD,
105-
env = TinCan.environment()
105+
env = TinCan.environment(),
106+
versions = TinCan.versions(),
107+
versionMatch = false,
108+
i
106109
;
107110

108111
cfg = cfg || {};
109112

113+
if (cfg.hasOwnProperty("alertOnRequestFailure")) {
114+
this.alertOnRequestFailure = cfg.alertOnRequestFailure;
115+
}
116+
110117
if (! cfg.hasOwnProperty("endpoint")) {
111118
if (env.isBrowser && this.alertOnRequestFailure) {
112119
alert("[error] LRS invalid: no endpoint");
@@ -118,6 +125,10 @@ TinCan client library
118125
}
119126

120127
this.endpoint = cfg.endpoint;
128+
if (this.endpoint.slice(-1) !== "/") {
129+
this.log("adding trailing slash to endpoint");
130+
this.endpoint += "/";
131+
}
121132

122133
if (cfg.hasOwnProperty("allowFail")) {
123134
this.allowFail = cfg.allowFail;
@@ -134,9 +145,18 @@ TinCan client library
134145
this.extended = cfg.extended;
135146
}
136147

137-
urlParts = cfg.endpoint.toLowerCase().match(/([A-Za-z]+:)\/\/([^:\/]+):?(\d+)?(\/.*)?$/);
138-
139148
if (env.isBrowser) {
149+
urlParts = this.endpoint.toLowerCase().match(/([A-Za-z]+:)\/\/([^:\/]+):?(\d+)?(\/.*)?$/);
150+
if (urlParts === null) {
151+
if (this.alertOnRequestFailure) {
152+
alert("[error] LRS invalid: failed to divide URL parts");
153+
}
154+
throw {
155+
code: 4,
156+
mesg: "LRS invalid: failed to divide URL parts"
157+
};
158+
}
159+
140160
//
141161
// determine whether this is a cross domain request,
142162
// whether our browser has CORS support at all, and then
@@ -200,7 +220,7 @@ TinCan client library
200220
alert("[error] LRS invalid: cross domain requests not supported in this browser");
201221
}
202222
throw {
203-
code: 2,
223+
code: 1,
204224
mesg: "LRS invalid: cross domain requests not supported in this browser"
205225
};
206226
}
@@ -213,14 +233,29 @@ TinCan client library
213233

214234
if (typeof cfg.version !== "undefined") {
215235
this.log("version: " + cfg.version);
236+
for (i = 0; i < versions.length; i += 1) {
237+
if (versions[i] === cfg.version) {
238+
versionMatch = true;
239+
break;
240+
}
241+
}
242+
if (! versionMatch) {
243+
if (env.isBrowser && this.alertOnRequestFailure) {
244+
alert("[error] LRS invalid: version not supported (" + cfg.version + ")");
245+
}
246+
throw {
247+
code: 5,
248+
mesg: "LRS invalid: version not supported (" + cfg.version + ")"
249+
};
250+
}
216251
this.version = cfg.version;
217252
}
218253
else {
219254
//
220255
// assume max supported when not specified,
221256
// TODO: add detection of LRS from call to endpoint
222257
//
223-
this.version = TinCan.versions()[0];
258+
this.version = versions[0];
224259
}
225260
},
226261

0 commit comments

Comments
 (0)