@@ -7,25 +7,28 @@ import type { WebRTCService } from "./webrtc";
77import { atoms } from "../store/atoms" ;
88import { Bind } from "@block-kit/utils" ;
99import { SERVER_EVENT } from "../../types/signaling" ;
10+ import { WEBRTC_EVENT } from "../../types/webrtc" ;
1011
1112export class MessageService {
1213 public readonly listAtom : PrimitiveAtom < TransferEntry [ ] > ;
1314
1415 constructor ( public signal : SignalService , public rtc : WebRTCService ) {
1516 this . listAtom = atom < TransferEntry [ ] > ( [ ] ) ;
16- this . rtc . onConnectionStateChange = this . onRTCStateChange ;
1717 this . signal . socket . on ( "connect" , this . onSignalConnected ) ;
1818 this . signal . socket . on ( "disconnect" , this . onSignalDisconnected ) ;
1919 this . signal . on ( SERVER_EVENT . SEND_OFFER , this . onReceiveOffer ) ;
20+ this . signal . on ( SERVER_EVENT . SEND_ICE , this . onReceiveIce ) ;
2021 this . signal . on ( SERVER_EVENT . SEND_ANSWER , this . onReceiveAnswer ) ;
22+ this . rtc . bus . on ( WEBRTC_EVENT . STATE_CHANGE , this . onRTCStateChange ) ;
2123 }
2224
2325 public destroy ( ) {
24- this . rtc . onConnectionStateChange = void 0 ;
2526 this . signal . socket . off ( "connect" , this . onSignalConnected ) ;
2627 this . signal . socket . off ( "disconnect" , this . onSignalDisconnected ) ;
2728 this . signal . off ( SERVER_EVENT . SEND_OFFER , this . onReceiveOffer ) ;
29+ this . signal . off ( SERVER_EVENT . SEND_ICE , this . onReceiveIce ) ;
2830 this . signal . off ( SERVER_EVENT . SEND_ANSWER , this . onReceiveAnswer ) ;
31+ this . rtc . bus . off ( WEBRTC_EVENT . STATE_CHANGE , this . onRTCStateChange ) ;
2932 }
3033
3134 public addEntry ( entry : TransferEntry ) {
@@ -34,10 +37,6 @@ export class MessageService {
3437 atoms . set ( this . listAtom , newList ) ;
3538 }
3639
37- public clearEntries ( ) {
38- atoms . set ( this . listAtom , [ ] ) ;
39- }
40-
4140 public addSystemEntry ( data : string ) {
4241 this . addEntry ( { key : TRANSFER_TYPE . SYSTEM , data } ) ;
4342 }
@@ -50,6 +49,10 @@ export class MessageService {
5049 this . addEntry ( { key : TRANSFER_TYPE . FILE , ...data } ) ;
5150 }
5251
52+ public clearEntries ( ) {
53+ atoms . set ( this . listAtom , [ ] ) ;
54+ }
55+
5356 @Bind
5457 private onSignalConnected ( ) {
5558 this . addSystemEntry ( "Signal Connected" ) ;
@@ -78,11 +81,16 @@ export class MessageService {
7881
7982 @Bind
8083 private onReceiveOffer ( ) {
81- this . addSystemEntry ( `Received RTC Offer` ) ;
84+ this . addSystemEntry ( "Received RTC Offer" ) ;
85+ }
86+
87+ @Bind
88+ private onReceiveIce ( ) {
89+ this . addSystemEntry ( "Received RTC ICE" ) ;
8290 }
8391
8492 @Bind
8593 private onReceiveAnswer ( ) {
86- this . addSystemEntry ( ` Received RTC Answer` ) ;
94+ this . addSystemEntry ( " Received RTC Answer" ) ;
8795 }
8896}
0 commit comments