@@ -141,6 +141,7 @@ export class PvwsPlugin implements Connection {
141141 private connected : boolean ;
142142 private disconnected : string [ ] = [ ] ;
143143 private subscriptions : { [ pvName : string ] : boolean } ;
144+ private initMsgRcvd : { [ pvName : string ] : boolean } ;
144145 private url = "" ;
145146 private socket ! : WebSocket ;
146147 private reconnect_ms = 5000 ;
@@ -155,6 +156,7 @@ export class PvwsPlugin implements Connection {
155156 this . onValueUpdate = nullValueCallback ;
156157 this . connected = false ;
157158 this . subscriptions = { } ;
159+ this . initMsgRcvd = { } ;
158160 }
159161
160162 /** Open the web socket, i.e. start PV communication */
@@ -184,10 +186,22 @@ export class PvwsPlugin implements Connection {
184186 private handleMessage ( message : string ) {
185187 const jm = JSON . parse ( message ) ;
186188 if ( jm . type === "update" ) {
187- if ( jm . readonly !== undefined ) {
189+ let updateConnection = false ;
190+ // PVWS only sends the readonly attribute if false
191+ // so set true by default and update later.
192+ let readonly = true ;
193+ if ( ! this . initMsgRcvd [ jm . pv ] ) {
194+ updateConnection = true ;
195+ this . initMsgRcvd [ jm . pv ] = true ;
196+ } else if ( jm . readonly !== undefined ) {
197+ updateConnection = true ;
198+ // Update readonly from PVWS message
199+ readonly = jm . readonly ;
200+ }
201+ if ( updateConnection ) {
188202 this . onConnectionUpdate ( jm . pv , {
189203 isConnected : true ,
190- isReadonly : jm . readonly
204+ isReadonly : readonly
191205 } ) ;
192206 }
193207
@@ -254,6 +268,7 @@ export class PvwsPlugin implements Connection {
254268 if ( this . subscriptions [ pvName ] === undefined ) {
255269 this . _subscribe ( pvName ) ;
256270 this . subscriptions [ pvName ] = true ;
271+ this . initMsgRcvd [ pvName ] = false ;
257272 }
258273 return pvName ;
259274 }
0 commit comments