Skip to content

Commit 141b624

Browse files
Merge pull request #134 from Detaysoft/video-message
(feature) Video Message Added
2 parents 5f674cd + 08d0791 commit 141b624

File tree

9 files changed

+290
-38
lines changed

9 files changed

+290
-38
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ import { ChatItem } from 'react-chat-elements'
101101

102102
## MessageBox Component
103103

104-
| file | photo | text | location |
105-
| ---- | ---- | ---- | ---- |
106-
| ![file-message](https://user-images.githubusercontent.com/15075759/29243524-786baf8c-7fa9-11e7-92b2-3960cc34fcf4.png) | ![photo-message](https://user-images.githubusercontent.com/15075759/29243556-1368c4e8-7faa-11e7-9fdd-57b67542c381.png) | ![text-message](https://user-images.githubusercontent.com/15075759/29243573-a809456e-7faa-11e7-97b4-d258bc6a7728.png) | ![location-message](https://user-images.githubusercontent.com/15075759/30582943-2b3338aa-9d2e-11e7-93d5-8614563b9217.png)
104+
| file | photo | text | location | video |
105+
| ---- | ---- | ---- | ---- | ---- |
106+
| ![file-message](https://user-images.githubusercontent.com/15075759/29243524-786baf8c-7fa9-11e7-92b2-3960cc34fcf4.png) | ![photo-message](https://user-images.githubusercontent.com/15075759/29243556-1368c4e8-7faa-11e7-9fdd-57b67542c381.png) | ![text-message](https://user-images.githubusercontent.com/15075759/29243573-a809456e-7faa-11e7-97b4-d258bc6a7728.png) | ![location-message](https://user-images.githubusercontent.com/15075759/30582943-2b3338aa-9d2e-11e7-93d5-8614563b9217.png) | ![](https://user-images.githubusercontent.com/15075759/98530021-74ca1300-228f-11eb-88ab-5ae5ae33616d.png)
107107

108108

109109
```javascript
@@ -126,13 +126,13 @@ import { MessageBox } from 'react-chat-elements'
126126

127127
| prop | default | type | description |
128128
| ---- | ---- | ---- | ---- |
129-
| id | i (index) | string | message box id |
130-
| position | left | string | message box position |
131-
| type | text | string | message type (text, photo, file, location, spotify) |
132-
| text | none | string | message text |
133-
| title | none | string | message title |
134-
| titleColor | none | string(color) | message title color |
135-
| data | {} | object | message data |
129+
| id | i (index) | string | message box id |
130+
| position | left | string | message box position |
131+
| type | text | string | message type (text, photo, file, location, spotify, video) |
132+
| text | none | string | message text |
133+
| title | none | string | message title |
134+
| titleColor | none | string(color) | message title color |
135+
| data | {} | object | message data |
136136
| date | new Date() | Date | message date |
137137
| dateString | none | string | message represents dateString or timeagojs(now, date) |
138138
| onClick | none | function | message on click (message(object) is returned) |
@@ -256,7 +256,7 @@ import { SystemMessage } from 'react-chat-elements'
256256

257257
| prop | default | type | description |
258258
| ---- | ---- | ---- | ---- |
259-
| text| none | string | message text |
259+
| text| none | string | message text |
260260

261261

262262
## MessageList Component
@@ -594,7 +594,7 @@ import { LocationMessage } from 'react-chat-elements'
594594
| apiKey | none | string | google staticmap api key |
595595
| zoom | 14 | int | google staticmap zoom level |
596596
| markerColor | red | string | google staticmap marker color |
597-
| data | {} | object | message data |
597+
| data | {} | object | message data |
598598
| target | _blank | string | image a tag target prop |
599599
| onOpen | none | function | image on open |
600600

@@ -620,7 +620,7 @@ import { SpotifyMessage } from 'react-chat-elements'
620620
| uri | none | uri | spotify uri |
621621
| theme | black | string | spotify theme color (black or white) |
622622
| view | list | string | spotify view type (list or coverart) |
623-
| data | {} | object | message data |
623+
| data | {} | object | message data |
624624
| width | 300 | int | spotify embed width |
625625
| height | 380 | int | spotify embed height |
626626

example/App.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ export class App extends Component {
3838
list: 'chat',
3939
messageList: [],
4040
};
41+
42+
this.addMessage = this.addMessage.bind(this);
4143
}
4244

4345
UNSAFE_componentWillMount() {
44-
// setInterval(this.addMessage.bind(this), 3000);
46+
this.addMessage(6)
4547
}
4648

4749
getRandomColor() {
@@ -54,7 +56,7 @@ export class App extends Component {
5456
}
5557

5658
token() {
57-
return (parseInt(Math.random() * 10 % 6));
59+
return (parseInt(Math.random() * 10 % 7));
5860
}
5961

6062
photo(size) {
@@ -64,35 +66,39 @@ export class App extends Component {
6466
}).toString()
6567
}
6668

67-
random(type) {
69+
random(type, mtype) {
6870
switch (type) {
6971
case 'message':
70-
var type = this.token();
72+
mtype = mtype || this.token();
7173
var status = 'waiting';
72-
switch (type) {
74+
switch (mtype) {
7375
case 0:
74-
type = 'photo';
76+
mtype = 'photo';
7577
status = 'sent';
7678
break;
7779
case 1:
78-
type = 'file';
80+
mtype = 'file';
7981
status = 'sent';
8082
break;
8183
case 2:
82-
type = 'system';
84+
mtype = 'system';
8385
status = 'received';
8486
break;
8587
case 3:
86-
type = 'location';
88+
mtype = 'location';
8789
break;
8890
case 4:
89-
type = 'spotify';
91+
mtype = 'spotify';
9092
break;
9193
case 5:
92-
type = 'meeting';
94+
mtype = 'meeting';
95+
break;
96+
case 6:
97+
mtype = 'video';
98+
status = 'sent';
9399
break;
94100
default:
95-
type = 'text';
101+
mtype = 'text';
96102
status = 'read';
97103
break;
98104
}
@@ -139,17 +145,19 @@ export class App extends Component {
139145
},
140146
})),
141147
}) : null,
142-
type: type,
148+
type: mtype,
143149
theme: 'white',
144150
view: 'list',
145151
title: loremIpsum({ count: 2, units: 'words' }),
146152
titleColor: this.getRandomColor(),
147-
text: type === 'spotify' ? 'spotify:track:7wGoVu4Dady5GV0Sv4UIsx' : loremIpsum({ count: 1, units: 'sentences' }),
153+
text: mtype === 'spotify' ? 'spotify:track:0QjjaCaXE45mvhCnV3C0TA' : loremIpsum({ count: 1, units: 'sentences' }),
148154
data: {
155+
videoURL: this.token() >= 1 ? 'https://www.w3schools.com/html/mov_bbb.mp4' : 'http://www.exit109.com/~dnn/clips/RW20seconds_1.mp4',
149156
uri: `data:image/png;base64,${this.photo(150)}`,
150157
status: {
151158
click: true,
152-
loading: .5,
159+
loading: 0.5,
160+
download: mtype === 'video',
153161
},
154162
size: "100MB",
155163
width: 300,
@@ -238,9 +246,9 @@ export class App extends Component {
238246
}
239247
}
240248

241-
addMessage() {
249+
addMessage(mtype) {
242250
var list = this.state.messageList;
243-
list.push(this.random('message'));
251+
list.push(this.random('message', mtype));
244252
this.setState({
245253
messageList: list,
246254
});
@@ -355,7 +363,7 @@ export class App extends Component {
355363
rightButtons={
356364
<Button
357365
text='Gönder'
358-
onClick={this.addMessage.bind(this)} />
366+
onClick={() => this.addMessage()} />
359367
} />
360368
</div>
361369
</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-chat-elements",
3-
"version": "10.11.3",
3+
"version": "10.12.0",
44
"description": "Reactjs chat components",
55
"author": "Avare Kodcu <[email protected]>",
66
"main": "dist/main.js",

src/MeetingMessage/__tests__/__snapshots__/MeetingMessage.js.snap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ exports[`MeetingMessage component should render without issues 1`] = `
3333
</span>
3434
</div>
3535
</div>
36-
<div
37-
className="rce-mtmg-right-icon"
38-
>
39-
<MdMoreHoriz />
40-
</div>
4136
</div>
4237
<div
4338
className="rce-mtmg-body-bottom"

src/MessageBox/MessageBox.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import LocationMessage from '../LocationMessage/LocationMessage';
88
import SpotifyMessage from '../SpotifyMessage/SpotifyMessage';
99
import ReplyMessage from '../ReplyMessage/ReplyMessage';
1010
import MeetingMessage from '../MeetingMessage/MeetingMessage';
11+
import VideoMessage from '../VideoMessage/VideoMessage';
1112

1213
import Avatar from '../Avatar/Avatar';
1314

@@ -40,7 +41,7 @@ export class MessageBox extends Component {
4041

4142
render() {
4243
var positionCls = classNames('rce-mbox', { 'rce-mbox-right': this.props.position === 'right' });
43-
var thatAbsoluteTime = !/(text|file|meeting)/g.test(this.props.type) && !(this.props.type === 'location' && this.props.text);
44+
var thatAbsoluteTime = !/(text|video|file|meeting)/g.test(this.props.type) && !(this.props.type === 'location' && this.props.text);
4445

4546
const dateText = this.props.date && !isNaN(this.props.date) && (
4647
this.props.dateString ||
@@ -166,6 +167,19 @@ export class MessageBox extends Component {
166167
text={this.props.text} />
167168
}
168169

170+
{
171+
this.props.type === 'video' &&
172+
<VideoMessage
173+
onOpen={this.props.onOpen}
174+
onDownload={this.props.onDownload}
175+
onLoad={this.props.onLoad}
176+
onPhotoError={this.props.onPhotoError}
177+
data={this.props.data}
178+
width={this.props.width}
179+
height={this.props.height}
180+
text={this.props.text} />
181+
}
182+
169183
{
170184
this.props.type === 'file' &&
171185
<FileMessage

src/VideoMessage/VideoMessage.css

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
.rce-mbox-video {
2+
margin-top: -3px;
3+
margin-right: -6px;
4+
margin-left: -6px;
5+
}
6+
7+
.rce-mbox-video.padding-time {
8+
padding-bottom: 12px;
9+
}
10+
11+
.rce-mbox-video .rce-mbox-text {
12+
padding: 5px 0px;
13+
max-width: 300px;
14+
margin: auto;
15+
}
16+
17+
.rce-mbox-video--video {
18+
position: relative;
19+
display: flex;
20+
overflow: hidden;
21+
justify-content: center;
22+
border-radius: 5px;
23+
max-height: 500px;
24+
}
25+
26+
.rce-mbox-video--video__block {
27+
position: absolute;
28+
top: 0;
29+
right: 0;
30+
left: 0;
31+
bottom: 0;
32+
background-color: rgba(0,0,0,0.5);
33+
border-radius: 5px;
34+
display: flex;
35+
}
36+
37+
.rce-mbox-video--video img {
38+
height: 100%;
39+
min-height: 100px;
40+
user-select: none;
41+
}
42+
43+
.rce-mbox-video--video video {
44+
width: 100%;
45+
/*min-height: 100px;*/
46+
user-select: none;
47+
}
48+
49+
.rce-mbox-video--video__block-item {
50+
margin: auto;
51+
cursor: pointer;
52+
width: 100px;
53+
height: 100px;
54+
}
55+
56+
.rce-mbox-video--download {
57+
color: #efe;
58+
display: flex;
59+
justify-content: center;
60+
background: none;
61+
border: none;
62+
font-size: 3.2em;
63+
outline: none;
64+
border: 1px solid #eee;
65+
border-radius: 100%;
66+
height: 100px;
67+
width: 100px;
68+
}
69+
70+
.rce-mbox-video--download:hover {
71+
opacity: .7;
72+
}
73+
74+
.rce-mbox-video--download:active {
75+
opacity: .3;
76+
}
77+
78+
.rce-mbox-video--error {
79+
display: flex;
80+
justify-content: center;
81+
align-items: center;
82+
background: none;
83+
font-size: 70px;
84+
color: #eaeaea;
85+
}

0 commit comments

Comments
 (0)