1
- import * as utils from "utils/utils" ;
2
- import * as app from 'application' ;
3
- import { ContentView } from 'ui/content-view'
4
- import { Observable } from "data/observable" ;
5
- import { TNSOTSession } from "./session" ;
1
+ import * as utils from "tns-core-modules/utils/utils" ;
2
+ import * as app from 'tns-core-modules/application' ;
3
+ import { View , CssProperty , Style } from 'tns-core-modules/ui/core/view'
4
+ import { Observable , fromObject } from "tns-core-modules/data/observable" ;
5
+ import { TNSOTSession } from "./session" ;
6
+ import { RENDERSTYLE } from "../common" ;
6
7
declare var com : any , android : any ;
7
8
const CameraListener = com . opentok . android . Publisher . CameraListener ;
8
9
const PublisherListener = com . opentok . android . PublisherKit . PublisherListener ;
@@ -11,50 +12,52 @@ const BaseVideoRenderer = com.opentok.android.BaseVideoRenderer;
11
12
const AbsoluteLayout = android . widget . AbsoluteLayout ;
12
13
const RelativeLayout = android . widget . RelativeLayout ;
13
14
14
- export class TNSOTPublisher extends ContentView {
15
- private _android : any ;
15
+ const renderStyle = new CssProperty < Style , string > ( {
16
+ name : 'renderStyle' ,
17
+ cssName : 'render-style' ,
18
+ defaultValue : 'fill' ,
19
+ valueConverter : ( v : RENDERSTYLE ) => { return String ( v ) }
20
+ } ) ;
21
+
22
+ export class TNSOTPublisher extends View {
16
23
private _publisher : any ;
17
24
public static toggleVideoEvent = "toggleVideo" ;
18
25
public static toggleAudioEvent = "toggleAudio" ;
19
26
public static cycleCameraEvent ;
20
- private _events ;
21
- _render_style : any ;
22
-
27
+ private _events : any ;
28
+ private _renderStyle : any ;
29
+ public renderStyle : any ;
23
30
constructor ( ) {
24
31
super ( ) ;
25
- this . _events = new Observable ( ) ;
32
+ this . _events = fromObject ( { } ) ;
26
33
}
27
34
28
35
get android ( ) {
29
- return this . _android ;
30
- }
31
-
32
- get _nativeView ( ) {
33
- return this . _android ;
36
+ return this . nativeView ;
34
37
}
35
38
36
- public _createUI ( ) {
37
- this . _android = new android . widget . LinearLayout ( this . _context ) ;
39
+ public createNativeView ( ) {
40
+ return new android . widget . LinearLayout ( this . _context ) ;
38
41
}
39
42
40
43
publish ( session : TNSOTSession , name ?: string , cameraResolution ?: string , cameraFrameRate ?: string ) {
41
44
const that = new WeakRef ( this ) ;
42
45
this . _publisher = new com . opentok . android . Publisher (
43
46
utils . ad . getApplicationContext ( ) ,
44
- name ? name : '' ,
45
- TNSOTPublisher . getCameraResolution ( cameraResolution ) ,
47
+ name ? name : '' ,
48
+ TNSOTPublisher . getCameraResolution ( cameraResolution ) ,
46
49
TNSOTPublisher . getCameraFrameRate ( cameraFrameRate )
47
50
) ;
48
51
let pub = this . _publisher . getView ( ) ;
49
- this . _android . addView ( pub ) ;
50
- this . _publisher . getRenderer ( ) . setStyle ( com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_SCALE , this . render_style ) ;
52
+ this . nativeView . addView ( pub ) ;
53
+ this . renderStyle = this . _renderStyle ;
51
54
this . _publisher . setPublisherListener ( new PublisherListener ( {
52
55
owner : that . get ( ) ,
53
56
onError ( publisher : any , error : any ) {
54
57
if ( this . owner . _events ) {
55
58
this . owner . _events . notify ( {
56
59
eventName : 'didFailWithError' ,
57
- object : new Observable ( {
60
+ object : fromObject ( {
58
61
publisher : publisher ,
59
62
error : error
60
63
} )
@@ -65,7 +68,7 @@ export class TNSOTPublisher extends ContentView {
65
68
if ( this . owner . _events ) {
66
69
this . owner . _events . notify ( {
67
70
eventName : 'streamCreated' ,
68
- object : new Observable ( {
71
+ object : fromObject ( {
69
72
publisher : publisher ,
70
73
stream : stream
71
74
} )
@@ -76,7 +79,7 @@ export class TNSOTPublisher extends ContentView {
76
79
if ( this . owner . _events ) {
77
80
this . owner . _events . notify ( {
78
81
eventName : 'streamDestroyed' ,
79
- object : new Observable ( {
82
+ object : fromObject ( {
80
83
publisher : publisher ,
81
84
stream : stream
82
85
} )
@@ -90,7 +93,7 @@ export class TNSOTPublisher extends ContentView {
90
93
if ( this . owner . _events ) {
91
94
this . owner . _events . notify ( {
92
95
eventName : 'cameraChanged' ,
93
- object : new Observable ( {
96
+ object : fromObject ( {
94
97
publisher : publisher ,
95
98
cameraId : newCameraId
96
99
} )
@@ -100,15 +103,15 @@ export class TNSOTPublisher extends ContentView {
100
103
if ( this . owner . _events ) {
101
104
this . owner . _events . notify ( {
102
105
eventName : 'cameraError' ,
103
- object : new Observable ( {
106
+ object : fromObject ( {
104
107
publisher : publisher ,
105
108
error : error
106
109
} )
107
110
} ) ;
108
111
}
109
112
}
110
113
} ) ) ;
111
- session . events . on ( 'sessionDidConnect' , ( result :any ) => {
114
+ session . events . on ( 'sessionDidConnect' , ( result : any ) => {
112
115
try {
113
116
let stream : any = result . object ;
114
117
session . session . publish ( this . _publisher ) ;
@@ -149,23 +152,17 @@ export class TNSOTPublisher extends ContentView {
149
152
return com . opentok . android . Publisher . CameraCaptureFrameRate . FPS_30 ;
150
153
}
151
154
152
- get render_style ( ) {
153
- return this . _render_style ;
154
- }
155
-
156
- set render_style ( value : any ) {
155
+ [ renderStyle . setNative ] ( value : any ) {
156
+ this . _renderStyle = value ;
157
157
switch ( value ) {
158
- case 'fit' :
159
- this . _render_style = com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_FIT ;
160
- break ;
161
158
case 'fill' :
162
- this . _render_style = com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_FILL ;
159
+ this . _publisher . getRenderer ( ) . setStyle ( com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_SCALE , com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_FILL ) ;
163
160
break ;
164
161
case 'scale' :
165
- this . _render_style = com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_SCALE ;
162
+ this . _publisher . getRenderer ( ) . setStyle ( com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_SCALE , com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_SCALE ) ;
166
163
break ;
167
164
default :
168
- this . _render_style = com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_FIT ;
165
+ this . _publisher . getRenderer ( ) . setStyle ( com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_SCALE , com . opentok . android . BaseVideoRenderer . STYLE_VIDEO_FIT ) ;
169
166
break ;
170
167
}
171
168
}
@@ -174,9 +171,10 @@ export class TNSOTPublisher extends ContentView {
174
171
return this . _publisher ;
175
172
}
176
173
177
- get events ( ) :Observable {
174
+ get events ( ) : Observable {
178
175
return this . _events ;
179
176
}
177
+
180
178
toggleCamera ( ) {
181
179
this . publishVideo = ! this . publishVideo ;
182
180
}
@@ -218,3 +216,4 @@ export class TNSOTPublisher extends ContentView {
218
216
}
219
217
220
218
}
219
+ renderStyle . register ( Style ) ;
0 commit comments