Skip to content

Commit 5598371

Browse files
authored
Merge pull request #319 from billba/master
video cleanup; versioning
2 parents 6dd5ddb + 09f69dd commit 5598371

File tree

2 files changed

+31
-61
lines changed

2 files changed

+31
-61
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "botframework-webchat",
3-
"version": "0.5.1",
3+
"version": "0.6.5",
44
"description": "Embeddable web chat control for the Microsoft Bot Framework",
55
"main": "built/BotChat.js",
66
"types": "botchat.d.ts",
@@ -21,7 +21,7 @@
2121
"author": "Microsoft Corp",
2222
"license": "MIT",
2323
"dependencies": {
24-
"botframework-directlinejs": "^0.6.3",
24+
"botframework-directlinejs": "^0.6.4",
2525
"core-js": "^2.4.1",
2626
"he": "^1.1.0",
2727
"marked": "^0.3.6",

src/Attachment.tsx

Lines changed: 29 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,24 @@ const YOUTUBE_WWW_SHORT_DOMAIN = "www.youtu.be";
1313
const VIMEO_DOMAIN = "vimeo.com";
1414
const VIMEO_WWW_DOMAIN = "www.vimeo.com";
1515

16-
interface VideoEmbedQuery {
17-
loop?: number;
18-
autoplay?: number;
19-
modestbranding?: number;
20-
title?: number;
21-
byline?: number;
22-
portait?: number;
23-
badge?: number;
24-
[propName: string]: number;
16+
interface QueryParams {
17+
[propName: string]: string;
2518
}
2619

27-
export const queryParams = (
28-
src: string
29-
) => {
30-
const queryObject = {};
31-
32-
src.substr(1)
33-
.split('&')
34-
.forEach(field => {
35-
const keyValue = field.split('=');
36-
queryObject[decodeURIComponent(keyValue[0])] = decodeURIComponent(keyValue[1]);
37-
});
38-
39-
return queryObject;
40-
}
41-
42-
const buildUrl = (
43-
src: string,
44-
query: VideoEmbedQuery,
45-
) => {
46-
return [
47-
src,
48-
'?',
49-
Object.keys(query)
50-
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(query[key].toString()))
51-
.join('&')
52-
].join('');
53-
}
20+
export const queryParams = (src: string) =>
21+
src
22+
.substr(1)
23+
.split('&')
24+
.reduce((previous, current) => {
25+
const keyValue = current.split('=');
26+
previous[decodeURIComponent(keyValue[0])] = decodeURIComponent(keyValue[1]);
27+
return previous;
28+
}, {} as QueryParams);
29+
30+
const queryString = (query: QueryParams) =>
31+
Object.keys(query)
32+
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(query[key].toString()))
33+
.join('&');
5434

5535
const buttons = (
5636
buttons: Button[],
@@ -67,16 +47,11 @@ const Youtube = (props: {
6747
}) =>
6848
<iframe
6949
type="text/html"
70-
src={
71-
buildUrl(
72-
`https://${YOUTUBE_DOMAIN}/embed/${props.embedId}`,
73-
{
74-
modestbranding: 1,
75-
loop: props.loop ? 1 : 0,
76-
autoplay: props.autoPlay ? 1 : 0
77-
}
78-
)
79-
}
50+
src={ `https://${YOUTUBE_DOMAIN}/embed/${props.embedId}?${queryString({
51+
modestbranding: '1',
52+
loop: props.loop ? '1' : '0',
53+
autoplay: props.autoPlay ? '1' : '0'
54+
})}` }
8055
/>;
8156

8257
const Vimeo = (props: {
@@ -86,19 +61,14 @@ const Vimeo = (props: {
8661
}) =>
8762
<iframe
8863
type="text/html"
89-
src={
90-
buildUrl(
91-
`https://player.${VIMEO_DOMAIN}/video/${props.embedId}`,
92-
{
93-
title: 0,
94-
byline: 0,
95-
portrait: 0,
96-
badge: 0,
97-
autoplay: props.autoPlay ? 1 : 0,
98-
loop: props.loop ? 1 : 0
99-
}
100-
)
101-
}
64+
src={ `https://player.${VIMEO_DOMAIN}/video/${props.embedId}?${queryString({
65+
title: '0',
66+
byline: '0',
67+
portrait: '0',
68+
badge: '0',
69+
autoplay: props.autoPlay ? '1' : '0',
70+
loop: props.loop ? '1' : '0'
71+
})}` }
10272
/>;
10373

10474
const Video = (props: {

0 commit comments

Comments
 (0)