@@ -16,8 +16,9 @@ let socket;
16
16
let channel ;
17
17
let pc ;
18
18
19
- async function run ( ) {
20
- console . log ( "Starting" ) ;
19
+ async function connect ( ) {
20
+ console . log ( "Connecting" ) ;
21
+ button . onclick = disconnect ;
21
22
22
23
localStream = await navigator . mediaDevices . getUserMedia ( {
23
24
audio : true ,
@@ -34,13 +35,13 @@ async function run() {
34
35
socket . connect ( ) ;
35
36
36
37
channel = socket . channel ( "room:" + roomId , { } ) ;
37
- channel . onClose ( _ => { window . location . href = "/reco " } ) ;
38
+ channel . onClose ( _ => { window . location . href = "/" } ) ;
38
39
39
40
channel . join ( )
40
41
. receive ( "ok" , resp => { console . log ( "Joined successfully" , resp ) } )
41
42
. receive ( "error" , resp => {
42
43
console . log ( "Unable to join" , resp ) ;
43
- window . location . href = "/reco " ;
44
+ window . location . href = "/" ;
44
45
} )
45
46
46
47
channel . on ( "signaling" , msg => {
@@ -56,7 +57,7 @@ async function run() {
56
57
channel . on ( "imgReco" , msg => {
57
58
const pred = msg [ 'predictions' ] [ 0 ] ;
58
59
imgpred . innerText = pred [ 'label' ] ;
59
- imgscore . innerText = pred [ 'score' ] ;
60
+ imgscore . innerText = pred [ 'score' ] . toFixed ( 3 ) ;
60
61
} )
61
62
62
63
channel . on ( "sessionTime" , msg => {
@@ -75,8 +76,8 @@ async function run() {
75
76
channel . push ( "signaling" , JSON . stringify ( offer ) ) ;
76
77
}
77
78
78
- button . onclick = ( ) => {
79
- console . log ( "Leaving " ) ;
79
+ function disconnect ( ) {
80
+ console . log ( "Disconnecting " ) ;
80
81
localStream . getTracks ( ) . forEach ( track => track . stop ( ) ) ;
81
82
videoPlayer . srcObject = null ;
82
83
@@ -93,4 +94,8 @@ button.onclick = () => {
93
94
}
94
95
}
95
96
96
- run ( ) ;
97
+ export const Room = {
98
+ mounted ( ) {
99
+ connect ( ) ;
100
+ }
101
+ }
0 commit comments